1

I'm trying to set a SCTP connection between a server and clients (Linux). The server has several ip addresses and the outgoing ip packets are routed depending on the source addresss. I want the sctp connections use certain address by default (in order to use certain route by default)

The only options I have found are:

   SCTP_SET_PEER_PRIMARY_ADDR
          Requests that the peer mark the enclosed address as the association primary. The enclosed address must be one of the association's locally bound addresses. The struc‐
          ture sctp_setpeerprim defined in /usr/include/netinet/sctp.h is used to make a set peer primary request.

   SCTP_PRIMARY_ADDR
          Requests that the local SCTP stack use the enclosed peer address as the association primary. The enclosed address must be one of the association peer's addresses. The
          structure sctp_prim defined in /usr/include/netinet/sctp.h is used to make a get/set primary request.

As far as I understand, this options allow to select the peer's primary address (when sending) and to ask the peer to use one of the local addresses (when receiving).

The quesion is: Is there a way to select the local address from which outgoing messages are sent?

4

3 回答 3

0

选择界面,对你有帮助吗?

您可以使用 setsockopt 来做到这一点:

struct ifreq ifr;
strncpy_IFNAMSIZ(ifr.ifr_name, "ethX");
setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr));
于 2012-02-08T16:02:10.997 回答
0

免责声明:我没有使用 lksctp 的多路径或 ASCONF 的东西,但我已经阅读了内核模块源代码。

为每个对等地址构建一个单独的 sctp_transport,因此这取决于您的本地地址是多路径到一个远程地址还是两个。

该关联保存接收到的数据包的目标地址,以便在通过特定 sctp_transport 发送时作为首选源重用。设置 SCTP_SET_PEER_PRIMARY_ADDR 将使对等点帮助您将正确的本地地址作为特定传输的主要地址,如果只有一个传输,也许您已经完成了。如果有多个传输,它可能会使对等点选择一个特定的传输。设置 SCTP_PRIMARY_ADDR 是翻转的情况,如果有多个传输,它肯定会更新哪个传输是主要的。

对于多个传输,除非上层要求,否则不应从“主要”传输切换。但是,哪个传输是“活动的”取决于错误等,对于重传,规范明确鼓励使用备用传输地址。总的来说,我会说尝试始终控制哪个传输处于活动状态(与主要传输相比)是非常没有希望的。简单的事情,比如在对等点启动之前发送 INIT 会来回切换它。

不要忽视这样一个事实,如果您绑定/绑定到特定地址(与 0.0.0.0 相比),它只会使用那些,在您有绝对不希望使用的地址的情况下。

祝你好运。

于 2012-05-25T19:35:07.223 回答
0

sctp_sendmessage 有选项。 http://linux.die.net/man/3/sctp_sendmsg [SCTP_SendMessage][1]

于 2012-10-02T14:01:57.487 回答