Mercurial > hg > freeDiameter
annotate freeDiameter/endpoints.c @ 559:85ba85b4739c
Cleanups
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 15 Sep 2010 18:35:31 +0900 |
parents | 16224de837fd |
children | 237cf6339546 |
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) |
512
16224de837fd
Fix problem reported by ????? ????????? on dev@freediameter.net
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
383
diff
changeset
|
76 /* the next one filters both EXPERIMENTAL, BADCLASS and MULTICAST. */ |
559 | 77 || ((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
|
78 || (ptr.sin->sin_addr.s_addr == INADDR_BROADCAST)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
79 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
80 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
|
81 } |
140 | 82 return 0; |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
83 } |
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
|
84 } |
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 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
|
86 break; |
140 | 87 |
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
|
88 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
|
89 if (! (flags & EP_ACCEPTALL)) { |
178
a32646b7e7d7
Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
140
diff
changeset
|
90 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
|
91 || 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
|
92 || 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
|
93 || 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
|
94 || IN6_IS_ADDR_SITELOCAL(&ptr.sin6->sin6_addr)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
95 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
96 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
|
97 } |
140 | 98 return 0; |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
99 } |
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
|
100 } |
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 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
|
102 break; |
140 | 103 |
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
|
104 default: |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
105 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
106 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
|
107 } |
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
|
108 return 0; |
133
5a21124536b4
Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
109 } |
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
|
110 |
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 /* 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
|
112 flags &= ~EP_ACCEPTALL; |
133
5a21124536b4
Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
113 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
114 /* Search place in the list */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
115 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
|
116 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
|
117 in_port_t * ep_port; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
118 |
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
|
119 /* 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 |
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 /* 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 default: |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
136 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
|
137 } |
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 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
|
139 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
|
140 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
|
141 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
|
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 /* 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
|
144 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
|
145 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
|
146 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
|
147 /* 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
|
148 *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
|
149 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
|
150 } |
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 < *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
|
152 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
|
153 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
|
154 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
|
155 break; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
156 } |
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 if (cmp) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
159 /* new item to be added */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
160 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
|
161 memset(ep, 0, sizeof(struct fd_endpoint)); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
162 fd_list_init(&ep->chain, NULL); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
163 memcpy(&ep->ss, sa, sl); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
164 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
165 /* Insert in the list */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
166 fd_list_insert_before(li, &ep->chain); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
167 } |
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 /* Merge the flags */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
170 ep->flags |= flags; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
171 |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
172 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
173 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
|
174 fd_ep_dump( 4, list ); |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
175 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
176 return 0; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
177 } |
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 /* 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
|
180 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
|
181 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
182 struct fd_list * li; |
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 TRACE_ENTRY("%p %x", list, flags); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
185 CHECK_PARAMS(list); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
186 |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
187 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
188 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
|
189 fd_ep_dump( 4, list ); |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
190 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
191 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
|
192 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
|
193 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
194 if (! (ep->flags & flags)) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
195 li = li->prev; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
196 fd_list_unlink(&ep->chain); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
197 free(ep); |
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 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
200 |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
201 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
202 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
|
203 fd_ep_dump( 4, list ); |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
204 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
205 return 0; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
206 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
207 |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
208 /* 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
|
209 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
|
210 { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
211 struct fd_list * li; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
212 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
213 TRACE_ENTRY("%p %d", list, af); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
214 CHECK_PARAMS(list); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
215 |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
216 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
217 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
|
218 fd_ep_dump( 4, list ); |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
219 } |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
220 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
|
221 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
|
222 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
223 if (ep->sa.sa_family != af) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
224 li = li->prev; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
225 fd_list_unlink(&ep->chain); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
226 free(ep); |
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 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
229 |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
230 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
231 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
|
232 fd_ep_dump( 4, list ); |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
233 } |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
234 return 0; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
235 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
236 |
379
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
237 /* 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
|
238 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
|
239 { |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
240 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
|
241 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
|
242 |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
243 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
|
244 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
|
245 |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
246 /* 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
|
247 li_out = list->next; |
383
535b516d875d
Fix broken function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
382
diff
changeset
|
248 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
|
249 |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
250 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
251 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
|
252 fd_ep_dump( 4, list ); |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
253 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
|
254 fd_ep_dump( 6, exclude_list ); |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
255 } |
379
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
256 /* 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
|
257 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
|
258 int cmp; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
259 |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
260 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
|
261 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
|
262 |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
263 /* 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
|
264 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
|
265 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
|
266 continue; |
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 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
|
269 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
|
270 continue; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
271 } |
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 /* 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
|
274 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
|
275 case AF_INET: |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
276 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
|
277 break; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
278 case AF_INET6: |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
279 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
|
280 break; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
281 default: |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
282 /* Filter this out */ |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
283 cmp = 0; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
284 } |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
285 if (cmp < 0) { |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
286 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
|
287 continue; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
288 } |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
289 if (cmp > 0) { |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
290 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
|
291 continue; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
292 } |
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 /* 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
|
295 li = li_out; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
296 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
|
297 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
|
298 free(li); |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
299 } |
382
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
300 |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
301 if (TRACE_BOOL(ANNOYING + 1)) { |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
302 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
|
303 fd_ep_dump( 4, list ); |
7f042dc6c6e9
Added debug information for endpoints
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
379
diff
changeset
|
304 } |
379
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
305 return 0; |
7337305ee51e
Workaround to prevent peer connecting to itself (ipv6 local addresses)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
306 |
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 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
310 /* 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
|
311 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
|
312 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
313 struct fd_list * li; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
314 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
315 TRACE_ENTRY("%p %x", list, flags); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
316 CHECK_PARAMS(list); |
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 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
|
319 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
|
320 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
|
321 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
|
322 li = li->prev; |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
323 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
|
324 free(ep); |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
325 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
326 } |
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 return 0; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
329 } |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
330 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
331 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
|
332 { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
333 if (prefix) |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
334 fd_log_debug("%s", prefix); |
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 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
|
337 fd_log_debug(" {%s%s%s%s}", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
338 (ep->flags & EP_FL_CONF) ? "C" : "-", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
339 (ep->flags & EP_FL_DISC) ? "D" : "-", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
340 (ep->flags & EP_FL_ADV) ? "A" : "-", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
341 (ep->flags & EP_FL_LL) ? "L" : "-", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
342 (ep->flags & EP_FL_PRIMARY) ? "P" : "-"); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
343 if (suffix) |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
344 fd_log_debug("%s", suffix); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
345 } |
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 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
|
348 { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
349 struct fd_list * li; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
350 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
|
351 struct fd_endpoint * ep = (struct fd_endpoint *)li; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
352 fd_log_debug("%*s", indent, ""); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
353 fd_ep_dump_one( NULL, ep, "\n" ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
354 } |
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 |