Mercurial > hg > freeDiameter
annotate freeDiameter/endpoints.c @ 210:2b5027949f85
Fix issue where the same address can be added several times in a list
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 16 Feb 2010 16:33:03 +0900 |
parents | a32646b7e7d7 |
children | 5df55136361b |
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 * * |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
5 * Copyright (c) 2009, WIDE Project and NICT * |
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 |
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
|
55 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
|
56 |
178
a32646b7e7d7
Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
140
diff
changeset
|
57 /* 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
|
58 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
|
59 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
|
60 if (! (flags & EP_ACCEPTALL)) { |
178
a32646b7e7d7
Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
140
diff
changeset
|
61 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
|
62 || IN_IS_ADDR_LOOPBACK(&ptr.sin->sin_addr) |
a32646b7e7d7
Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
140
diff
changeset
|
63 || IN_MULTICAST(ptr.sin->sin_addr.s_addr) |
a32646b7e7d7
Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
140
diff
changeset
|
64 || IN_EXPERIMENTAL(ptr.sin->sin_addr.s_addr) |
a32646b7e7d7
Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
140
diff
changeset
|
65 || IN_BADCLASS(ptr.sin->sin_addr.s_addr) |
a32646b7e7d7
Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
140
diff
changeset
|
66 || (ptr.sin->sin_addr.s_addr == INADDR_BROADCAST)) |
140 | 67 return 0; |
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 } |
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 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
|
70 break; |
140 | 71 |
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
|
72 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
|
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 (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
|
75 || 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
|
76 || 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
|
77 || IN6_IS_ADDR_LINKLOCAL(&ptr.sin6->sin6_addr) |
a32646b7e7d7
Filter more addresses out, such as link-local
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
140
diff
changeset
|
78 || IN6_IS_ADDR_SITELOCAL(&ptr.sin6->sin6_addr)) |
140 | 79 return 0; |
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
|
80 } |
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
|
81 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
|
82 break; |
140 | 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 default: |
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 return 0; |
133
5a21124536b4
Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
86 } |
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
|
87 |
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 /* 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
|
89 flags &= ~EP_ACCEPTALL; |
133
5a21124536b4
Fix: remove loopback addresses from lists
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
90 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
91 /* Search place in the list */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
92 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
|
93 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
|
94 in_port_t * ep_port; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
95 |
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
|
96 /* 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 |
2b5027949f85
Fix issue where the same address can be added several times in a list
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
178
diff
changeset
|
102 /* 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 default: |
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 /* Filter this out */ |
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
|
114 return 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
|
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 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
|
117 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
|
118 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
|
119 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
|
120 |
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 /* 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
|
122 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
|
123 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
|
124 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
|
125 /* 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
|
126 *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
|
127 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
|
128 } |
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 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
|
130 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
|
131 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
|
132 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
|
133 break; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
134 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
135 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
136 if (cmp) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
137 /* new item to be added */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
138 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
|
139 memset(ep, 0, sizeof(struct fd_endpoint)); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
140 fd_list_init(&ep->chain, NULL); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
141 memcpy(&ep->ss, sa, sl); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
142 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
143 /* Insert in the list */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
144 fd_list_insert_before(li, &ep->chain); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
145 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
146 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
147 /* Merge the flags */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
148 ep->flags |= flags; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
149 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
150 return 0; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
151 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
152 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
153 /* 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
|
154 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
|
155 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
156 struct fd_list * li; |
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 TRACE_ENTRY("%p %x", list, flags); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
159 CHECK_PARAMS(list); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
160 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
161 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
|
162 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
|
163 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
164 if (! (ep->flags & flags)) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
165 li = li->prev; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
166 fd_list_unlink(&ep->chain); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
167 free(ep); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
168 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
169 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
170 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
171 return 0; |
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 |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
174 /* 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
|
175 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
|
176 { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
177 struct fd_list * li; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
178 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
179 TRACE_ENTRY("%p %d", list, af); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
180 CHECK_PARAMS(list); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
181 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
182 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
|
183 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
|
184 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
185 if (ep->sa.sa_family != af) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
186 li = li->prev; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
187 fd_list_unlink(&ep->chain); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
188 free(ep); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
189 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
190 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
191 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
192 return 0; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
193 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
194 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
195 /* 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
|
196 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
|
197 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
198 struct fd_list * li; |
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 TRACE_ENTRY("%p %x", list, flags); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
201 CHECK_PARAMS(list); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
202 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 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
|
207 li = li->prev; |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
208 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
|
209 free(ep); |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
210 } |
24
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 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
213 return 0; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
214 } |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
215 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
216 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
|
217 { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
218 if (prefix) |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
219 fd_log_debug("%s", prefix); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
220 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
221 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
|
222 fd_log_debug(" {%s%s%s%s}", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
223 (ep->flags & EP_FL_CONF) ? "C" : "-", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
224 (ep->flags & EP_FL_DISC) ? "D" : "-", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
225 (ep->flags & EP_FL_ADV) ? "A" : "-", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
226 (ep->flags & EP_FL_LL) ? "L" : "-", |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
227 (ep->flags & EP_FL_PRIMARY) ? "P" : "-"); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
228 if (suffix) |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
229 fd_log_debug("%s", suffix); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
230 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
231 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
232 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
|
233 { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
234 struct fd_list * li; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
235 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
|
236 struct fd_endpoint * ep = (struct fd_endpoint *)li; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
237 fd_log_debug("%*s", indent, ""); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
238 fd_ep_dump_one( NULL, ep, "\n" ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
239 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
240 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
241 |