annotate libfdcore/sctp.c @ 1544:7bad8025e69d

merge
author Thomas Klausner <tk@giga.or.at>
date Mon, 25 May 2020 10:34:47 +0200
parents 9222d31123b1 3365e95bed57
children 566bb46cc73f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 710
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
1268
25fad6714991 Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1266
diff changeset
5 * Copyright (c) 2015, WIDE Project and NICT *
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 590
diff changeset
36 #include "fdcore-internal.h"
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
37 #include "cnxctx.h"
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
38
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
39 #include <netinet/sctp.h>
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
40 #include <sys/uio.h>
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
41
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
42 /* Size of buffer to receive ancilliary data. May need to be enlarged if more sockopt are set... */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
43 #ifndef CMSG_BUF_LEN
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
44 #define CMSG_BUF_LEN 1024
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
45 #endif /* CMSG_BUF_LEN */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
46
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
47 /* Use old draft-ietf-tsvwg-sctpsocket-17 API ? If not defined, RFC6458 API will be used */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
48 /* #define OLD_SCTP_SOCKET_API */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
49
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
50 /* Automatically fallback to old API if some of the new symbols are not defined */
1474
732e0f76dbfb Fix build on Debian Stable.
Thomas Klausner <tk@giga.or.at>
parents: 1332
diff changeset
51 #if (!defined(SCTP_CONNECTX_4_ARGS) || (!defined(SCTP_RECVRCVINFO)) || (!defined(SCTP_SNDINFO)) || (!defined(SCTP_SEND_FAILED_EVENT)))
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
52 # define OLD_SCTP_SOCKET_API
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
53 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
54
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
55
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
56 /* Temper with the retransmission timers to try and improve disconnection detection response? Undef this to keep the defaults of SCTP stack */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
57 #ifndef USE_DEFAULT_SCTP_RTX_PARAMS /* make this a configuration option if useful */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
58 #define ADJUST_RTX_PARAMS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
59 #endif /* USE_DEFAULT_SCTP_RTX_PARAMS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
60
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
61
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
62 DECLARE_FD_DUMP_PROTOTYPE(fd_sa_dump_array, sSA * saddrs, int saddrs_count)
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
63 {
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
64 union {
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
65 sSA *sa;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
66 uint8_t *buf;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
67 } ptr;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
68 int i;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
69 int salen;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
70
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
71 FD_DUMP_HANDLE_OFFSET();
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
72
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
73 ptr.sa = saddrs;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
74 for (i = 0; i < saddrs_count; i++) {
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
75 salen = sSAlen(ptr.sa);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
76 if (salen == 0) {
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
77 LOG_E("fd_sa_dump_array: Unknown sockaddr family");
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
78 break;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
79 }
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
80 if (i > 0) {
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
81 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " "), return NULL);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
82 }
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
83 CHECK_MALLOC_DO( fd_sa_dump( FD_DUMP_STD_PARAMS, ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV), return NULL);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
84 ptr.buf += salen;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
85 }
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
86 return *buf;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
87 }
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
88
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
89 /* Pre-binding socket options -- # streams read in config */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
90 static int fd_setsockopt_prebind(int sk)
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
91 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
92 socklen_t sz;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
93
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
94 TRACE_ENTRY( "%d", sk);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
95
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
96 CHECK_PARAMS( sk > 0 );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
97
252
433ef00ac049 Use SO_REUSEADDR in debug builds
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 248
diff changeset
98 {
433ef00ac049 Use SO_REUSEADDR in debug builds
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 248
diff changeset
99 int reuse = 1;
433ef00ac049 Use SO_REUSEADDR in debug builds
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 248
diff changeset
100 CHECK_SYS( setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) );
433ef00ac049 Use SO_REUSEADDR in debug builds
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 248
diff changeset
101 }
433ef00ac049 Use SO_REUSEADDR in debug builds
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 248
diff changeset
102
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
103 #ifdef ADJUST_RTX_PARAMS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
104 /* Set the retransmit parameters */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
105 #ifdef SCTP_RTOINFO
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
106 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
107 struct sctp_rtoinfo rtoinfo;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
108 memset(&rtoinfo, 0, sizeof(rtoinfo));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
109
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
110 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
111 sz = sizeof(rtoinfo);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
112 /* Read socket defaults */
1543
9222d31123b1 Use more portable sctp_opt_info() instead of getsockopt() for SCTP.
Thomas Klausner <tk@giga.or.at>
parents: 1495
diff changeset
113 CHECK_SYS( sctp_opt_info(sk, 0, SCTP_RTOINFO, &rtoinfo, &sz) );
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
114 if (sz != sizeof(rtoinfo))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
115 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
116 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(rtoinfo));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
117 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
118 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
119 fd_log_debug( "Def SCTP_RTOINFO : srto_initial : %u", rtoinfo.srto_initial);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
120 fd_log_debug( " srto_min : %u", rtoinfo.srto_min);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
121 fd_log_debug( " srto_max : %u", rtoinfo.srto_max);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
122 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
123
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
124 /* rtoinfo.srto_initial: Estimate of the RTT before it can be measured; keep the default value */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
125 rtoinfo.srto_max = 5000; /* Maximum retransmit timer (in ms), we want fast retransmission time. */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
126 rtoinfo.srto_min = 1000; /* Value under which the RTO does not descend, we set this value to not conflict with srto_max */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
127
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
128 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
129 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_RTOINFO, &rtoinfo, sizeof(rtoinfo)) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
130
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
131 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
132 /* Check new values */
1543
9222d31123b1 Use more portable sctp_opt_info() instead of getsockopt() for SCTP.
Thomas Klausner <tk@giga.or.at>
parents: 1495
diff changeset
133 CHECK_SYS( sctp_opt_info(sk, 0, SCTP_RTOINFO, &rtoinfo, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
134 fd_log_debug( "New SCTP_RTOINFO : srto_initial : %u", rtoinfo.srto_initial);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
135 fd_log_debug( " srto_max : %u", rtoinfo.srto_max);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
136 fd_log_debug( " srto_min : %u", rtoinfo.srto_min);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
137 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
138 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
139 #else /* SCTP_RTOINFO */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
140 TRACE_DEBUG(ANNOYING, "Skipping SCTP_RTOINFO");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
141 #endif /* SCTP_RTOINFO */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
142
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
143 /* Set the association parameters: max number of retransmits, ... */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
144 #ifdef SCTP_ASSOCINFO
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
145 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
146 struct sctp_assocparams assoc;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
147 memset(&assoc, 0, sizeof(assoc));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
148
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
149 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
150 sz = sizeof(assoc);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
151 /* Read socket defaults */
1543
9222d31123b1 Use more portable sctp_opt_info() instead of getsockopt() for SCTP.
Thomas Klausner <tk@giga.or.at>
parents: 1495
diff changeset
152 CHECK_SYS( sctp_opt_info(sk, 0, SCTP_ASSOCINFO, &assoc, &sz) );
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
153 if (sz != sizeof(assoc))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
154 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
155 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(assoc));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
156 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
157 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
158 fd_log_debug( "Def SCTP_ASSOCINFO : sasoc_asocmaxrxt : %hu", assoc.sasoc_asocmaxrxt);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
159 fd_log_debug( " sasoc_number_peer_destinations : %hu", assoc.sasoc_number_peer_destinations);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
160 fd_log_debug( " sasoc_peer_rwnd : %u" , assoc.sasoc_peer_rwnd);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
161 fd_log_debug( " sasoc_local_rwnd : %u" , assoc.sasoc_local_rwnd);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
162 fd_log_debug( " sasoc_cookie_life : %u" , assoc.sasoc_cookie_life);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
163 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
164
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
165 assoc.sasoc_asocmaxrxt = 4; /* Maximum number of retransmission attempts: we want fast detection of errors */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
166 /* Note that this must remain less than the sum of retransmission parameters of the different paths. */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
167
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
168 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
169 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_ASSOCINFO, &assoc, sizeof(assoc)) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
170
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
171 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
172 /* Check new values */
1543
9222d31123b1 Use more portable sctp_opt_info() instead of getsockopt() for SCTP.
Thomas Klausner <tk@giga.or.at>
parents: 1495
diff changeset
173 CHECK_SYS( sctp_opt_info(sk, 0, SCTP_ASSOCINFO, &assoc, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
174 fd_log_debug( "New SCTP_ASSOCINFO : sasoc_asocmaxrxt : %hu", assoc.sasoc_asocmaxrxt);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
175 fd_log_debug( " sasoc_number_peer_destinations : %hu", assoc.sasoc_number_peer_destinations);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
176 fd_log_debug( " sasoc_peer_rwnd : %u" , assoc.sasoc_peer_rwnd);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
177 fd_log_debug( " sasoc_local_rwnd : %u" , assoc.sasoc_local_rwnd);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
178 fd_log_debug( " sasoc_cookie_life : %u" , assoc.sasoc_cookie_life);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
179 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
180 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
181 #else /* SCTP_ASSOCINFO */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
182 TRACE_DEBUG(ANNOYING, "Skipping SCTP_ASSOCINFO");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
183 #endif /* SCTP_ASSOCINFO */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
184 #endif /* ADJUST_RTX_PARAMS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
185
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
186 /* Set the INIT parameters, such as number of streams */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
187 #ifdef SCTP_INITMSG
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
188 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
189 struct sctp_initmsg init;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
190 memset(&init, 0, sizeof(init));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
191
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
192 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
193 sz = sizeof(init);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
194
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
195 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
196 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_INITMSG, &init, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
197 if (sz != sizeof(init))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
198 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
199 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(init));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
200 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
201 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
202 fd_log_debug( "Def SCTP_INITMSG : sinit_num_ostreams : %hu", init.sinit_num_ostreams);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
203 fd_log_debug( " sinit_max_instreams : %hu", init.sinit_max_instreams);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
204 fd_log_debug( " sinit_max_attempts : %hu", init.sinit_max_attempts);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
205 fd_log_debug( " sinit_max_init_timeo : %hu", init.sinit_max_init_timeo);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
206 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
207
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
208 /* Set the init options -- need to receive SCTP_COMM_UP to confirm the requested parameters, but we don't care (best effort) */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
209 init.sinit_num_ostreams = fd_g_config->cnf_sctp_str; /* desired number of outgoing streams */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
210 init.sinit_max_init_timeo = CNX_TIMEOUT * 1000;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
211
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
212 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
213 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_INITMSG, &init, sizeof(init)) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
214
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
215 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
216 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
217 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_INITMSG, &init, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
218 fd_log_debug( "New SCTP_INITMSG : sinit_num_ostreams : %hu", init.sinit_num_ostreams);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
219 fd_log_debug( " sinit_max_instreams : %hu", init.sinit_max_instreams);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
220 fd_log_debug( " sinit_max_attempts : %hu", init.sinit_max_attempts);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
221 fd_log_debug( " sinit_max_init_timeo : %hu", init.sinit_max_init_timeo);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
222 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
223 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
224 #else /* SCTP_INITMSG */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
225 TRACE_DEBUG(ANNOYING, "Skipping SCTP_INITMSG");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
226 #endif /* SCTP_INITMSG */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
227
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
228 /* The SO_LINGER option will be reset if we want to perform SCTP ABORT */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
229 #ifdef SO_LINGER
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
230 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
231 struct linger linger;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
232 memset(&linger, 0, sizeof(linger));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
233
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
234 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
235 sz = sizeof(linger);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
236 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
237 CHECK_SYS( getsockopt(sk, SOL_SOCKET, SO_LINGER, &linger, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
238 if (sz != sizeof(linger))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
239 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
240 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(linger));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
241 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
242 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
243 fd_log_debug( "Def SO_LINGER : l_onoff : %d", linger.l_onoff);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
244 fd_log_debug( " l_linger : %d", linger.l_linger);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
245 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
246
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
247 linger.l_onoff = 0; /* Do not activate the linger */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
248 linger.l_linger = 0; /* Ignored, but it would mean : Return immediately when closing (=> abort) (graceful shutdown in background) */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
249
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
250 /* Set the option */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
251 CHECK_SYS( setsockopt(sk, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger)) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
252
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
253 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
254 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
255 CHECK_SYS( getsockopt(sk, SOL_SOCKET, SO_LINGER, &linger, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
256 fd_log_debug( "New SO_LINGER : l_onoff : %d", linger.l_onoff);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
257 fd_log_debug( " l_linger : %d", linger.l_linger);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
258 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
259 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
260 #else /* SO_LINGER */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
261 TRACE_DEBUG(ANNOYING, "Skipping SO_LINGER");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
262 #endif /* SO_LINGER */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
263
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
264 /* Set the NODELAY option (Nagle-like algorithm) */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
265 #ifdef SCTP_NODELAY
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
266 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
267 int nodelay;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
268
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
269 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
270 sz = sizeof(nodelay);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
271 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
272 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_NODELAY, &nodelay, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
273 if (sz != sizeof(nodelay))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
274 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
275 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(nodelay));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
276 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
277 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
278 fd_log_debug( "Def SCTP_NODELAY value : %s", nodelay ? "true" : "false");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
279 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
280
1197
823829bf1037 Couple of typos in the comments
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
281 nodelay = 1; /* We turn ON to disable the Nagle algorithm, so that packets are sent ASAP. */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
282
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
283 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
284 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_NODELAY, &nodelay, sizeof(nodelay)) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
285
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
286 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
287 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
288 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_NODELAY, &nodelay, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
289 fd_log_debug( "New SCTP_NODELAY value : %s", nodelay ? "true" : "false");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
290 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
291 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
292 #else /* SCTP_NODELAY */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
293 TRACE_DEBUG(ANNOYING, "Skipping SCTP_NODELAY");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
294 #endif /* SCTP_NODELAY */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
295
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
296 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
297 SO_RCVBUF size of receiver window
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
298 SO_SNDBUF size of pending data to send
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
299 SCTP_AUTOCLOSE for one-to-many only
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
300 SCTP_PRIMARY_ADDR use this address as primary locally
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
301 SCTP_ADAPTATION_LAYER set adaptation layer indication, we don't use this
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
302 */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
303
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
304 /* Set the SCTP_DISABLE_FRAGMENTS option, required for TLS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
305 #ifdef SCTP_DISABLE_FRAGMENTS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
306 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
307 int nofrag;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
308
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
309 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
310 sz = sizeof(nofrag);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
311 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
312 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_DISABLE_FRAGMENTS, &nofrag, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
313 if (sz != sizeof(nofrag))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
314 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
315 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(nofrag));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
316 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
317 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
318 fd_log_debug( "Def SCTP_DISABLE_FRAGMENTS value : %s", nofrag ? "true" : "false");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
319 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
320
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
321 nofrag = 0; /* We turn ON the fragmentation, since Diameter messages & TLS messages can be quite large. */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
322
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
323 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
324 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_DISABLE_FRAGMENTS, &nofrag, sizeof(nofrag)) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
325
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
326 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
327 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
328 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_DISABLE_FRAGMENTS, &nofrag, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
329 fd_log_debug( "New SCTP_DISABLE_FRAGMENTS value : %s", nofrag ? "true" : "false");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
330 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
331 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
332 #else /* SCTP_DISABLE_FRAGMENTS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
333 # error "TLS requires support of SCTP_DISABLE_FRAGMENTS"
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
334 #endif /* SCTP_DISABLE_FRAGMENTS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
335
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
336 /* SCTP_PEER_ADDR_PARAMS control heartbeat per peer address. We set it as a default for all addresses in the association; not sure if it works ... */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
337 #ifdef SCTP_PEER_ADDR_PARAMS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
338 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
339 struct sctp_paddrparams parms;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
340 memset(&parms, 0, sizeof(parms));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
341
172
9c5dfc6399a4 Fix bug with Debian Lenny kernel
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 171
diff changeset
342 /* Some kernel versions need this to be set */
9c5dfc6399a4 Fix bug with Debian Lenny kernel
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 171
diff changeset
343 parms.spp_address.ss_family = AF_INET;
9c5dfc6399a4 Fix bug with Debian Lenny kernel
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 171
diff changeset
344
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
345 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
346 sz = sizeof(parms);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
347
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
348 /* Read socket defaults */
1543
9222d31123b1 Use more portable sctp_opt_info() instead of getsockopt() for SCTP.
Thomas Klausner <tk@giga.or.at>
parents: 1495
diff changeset
349 CHECK_SYS( sctp_opt_info(sk, 0, SCTP_PEER_ADDR_PARAMS, &parms, &sz) );
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
350 if (sz != sizeof(parms))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
351 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
352 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(parms));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
353 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
354 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
355 fd_log_debug( "Def SCTP_PEER_ADDR_PARAMS : spp_hbinterval : %u", parms.spp_hbinterval);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
356 fd_log_debug( " spp_pathmaxrxt : %hu", parms.spp_pathmaxrxt);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
357 fd_log_debug( " spp_pathmtu : %u", parms.spp_pathmtu);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
358 fd_log_debug( " spp_flags : %x", parms.spp_flags);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
359 // fd_log_debug( " spp_ipv6_flowlabel: %u", parms.spp_ipv6_flowlabel);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
360 // fd_log_debug( " spp_ipv4_tos : %hhu",parms.spp_ipv4_tos);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
361 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
362
172
9c5dfc6399a4 Fix bug with Debian Lenny kernel
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 171
diff changeset
363 parms.spp_flags = SPP_HB_ENABLE; /* Enable heartbeat for the association */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
364 #ifdef SPP_PMTUD_ENABLE
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
365 parms.spp_flags |= SPP_PMTUD_ENABLE; /* also enable path MTU discovery mechanism */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
366 #endif /* SPP_PMTUD_ENABLE */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
367
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
368 #ifdef ADJUST_RTX_PARAMS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
369 parms.spp_hbinterval = 6000; /* Send an heartbeat every 6 seconds to quickly start retransmissions */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
370 /* parms.spp_pathmaxrxt : max nbr of restransmissions on this address. There is a relationship with sasoc_asocmaxrxt, so we leave the default here */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
371 #endif /* ADJUST_RTX_PARAMS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
372
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
373 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
374 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &parms, sizeof(parms)) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
375
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
376 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
377 /* Check new values */
1543
9222d31123b1 Use more portable sctp_opt_info() instead of getsockopt() for SCTP.
Thomas Klausner <tk@giga.or.at>
parents: 1495
diff changeset
378 CHECK_SYS( sctp_opt_info(sk, 0, SCTP_PEER_ADDR_PARAMS, &parms, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
379 fd_log_debug( "New SCTP_PEER_ADDR_PARAMS : spp_hbinterval : %u", parms.spp_hbinterval);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
380 fd_log_debug( " spp_pathmaxrxt : %hu", parms.spp_pathmaxrxt);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
381 fd_log_debug( " spp_pathmtu : %u", parms.spp_pathmtu);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
382 fd_log_debug( " spp_flags : %x", parms.spp_flags);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
383 // fd_log_debug( " spp_ipv6_flowlabel: %u", parms.spp_ipv6_flowlabel);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
384 // fd_log_debug( " spp_ipv4_tos : %hhu",parms.spp_ipv4_tos);
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
385 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
386 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
387 #else /* SCTP_PEER_ADDR_PARAMS */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
388 TRACE_DEBUG(ANNOYING, "Skipping SCTP_PEER_ADDR_PARAMS");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
389 #endif /* SCTP_PEER_ADDR_PARAMS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
390
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
391 /*
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
392 SCTP_DEFAULT_SEND_PARAM - DEPRECATED // parameters for the sendto() call, we don't use it.
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
393 */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
394
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
395 /* Subscribe to some notifications */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
396 #ifdef OLD_SCTP_SOCKET_API
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
397 #ifdef SCTP_EVENTS /* DEPRECATED */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
398 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
399 struct sctp_event_subscribe event;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
400
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
401 memset(&event, 0, sizeof(event));
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
402 event.sctp_data_io_event = 1; /* to receive the stream ID in SCTP_SNDRCV ancilliary data on message reception */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
403 event.sctp_association_event = 0; /* new or closed associations (mostly for one-to-many style sockets) */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
404 event.sctp_address_event = 1; /* address changes */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
405 event.sctp_send_failure_event = 1; /* delivery failures */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
406 event.sctp_peer_error_event = 1; /* remote peer sends an error */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
407 event.sctp_shutdown_event = 1; /* peer has sent a SHUTDOWN */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
408 event.sctp_partial_delivery_event = 1; /* a partial delivery is aborted, probably indicating the connection is being shutdown */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
409 // event.sctp_adaptation_layer_event = 0; /* adaptation layer notifications */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
410 // event.sctp_authentication_event = 0; /* when new key is made active */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
411
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
412 /* Set the option to the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
413 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(event)) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
414
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
415 if (TRACE_BOOL(ANNOYING)) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
416 sz = sizeof(event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
417 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_EVENTS, &event, &sz) );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
418 if (sz != sizeof(event))
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
419 {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
420 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(event));
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
421 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
422 }
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
423
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
424 fd_log_debug( "SCTP_EVENTS : sctp_data_io_event : %hhu", event.sctp_data_io_event);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
425 fd_log_debug( " sctp_association_event : %hhu", event.sctp_association_event);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
426 fd_log_debug( " sctp_address_event : %hhu", event.sctp_address_event);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
427 fd_log_debug( " sctp_send_failure_event : %hhu", event.sctp_send_failure_event);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
428 fd_log_debug( " sctp_peer_error_event : %hhu", event.sctp_peer_error_event);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
429 fd_log_debug( " sctp_shutdown_event : %hhu", event.sctp_shutdown_event);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
430 fd_log_debug( " sctp_partial_delivery_event : %hhu", event.sctp_partial_delivery_event);
1332
b75556f40346 Comment out reference to sctp_adaptation_layer_event.
Thomas Klausner <tk@giga.or.at>
parents: 1268
diff changeset
431 // fd_log_debug( " sctp_adaptation_layer_event : %hhu", event.sctp_adaptation_layer_event);
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
432 // fd_log_debug( " sctp_authentication_event : %hhu", event.sctp_authentication_event);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
433 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
434 }
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
435 #else /* SCTP_EVENTS */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
436 TRACE_DEBUG(ANNOYING, "Skipping SCTP_EVENTS");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
437 #endif /* SCTP_EVENTS */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
438 #endif /* OLD_SCTP_SOCKET_API */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
439
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
440 /* Set the v4 mapped addresses option */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
441 #ifdef SCTP_I_WANT_MAPPED_V4_ADDR
817
7541554029bf Fix SCTP_I_WANT_MAPPED_V4_ADDR behavior when IPv6 is disabled in config; thank you Michael Tuexen for the issue report \& patch.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 788
diff changeset
442 if (!fd_g_config->cnf_flags.no_ip6) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
443 int v4mapped;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
444
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
445 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
446 sz = sizeof(v4mapped);
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
447 /* Read socket defaults */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
448 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_I_WANT_MAPPED_V4_ADDR, &v4mapped, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
449 if (sz != sizeof(v4mapped))
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
450 {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
451 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(v4mapped));
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
452 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
453 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
454 fd_log_debug( "Def SCTP_I_WANT_MAPPED_V4_ADDR value : %s", v4mapped ? "true" : "false");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
455 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
456
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
457 #ifndef SCTP_USE_MAPPED_ADDRESSES
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
458 v4mapped = 0; /* We don't want v4 mapped addresses */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
459 #else /* SCTP_USE_MAPPED_ADDRESSES */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
460 v4mapped = 1; /* but we may have to, otherwise the bind fails in some environments */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
461 #endif /* SCTP_USE_MAPPED_ADDRESSES */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
462
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
463 /* Set the option to the socket */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
464 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_I_WANT_MAPPED_V4_ADDR, &v4mapped, sizeof(v4mapped)) );
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
465
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
466 if (TRACE_BOOL(ANNOYING)) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
467 /* Check new values */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
468 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_I_WANT_MAPPED_V4_ADDR, &v4mapped, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
469 fd_log_debug( "New SCTP_I_WANT_MAPPED_V4_ADDR value : %s", v4mapped ? "true" : "false");
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
470 }
817
7541554029bf Fix SCTP_I_WANT_MAPPED_V4_ADDR behavior when IPv6 is disabled in config; thank you Michael Tuexen for the issue report \& patch.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 788
diff changeset
471 } else {
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
472 TRACE_DEBUG(ANNOYING, "Skipping SCTP_I_WANT_MAPPED_V4_ADDR, since IPv6 disabled.");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
473 }
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
474 #else /* SCTP_I_WANT_MAPPED_V4_ADDR */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
475 TRACE_DEBUG(ANNOYING, "Skipping SCTP_I_WANT_MAPPED_V4_ADDR");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
476 #endif /* SCTP_I_WANT_MAPPED_V4_ADDR */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
477
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
478 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
479 SCTP_MAXSEG max size of fragmented segments -- bound to PMTU
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
480 SCTP_HMAC_IDENT authentication algorithms
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
481 SCTP_AUTH_ACTIVE_KEY set the active key
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
482 SCTP_DELAYED_SACK control delayed acks
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
483 */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
484
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
485
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
486 /* Set the interleaving option */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
487 #ifdef SCTP_FRAGMENT_INTERLEAVE
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
488 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
489 int interleave;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
490
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
491 if (TRACE_BOOL(ANNOYING)) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
492 sz = sizeof(interleave);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
493 /* Read socket defaults */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
494 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_FRAGMENT_INTERLEAVE, &interleave, &sz) );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
495 if (sz != sizeof(interleave))
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
496 {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
497 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(interleave));
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
498 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
499 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
500 fd_log_debug( "Def SCTP_FRAGMENT_INTERLEAVE value : %d", interleave);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
501 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
502
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
503 #if 0
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
504 interleave = 2; /* Allow partial delivery on several streams at the same time, since we are stream-aware in our security modules */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
505 #else /* 0 */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
506 interleave = 1; /* hmmm actually, we are not yet capable of handling this, and we don t need it. */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
507 #endif /* 0 */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
508
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
509 /* Set the option to the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
510 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_FRAGMENT_INTERLEAVE, &interleave, sizeof(interleave)) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
511
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
512 if (TRACE_BOOL(ANNOYING)) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
513 /* Check new values */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
514 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_FRAGMENT_INTERLEAVE, &interleave, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
515 fd_log_debug( "New SCTP_FRAGMENT_INTERLEAVE value : %d", interleave);
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
516 }
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
517 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
518 #else /* SCTP_FRAGMENT_INTERLEAVE */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
519 TRACE_DEBUG(ANNOYING, "Skipping SCTP_FRAGMENT_INTERLEAVE");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
520 #endif /* SCTP_FRAGMENT_INTERLEAVE */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
521
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
522 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
523 SCTP_PARTIAL_DELIVERY_POINT control partial delivery size
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
524 SCTP_USE_EXT_RCVINFO - DEPRECATED use extended receive info structure (information about the next message if available)
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
525 */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
526 /* SCTP_AUTO_ASCONF is set by the postbind function */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
527 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
528 SCTP_MAX_BURST number of packets that can be burst emitted
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
529 SCTP_CONTEXT save a context information along with the association.
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
530 */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
531
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
532 /* SCTP_EXPLICIT_EOR: we assume implicit EOR in freeDiameter, so let's ensure this is known by the stack */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
533 #ifdef SCTP_EXPLICIT_EOR
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
534 {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
535 int bool;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
536
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
537 if (TRACE_BOOL(ANNOYING)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
538 sz = sizeof(bool);
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
539 /* Read socket defaults */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
540 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_EXPLICIT_EOR, &bool, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
541 if (sz != sizeof(bool))
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
542 {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
543 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(bool));
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
544 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
545 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
546 fd_log_debug( "Def SCTP_EXPLICIT_EOR value : %s", bool ? "true" : "false");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
547 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
548
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
549 bool = 0;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
550
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
551 /* Set the option to the socket */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
552 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_EXPLICIT_EOR, &bool, sizeof(bool)) );
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
553
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
554 if (TRACE_BOOL(ANNOYING)) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
555 /* Check new values */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
556 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_EXPLICIT_EOR, &bool, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
557 fd_log_debug( "New SCTP_EXPLICIT_EOR value : %s", bool ? "true" : "false");
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
558 }
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
559 }
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
560 #else /* SCTP_EXPLICIT_EOR */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
561 TRACE_DEBUG(ANNOYING, "Skipping SCTP_EXPLICIT_EOR");
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
562 #endif /* SCTP_EXPLICIT_EOR */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
563
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
564 /*
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
565 SCTP_REUSE_PORT share one listening port with several sockets
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
566 */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
567
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
568 #ifndef OLD_SCTP_SOCKET_API
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
569 #ifdef SCTP_EVENT
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
570 {
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
571 /* Subscribe to the following events */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
572 int events_I_want[] = {
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
573 #ifdef SCTP_ASSOC_CHANGE
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
574 /* SCTP_ASSOC_CHANGE, */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
575 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
576 #ifdef SCTP_PEER_ADDR_CHANGE
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
577 SCTP_PEER_ADDR_CHANGE,
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
578 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
579 #ifdef SCTP_REMOTE_ERROR
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
580 SCTP_REMOTE_ERROR,
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
581 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
582 #ifdef SCTP_SEND_FAILED_EVENT
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
583 SCTP_SEND_FAILED_EVENT,
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
584 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
585 #ifdef SCTP_SHUTDOWN_EVENT
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
586 SCTP_SHUTDOWN_EVENT,
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
587 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
588 #ifdef SCTP_ADAPTATION_INDICATION
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
589 /* SCTP_ADAPTATION_INDICATION, */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
590 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
591 #ifdef SCTP_PARTIAL_DELIVERY_EVENT
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
592 /* SCTP_PARTIAL_DELIVERY_EVENT, */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
593 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
594 #ifdef SCTP_AUTHENTICATION_EVENT
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
595 /* SCTP_AUTHENTICATION_EVENT, */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
596 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
597 #ifdef SCTP_SENDER_DRY_EVENT
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
598 /* SCTP_SENDER_DRY_EVENT, */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
599 #endif
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
600 0
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
601 };
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
602 int i;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
603
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
604 struct sctp_event event;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
605
1266
85a425a201b6 Fix compilation error as reported by Nikola in http://lists.freediameter.net/pipermail/help/2014-September/000860.html
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1228
diff changeset
606 for (i = 0; i < (sizeof(events_I_want) / sizeof(events_I_want[0]) - 1); i++) {
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
607 memset(&event, 0, sizeof(event));
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
608 event.se_type = events_I_want[i];
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
609 event.se_on = 1;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
610
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
611 /* Set the option to the socket */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
612 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_EVENT, &event, sizeof(event)) );
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
613 }
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
614 }
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
615 #else /* SCTP_EVENT */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
616 TRACE_DEBUG(ANNOYING, "Skipping SCTP_EVENT");
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
617 #endif /* SCTP_EVENT */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
618
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
619
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
620 #ifdef SCTP_RECVRCVINFO /* Replaces SCTP_SNDRCV */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
621 {
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
622 int bool = 1;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
623
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
624 /* Set the option to the socket */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
625 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_RECVRCVINFO, &bool, sizeof(bool)) );
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
626
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
627 }
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
628 #else /* SCTP_RECVRCVINFO */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
629 TRACE_DEBUG(ANNOYING, "Skipping SCTP_RECVRCVINFO");
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
630 #endif /* SCTP_RECVRCVINFO */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
631
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
632
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
633 #endif /* OLD_SCTP_SOCKET_API */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
634
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
635 /*
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
636 SCTP_RECVNXTINFO
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
637
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
638 SCTP_DEFAULT_SNDINFO : send defaults
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
639 SCTP_DEFAULT_PRINFO : default PR-SCTP
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
640 */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
641
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
642
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
643 /* In case of no_ip4, force the v6only option */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
644 #ifdef IPV6_V6ONLY
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
645 if (fd_g_config->cnf_flags.no_ip4) {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
646 int opt = 1;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
647 CHECK_SYS(setsockopt(sk, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)));
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
648 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
649 #endif /* IPV6_V6ONLY */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
650
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
651 return 0;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
652 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
653
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
654
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
655 /* Post-binding socket options */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
656 static int fd_setsockopt_postbind(int sk, int bound_to_default)
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
657 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
658 TRACE_ENTRY( "%d %d", sk, bound_to_default);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
659
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
660 CHECK_PARAMS( (sk > 0) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
661
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
662 /* Set the ASCONF option */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
663 #ifdef SCTP_AUTO_ASCONF
248
d3e892306468 Cannot read/write SCTP_AUTO_ASCONF for bound sockets in FreeBSD
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
664 if (bound_to_default) {
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
665 int asconf;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
666
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
667 if (TRACE_BOOL(ANNOYING)) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
668 socklen_t sz;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
669
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
670 sz = sizeof(asconf);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
671 /* Read socket defaults */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
672 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz) );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
673 if (sz != sizeof(asconf))
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
674 {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
675 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(asconf));
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
676 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
677 }
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
678 fd_log_debug( "Def SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
679 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
680
248
d3e892306468 Cannot read/write SCTP_AUTO_ASCONF for bound sockets in FreeBSD
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
681 asconf = 1; /* allow automatic use of added or removed addresses in the association (for bound-all sockets) */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
682
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
683 /* Set the option to the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
684 CHECK_SYS( setsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, sizeof(asconf)) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
685
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
686 if (TRACE_BOOL(ANNOYING)) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
687 socklen_t sz = sizeof(asconf);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
688 /* Check new values */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
689 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz) );
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
690 fd_log_debug( "New SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false");
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
691 }
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
692 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
693 #else /* SCTP_AUTO_ASCONF */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
694 TRACE_DEBUG(ANNOYING, "Skipping SCTP_AUTO_ASCONF");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
695 #endif /* SCTP_AUTO_ASCONF */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
696
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
697 return 0;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
698 }
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
699
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
700 /* Add addresses from a list to an array, with filter on the flags */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
701 static int add_addresses_from_list_mask(uint8_t ** array, size_t * size, int * addr_count, int target_family, uint16_t port, struct fd_list * list, uint32_t mask, uint32_t val)
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
702 {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
703 struct fd_list * li;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
704 int to_add4 = 0;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
705 int to_add6 = 0;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
706 union {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
707 uint8_t *buf;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
708 sSA4 *sin;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
709 sSA6 *sin6;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
710 } ptr;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
711 size_t sz;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
712
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
713 /* First, count the number of addresses to add */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
714 for (li = list->next; li != list; li = li->next) {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
715 struct fd_endpoint * ep = (struct fd_endpoint *) li;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
716
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
717 /* Do the flag match ? */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
718 if ((val & mask) != (ep->flags & mask))
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
719 continue;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
720
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
721 if (ep->sa.sa_family == AF_INET) {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
722 to_add4 ++;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
723 } else {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
724 to_add6 ++;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
725 }
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
726 }
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
727
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
728 if ((to_add4 + to_add6) == 0)
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
729 return 0; /* nothing to do */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
730
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
731 /* The size to add */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
732 if (target_family == AF_INET) {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
733 sz = to_add4 * sizeof(sSA4);
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
734 } else {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
735 #ifndef SCTP_USE_MAPPED_ADDRESSES
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
736 sz = (to_add4 * sizeof(sSA4)) + (to_add6 * sizeof(sSA6));
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
737 #else /* SCTP_USE_MAPPED_ADDRESSES */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
738 sz = (to_add4 + to_add6) * sizeof(sSA6);
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
739 #endif /* SCTP_USE_MAPPED_ADDRESSES */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
740 }
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
741
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
742 /* Now, (re)alloc the array to store the new addresses */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
743 CHECK_MALLOC( *array = realloc(*array, *size + sz) );
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
744
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
745 /* Finally, add the addresses */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
746 for (li = list->next; li != list; li = li->next) {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
747 struct fd_endpoint * ep = (struct fd_endpoint *) li;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
748
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
749 /* Skip v6 addresses for v4 socket */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
750 if ((target_family == AF_INET) && (ep->sa.sa_family == AF_INET6))
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
751 continue;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
752
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
753 /* Are the flags matching ? */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
754 if ((val & mask) != (ep->flags & mask))
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
755 continue;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
756
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
757 /* Size of the new SA we are adding (array may contain a mix of sockaddr_in and sockaddr_in6) */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
758 #ifndef SCTP_USE_MAPPED_ADDRESSES
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
759 if (ep->sa.sa_family == AF_INET6)
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
760 #else /* SCTP_USE_MAPPED_ADDRESSES */
921
a0ab56aa089f Fix compilation when SCTP_USE_MAPPED_ADDRESSES is true, and add a note about this for FreeBSD (seems to be needed at least for FreeBSD 9.1)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 914
diff changeset
761 if (target_family == AF_INET6)
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
762 #endif /* SCTP_USE_MAPPED_ADDRESSES */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
763 sz = sizeof(sSA6);
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
764 else
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
765 sz = sizeof(sSA4);
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
766
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
767 /* Place where we add the new address */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
768 ptr.buf = *array + *size; /* place of the new SA */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
769
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
770 /* Update other information */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
771 *size += sz;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
772 *addr_count += 1;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
773
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
774 /* And write the addr in the buffer */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
775 if (sz == sizeof(sSA4)) {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
776 memcpy(ptr.buf, &ep->sin, sz);
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
777 ptr.sin->sin_port = port;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
778 } else {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
779 if (ep->sa.sa_family == AF_INET) { /* We must map the address */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
780 memset(ptr.buf, 0, sz);
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
781 ptr.sin6->sin6_family = AF_INET6;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
782 IN6_ADDR_V4MAP( &ptr.sin6->sin6_addr.s6_addr, ep->sin.sin_addr.s_addr );
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
783 } else {
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
784 memcpy(ptr.sin6, &ep->sin6, sz);
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
785 }
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
786 ptr.sin6->sin6_port = port;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
787 }
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
788 }
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
789
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
790 return 0;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
791 }
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
792
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
793 /* Create a socket server and bind it according to daemon s configuration */
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
794 int fd_sctp_create_bind_server( int * sock, int family, struct fd_list * list, uint16_t port )
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
795 {
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
796 int bind_default;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
797
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
798 TRACE_ENTRY("%p %i %p %hu", sock, family, list, port);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
799 CHECK_PARAMS(sock);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
800
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
801 /* Create the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
802 CHECK_SYS( *sock = socket(family, SOCK_STREAM, IPPROTO_SCTP) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
803
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
804 /* Set pre-binding socket options, including number of streams etc... */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
805 CHECK_FCT( fd_setsockopt_prebind(*sock) );
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
806
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
807 bind_default = (! list) || (FD_IS_LIST_EMPTY(list)) ;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
808 redo:
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
809 if ( bind_default ) {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
810 /* Implicit endpoints : bind to default addresses */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
811 union {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
812 sSS ss;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
813 sSA sa;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
814 sSA4 sin;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
815 sSA6 sin6;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
816 } s;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
817
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
818 /* 0.0.0.0 and [::] are all zeros */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
819 memset(&s, 0, sizeof(s));
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
820
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
821 s.sa.sa_family = family;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
822
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
823 if (family == AF_INET)
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
824 s.sin.sin_port = htons(port);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
825 else
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
826 s.sin6.sin6_port = htons(port);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
827
246
6418a188c1b5 getnameinfo is also more sensitive on freeBSD
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 245
diff changeset
828 CHECK_SYS( bind(*sock, &s.sa, sSAlen(&s)) );
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
829
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
830 } else {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
831 /* Explicit endpoints to bind to from config */
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
832
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
833 sSA * sar = NULL; /* array of addresses */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
834 size_t sz = 0; /* size of the array */
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
835 int count = 0; /* number of sock addr in the array */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
836
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
837 /* Create the array of configured addresses */
590
da93c7a5e1d0 Fix SCTP port when ListenOn is set (Patch by Vlada) - closes #20
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 486
diff changeset
838 CHECK_FCT( add_addresses_from_list_mask((void *)&sar, &sz, &count, family, htons(port), list, EP_FL_CONF, EP_FL_CONF) );
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
839
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
840 if (!count) {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
841 /* None of the addresses in the list came from configuration, we bind to default */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
842 bind_default = 1;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
843 goto redo;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
844 }
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
845
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
846 /* Debug: show bound addresses */
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
847 {
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
848 char * buf = NULL;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
849 size_t len = 0;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
850 CHECK_MALLOC_DO( fd_sa_dump_array( &buf, &len, 0, sar, count), );
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
851 LOG_D("SCTP server binding local addresses: %s", buf);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
852 free(buf);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
853 }
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
854
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
855 /* Bind to this array */
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
856 CHECK_SYS( sctp_bindx(*sock, sar, count, SCTP_BINDX_ADD_ADDR) );
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
857
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
858 /* We don't need sar anymore */
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
859 free(sar);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
860 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
861
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
862 /* Now, the server is bound, set remaining sockopt */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
863 CHECK_FCT( fd_setsockopt_postbind(*sock, bind_default) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
864
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
865 /* Debug: show all local listening addresses */
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
866 {
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
867 sSA *sar = NULL;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
868 int sz = 0;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
869 char * buf = NULL;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
870 size_t len = 0;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
871
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
872 CHECK_SYS( sz = sctp_getladdrs(*sock, 0, &sar) );
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
873
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
874 CHECK_MALLOC_DO( fd_sa_dump_array( &buf, &len, 0, sar, sz), );
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
875 LOG_D("SCTP server locally bound addresses: %s", buf);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
876 sctp_freeladdrs(sar);
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
877 free(buf);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
878 }
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
879
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
880 return 0;
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
881 }
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
882
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
883 /* Allow clients connections on server sockets */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
884 int fd_sctp_listen( int sock )
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
885 {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
886 TRACE_ENTRY("%d", sock);
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
887 CHECK_SYS( listen(sock, 5) );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
888 return 0;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
889 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
890
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
891 /* Create a client socket and connect to remote server */
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
892 int fd_sctp_client( int *sock, int no_ip6, uint16_t port, struct fd_list * list, struct fd_list * src_list )
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
893 {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
894 int family;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
895 union {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
896 uint8_t *buf;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
897 sSA *sa;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
898 } sar;
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
899 size_t size = 0;
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
900 int count = 0;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
901 int ret;
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
902 int bind_default = 1; /* enable ASCONF in postbind */
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
903
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
904 sar.buf = NULL;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
905
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
906 TRACE_ENTRY("%p %i %hu %p %p", sock, no_ip6, port, list, src_list);
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
907 CHECK_PARAMS( sock && list && (!FD_IS_LIST_EMPTY(list)) );
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
908 CHECK_PARAMS( !src_list || (src_list && (!FD_IS_LIST_EMPTY(src_list))) );
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
909
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
910 if (no_ip6) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
911 family = AF_INET;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
912 } else {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
913 family = AF_INET6;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
914 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
915
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
916 /* Create the socket */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
917 CHECK_SYS( *sock = socket(family, SOCK_STREAM, IPPROTO_SCTP) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
918
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
919 /* Cleanup if we are cancelled */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
920 pthread_cleanup_push(fd_cleanup_socket, sock);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
921
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
922 /* Set the socket options */
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
923 CHECK_FCT_DO( ret = fd_setsockopt_prebind(*sock), goto out );
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
924
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
925 /* Bind to explicit source addresses if requested */
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
926 if (src_list && !FD_IS_LIST_EMPTY(src_list)) {
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
927 sSA * bindsar = NULL; /* array of addresses */
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
928 size_t sz = 0; /* size of the array */
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
929 int sarcount = 0; /* number of sock addr in the array */
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
930
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
931 /* Create the array of configured addresses */
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
932 CHECK_FCT_DO( ret = add_addresses_from_list_mask((void *)&bindsar, &sz, &sarcount, family, 0, src_list, EP_FL_CONF, EP_FL_CONF), goto out );
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
933
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
934 if (sarcount) {
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
935 char * buf = NULL;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
936 size_t len = 0;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
937 CHECK_MALLOC_DO( fd_sa_dump_array( &buf, &len, 0, bindsar, sarcount), goto out );
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
938 LOG_A("SCTP client binding local addresses: %s", buf);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
939 free(buf);
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
940
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
941 CHECK_SYS_DO( ret = sctp_bindx(*sock, bindsar, sarcount, SCTP_BINDX_ADD_ADDR), goto out );
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
942 }
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
943
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
944 /* Disable ASCONF option in postbind */
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
945 bind_default = 0;
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
946
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
947 /* We don't need bindsar anymore */
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
948 free(bindsar);
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
949 }
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
950
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
951 /* Create the array of addresses, add first the configured addresses, then the discovered, then the other ones */
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
952 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF, EP_FL_CONF ), goto out );
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
953 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF | EP_FL_DISC, EP_FL_DISC ), goto out );
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
954 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF | EP_FL_DISC, 0 ), goto out );
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
955
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
956 /* Try connecting */
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
957 {
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
958 char * buf = NULL;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
959 size_t len = 0;
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
960 CHECK_MALLOC_DO( fd_sa_dump_array( &buf, &len, 0, sar.sa, count), goto out );
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
961 LOG_A("SCTP client connecting to addresses: %s", buf);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
962 free(buf);
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
963 }
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
964
1175
2da13c87baa7 Allow cancelation of thread in sctp_connectx when this function is not a cancelation point (bug of the system, seen on Ubuntu Precise at least)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1174
diff changeset
965 /* Bug in some Linux kernel, the sctp_connectx is not a cancellation point. To avoid blocking freeDiameter, we allow async cancel here */
2da13c87baa7 Allow cancelation of thread in sctp_connectx when this function is not a cancelation point (bug of the system, seen on Ubuntu Precise at least)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1174
diff changeset
966 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
51
08d8cbeff30b Fix for number of args to sctp_connectx
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 47
diff changeset
967 #ifdef SCTP_CONNECTX_4_ARGS
227
80a7e65167c4 Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
968 ret = sctp_connectx(*sock, sar.sa, count, NULL);
51
08d8cbeff30b Fix for number of args to sctp_connectx
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 47
diff changeset
969 #else /* SCTP_CONNECTX_4_ARGS */
227
80a7e65167c4 Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
970 ret = sctp_connectx(*sock, sar.sa, count);
51
08d8cbeff30b Fix for number of args to sctp_connectx
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 47
diff changeset
971 #endif /* SCTP_CONNECTX_4_ARGS */
1175
2da13c87baa7 Allow cancelation of thread in sctp_connectx when this function is not a cancelation point (bug of the system, seen on Ubuntu Precise at least)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1174
diff changeset
972 /* back to normal cancelation behabior */
2da13c87baa7 Allow cancelation of thread in sctp_connectx when this function is not a cancelation point (bug of the system, seen on Ubuntu Precise at least)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1174
diff changeset
973 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
75
e6bf3e262e49 Added comment about a bug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 68
diff changeset
974
227
80a7e65167c4 Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
975 if (ret < 0) {
1198
8c4dd4b693c6 Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1197
diff changeset
976 ret = errno;
227
80a7e65167c4 Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
977 /* Some errors are expected, we log at different level */
1198
8c4dd4b693c6 Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1197
diff changeset
978 LOG_A("sctp_connectx returned an error: %s", strerror(ret));
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
979 goto out;
227
80a7e65167c4 Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
980 }
80a7e65167c4 Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
981
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
982 free(sar.buf); sar.buf = NULL;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
983
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
984 /* Set the remaining sockopts */
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1495
diff changeset
985 CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, bind_default),
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
986 {
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
987 CHECK_SYS_DO( shutdown(*sock, SHUT_RDWR), /* continue */ );
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
988 } );
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
989
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
990 out:
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
991 ;
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
992 pthread_cleanup_pop(0);
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
993
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
994 if (ret) {
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
995 if (*sock > 0) {
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
996 CHECK_SYS_DO( close(*sock), /* continue */ );
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
997 *sock = -1;
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
998 }
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
999 free(sar.buf);
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1000 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1001 return ret;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1002 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1003
1228
e5010975da35 Fix typo in comment.
Thomas Klausner <tk@giga.or.at>
parents: 1200
diff changeset
1004 /* Retrieve streams information from a connected association -- optionally provide the primary address */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1005 int fd_sctp_get_str_info( int sock, uint16_t *in, uint16_t *out, sSS *primary )
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1006 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1007 struct sctp_status status;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1008 socklen_t sz = sizeof(status);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1009
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1010 TRACE_ENTRY("%d %p %p %p", sock, in, out, primary);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1011 CHECK_PARAMS( (sock > 0) && in && out );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1012
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1013 /* Read the association parameters */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1014 memset(&status, 0, sizeof(status));
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1015 CHECK_SYS( getsockopt(sock, IPPROTO_SCTP, SCTP_STATUS, &status, &sz) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1016 if (sz != sizeof(status))
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1017 {
27
b3a1773e9f46 again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 26
diff changeset
1018 TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %zd", sz, sizeof(status));
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1019 return ENOTSUP;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1020 }
1107
96f2051215c8 Replaced calls to TRACE_sSA and sSA_DUMP_NODE* macros
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1102
diff changeset
1021 #if 0
96f2051215c8 Replaced calls to TRACE_sSA and sSA_DUMP_NODE* macros
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1102
diff changeset
1022 char sa_buf[sSA_DUMP_STRLEN];
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
1023 fd_sa_sdump_numeric(sa_buf, (sSA *)&status.sstat_primary.spinfo_address);
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1024 fd_log_debug( "SCTP_STATUS : sstat_state : %i" , status.sstat_state);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1025 fd_log_debug( " sstat_rwnd : %u" , status.sstat_rwnd);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1026 fd_log_debug( " sstat_unackdata : %hu", status.sstat_unackdata);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1027 fd_log_debug( " sstat_penddata : %hu", status.sstat_penddata);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1028 fd_log_debug( " sstat_instrms : %hu", status.sstat_instrms);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1029 fd_log_debug( " sstat_outstrms : %hu", status.sstat_outstrms);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1030 fd_log_debug( " sstat_fragmentation_point : %u" , status.sstat_fragmentation_point);
1107
96f2051215c8 Replaced calls to TRACE_sSA and sSA_DUMP_NODE* macros
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1102
diff changeset
1031 fd_log_debug( " sstat_primary.spinfo_address : %s" , sa_buf);
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1032 fd_log_debug( " sstat_primary.spinfo_state : %d" , status.sstat_primary.spinfo_state);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1033 fd_log_debug( " sstat_primary.spinfo_cwnd : %u" , status.sstat_primary.spinfo_cwnd);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1034 fd_log_debug( " sstat_primary.spinfo_srtt : %u" , status.sstat_primary.spinfo_srtt);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1035 fd_log_debug( " sstat_primary.spinfo_rto : %u" , status.sstat_primary.spinfo_rto);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1036 fd_log_debug( " sstat_primary.spinfo_mtu : %u" , status.sstat_primary.spinfo_mtu);
1107
96f2051215c8 Replaced calls to TRACE_sSA and sSA_DUMP_NODE* macros
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1102
diff changeset
1037 #endif /* 0 */
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1038
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1039 *in = status.sstat_instrms;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1040 *out = status.sstat_outstrms;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1041
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1042 if (primary)
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1043 memcpy(primary, &status.sstat_primary.spinfo_address, sizeof(sSS));
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1044
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1045 return 0;
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1046 }
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
1047
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
1048 /* Get the list of remote endpoints of the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
1049 int fd_sctp_get_remote_ep(int sock, struct fd_list * list)
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
1050 {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1051 union {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1052 sSA *sa;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1053 uint8_t *buf;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1054 } ptr;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1055
60
04ae89829faa Initialize pointer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 58
diff changeset
1056 sSA * data = NULL;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1057 int count;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1058
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1059 TRACE_ENTRY("%d %p", sock, list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1060 CHECK_PARAMS(list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1061
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1062 /* Read the list on the socket */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1063 CHECK_SYS( count = sctp_getpaddrs(sock, 0, &data) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1064 ptr.sa = data;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
1065
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1066 while (count) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1067 socklen_t sl;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1068 switch (ptr.sa->sa_family) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1069 case AF_INET: sl = sizeof(sSA4); break;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1070 case AF_INET6: sl = sizeof(sSA6); break;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1071 default:
231
7ebe220d6572 Fix typo
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1072 TRACE_DEBUG(INFO, "Unknown address family returned in sctp_getpaddrs: %d, skip", ptr.sa->sa_family);
222
c8ad11effa95 Added comment about bug in sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 221
diff changeset
1073 /* There is a bug in current Linux kernel: http://www.spinics.net/lists/linux-sctp/msg00760.html */
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
1074 goto stop;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1075 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1076
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1077 CHECK_FCT( fd_ep_add_merge( list, ptr.sa, sl, EP_FL_LL ) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1078 ptr.buf += sl;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1079 count --;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1080 }
220
5f2ce627db3c Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
1081 stop:
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1082 /* Free the list */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1083 sctp_freepaddrs(data);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1084
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1085 /* Now get the primary address, the add function will take care of merging with existing entry */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1086 {
193
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1087
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1088 struct sctp_status status;
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1089 socklen_t sz = sizeof(status);
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1090 int ret;
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1091
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1092 memset(&status, 0, sizeof(status));
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1093 /* Attempt to use SCTP_STATUS message to retrieve the primary address */
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1094 CHECK_SYS_DO( ret = getsockopt(sock, IPPROTO_SCTP, SCTP_STATUS, &status, &sz), /* continue */);
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1095 if (sz != sizeof(status))
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1096 ret = -1;
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1097 sz = sizeof(sSS);
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1098 if (ret < 0)
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1099 {
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1100 /* Fallback to getsockname -- not recommended by draft-ietf-tsvwg-sctpsocket-19#section-7.4 */
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1101 CHECK_SYS(getpeername(sock, (sSA *)&status.sstat_primary.spinfo_address, &sz));
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1102 }
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1103
ee247ce69349 Fix invalid use of SCTP_STATUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 192
diff changeset
1104 CHECK_FCT( fd_ep_add_merge( list, (sSA *)&status.sstat_primary.spinfo_address, sz, EP_FL_PRIMARY ) );
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1105 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1106
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1107 /* Done! */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1108 return 0;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
1109 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
1110
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1111 /* Send a vector over a specified stream */
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1112 ssize_t fd_sctp_sendstrv(struct cnxctx * conn, uint16_t strid, const struct iovec *iov, int iovcnt)
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1113 {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1114 struct msghdr mhdr;
486
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1115 struct cmsghdr *hdr;
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1116 #ifdef OLD_SCTP_SOCKET_API
486
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1117 struct sctp_sndrcvinfo *sndrcv;
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1118 uint8_t anci[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1119 #else /* OLD_SCTP_SOCKET_API */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1120 struct sctp_sndinfo *sndinf;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1121 uint8_t anci[CMSG_SPACE(sizeof(struct sctp_sndinfo))];
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1122 #endif /* OLD_SCTP_SOCKET_API */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1123 ssize_t ret;
1200
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1124 struct timespec ts, now;
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1125
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1126 TRACE_ENTRY("%p %hu %p %d", conn, strid, iov, iovcnt);
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1127 CHECK_PARAMS_DO(conn && iov && iovcnt, { errno = EINVAL; return -1; } );
1200
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1128 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), return -1 );
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1129
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1130 memset(&mhdr, 0, sizeof(mhdr));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1131 memset(&anci, 0, sizeof(anci));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1132
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1133 /* Anciliary data: specify SCTP stream */
486
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1134 hdr = (struct cmsghdr *)anci;
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1135 hdr->cmsg_len = sizeof(anci);
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1136 hdr->cmsg_level = IPPROTO_SCTP;
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1137 #ifdef OLD_SCTP_SOCKET_API
486
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1138 hdr->cmsg_type = SCTP_SNDRCV;
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1139 sndrcv = (struct sctp_sndrcvinfo *)CMSG_DATA(hdr);
486
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1140 sndrcv->sinfo_stream = strid;
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1141 #else /* OLD_SCTP_SOCKET_API */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1142 hdr->cmsg_type = SCTP_SNDINFO;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1143 sndinf = (struct sctp_sndinfo *)CMSG_DATA(hdr);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1144 sndinf->snd_sid = strid;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1145 #endif /* OLD_SCTP_SOCKET_API */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1146 /* note : we could store other data also, for example in .sinfo_ppid for remote peer or in .sinfo_context for errors. */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1147
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1148 /* We don't use mhdr.msg_name here; it could be used to specify an address different from the primary */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1149
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1150 mhdr.msg_iov = (struct iovec *)iov;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1151 mhdr.msg_iovlen = iovcnt;
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1152
486
65efe8ff2c30 Change creation of anciliary data to avoid padding, should close #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
1153 mhdr.msg_control = anci;
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1154 mhdr.msg_controllen = sizeof(anci);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1155
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1156 TRACE_DEBUG(FULL, "Sending %d chunks of data (first:%zdb) on stream %hu of socket %d", iovcnt, iov[0].iov_len, strid, conn->cc_socket);
201
1b47afa59358 Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 196
diff changeset
1157 again:
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1158 ret = sendmsg(conn->cc_socket, &mhdr, 0);
201
1b47afa59358 Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 196
diff changeset
1159 /* Handle special case of timeout */
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
1160 if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
1161 pthread_testcancel();
1200
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1162 /* Check how much time we were blocked for this sending. */
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1163 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), return -1 );
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1164 if ( ((now.tv_sec - ts.tv_sec) * 1000 + ((now.tv_nsec - ts.tv_nsec) / 1000000L)) > MAX_HOTL_BLOCKING_TIME) {
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1165 LOG_D("Unable to send any data for %dms, closing the connection", MAX_HOTL_BLOCKING_TIME);
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1166 } else if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING )) {
201
1b47afa59358 Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 196
diff changeset
1167 goto again; /* don't care, just ignore */
1b47afa59358 Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 196
diff changeset
1168 }
1200
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1169
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1170 /* propagate the error */
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1171 errno = -ret;
ce2b00dc86c1 React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
1172 ret = -1;
201
1b47afa59358 Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 196
diff changeset
1173 }
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1174
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1175 CHECK_SYS_DO( ret, ); /* for tracing error only */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1176
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1175
diff changeset
1177 return ret;
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1178 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1179
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1180 /* Receive the next data from the socket, or next notification */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1181 int fd_sctp_recvmeta(struct cnxctx * conn, uint16_t * strid, uint8_t ** buf, size_t * len, int *event)
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1182 {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1183 ssize_t ret = 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1184 struct msghdr mhdr;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1185 char ancidata[ CMSG_BUF_LEN ];
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1186 struct iovec iov;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1187 uint8_t *data = NULL;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1188 size_t bufsz = 0, datasize = 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1189 size_t mempagesz = sysconf(_SC_PAGESIZE); /* We alloc buffer by memory pages for efficiency */
194
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1190 int timedout = 0;
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1191
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1192 TRACE_ENTRY("%p %p %p %p %p", conn, strid, buf, len, event);
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1193 CHECK_PARAMS( conn && buf && len && event );
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1194
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1195 /* Cleanup out parameters */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1196 *buf = NULL;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1197 *len = 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1198 *event = 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1199
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1200 /* Prepare header for receiving message */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1201 memset(&mhdr, 0, sizeof(mhdr));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1202 mhdr.msg_iov = &iov;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1203 mhdr.msg_iovlen = 1;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1204 mhdr.msg_control = &ancidata;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1205 mhdr.msg_controllen = sizeof(ancidata);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1206
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1207 next_message:
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1208 datasize = 0;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1209
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1210 /* We will loop while all data is not received. */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1211 incomplete:
1102
1d7b3ebda27f Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
1212 while (datasize >= bufsz ) {
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1213 /* The buffer is full, enlarge it */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1214 bufsz += mempagesz;
894
43fb27a9037f Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents: 817
diff changeset
1215 CHECK_MALLOC( data = realloc(data, bufsz ) );
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1216 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1217 /* the new data will be received following the preceding */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1218 memset(&iov, 0, sizeof(iov));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1219 iov.iov_base = data + datasize ;
1102
1d7b3ebda27f Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
1220 iov.iov_len = bufsz - datasize;
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1221
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1222 /* Receive data from the socket */
194
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1223 again:
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1224 pthread_cleanup_push(free, data);
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1225 ret = recvmsg(conn->cc_socket, &mhdr, 0);
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
1226 pthread_testcancel();
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1227 pthread_cleanup_pop(0);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1228
194
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1229 /* First, handle timeouts (same as fd_cnx_s_recv) */
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
1230 if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1231 if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING ))
194
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1232 goto again; /* don't care, just ignore */
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1233 if (!timedout) {
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1234 timedout ++; /* allow for one timeout while closing */
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1235 goto again;
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1236 }
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1237 /* fallback to normal handling */
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1238 }
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1239
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1240 /* Handle errors */
194
d1af490d6e85 Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1241 if (ret <= 0) { /* Socket timedout, closed, or an error occurred */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1242 CHECK_SYS_DO(ret, /* to log in case of error */);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1243 free(data);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1244 *event = FDEVP_CNX_ERROR;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1245 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1246 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1247
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1248 /* Update the size of data we received */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1249 datasize += ret;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1250
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1251 /* SCTP provides an indication when we received a full record; loop if it is not the case */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1252 if ( ! (mhdr.msg_flags & MSG_EOR) ) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1253 goto incomplete;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1254 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1255
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1256 /* Handle the case where the data received is a notification */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1257 if (mhdr.msg_flags & MSG_NOTIFICATION) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1258 union sctp_notification * notif = (union sctp_notification *) data;
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
1259 char sa_buf[sSA_DUMP_STRLEN];
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1260
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
1261 TRACE_DEBUG(FULL, "Received %zdb data of notification on socket %d", datasize, conn->cc_socket);
68
f09247048015 Add stream information in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 60
diff changeset
1262
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1263 switch (notif->sn_header.sn_type) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1264
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1265 case SCTP_ASSOC_CHANGE: /* We should not receive these as we did not subscribe for it */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1266 TRACE_DEBUG(FULL, "Received SCTP_ASSOC_CHANGE notification");
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1267 TRACE_DEBUG(ANNOYING, " state : %hu", notif->sn_assoc_change.sac_state);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1268 TRACE_DEBUG(ANNOYING, " error : %hu", notif->sn_assoc_change.sac_error);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1269 TRACE_DEBUG(ANNOYING, " instr : %hu", notif->sn_assoc_change.sac_inbound_streams);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1270 TRACE_DEBUG(ANNOYING, " outstr : %hu", notif->sn_assoc_change.sac_outbound_streams);
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1271
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1272 *event = FDEVP_CNX_EP_CHANGE;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1273 break;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1274
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1275 case SCTP_PEER_ADDR_CHANGE:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1276 TRACE_DEBUG(FULL, "Received SCTP_PEER_ADDR_CHANGE notification");
1541
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
1277 fd_sa_sdump_numeric(sa_buf, (sSA *)&(notif->sn_paddr_change.spc_aaddr));
3365e95bed57 sctp: improve sockaddr array logging
Luke Mewburn <luke@mewburn.net>
parents: 1540
diff changeset
1278 TRACE_DEBUG(ANNOYING, " intf_change : %s", sa_buf);
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1279 TRACE_DEBUG(ANNOYING, " state : %d", notif->sn_paddr_change.spc_state);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1280 TRACE_DEBUG(ANNOYING, " error : %d", notif->sn_paddr_change.spc_error);
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1281
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1282 *event = FDEVP_CNX_EP_CHANGE;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1283 break;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1284
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1285 case SCTP_REMOTE_ERROR:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1286 TRACE_DEBUG(FULL, "Received SCTP_REMOTE_ERROR notification");
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1287 TRACE_DEBUG(ANNOYING, " err : %hu", ntohs(notif->sn_remote_error.sre_error));
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1288 TRACE_DEBUG(ANNOYING, " len : %hu", ntohs(notif->sn_remote_error.sre_length));
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1289
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1290 *event = FDEVP_CNX_ERROR;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1291 break;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1292
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1293 #ifdef OLD_SCTP_SOCKET_API
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1294 case SCTP_SEND_FAILED:
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1295 TRACE_DEBUG(FULL, "Received SCTP_SEND_FAILED notification");
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1296 TRACE_DEBUG(ANNOYING, " len : %hu", notif->sn_send_failed.ssf_length);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1297 TRACE_DEBUG(ANNOYING, " err : %d", notif->sn_send_failed.ssf_error);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1298
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1299 *event = FDEVP_CNX_ERROR;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1300 break;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1301 #else /* OLD_SCTP_SOCKET_API */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1302 case SCTP_SEND_FAILED_EVENT:
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1303 TRACE_DEBUG(FULL, "Received SCTP_SEND_FAILED_EVENT notification");
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1304 *event = FDEVP_CNX_ERROR;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1305 break;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1306 #endif /* OLD_SCTP_SOCKET_API */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1307 case SCTP_SHUTDOWN_EVENT:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1308 TRACE_DEBUG(FULL, "Received SCTP_SHUTDOWN_EVENT notification");
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1309
228
dcb58243e91f More cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 227
diff changeset
1310 *event = FDEVP_CNX_SHUTDOWN;
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1311 break;
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1312
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1313 #ifndef OLD_SCTP_SOCKET_API
1495
acbfec3df281 Fix SCTP build on Fedora 31
Luke Mewburn <luke@mewburn.net>
parents: 1474
diff changeset
1314 #ifdef SCTP_NOTIFICATIONS_STOPPED_EVENT
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1315 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1316 TRACE_DEBUG(INFO, "Received SCTP_NOTIFICATIONS_STOPPED_EVENT notification, marking the association in error state");
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1317 *event = FDEVP_CNX_ERROR;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1318 break;
1495
acbfec3df281 Fix SCTP build on Fedora 31
Luke Mewburn <luke@mewburn.net>
parents: 1474
diff changeset
1319 #endif /* SCTP_NOTIFICATIONS_STOPPED_EVENT */
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1320 #endif /* OLD_SCTP_SOCKET_API */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1321
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1322 default:
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1323 TRACE_DEBUG(FULL, "Received unknown notification %d, ignored", notif->sn_header.sn_type);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1324 goto next_message;
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1325 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1326
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1327 free(data);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1328 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1329 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1330
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1331 /* From this point, we have received a message */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1332 *event = FDEVP_CNX_MSG_RECV;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1333 *buf = data;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1334 *len = datasize;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1335
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1336 if (strid) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1337 struct cmsghdr *hdr;
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1338 #ifdef OLD_SCTP_SOCKET_API
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1339 struct sctp_sndrcvinfo *sndrcv;
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1340 #else /* OLD_SCTP_SOCKET_API */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1341 struct sctp_rcvinfo *rcvinf;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1342 #endif /* OLD_SCTP_SOCKET_API */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1343
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1344 /* Handle the anciliary data */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1345 for (hdr = CMSG_FIRSTHDR(&mhdr); hdr; hdr = CMSG_NXTHDR(&mhdr, hdr)) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1346
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1347 /* We deal only with anciliary data at SCTP level */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1348 if (hdr->cmsg_level != IPPROTO_SCTP) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1349 TRACE_DEBUG(FULL, "Received some anciliary data at level %d, skipped", hdr->cmsg_level);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1350 continue;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1351 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1352
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1353 #ifdef OLD_SCTP_SOCKET_API
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1354 /* Also only interested in SCTP_SNDRCV message for the moment */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1355 if (hdr->cmsg_type != SCTP_SNDRCV) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1356 TRACE_DEBUG(FULL, "Anciliary block IPPROTO_SCTP / %d, skipped", hdr->cmsg_type);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1357 continue;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1358 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1359
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1360 sndrcv = (struct sctp_sndrcvinfo *) CMSG_DATA(hdr);
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1361 if (TRACE_BOOL(ANNOYING)) {
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1362 fd_log_debug( "Anciliary block IPPROTO_SCTP / SCTP_SNDRCV");
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1363 fd_log_debug( " sinfo_stream : %hu", sndrcv->sinfo_stream);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1364 fd_log_debug( " sinfo_ssn : %hu", sndrcv->sinfo_ssn);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1365 fd_log_debug( " sinfo_flags : %hu", sndrcv->sinfo_flags);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1366 /* fd_log_debug( " sinfo_pr_policy : %hu", sndrcv->sinfo_pr_policy); */
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1367 fd_log_debug( " sinfo_ppid : %u" , sndrcv->sinfo_ppid);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1368 fd_log_debug( " sinfo_context : %u" , sndrcv->sinfo_context);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1369 /* fd_log_debug( " sinfo_pr_value : %u" , sndrcv->sinfo_pr_value); */
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1370 fd_log_debug( " sinfo_tsn : %u" , sndrcv->sinfo_tsn);
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 965
diff changeset
1371 fd_log_debug( " sinfo_cumtsn : %u" , sndrcv->sinfo_cumtsn);
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1372 }
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1373
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1374 *strid = sndrcv->sinfo_stream;
1174
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1375 #else /* OLD_SCTP_SOCKET_API */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1376 /* Also only interested in SCTP_RCVINFO message for the moment */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1377 if (hdr->cmsg_type != SCTP_RCVINFO) {
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1378 TRACE_DEBUG(FULL, "Anciliary block IPPROTO_SCTP / %d, skipped", hdr->cmsg_type);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1379 continue;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1380 }
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1381
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1382 rcvinf = (struct sctp_rcvinfo *) CMSG_DATA(hdr);
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1383
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1384 *strid = rcvinf->rcv_sid;
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1385 #endif /* OLD_SCTP_SOCKET_API */
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1386
b72836fb814b Add some compliancy to RFC6458. Not tested however as Ubuntu does not support this yet
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1107
diff changeset
1387
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1388 }
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
1389 TRACE_DEBUG(FULL, "Received %zdb data on socket %d, stream %hu", datasize, conn->cc_socket, *strid);
68
f09247048015 Add stream information in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 60
diff changeset
1390 } else {
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
1391 TRACE_DEBUG(FULL, "Received %zdb data on socket %d (stream ignored)", datasize, conn->cc_socket);
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1392 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1393
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1394 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1395 }
"Welcome to our mercurial repository"