annotate libfdcore/endpoints.c @ 662:2e94ef0515d7 1.1.0-rc1

Updated copyright information
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 14 Jan 2011 16:27:21 +0900
parents f198d16fa7f4
children 4a9f08d6b6ba
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 * *
662
2e94ef0515d7 Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 658
diff changeset
5 * Copyright (c) 2011, 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
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 640
diff changeset
36 #include "fdcore-internal.h"
24
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
640
237cf6339546 dbg_interactive almost complete
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 559
diff changeset
55 if (list->next == NULL) {
237cf6339546 dbg_interactive almost complete
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 559
diff changeset
56 /* the list is not initialized yet, do it */
237cf6339546 dbg_interactive almost complete
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 559
diff changeset
57 fd_list_init(list, NULL);
237cf6339546 dbg_interactive almost complete
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 559
diff changeset
58 }
237cf6339546 dbg_interactive almost complete
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 559
diff changeset
59
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
60 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
61 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
62 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
63 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
64 fd_log_debug(" ");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
65 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
66 fd_log_debug(" {%s%s%s%s}\n",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
67 (flags & EP_FL_CONF) ? "C" : "-",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
68 (flags & EP_FL_DISC) ? "D" : "-",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
69 (flags & EP_FL_ADV) ? "A" : "-",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
70 (flags & EP_FL_LL) ? "L" : "-",
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
71 (flags & EP_FL_PRIMARY) ? "P" : "-");
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
72 }
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
73 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
74
178
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
75 /* 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
76 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
77 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
78 if (! (flags & EP_ACCEPTALL)) {
178
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
79 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
80 || IN_IS_ADDR_LOOPBACK(&ptr.sin->sin_addr)
512
16224de837fd Fix problem reported by ????? ????????? on dev@freediameter.net
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 383
diff changeset
81 /* the next one filters both EXPERIMENTAL, BADCLASS and MULTICAST. */
559
85ba85b4739c Cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 512
diff changeset
82 || ((ntohl(ptr.sin->sin_addr.s_addr) & 0xe0000000) == 0xe0000000)
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
83 || (ptr.sin->sin_addr.s_addr == INADDR_BROADCAST)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
84 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
85 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
86 }
140
34e47f4addf8 Fix broken test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 135
diff changeset
87 return 0;
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
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 }
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 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
91 break;
140
34e47f4addf8 Fix broken test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 135
diff changeset
92
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
93 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
94 if (! (flags & EP_ACCEPTALL)) {
178
a32646b7e7d7 Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 140
diff changeset
95 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
96 || 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
97 || 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
98 || 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
99 || IN6_IS_ADDR_SITELOCAL(&ptr.sin6->sin6_addr)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
100 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
101 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
102 }
140
34e47f4addf8 Fix broken test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 135
diff changeset
103 return 0;
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
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 }
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
106 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
107 break;
140
34e47f4addf8 Fix broken test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 135
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 default:
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
110 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
111 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
112 }
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
113 return 0;
133
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
114 }
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
115
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
116 /* 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
117 flags &= ~EP_ACCEPTALL;
133
5a21124536b4 Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
118
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119 /* Search place in the list */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 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
121 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
122 in_port_t * ep_port;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123
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
124 /* 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
125 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
126 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
127 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
128 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
129
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 /* 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
131 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
132 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
133 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
134 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
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 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
137 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
138 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
139 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
140 default:
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
141 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
142 }
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 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
144 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
145 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
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
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 /* 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
149 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
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 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
152 /* 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
153 *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
154 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
155 }
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 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
157 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
158 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
159 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
160 break;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 if (cmp) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 /* new item to be added */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 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
166 memset(ep, 0, sizeof(struct fd_endpoint));
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 fd_list_init(&ep->chain, NULL);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 memcpy(&ep->ss, sa, sl);
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 /* Insert in the list */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 fd_list_insert_before(li, &ep->chain);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
173
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
174 /* Merge the flags */
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175 ep->flags |= flags;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
177 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
178 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
179 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
180 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 return 0;
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
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 /* 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
185 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
186 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 struct fd_list * li;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 TRACE_ENTRY("%p %x", list, flags);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190 CHECK_PARAMS(list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
192 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
193 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
194 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
195 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 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
197 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
198
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 if (! (ep->flags & flags)) {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 li = li->prev;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201 fd_list_unlink(&ep->chain);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202 free(ep);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
203 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
204 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
205
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
206 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
207 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
208 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
209 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 return 0;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
211 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
213 /* 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
214 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
215 {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
216 struct fd_list * li;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
217
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
218 TRACE_ENTRY("%p %d", list, af);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
219 CHECK_PARAMS(list);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
220
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
221 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
222 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
223 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
224 }
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
225 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
226 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
227
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
228 if (ep->sa.sa_family != af) {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
229 li = li->prev;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
230 fd_list_unlink(&ep->chain);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
231 free(ep);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
232 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
233 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
234
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
235 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
236 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
237 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
238 }
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
239 return 0;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
240 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
241
379
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
242 /* 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
243 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
244 {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
245 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
246 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
247
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
248 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
249 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
250
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
251 /* 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
252 li_out = list->next;
383
535b516d875d Fix broken function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 382
diff changeset
253 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
254
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
255 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
256 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
257 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
258 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
259 fd_ep_dump( 6, exclude_list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
260 }
379
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
261 /* 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
262 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
263 int cmp;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
264
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
265 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
266 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
267
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
268 /* 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
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_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
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 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
274 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
275 continue;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
276 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
277
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
278 /* 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
279 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
280 case AF_INET:
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
281 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
282 break;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
283 case AF_INET6:
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
284 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
285 break;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
286 default:
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
287 /* Filter this out */
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
288 cmp = 0;
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_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
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 if (cmp > 0) {
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
295 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
296 continue;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
297 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
298
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
299 /* 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
300 li = li_out;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
301 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
302 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
303 free(li);
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
304 }
382
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
305
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
306 if (TRACE_BOOL(ANNOYING + 1)) {
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
307 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
308 fd_ep_dump( 4, list );
7f042dc6c6e9 Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
309 }
379
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
310 return 0;
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
311
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
312 }
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
313
7337305ee51e Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
314
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
315 /* 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
316 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
317 {
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
318 struct fd_list * li;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
319
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
320 TRACE_ENTRY("%p %x", list, flags);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
321 CHECK_PARAMS(list);
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
322
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
323 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
324 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
325 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
326 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
327 li = li->prev;
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
328 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
329 free(ep);
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
330 }
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
331 }
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
332
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
333 return 0;
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
334 }
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
335
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
336 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
337 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
338 if (prefix)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
339 fd_log_debug("%s", prefix);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
340
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
341 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
342 fd_log_debug(" {%s%s%s%s}",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
343 (ep->flags & EP_FL_CONF) ? "C" : "-",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
344 (ep->flags & EP_FL_DISC) ? "D" : "-",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
345 (ep->flags & EP_FL_ADV) ? "A" : "-",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
346 (ep->flags & EP_FL_LL) ? "L" : "-",
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
347 (ep->flags & EP_FL_PRIMARY) ? "P" : "-");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
348 if (suffix)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
349 fd_log_debug("%s", suffix);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
350 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
351
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
352 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
353 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
354 struct fd_list * li;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
355 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
356 struct fd_endpoint * ep = (struct fd_endpoint *)li;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
357 fd_log_debug("%*s", indent, "");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
358 fd_ep_dump_one( NULL, ep, "\n" );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
359 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
360 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
361
"Welcome to our mercurial repository"