簡體   English   中英

如何修復sctp_sendmsg的掛起到無法訪問的主機

[英]How to fix hang of sctp_sendmsg to unreachable host

我正在C應用程序中通過lksctp-tools(CentOS 7.3,lksctp-tools-1.0.17-2.el7.x86_64)使用Linux SCTP。 sctp_sendmsg()函數用於與無法訪問的目標主機建立新的SCTP關聯時,如何避免其掛起。

當從C代碼觸發sctp_sendmsg()與無法到達的dest主機建立新的SCTP關聯時,它掛起了幾分鍾,並在Wireshark中,我看到Linux發送SCTP INIT重試。 如何避免這種死機? 是否可以配置一些超時(例如1秒鍾)來中斷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: %s\n", 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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM