annotate freeDiameter/endpoints.c @ 502:a9a938287b49

Updated help message
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 18 Aug 2010 18:20:05 +0900
parents 535b516d875d
children 16224de837fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
258
5df55136361b Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 210
diff changeset
5 * Copyright (c) 2010, WIDE Project and NICT *
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
bd83ce9328ed Cleanups and completed sctp code (not finished)
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 *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
bd83ce9328ed Cleanups and completed sctp code (not finished)
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 *
bd83ce9328ed Cleanups and completed sctp code (not finished)
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 *
bd83ce9328ed Cleanups and completed sctp code (not finished)
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 *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
bd83ce9328ed Cleanups and completed sctp code (not finished)
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 *
bd83ce9328ed Cleanups and completed sctp code (not finished)
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 *
bd83ce9328ed Cleanups and completed sctp code (not finished)
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 *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 #include "fD.h"
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 /* Add an endpoint information in a list */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 int fd_ep_add_merge( struct fd_list * list, sSA * sa, socklen_t sl, uint32_t flags )
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 struct fd_endpoint * ep;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43 struct fd_list * li;
133
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
44 union {
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
45 sSA * sa;
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
46 sSA4 *sin;
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
47 sSA6 *sin6;
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
48 } ptr;
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
49 in_port_t * port;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 int cmp = -1;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 TRACE_ENTRY("%p %p %u %x", list, sa, sl, flags);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 CHECK_PARAMS( list && sa && (sl <= sizeof(sSS)) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
55 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
56 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_add_merge Current list:");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
57 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
58 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_add_merge Adding:");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
59 fd_log_debug(" ");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
60 sSA_DUMP_NODE_SERV( sa, NI_NUMERICHOST | NI_NUMERICSERV );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
61 fd_log_debug(" {%s%s%s%s}\n",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
62 (flags & EP_FL_CONF) ? "C" : "-",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
63 (flags & EP_FL_DISC) ? "D" : "-",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
64 (flags & EP_FL_ADV) ? "A" : "-",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
65 (flags & EP_FL_LL) ? "L" : "-",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
66 (flags & EP_FL_PRIMARY) ? "P" : "-");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
67 }
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
68 ptr.sa = sa;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
69
178
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
70 /* Filter out a bunch of invalid addresses */
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
71 switch (sa->sa_family) {
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
72 case AF_INET:
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
73 if (! (flags & EP_ACCEPTALL)) {
178
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
74 if (IN_IS_ADDR_UNSPECIFIED(&ptr.sin->sin_addr)
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
75 || IN_IS_ADDR_LOOPBACK(&ptr.sin->sin_addr)
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
76 || IN_MULTICAST(ptr.sin->sin_addr.s_addr)
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
77 || IN_EXPERIMENTAL(ptr.sin->sin_addr.s_addr)
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
78 || IN_BADCLASS(ptr.sin->sin_addr.s_addr)
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
79 || (ptr.sin->sin_addr.s_addr == INADDR_BROADCAST)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
80 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
81 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_add_merge Address was ignored, not added.");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
82 }
140
34e47f4addf8 Fix broken test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 135
diff changeset
83 return 0;
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
84 }
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
85 }
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
86 port = &ptr.sin->sin_port;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
87 break;
140
34e47f4addf8 Fix broken test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 135
diff changeset
88
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
89 case AF_INET6:
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
90 if (! (flags & EP_ACCEPTALL)) {
178
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
91 if (IN6_IS_ADDR_UNSPECIFIED(&ptr.sin6->sin6_addr)
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
92 || IN6_IS_ADDR_LOOPBACK(&ptr.sin6->sin6_addr)
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
93 || IN6_IS_ADDR_MULTICAST(&ptr.sin6->sin6_addr)
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
94 || IN6_IS_ADDR_LINKLOCAL(&ptr.sin6->sin6_addr)
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
95 || IN6_IS_ADDR_SITELOCAL(&ptr.sin6->sin6_addr)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
96 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
97 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_add_merge Address was ignored, not added.");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
98 }
140
34e47f4addf8 Fix broken test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 135
diff changeset
99 return 0;
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
100 }
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
101 }
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
102 port = &ptr.sin6->sin6_port;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
103 break;
140
34e47f4addf8 Fix broken test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 135
diff changeset
104
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
105 default:
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
106 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
107 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_add_merge Address family was unknown, not added.");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
108 }
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
109 return 0;
133
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
110 }
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
111
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
112 /* remove the ACCEPTALL flag */
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
113 flags &= ~EP_ACCEPTALL;
133
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
114
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 /* Search place in the list */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 for (li = list->next; li != list; li = li->next) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 ep = (struct fd_endpoint *)li;
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
118 in_port_t * ep_port;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
120 /* First, compare the address family */
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
121 if (ep->sa.sa_family < sa->sa_family)
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
122 continue;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
123 if (ep->sa.sa_family > sa->sa_family)
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124 break;
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
125
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
126 /* Then compare the address field */
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
127 switch (sa->sa_family) {
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
128 case AF_INET:
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
129 cmp = memcmp(&ep->sin.sin_addr, &ptr.sin->sin_addr, sizeof(struct in_addr));
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
130 ep_port = &ep->sin.sin_port;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
131 break;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
132 case AF_INET6:
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
133 cmp = memcmp(&ep->sin6.sin6_addr, &ptr.sin6->sin6_addr, sizeof(struct in6_addr));
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
134 ep_port = &ep->sin6.sin6_port;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
135 break;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
136 default:
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
137 ASSERT( 0 ); /* we got a different value previously in this same function */
210
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
138 }
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
139 if (cmp < 0)
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
140 continue;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
141 if (cmp > 0)
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
142 break;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
143
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
144 /* Finally compare the port, only if not 0 */
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
145 if (*port == 0)
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
146 break;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
147 if (*ep_port == 0) {
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
148 /* save the port information in the list, and break */
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
149 *ep_port = *port;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
150 break;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
151 }
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
152 if (*ep_port < *port)
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
153 continue;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
154 if (*ep_port > *port)
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
155 cmp = 1;
2b5027949f85 Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 178
diff changeset
156 break;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 if (cmp) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160 /* new item to be added */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 CHECK_MALLOC( ep = malloc(sizeof(struct fd_endpoint)) );
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 memset(ep, 0, sizeof(struct fd_endpoint));
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 fd_list_init(&ep->chain, NULL);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 memcpy(&ep->ss, sa, sl);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 /* Insert in the list */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 fd_list_insert_before(li, &ep->chain);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170 /* Merge the flags */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 ep->flags |= flags;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
173 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
174 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_add_merge New list:");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
175 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
176 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 return 0;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 /* Delete endpoints that do not have a matching flag from a list (0: delete all endpoints) */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 int fd_ep_filter( struct fd_list * list, uint32_t flags )
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 struct fd_list * li;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 TRACE_ENTRY("%p %x", list, flags);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186 CHECK_PARAMS(list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
188 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
189 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_filter Filter this list for flags %x:", flags);
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
190 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
191 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192 for (li = list->next; li != list; li = li->next) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 struct fd_endpoint * ep = (struct fd_endpoint *)li;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 if (! (ep->flags & flags)) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 li = li->prev;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 fd_list_unlink(&ep->chain);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198 free(ep);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
202 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
203 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_filter Resulting list:");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
204 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
205 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
206 return 0;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
209 /* Keep only endpoints of the same family as af */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
210 int fd_ep_filter_family( struct fd_list * list, int af )
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
211 {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
212 struct fd_list * li;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
213
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
214 TRACE_ENTRY("%p %d", list, af);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
215 CHECK_PARAMS(list);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
216
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
217 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
218 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_filter_family Filter this list for family %d:", af);
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
219 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
220 }
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
221 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
222 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
223
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
224 if (ep->sa.sa_family != af) {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
225 li = li->prev;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
226 fd_list_unlink(&ep->chain);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
227 free(ep);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
228 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
229 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
230
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
231 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
232 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_filter_family Resulting list:");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
233 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
234 }
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
235 return 0;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
236 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
237
379
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
238 /* Remove any endpoint from the exclude list in the list */
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
239 int fd_ep_filter_list( struct fd_list * list, struct fd_list * exclude_list )
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
240 {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
241 struct fd_list * li_out, *li_ex, *li;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
242 struct fd_endpoint * out, * ex;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
243
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
244 TRACE_ENTRY("%p %p", list, exclude_list);
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
245 CHECK_PARAMS(list && exclude_list);
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
246
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
247 /* initialize. Both lists are ordered */
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
248 li_out = list->next;
383
535b516d875d Fix broken function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 382
diff changeset
249 li_ex = exclude_list->next;
379
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
250
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
251 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
252 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_filter_list Filter this list ");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
253 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
254 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_filter_list Removing from list");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
255 fd_ep_dump( 6, exclude_list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
256 }
379
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
257 /* Now browse both lists in parallel */
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
258 while ((li_out != list) && (li_ex != exclude_list)) {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
259 int cmp;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
260
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
261 out = (struct fd_endpoint *)li_out;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
262 ex = (struct fd_endpoint *)li_ex;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
263
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
264 /* Compare the next elements families */
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
265 if (out->sa.sa_family < ex->sa.sa_family) {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
266 li_out = li_out->next;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
267 continue;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
268 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
269 if (out->sa.sa_family > ex->sa.sa_family) {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
270 li_ex = li_ex->next;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
271 continue;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
272 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
273
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
274 /* Then compare the address fields */
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
275 switch (out->sa.sa_family) {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
276 case AF_INET:
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
277 cmp = memcmp(&out->sin.sin_addr, &ex->sin.sin_addr, sizeof(struct in_addr));
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
278 break;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
279 case AF_INET6:
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
280 cmp = memcmp(&out->sin6.sin6_addr, &ex->sin6.sin6_addr, sizeof(struct in6_addr));
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
281 break;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
282 default:
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
283 /* Filter this out */
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
284 cmp = 0;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
285 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
286 if (cmp < 0) {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
287 li_out = li_out->next;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
288 continue;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
289 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
290 if (cmp > 0) {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
291 li_ex = li_ex->next;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
292 continue;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
293 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
294
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
295 /* We remove this element then loop */
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
296 li = li_out;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
297 li_out = li->next;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
298 fd_list_unlink(li);
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
299 free(li);
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
300 }
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
301
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
302 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
303 TRACE_DEBUG(ANNOYING, " DEBUG:fd_ep_filter_list Resulting list:");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
304 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
305 }
379
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
306 return 0;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
307
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
308 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
309
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
310
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
311 /* Reset the given flag(s) from all items in the list */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
312 int fd_ep_clearflags( struct fd_list * list, uint32_t flags )
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
313 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
314 struct fd_list * li;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
315
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
316 TRACE_ENTRY("%p %x", list, flags);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
317 CHECK_PARAMS(list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
318
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
319 for (li = list->next; li != list; li = li->next) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
320 struct fd_endpoint * ep = (struct fd_endpoint *)li;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
321 ep->flags &= ~flags;
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
322 if (ep->flags == 0) {
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
323 li = li->prev;
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
324 fd_list_unlink(&ep->chain);
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
325 free(ep);
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
326 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
327 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
328
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
329 return 0;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
330 }
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
331
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
332 void fd_ep_dump_one( char * prefix, struct fd_endpoint * ep, char * suffix )
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
333 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
334 if (prefix)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
335 fd_log_debug("%s", prefix);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
336
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
337 sSA_DUMP_NODE_SERV( &ep->sa, NI_NUMERICHOST | NI_NUMERICSERV );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
338 fd_log_debug(" {%s%s%s%s}",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
339 (ep->flags & EP_FL_CONF) ? "C" : "-",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
340 (ep->flags & EP_FL_DISC) ? "D" : "-",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
341 (ep->flags & EP_FL_ADV) ? "A" : "-",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
342 (ep->flags & EP_FL_LL) ? "L" : "-",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
343 (ep->flags & EP_FL_PRIMARY) ? "P" : "-");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
344 if (suffix)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
345 fd_log_debug("%s", suffix);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
346 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
347
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
348 void fd_ep_dump( int indent, struct fd_list * eps )
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
349 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
350 struct fd_list * li;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
351 for (li = eps->next; li != eps; li = li->next) {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
352 struct fd_endpoint * ep = (struct fd_endpoint *)li;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
353 fd_log_debug("%*s", indent, "");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
354 fd_ep_dump_one( NULL, ep, "\n" );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
355 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
356 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
357
"Welcome to our mercurial repository"