我在我的C应用程序中使用lksctp-tools(Centos 7.3,Lksctp-tools-1.0.17-2.el7.x86_64(使用Linux SCTP。如何避免使用sctp_sendmsg()
函数与无法到达目标主机建立新的SCTP关联时。
当sctp_sendmsg()
从C代码触发以建立与DEST主机建立新的SCTP关联,而DEST主机无法触及,然后将其悬挂几分钟,在Wireshark中,我看到Linux发送了SCTP INIT RETRIES。如何避免这种悬挂?是否可以配置某些超时(对于Ex:1 sec(会中断 sctp_sendmsg()
,否则可能会以某种方式快速检查目标是否活着(我不想遵循ICMP REQ-RESP方式(
配置的TTL和标志参数无助于解决此问题。
const uint32_t ttl = 1000; //ms
rc = sctp_sendmsg(sctp_socket->fd, data.s, data.len, (struct sockaddr*)&sin, sizeof(sin), htonl(ppid), 0, 0, ttl, 0);
if (rc < 0) {
printf("Could not connect: %sn", strerror(errno));
return 0;
}
我认为设置sctp_init参数将有所帮助
struct sctp_initmsg {
uint16_t sinit_num_ostreams;
uint16_t sinit_max_instreams;
uint16_t sinit_max_attempts;
uint16_t sinit_max_init_timeo;
};
sinit_max_attempts: This integer specifies how many attempts the
SCTP endpoint should make at resending the INIT. This value
overrides the system SCTP 'Max.Init.Retransmits' value. The
default value of 0 indicates the use of the endpoint's default
value. This is normally set to the system's default
'Max.Init.Retransmit' value.
sinit_max_init_timeo: This value represents the largest timeout or
retransmission timeout (RTO) value (in milliseconds) to use in
attempting an INIT. Normally, the 'RTO.Max' is used to limit the
doubling of the RTO upon timeout. For the INIT message, this
value may override 'RTO.Max'. This value must not influence
'RTO.Max' during data transmission and is only used to bound the
initial setup time. A default value of 0 indicates the use of the
endpoint's default value. This is normally set to the system's
'RTO.Max' value (60 seconds).
在建立连接之前(或调用sctp_sendmsg(设置套接字选项:
sctp_initmsg init;
init.sinit_max_attempts = m_nMaxAttempts;
init.sinit_max_init_timeo = m_nMaxInitTimeout;
if (setsockopt(nSockID, SOL_SCTP, SCTP_INITMSG, &init, sizeof(init)) != 0)
{
std::cout << strerror(errno);
return -1;
}
return 0;