annotate freeDiameter/sctp.c @ 172:9c5dfc6399a4

Fix bug with Debian Lenny kernel
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 03 Feb 2010 11:27:27 +0900
parents 8ccbfdb49f1c
children 09b9cb9cfd01
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) *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
5 * Copyright (c) 2009, WIDE Project and NICT *
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
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 #include "fD.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
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
47 /* Level of SCTP-specific traces */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
48 #ifdef DEBUG_SCTP
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
49 #define SCTP_LEVEL FULL
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
50 #else /* DEBUG_SCTP */
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
51 #define SCTP_LEVEL (FCTS + 1)
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
52 #endif /* DEBUG_SCTP */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
53
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
54 /* 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
55 #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
56 #define ADJUST_RTX_PARAMS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
57 #endif /* USE_DEFAULT_SCTP_RTX_PARAMS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
58
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
59 /* Pre-binding socket options -- # streams read in config */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
60 /* The code of this file is based on draft-ietf-tsvwg-sctpsocket, versions 17 to 21 */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
61 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
62 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
63 socklen_t sz;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
64
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
65 TRACE_ENTRY( "%d", sk);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
66
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
67 CHECK_PARAMS( sk > 0 );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
68
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
69 #ifdef ADJUST_RTX_PARAMS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
70 /* Set the retransmit parameters */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
71 #ifdef SCTP_RTOINFO
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
72 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
73 struct sctp_rtoinfo rtoinfo;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
74 memset(&rtoinfo, 0, sizeof(rtoinfo));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
75
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
76 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
77 sz = sizeof(rtoinfo);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
78 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
79 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_RTOINFO, &rtoinfo, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
80 if (sz != sizeof(rtoinfo))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
81 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
82 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
83 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
84 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
85 fd_log_debug( "Def SCTP_RTOINFO : srto_initial : %u\n", rtoinfo.srto_initial);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
86 fd_log_debug( " srto_min : %u\n", rtoinfo.srto_min);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
87 fd_log_debug( " srto_max : %u\n", rtoinfo.srto_max);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
88 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
89
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
90 /* 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
91 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
92 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
93
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
94 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
95 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
96
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
97 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
98 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
99 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_RTOINFO, &rtoinfo, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
100 fd_log_debug( "New SCTP_RTOINFO : srto_initial : %u\n", rtoinfo.srto_initial);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
101 fd_log_debug( " srto_max : %u\n", rtoinfo.srto_max);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
102 fd_log_debug( " srto_min : %u\n", rtoinfo.srto_min);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
103 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
104 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
105 #else /* SCTP_RTOINFO */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
106 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_RTOINFO");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
107 #endif /* SCTP_RTOINFO */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
108
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
109 /* Set the association parameters: max number of retransmits, ... */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
110 #ifdef SCTP_ASSOCINFO
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
111 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
112 struct sctp_assocparams assoc;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
113 memset(&assoc, 0, sizeof(assoc));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
114
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
115 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
116 sz = sizeof(assoc);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
117 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
118 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_ASSOCINFO, &assoc, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
119 if (sz != sizeof(assoc))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
120 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
121 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
122 return ENOTSUP;
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 fd_log_debug( "Def SCTP_ASSOCINFO : sasoc_asocmaxrxt : %hu\n", assoc.sasoc_asocmaxrxt);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
125 fd_log_debug( " sasoc_number_peer_destinations : %hu\n", assoc.sasoc_number_peer_destinations);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
126 fd_log_debug( " sasoc_peer_rwnd : %u\n" , assoc.sasoc_peer_rwnd);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
127 fd_log_debug( " sasoc_local_rwnd : %u\n" , assoc.sasoc_local_rwnd);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
128 fd_log_debug( " sasoc_cookie_life : %u\n" , assoc.sasoc_cookie_life);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
129 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
130
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
131 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
132 /* 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
133
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
134 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
135 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
136
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
137 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
138 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
139 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_ASSOCINFO, &assoc, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
140 fd_log_debug( "New SCTP_ASSOCINFO : sasoc_asocmaxrxt : %hu\n", assoc.sasoc_asocmaxrxt);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
141 fd_log_debug( " sasoc_number_peer_destinations : %hu\n", assoc.sasoc_number_peer_destinations);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
142 fd_log_debug( " sasoc_peer_rwnd : %u\n" , assoc.sasoc_peer_rwnd);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
143 fd_log_debug( " sasoc_local_rwnd : %u\n" , assoc.sasoc_local_rwnd);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
144 fd_log_debug( " sasoc_cookie_life : %u\n" , assoc.sasoc_cookie_life);
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 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
147 #else /* SCTP_ASSOCINFO */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
148 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_ASSOCINFO");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
149 #endif /* SCTP_ASSOCINFO */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
150 #endif /* ADJUST_RTX_PARAMS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
151
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
152 /* 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
153 #ifdef SCTP_INITMSG
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 struct sctp_initmsg init;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
156 memset(&init, 0, sizeof(init));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
157
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
158 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
159 sz = sizeof(init);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
160
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
161 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
162 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
163 if (sz != sizeof(init))
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 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
166 return ENOTSUP;
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 fd_log_debug( "Def SCTP_INITMSG : sinit_num_ostreams : %hu\n", init.sinit_num_ostreams);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
169 fd_log_debug( " sinit_max_instreams : %hu\n", init.sinit_max_instreams);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
170 fd_log_debug( " sinit_max_attempts : %hu\n", init.sinit_max_attempts);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
171 fd_log_debug( " sinit_max_init_timeo : %hu\n", init.sinit_max_init_timeo);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
172 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
173
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
174 /* 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
175 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
176 init.sinit_max_init_timeo = CNX_TIMEOUT * 1000;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
177
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
178 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
179 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
180
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
181 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
182 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
183 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
184 fd_log_debug( "New SCTP_INITMSG : sinit_num_ostreams : %hu\n", init.sinit_num_ostreams);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
185 fd_log_debug( " sinit_max_instreams : %hu\n", init.sinit_max_instreams);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
186 fd_log_debug( " sinit_max_attempts : %hu\n", init.sinit_max_attempts);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
187 fd_log_debug( " sinit_max_init_timeo : %hu\n", init.sinit_max_init_timeo);
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 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
190 #else /* SCTP_INITMSG */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
191 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_INITMSG");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
192 #endif /* SCTP_INITMSG */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
193
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
194 /* 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
195 #ifdef SO_LINGER
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
196 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
197 struct linger linger;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
198 memset(&linger, 0, sizeof(linger));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
199
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
200 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
201 sz = sizeof(linger);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
202 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
203 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
204 if (sz != sizeof(linger))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
205 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
206 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
207 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
208 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
209 fd_log_debug( "Def SO_LINGER : l_onoff : %d\n", linger.l_onoff);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
210 fd_log_debug( " l_linger : %d\n", linger.l_linger);
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
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
213 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
214 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
215
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
216 /* Set the option */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
217 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
218
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
219 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
220 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
221 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
222 fd_log_debug( "New SO_LINGER : l_onoff : %d\n", linger.l_onoff);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
223 fd_log_debug( " l_linger : %d\n", linger.l_linger);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
224 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
225 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
226 #else /* SO_LINGER */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
227 TRACE_DEBUG(SCTP_LEVEL, "Skipping SO_LINGER");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
228 #endif /* SO_LINGER */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
229
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
230 /* Set the NODELAY option (Nagle-like algorithm) */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
231 #ifdef SCTP_NODELAY
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
232 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
233 int nodelay;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
234
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
235 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
236 sz = sizeof(nodelay);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
237 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
238 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
239 if (sz != sizeof(nodelay))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
240 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
241 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
242 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
243 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
244 fd_log_debug( "Def SCTP_NODELAY value : %s\n", nodelay ? "true" : "false");
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 nodelay = 1; /* We turn ON the Nagle algorithm (probably the default already), since we might have several messages to send through the same proxy (not the same session). */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
248
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
249 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
250 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
251
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
252 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
253 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
254 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
255 fd_log_debug( "New SCTP_NODELAY value : %s\n", nodelay ? "true" : "false");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
256 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
257 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
258 #else /* SCTP_NODELAY */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
259 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_NODELAY");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
260 #endif /* SCTP_NODELAY */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
261
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
262 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
263 SO_RCVBUF size of receiver window
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
264 SO_SNDBUF size of pending data to send
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
265 SCTP_AUTOCLOSE for one-to-many only
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
266 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
267 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
268 */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
269
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
270 /* 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
271 #ifdef SCTP_DISABLE_FRAGMENTS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
272 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
273 int nofrag;
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 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
276 sz = sizeof(nofrag);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
277 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
278 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
279 if (sz != sizeof(nofrag))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
280 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
281 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
282 return ENOTSUP;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
283 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
284 fd_log_debug( "Def SCTP_DISABLE_FRAGMENTS value : %s\n", nofrag ? "true" : "false");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
285 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
286
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
287 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
288
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
289 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
290 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
291
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
292 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
293 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
294 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
295 fd_log_debug( "New SCTP_DISABLE_FRAGMENTS value : %s\n", nofrag ? "true" : "false");
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 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
298 #else /* SCTP_DISABLE_FRAGMENTS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
299 # error "TLS requires support of SCTP_DISABLE_FRAGMENTS"
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
300 #endif /* SCTP_DISABLE_FRAGMENTS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
301
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
302 /* 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
303 #ifdef SCTP_PEER_ADDR_PARAMS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
304 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
305 struct sctp_paddrparams parms;
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
306 memset(&parms, 0, sizeof(parms));
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
307
172
9c5dfc6399a4 Fix bug with Debian Lenny kernel
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 171
diff changeset
308 /* 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
309 parms.spp_address.ss_family = AF_INET;
9c5dfc6399a4 Fix bug with Debian Lenny kernel
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 171
diff changeset
310
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
311 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
312 sz = sizeof(parms);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
313
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
314 /* Read socket defaults */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
315 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &parms, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
316 if (sz != sizeof(parms))
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
317 {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
318 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
319 return ENOTSUP;
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 fd_log_debug( "Def SCTP_PEER_ADDR_PARAMS : spp_hbinterval : %u\n", parms.spp_hbinterval);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
322 fd_log_debug( " spp_pathmaxrxt : %hu\n", parms.spp_pathmaxrxt);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
323 fd_log_debug( " spp_pathmtu : %u\n", parms.spp_pathmtu);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
324 fd_log_debug( " spp_flags : %x\n", parms.spp_flags);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
325 // fd_log_debug( " spp_ipv6_flowlabel: %u\n", parms.spp_ipv6_flowlabel);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
326 // fd_log_debug( " spp_ipv4_tos : %hhu\n",parms.spp_ipv4_tos);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
327 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
328
172
9c5dfc6399a4 Fix bug with Debian Lenny kernel
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 171
diff changeset
329 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
330 #ifdef SPP_PMTUD_ENABLE
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
331 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
332 #endif /* SPP_PMTUD_ENABLE */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
333
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
334 #ifdef ADJUST_RTX_PARAMS
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
335 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
336 /* 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
337 #endif /* ADJUST_RTX_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 /* Set the option to the socket */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
340 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
341
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
342 if (TRACE_BOOL(SCTP_LEVEL)) {
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
343 /* Check new values */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
344 CHECK_SYS( getsockopt(sk, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &parms, &sz) );
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
345 fd_log_debug( "New SCTP_PEER_ADDR_PARAMS : spp_hbinterval : %u\n", parms.spp_hbinterval);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
346 fd_log_debug( " spp_pathmaxrxt : %hu\n", parms.spp_pathmaxrxt);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
347 fd_log_debug( " spp_pathmtu : %u\n", parms.spp_pathmtu);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
348 fd_log_debug( " spp_flags : %x\n", parms.spp_flags);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
349 // fd_log_debug( " spp_ipv6_flowlabel: %u\n", parms.spp_ipv6_flowlabel);
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
350 // fd_log_debug( " spp_ipv4_tos : %hhu\n",parms.spp_ipv4_tos);
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 }
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
353 #else /* SCTP_PEER_ADDR_PARAMS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
354 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_PEER_ADDR_PARAMS");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
355 #endif /* SCTP_PEER_ADDR_PARAMS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
356
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
357 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
358 SCTP_DEFAULT_SEND_PARAM parameters for the sendto() call, we don't use it.
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
359 */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
360
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
361 /* Subscribe to some notifications */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
362 #ifdef SCTP_EVENTS
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
363 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
364 struct sctp_event_subscribe event;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
365
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
366 memset(&event, 0, sizeof(event));
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
367 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
368 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
369 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
370 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
371 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
372 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
373 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
374 // 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
375 // 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
376
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
377 /* Set the option to the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
378 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
379
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
380 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
381 sz = sizeof(event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
382 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
383 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
384 {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
385 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
386 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
387 }
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
388
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
389 fd_log_debug( "SCTP_EVENTS : sctp_data_io_event : %hhu\n", event.sctp_data_io_event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
390 fd_log_debug( " sctp_association_event : %hhu\n", event.sctp_association_event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
391 fd_log_debug( " sctp_address_event : %hhu\n", event.sctp_address_event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
392 fd_log_debug( " sctp_send_failure_event : %hhu\n", event.sctp_send_failure_event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
393 fd_log_debug( " sctp_peer_error_event : %hhu\n", event.sctp_peer_error_event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
394 fd_log_debug( " sctp_shutdown_event : %hhu\n", event.sctp_shutdown_event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
395 fd_log_debug( " sctp_partial_delivery_event : %hhu\n", event.sctp_partial_delivery_event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
396 fd_log_debug( " sctp_adaptation_layer_event : %hhu\n", event.sctp_adaptation_layer_event);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
397 // fd_log_debug( " sctp_authentication_event : %hhu\n", event.sctp_authentication_event);
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 }
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
400 #else /* SCTP_EVENTS */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
401 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_EVENTS");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
402 #endif /* SCTP_EVENTS */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
403
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
404 /* Set the v4 mapped addresses option */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
405 #ifdef 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
406 {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
407 int v4mapped;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
408
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
409 if (TRACE_BOOL(SCTP_LEVEL)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
410 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
411 /* Read socket defaults */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
412 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
413 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
414 {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
415 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
416 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
417 }
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
418 fd_log_debug( "Def SCTP_I_WANT_MAPPED_V4_ADDR value : %s\n", v4mapped ? "true" : "false");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
419 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
420
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
421 #ifndef SCTP_USE_MAPPED_ADDRESSES
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
422 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
423 #else /* SCTP_USE_MAPPED_ADDRESSES */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
424 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
425 #endif /* SCTP_USE_MAPPED_ADDRESSES */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
426
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
427 /* Set the option to the socket */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
428 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
429
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
430 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
431 /* Check new values */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
432 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
433 fd_log_debug( "New SCTP_I_WANT_MAPPED_V4_ADDR value : %s\n", 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
434 }
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
435 }
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
436 #else /* SCTP_I_WANT_MAPPED_V4_ADDR */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
437 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_I_WANT_MAPPED_V4_ADDR");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
438 #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
439
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
440 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
441 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
442 SCTP_HMAC_IDENT authentication algorithms
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
443 SCTP_AUTH_ACTIVE_KEY set the active key
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
444 SCTP_DELAYED_SACK control delayed acks
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
445 */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
446
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
447
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
448 /* Set the interleaving option */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
449 #ifdef SCTP_FRAGMENT_INTERLEAVE
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
450 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
451 int interleave;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
452
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
453 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
454 sz = sizeof(interleave);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
455 /* Read socket defaults */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
456 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
457 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
458 {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
459 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
460 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
461 }
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
462 fd_log_debug( "Def SCTP_FRAGMENT_INTERLEAVE value : %d\n", interleave);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
463 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
464
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
465 #if 0
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
466 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
467 #else /* 0 */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
468 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
469 #endif /* 0 */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
470
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
471 /* Set the option to the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
472 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
473
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
474 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
475 /* Check new values */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
476 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
477 fd_log_debug( "New SCTP_FRAGMENT_INTERLEAVE value : %d\n", interleave);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
478 }
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
479 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
480 #else /* SCTP_FRAGMENT_INTERLEAVE */
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
481 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_FRAGMENT_INTERLEAVE");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
482 #endif /* SCTP_FRAGMENT_INTERLEAVE */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
483
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
484 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
485 SCTP_PARTIAL_DELIVERY_POINT control partial delivery size
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
486 SCTP_USE_EXT_RCVINFO use extended receive info structure (information about the next message if available)
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
487 */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
488 /* 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
489 /*
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
490 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
491 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
492 */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
493
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
494 /* 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
495 #ifdef SCTP_EXPLICIT_EOR
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
496 {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
497 int bool;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
498
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
499 if (TRACE_BOOL(SCTP_LEVEL)) {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
500 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
501 /* Read socket defaults */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
502 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
503 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
504 {
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
505 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
506 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
507 }
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
508 fd_log_debug( "Def SCTP_EXPLICIT_EOR value : %s\n", bool ? "true" : "false");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
509 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
510
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
511 bool = 0;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
512
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
513 /* Set the option to the socket */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
514 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
515
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
516 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
517 /* Check new values */
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
518 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
519 fd_log_debug( "New SCTP_EXPLICIT_EOR value : %s\n", 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
520 }
23
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 #else /* SCTP_EXPLICIT_EOR */
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
523 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_EXPLICIT_EOR");
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
524 #endif /* SCTP_EXPLICIT_EOR */
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 /*
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
527 SCTP_REUSE_PORT share one listening port with several sockets
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
528 SCTP_EVENT same as EVENTS ?
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
529 */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
530
171
8ccbfdb49f1c Adjustments on the SCTP parameters
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 77
diff changeset
531 /* 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
532 #ifdef IPV6_V6ONLY
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
533 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
534 int opt = 1;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
535 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
536 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
537 #endif /* IPV6_V6ONLY */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
538
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
539 return 0;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
540 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
541
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
542
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
543 /* Post-binding socket options */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
544 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
545 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
546 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
547
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
548 CHECK_PARAMS( (sk > 0) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
549
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
550 /* Set the ASCONF option */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
551 #ifdef SCTP_AUTO_ASCONF
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
552 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
553 int asconf;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
554
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
555 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
556 socklen_t sz;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
557
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
558 sz = sizeof(asconf);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
559 /* Read socket defaults */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
560 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
561 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
562 {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
563 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
564 return ENOTSUP;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
565 }
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
566 fd_log_debug( "Def SCTP_AUTO_ASCONF value : %s\n", asconf ? "true" : "false");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
567 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
568
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
569 asconf = bound_to_default ? 1 : 0; /* allow automatic use of added or removed addresses in the association (for bound-all sockets) */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
570
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
571 /* Set the option to the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
572 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
573
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
574 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
575 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
576 /* Check new values */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
577 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
578 fd_log_debug( "New SCTP_AUTO_ASCONF value : %s\n", asconf ? "true" : "false");
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
579 }
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
580 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
581 #else /* SCTP_AUTO_ASCONF */
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
582 TRACE_DEBUG(SCTP_LEVEL, "Skipping SCTP_AUTO_ASCONF");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
583 #endif /* SCTP_AUTO_ASCONF */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
584
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
585 return 0;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
586 }
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
587
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
588 /* Create a socket server and bind it according to daemon s configuration */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
589 int fd_sctp_create_bind_server( int * sock, 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
590 {
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
591 int family;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
592 int bind_default;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
593
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
594 TRACE_ENTRY("%p %p %hu", sock, list, port);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
595 CHECK_PARAMS(sock);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
596
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
597 if (fd_g_config->cnf_flags.no_ip6) {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
598 family = AF_INET;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
599 } else {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
600 family = AF_INET6; /* can create socket for both IP and IPv6 */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
601 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
602
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
603 /* Create the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
604 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
605
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
606 /* 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
607 CHECK_FCT( fd_setsockopt_prebind(*sock) );
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
608
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
609 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
610 redo:
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
611 if ( bind_default ) {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
612 /* Implicit endpoints : bind to default addresses */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
613 union {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
614 sSS ss;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
615 sSA sa;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
616 sSA4 sin;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
617 sSA6 sin6;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
618 } s;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
619
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
620 /* 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
621 memset(&s, 0, sizeof(s));
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
622
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
623 s.sa.sa_family = family;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
624
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
625 if (family == AF_INET)
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
626 s.sin.sin_port = htons(port);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
627 else
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
628 s.sin6.sin6_port = htons(port);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
629
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
630 CHECK_SYS( bind(*sock, &s.sa, sizeof(s)) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
631
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
632 } else {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
633 /* 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
634
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
635 union {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
636 sSA * sa;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
637 sSA4 *sin;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
638 sSA6 *sin6;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
639 uint8_t *buf;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
640 } ptr;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
641 union {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
642 sSA * sa;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
643 uint8_t * buf;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
644 } sar;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
645 int count = 0; /* number of sock addr in sar array */
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
646 size_t offset = 0;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
647 struct fd_list * li;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
648
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
649 sar.buf = NULL;
23
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 /* Create a flat array from the list of configured addresses */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
652 for (li = list->next; li != list; li = li->next) {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
653 struct fd_endpoint * ep = (struct fd_endpoint *)li;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
654 size_t sz = 0;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
655
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
656 if (! (ep->flags & EP_FL_CONF))
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
657 continue;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
658
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
659 count++;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
660
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
661 /* Size of the new SA we are adding (sar may contain a mix of sockaddr_in and sockaddr_in6) */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
662 #ifndef SCTP_USE_MAPPED_ADDRESSES
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
663 if (ep->sa.sa_family == AF_INET6)
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
664 #else /* SCTP_USE_MAPPED_ADDRESSES */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
665 if (family == AF_INET6)
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
666 #endif /* SCTP_USE_MAPPED_ADDRESSES */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
667 sz = sizeof(sSA6);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
668 else
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
669 sz = sizeof(sSA4);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
670
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
671 /* augment sar to contain the additional info */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
672 CHECK_MALLOC( sar.buf = realloc(sar.buf, offset + sz) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
673
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
674 ptr.buf = sar.buf + offset; /* place of the new SA */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
675 offset += sz; /* update to end of sar */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
676
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
677 if (sz == sizeof(sSA4)) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
678 memcpy(ptr.buf, &ep->sin, sz);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
679 ptr.sin->sin_port = htons(port);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
680 } else {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
681 if (ep->sa.sa_family == AF_INET) { /* We must map the address */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
682 memset(ptr.buf, 0, sz);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
683 ptr.sin6->sin6_family = AF_INET6;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
684 IN6_ADDR_V4MAP( &ptr.sin6->sin6_addr.s6_addr, ep->sin.sin_addr.s_addr );
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
685 } else {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
686 memcpy(ptr.sin6, &ep->sin6, sz);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
687 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
688 ptr.sin6->sin6_port = htons(port);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
689 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
690 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
691
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
692 if (!count) {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
693 /* 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
694 bind_default = 1;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
695 goto redo;
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
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
698 if (TRACE_BOOL(SCTP_LEVEL)) {
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
699 int i;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
700 ptr.buf = sar.buf;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
701 fd_log_debug("Calling sctp_bindx with the following address array:\n");
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
702 for (i = 0; i < count; i++) {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
703 TRACE_DEBUG_sSA(FULL, " - ", ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV, "" );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
704 ptr.buf += (ptr.sa->sa_family == AF_INET) ? sizeof(sSA4) : sizeof(sSA6) ;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
705 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
706 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
707
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
708 /* Bind to this array */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
709 CHECK_SYS( sctp_bindx(*sock, sar.sa, count, SCTP_BINDX_ADD_ADDR) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
710
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
711 /* We don't need sar anymore */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
712 free(sar.buf);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
713 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
714
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
715 /* 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
716 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
717
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
718 /* Debug: show all local listening addresses */
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
719 if (TRACE_BOOL(SCTP_LEVEL)) {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
720 sSA *sar;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
721 union {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
722 sSA *sa;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
723 uint8_t *buf;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
724 } ptr;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
725 int sz;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
726
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
727 CHECK_SYS( sz = sctp_getladdrs(*sock, 0, &sar) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
728
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
729 fd_log_debug("SCTP server bound on :\n");
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
730 for (ptr.sa = sar; sz-- > 0; ptr.buf += (ptr.sa->sa_family == AF_INET) ? sizeof(sSA4) : sizeof(sSA6)) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
731 TRACE_DEBUG_sSA(FULL, " - ", ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV, "" );
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
732 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
733 sctp_freeladdrs(sar);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
734 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
735
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
736 return 0;
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
737 }
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
738
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
739 /* Allow clients connections on server sockets */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
740 int fd_sctp_listen( int sock )
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
741 {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
742 TRACE_ENTRY("%d", sock);
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
743 CHECK_SYS( listen(sock, 5) );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
744 return 0;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
745 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
746
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
747 /* Add addresses from the list that match the flags to the array */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
748 static int add_addresses_from_list_mask(uint8_t ** array, int * count, size_t * offset, uint16_t port, struct fd_list * list, uint32_t mask, uint32_t val)
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
749 {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
750 size_t sz;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
751 struct fd_list * li;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
752 union {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
753 uint8_t *buf;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
754 sSA4 *sin;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
755 sSA6 *sin6;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
756 } ptr;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
757
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
758 for (li = list->next; li != list; li = li->next) {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
759 struct fd_endpoint * ep = (struct fd_endpoint *) li;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
760
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
761 /* Do the flag match ? */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
762 if ((val & mask) != (ep->flags & mask))
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
763 continue;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
764
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
765 /* We add this endpoint at the end of array */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
766 (*count)++;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
767
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
768 /* Size of the new SA we are adding (array may contain a mix of sockaddr_in and sockaddr_in6) */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
769 #ifndef SCTP_USE_MAPPED_ADDRESSES
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
770 if (ep->sa.sa_family == AF_INET6)
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
771 #else /* SCTP_USE_MAPPED_ADDRESSES */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
772 if (family == AF_INET6)
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
773 #endif /* SCTP_USE_MAPPED_ADDRESSES */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
774 sz = sizeof(sSA6);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
775 else
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
776 sz = sizeof(sSA4);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
777
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
778 /* augment array to contain the additional info */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
779 CHECK_MALLOC( *array = realloc(*array, (*offset) + sz) );
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
780
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
781 ptr.buf = *array + *offset; /* place of the new SA */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
782 (*offset) += sz; /* update to end of sar */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
783
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
784 if (sz == sizeof(sSA4)) {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
785 memcpy(ptr.buf, &ep->sin, sz);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
786 ptr.sin->sin_port = port;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
787 } else {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
788 if (ep->sa.sa_family == AF_INET) { /* We must map the address */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
789 memset(ptr.buf, 0, sz);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
790 ptr.sin6->sin6_family = AF_INET6;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
791 IN6_ADDR_V4MAP( &ptr.sin6->sin6_addr.s6_addr, ep->sin.sin_addr.s_addr );
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
792 } else {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
793 memcpy(ptr.sin6, &ep->sin6, sz);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
794 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
795 ptr.sin6->sin6_port = port;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
796 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
797 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
798
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
799 return 0;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
800 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
801
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
802 /* Create a client socket and connect to remote server */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
803 int fd_sctp_client( int *sock, int no_ip6, uint16_t port, struct fd_list * list )
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
804 {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
805 int family;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
806 int count = 0;
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
807 size_t offset = 0;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
808 union {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
809 uint8_t *buf;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
810 sSA *sa;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
811 } sar;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
812 int ret;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
813
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
814 sar.buf = NULL;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
815
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
816 TRACE_ENTRY("%p %i %hu %p", sock, no_ip6, port, list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
817 CHECK_PARAMS( sock && list && (!FD_IS_LIST_EMPTY(list)) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
818
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
819 if (no_ip6) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
820 family = AF_INET;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
821 } else {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
822 family = AF_INET6;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
823 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
824
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
825 /* Create the socket */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
826 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
827
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
828 /* Cleanup if we are cancelled */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
829 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
830
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
831 /* Set the socket options */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
832 CHECK_FCT_DO( ret = fd_setsockopt_prebind(*sock), goto fail );
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
833
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
834 /* Create the array of addresses, add first the configured addresses, then the discovered, then the other ones */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
835 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &count, &offset, htons(port), list, EP_FL_CONF, EP_FL_CONF ), goto fail );
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
836 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &count, &offset, htons(port), list, EP_FL_CONF | EP_FL_DISC, EP_FL_DISC ), goto fail );
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
837 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &count, &offset, htons(port), list, EP_FL_CONF | EP_FL_DISC, 0 ), goto fail );
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
838
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
839 /* Try connecting */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
840 TRACE_DEBUG(FULL, "Attempting SCTP connection (%d addresses attempted)...", count);
51
08d8cbeff30b Fix for number of args to sctp_connectx
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 47
diff changeset
841 #ifdef SCTP_CONNECTX_4_ARGS
47
43dc87ac5e11 Added new parameter in sctp_connectx in latest libsctp (Ubuntu Karmic)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
842 CHECK_SYS_DO( sctp_connectx(*sock, sar.sa, count, NULL), { ret = errno; goto fail; } );
51
08d8cbeff30b Fix for number of args to sctp_connectx
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 47
diff changeset
843 #else /* SCTP_CONNECTX_4_ARGS */
08d8cbeff30b Fix for number of args to sctp_connectx
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 47
diff changeset
844 CHECK_SYS_DO( sctp_connectx(*sock, sar.sa, count), { ret = errno; goto fail; } );
08d8cbeff30b Fix for number of args to sctp_connectx
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 47
diff changeset
845 #endif /* SCTP_CONNECTX_4_ARGS */
75
e6bf3e262e49 Added comment about a bug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 68
diff changeset
846
e6bf3e262e49 Added comment about a bug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 68
diff changeset
847 /*****************
e6bf3e262e49 Added comment about a bug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 68
diff changeset
848 BUG : received "EINVAL" at reconnection attempt... Should probably filter a little what is in list !
e6bf3e262e49 Added comment about a bug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 68
diff changeset
849 *****************/
e6bf3e262e49 Added comment about a bug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 68
diff changeset
850
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
851 free(sar.buf); sar.buf = NULL;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
852
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
853 /* Set the remaining sockopts */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
854 CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, 1), goto fail );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
855
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
856 /* Done! */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
857 pthread_cleanup_pop(0);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
858 return 0;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
859
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
860 fail:
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
861 if (*sock > 0) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
862 shutdown(*sock, SHUT_RDWR);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
863 *sock = -1;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
864 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
865 free(sar.buf);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
866 return ret;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
867 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
868
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
869 /* Retrieve streams information from a connected association -- optionaly provide the primary address */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
870 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
871 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
872 struct sctp_status status;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
873 socklen_t sz = sizeof(status);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
874
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
875 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
876 CHECK_PARAMS( (sock > 0) && in && out );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
877
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
878 /* Read the association parameters */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
879 memset(&status, 0, sizeof(status));
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
880 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
881 if (sz != sizeof(status))
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
882 {
27
b3a1773e9f46 again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 26
diff changeset
883 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
884 return ENOTSUP;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
885 }
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
886 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
887 fd_log_debug( "SCTP_STATUS : sstat_state : %i\n" , status.sstat_state);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
888 fd_log_debug( " sstat_rwnd : %u\n" , status.sstat_rwnd);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
889 fd_log_debug( " sstat_unackdata : %hu\n", status.sstat_unackdata);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
890 fd_log_debug( " sstat_penddata : %hu\n", status.sstat_penddata);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
891 fd_log_debug( " sstat_instrms : %hu\n", status.sstat_instrms);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
892 fd_log_debug( " sstat_outstrms : %hu\n", status.sstat_outstrms);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
893 fd_log_debug( " sstat_fragmentation_point : %u\n" , status.sstat_fragmentation_point);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
894 fd_log_debug( " sstat_primary.spinfo_address : ");
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
895 sSA_DUMP_NODE_SERV(&status.sstat_primary.spinfo_address, NI_NUMERICHOST | NI_NUMERICSERV );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
896 fd_log_debug( "\n" );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
897 fd_log_debug( " sstat_primary.spinfo_state : %d\n" , status.sstat_primary.spinfo_state);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
898 fd_log_debug( " sstat_primary.spinfo_cwnd : %u\n" , status.sstat_primary.spinfo_cwnd);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
899 fd_log_debug( " sstat_primary.spinfo_srtt : %u\n" , status.sstat_primary.spinfo_srtt);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
900 fd_log_debug( " sstat_primary.spinfo_rto : %u\n" , status.sstat_primary.spinfo_rto);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
901 fd_log_debug( " sstat_primary.spinfo_mtu : %u\n" , status.sstat_primary.spinfo_mtu);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
902 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
903
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
904 *in = status.sstat_instrms;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
905 *out = status.sstat_outstrms;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
906
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
907 if (primary)
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
908 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
909
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
910 return 0;
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
911 }
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
912
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
913 /* Get the list of local endpoints of the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
914 int fd_sctp_get_local_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
915 {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
916 union {
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
917 sSA *sa;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
918 uint8_t *buf;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
919 } ptr;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
920
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
921 sSA * data;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
922 int count;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
923
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
924 TRACE_ENTRY("%d %p", sock, list);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
925 CHECK_PARAMS(list);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
926
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
927 /* Read the list on the socket */
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
928 CHECK_SYS( count = sctp_getladdrs(sock, 0, &data) );
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
929 ptr.sa = data;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
930
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
931 while (count) {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
932 socklen_t sl;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
933 switch (ptr.sa->sa_family) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
934 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
935 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
936 default:
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
937 TRACE_DEBUG(INFO, "Unkown address family returned in sctp_getladdrs: %d", ptr.sa->sa_family);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
938 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
939
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
940 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
941 ptr.buf += sl;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
942 count --;
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
943 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
944
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
945 /* Free the list */
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
946 sctp_freeladdrs(data);
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
947
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
948 /* 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
949 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
950
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
951 struct sctp_status status;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
952 socklen_t sz = sizeof(status);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
953 int ret;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
954
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
955 memset(&status, 0, sizeof(status));
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
956 /* Attempt to use SCTP_STATUS message to retrieve the primary address */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
957 ret = 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
958 if (sz != sizeof(status))
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
959 ret = -1;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
960 sz = sizeof(sSS);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
961 if (ret < 0)
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
962 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
963 /* Fallback to getsockname -- not recommended by draft-ietf-tsvwg-sctpsocket-19#section-7.4 */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
964 CHECK_SYS(getsockname(sock, (sSA *)&status.sstat_primary.spinfo_address, &sz));
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
965 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
966
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
967 CHECK_FCT( fd_ep_add_merge( list, (sSA *)&status.sstat_primary.spinfo_address, sz, EP_FL_PRIMARY ) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
968 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
969
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
970 return 0;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
971 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
972
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
973 /* 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
974 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
975 {
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
976 union {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
977 sSA *sa;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
978 uint8_t *buf;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
979 } ptr;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
980
60
04ae89829faa Initialize pointer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 58
diff changeset
981 sSA * data = NULL;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
982 int count;
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 TRACE_ENTRY("%d %p", sock, list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
985 CHECK_PARAMS(list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
986
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
987 /* Read the list on the socket */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
988 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
989 ptr.sa = data;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
990
55
d847a0f6d93d Added debug message temporarily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 51
diff changeset
991 TRACE_DEBUG(NONE, "DEBUG: count = %d", count);
d847a0f6d93d Added debug message temporarily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 51
diff changeset
992 TRACE_DEBUG_BUFFER(NONE, "DEBUG: data = ", ptr.buf, count * sizeof(sSA4), "" );
d847a0f6d93d Added debug message temporarily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 51
diff changeset
993
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
994 while (count) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
995 socklen_t sl;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
996 switch (ptr.sa->sa_family) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
997 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
998 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
999 default:
58
4083e32bff99 Handle properly broken sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 55
diff changeset
1000 TRACE_DEBUG(INFO, "Unkown address family returned in sctp_getpaddrs: %d, skip", ptr.sa->sa_family);
4083e32bff99 Handle properly broken sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 55
diff changeset
1001 goto next;
24
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
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1004 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
1005 ptr.buf += sl;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1006 count --;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1007 }
58
4083e32bff99 Handle properly broken sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 55
diff changeset
1008 next:
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1009 /* Free the list */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1010 sctp_freepaddrs(data);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1011
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1012 /* 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
1013 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1014 sSS ss;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1015 socklen_t sl = sizeof(sSS);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1016
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1017 CHECK_SYS(getpeername(sock, (sSA *)&ss, &sl));
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1018 CHECK_FCT( fd_ep_add_merge( list, (sSA *)&ss, sl, EP_FL_PRIMARY ) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1019 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1020
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1021 /* Done! */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
1022 return 0;
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
1023 }
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
1024
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1025 /* Send a buffer over a specified stream */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1026 int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len)
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1027 {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1028 struct msghdr mhdr;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1029 struct iovec iov;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1030 struct {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1031 struct cmsghdr hdr;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1032 struct sctp_sndrcvinfo sndrcv;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1033 } anci;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1034 ssize_t ret;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1035
27
b3a1773e9f46 again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 26
diff changeset
1036 TRACE_ENTRY("%d %hu %p %zd", sock, strid, buf, len);
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1037
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1038 memset(&mhdr, 0, sizeof(mhdr));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1039 memset(&iov, 0, sizeof(iov));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1040 memset(&anci, 0, sizeof(anci));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1041
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1042 /* IO Vector: message data */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1043 iov.iov_base = buf;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1044 iov.iov_len = len;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1045
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1046 /* Anciliary data: specify SCTP stream */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1047 anci.hdr.cmsg_len = sizeof(anci);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1048 anci.hdr.cmsg_level = IPPROTO_SCTP;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1049 anci.hdr.cmsg_type = SCTP_SNDRCV;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1050 anci.sndrcv.sinfo_stream = strid;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1051 /* 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
1052
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1053 /* 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
1054
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1055 mhdr.msg_iov = &iov;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1056 mhdr.msg_iovlen = 1;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1057
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1058 mhdr.msg_control = &anci;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1059 mhdr.msg_controllen = sizeof(anci);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1060
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1061 TRACE_DEBUG(FULL, "Sending %db data on stream %hu of socket %d", len, strid, sock);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1062
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1063 CHECK_SYS( ret = sendmsg(sock, &mhdr, 0) );
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1064 ASSERT( ret == len ); /* There should not be partial delivery with sendmsg... */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1065
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1066 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1067 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1068
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1069 /* Receive the next data from the socket, or next notification */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1070 int fd_sctp_recvmeta(int sock, uint16_t * strid, uint8_t ** buf, size_t * len, int *event)
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1071 {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1072 ssize_t ret = 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1073 struct msghdr mhdr;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1074 char ancidata[ CMSG_BUF_LEN ];
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1075 struct iovec iov;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1076 uint8_t *data = NULL;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1077 size_t bufsz = 0, datasize = 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1078 size_t mempagesz = sysconf(_SC_PAGESIZE); /* We alloc buffer by memory pages for efficiency */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1079
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1080 TRACE_ENTRY("%d %p %p %p %p", sock, strid, buf, len, event);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1081 CHECK_PARAMS( (sock > 0) && buf && len && event );
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1082
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1083 /* Cleanup out parameters */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1084 *buf = NULL;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1085 *len = 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1086 *event = 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1087
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1088 /* Prepare header for receiving message */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1089 memset(&mhdr, 0, sizeof(mhdr));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1090 mhdr.msg_iov = &iov;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1091 mhdr.msg_iovlen = 1;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1092 mhdr.msg_control = &ancidata;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1093 mhdr.msg_controllen = sizeof(ancidata);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1094
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1095 /* We will loop while all data is not received. */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1096 incomplete:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1097 if (datasize == bufsz) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1098 /* The buffer is full, enlarge it */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1099 bufsz += mempagesz;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1100 CHECK_MALLOC( data = realloc(data, bufsz) );
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1101 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1102 /* the new data will be received following the preceding */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1103 memset(&iov, 0, sizeof(iov));
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1104 iov.iov_base = data + datasize ;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1105 iov.iov_len = bufsz - datasize;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1106
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1107 /* Receive data from the socket */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1108 pthread_cleanup_push(free, data);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1109 ret = recvmsg(sock, &mhdr, 0);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1110 pthread_cleanup_pop(0);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1111
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1112 /* Handle errors */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1113 if (ret <= 0) { /* Socket is closed, or an error occurred */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1114 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
1115 free(data);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1116 *event = FDEVP_CNX_ERROR;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1117 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1118 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1119
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1120 /* Update the size of data we received */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1121 datasize += ret;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1122
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1123 /* 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
1124 if ( ! (mhdr.msg_flags & MSG_EOR) ) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1125 goto incomplete;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1126 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1127
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1128 /* 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
1129 if (mhdr.msg_flags & MSG_NOTIFICATION) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1130 union sctp_notification * notif = (union sctp_notification *) data;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1131
68
f09247048015 Add stream information in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 60
diff changeset
1132 TRACE_DEBUG(FULL, "Received %db data of notification on socket %d", datasize, sock);
f09247048015 Add stream information in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 60
diff changeset
1133
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1134 switch (notif->sn_header.sn_type) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1135
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1136 case SCTP_ASSOC_CHANGE:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1137 TRACE_DEBUG(FULL, "Received SCTP_ASSOC_CHANGE notification");
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1138 TRACE_DEBUG(SCTP_LEVEL, " state : %hu", notif->sn_assoc_change.sac_state);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1139 TRACE_DEBUG(SCTP_LEVEL, " error : %hu", notif->sn_assoc_change.sac_error);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1140 TRACE_DEBUG(SCTP_LEVEL, " instr : %hu", notif->sn_assoc_change.sac_inbound_streams);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1141 TRACE_DEBUG(SCTP_LEVEL, " 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
1142
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1143 *event = FDEVP_CNX_EP_CHANGE;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1144 break;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1145
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1146 case SCTP_PEER_ADDR_CHANGE:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1147 TRACE_DEBUG(FULL, "Received SCTP_PEER_ADDR_CHANGE notification");
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1148 TRACE_DEBUG_sSA(SCTP_LEVEL, " intf_change : ", &(notif->sn_paddr_change.spc_aaddr), NI_NUMERICHOST | NI_NUMERICSERV, "" );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1149 TRACE_DEBUG(SCTP_LEVEL, " state : %d", notif->sn_paddr_change.spc_state);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1150 TRACE_DEBUG(SCTP_LEVEL, " error : %d", notif->sn_paddr_change.spc_error);
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1151
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1152 *event = FDEVP_CNX_EP_CHANGE;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1153 break;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1154
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1155 case SCTP_SEND_FAILED:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1156 TRACE_DEBUG(FULL, "Received SCTP_SEND_FAILED notification");
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1157 TRACE_DEBUG(SCTP_LEVEL, " len : %hu", notif->sn_send_failed.ssf_length);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1158 TRACE_DEBUG(SCTP_LEVEL, " err : %d", notif->sn_send_failed.ssf_error);
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1159
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1160 *event = FDEVP_CNX_ERROR;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1161 break;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1162
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1163 case SCTP_REMOTE_ERROR:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1164 TRACE_DEBUG(FULL, "Received SCTP_REMOTE_ERROR notification");
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1165 TRACE_DEBUG(SCTP_LEVEL, " err : %hu", ntohs(notif->sn_remote_error.sre_error));
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1166 TRACE_DEBUG(SCTP_LEVEL, " 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
1167
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1168 *event = FDEVP_CNX_ERROR;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1169 break;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1170
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1171 case SCTP_SHUTDOWN_EVENT:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1172 TRACE_DEBUG(FULL, "Received SCTP_SHUTDOWN_EVENT notification");
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1173
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1174 *event = FDEVP_CNX_ERROR;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1175 break;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1176
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1177 default:
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1178 TRACE_DEBUG(FULL, "Received unknown notification %d, assume error", notif->sn_header.sn_type);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1179 *event = FDEVP_CNX_ERROR;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1180 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1181
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1182 free(data);
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1183 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1184 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1185
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1186 /* From this point, we have received a message */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1187 *event = FDEVP_CNX_MSG_RECV;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1188 *buf = data;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1189 *len = datasize;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1190
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1191 if (strid) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1192 struct cmsghdr *hdr;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1193 struct sctp_sndrcvinfo *sndrcv;
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 /* Handle the anciliary data */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1196 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
1197
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1198 /* We deal only with anciliary data at SCTP level */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1199 if (hdr->cmsg_level != IPPROTO_SCTP) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1200 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
1201 continue;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1202 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1203
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1204 /* 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
1205 if (hdr->cmsg_type != SCTP_SNDRCV) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1206 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
1207 continue;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1208 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1209
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1210 sndrcv = (struct sctp_sndrcvinfo *) CMSG_DATA(hdr);
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1211 if (TRACE_BOOL(SCTP_LEVEL)) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1212 fd_log_debug( "Anciliary block IPPROTO_SCTP / SCTP_SNDRCV\n");
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1213 fd_log_debug( " sinfo_stream : %hu\n", sndrcv->sinfo_stream);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1214 fd_log_debug( " sinfo_ssn : %hu\n", sndrcv->sinfo_ssn);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1215 fd_log_debug( " sinfo_flags : %hu\n", sndrcv->sinfo_flags);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1216 /* fd_log_debug( " sinfo_pr_policy : %hu\n", sndrcv->sinfo_pr_policy); */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1217 fd_log_debug( " sinfo_ppid : %u\n" , sndrcv->sinfo_ppid);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1218 fd_log_debug( " sinfo_context : %u\n" , sndrcv->sinfo_context);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1219 /* fd_log_debug( " sinfo_pr_value : %u\n" , sndrcv->sinfo_pr_value); */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1220 fd_log_debug( " sinfo_tsn : %u\n" , sndrcv->sinfo_tsn);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1221 fd_log_debug( " sinfo_cumtsn : %u\n" , sndrcv->sinfo_cumtsn);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
1222 }
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1223
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1224 *strid = sndrcv->sinfo_stream;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1225 }
68
f09247048015 Add stream information in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 60
diff changeset
1226 TRACE_DEBUG(FULL, "Received %db data on socket %d, stream %hu", datasize, sock, *strid);
f09247048015 Add stream information in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 60
diff changeset
1227 } else {
f09247048015 Add stream information in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 60
diff changeset
1228 TRACE_DEBUG(FULL, "Received %db data on socket %d (stream ignored)", datasize, sock);
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1229 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1230
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1231 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
1232 }
"Welcome to our mercurial repository"