Mercurial > hg > freeDiameter
annotate freeDiameter/p_cnx.c @ 39:d7535cf7bab5
Added initiator connection logic
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 05 Nov 2009 18:43:42 +0900 |
parents | 68c1890f7049 |
children | 2db15632a63d |
rev | line source |
---|---|
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
5 * Copyright (c) 2009, WIDE Project and NICT * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
cc3c59fe98fe
Lot of cleanups in peer structure management
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 * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
cc3c59fe98fe
Lot of cleanups in peer structure management
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 * |
cc3c59fe98fe
Lot of cleanups in peer structure management
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 * |
cc3c59fe98fe
Lot of cleanups in peer structure management
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 * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
cc3c59fe98fe
Lot of cleanups in peer structure management
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 * |
cc3c59fe98fe
Lot of cleanups in peer structure management
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 * |
cc3c59fe98fe
Lot of cleanups in peer structure management
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 * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 #include "fD.h" |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
38 /* This file contains code used by a peer state machine to initiate a connection to remote peer */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
39 |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
40 struct next_conn { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
41 struct fd_list chain; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
42 int proto; /* Protocol of the next attempt */ |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
43 union { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
44 sSS ss; /* The address, only for TCP */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
45 sSA4 sin; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
46 sSA6 sin6; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
47 }; |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
48 uint16_t port; /* The port, for SCTP (included in ss for TCP) */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
49 int dotls; /* Handshake TLS after connection ? */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
50 }; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
51 |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
52 static __inline__ void failed_connection_attempt(struct fd_peer * peer) |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
53 { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
54 /* Simply remove the first item in the list */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
55 struct fd_list * li = peer->p_connparams.next; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
56 fd_list_unlink(li); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
57 free(li); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
58 } |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
59 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
60 static void empty_connection_list(struct fd_peer * peer) |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
61 { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
62 /* Remove all items */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
63 while (!FD_IS_LIST_EMPTY(&peer->p_connparams)) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
64 failed_connection_attempt(peer); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
65 } |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
66 } |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
67 |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
68 static int prepare_connection_list(struct fd_peer * peer) |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
69 { |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
70 struct fd_list * li, *last_prio; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
71 struct next_conn * new; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
72 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
73 uint16_t port_no; /* network order */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
74 int dotls_immediate; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
75 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
76 TRACE_ENTRY("%p", peer); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
77 |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
78 /* Resolve peer address(es) if needed */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
79 if (FD_IS_LIST_EMPTY(&peer->p_hdr.info.pi_endpoints)) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
80 struct addrinfo hints, *ai, *aip; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
81 int ret; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
82 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
83 memset(&hints, 0, sizeof(hints)); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
84 hints.ai_flags = AI_ADDRCONFIG; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
85 ret = getaddrinfo(peer->p_hdr.info.pi_diamid, NULL, &hints, &ai); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
86 if (ret) { |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
87 fd_log_debug("Unable to resolve address for peer '%s' (%s), aborting\n", peer->p_hdr.info.pi_diamid, gai_strerror(ret)); |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
88 fd_psm_terminate( peer ); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
89 return 0; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
90 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
91 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
92 for (aip = ai; aip != NULL; aip = aip->ai_next) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
93 CHECK_FCT( fd_ep_add_merge( &peer->p_hdr.info.pi_endpoints, aip->ai_addr, aip->ai_addrlen, EP_FL_DISC ) ); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
94 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
95 freeaddrinfo(ai); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
96 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
97 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
98 /* Remove addresses from unwanted family */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
99 if (peer->p_hdr.info.config.pic_flags.pro3) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
100 CHECK_FCT( fd_ep_filter_family( |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
101 &peer->p_hdr.info.pi_endpoints, |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
102 (peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_IP) ? |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
103 AF_INET |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
104 : AF_INET6)); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
105 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
106 |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
107 /* Now check we have at least one address to attempt */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
108 if (FD_IS_LIST_EMPTY(&peer->p_hdr.info.pi_endpoints)) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
109 fd_log_debug("No address %savailable to connect to peer '%s', aborting\n", peer->p_hdr.info.config.pic_flags.pro3 ? "in the configured family " : "", peer->p_hdr.info.pi_diamid); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
110 fd_psm_terminate( peer ); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
111 return 0; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
112 } |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
113 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
114 /* Cleanup any previous list */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
115 empty_connection_list(peer); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
116 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
117 /* Prepare the parameters */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
118 if (peer->p_hdr.info.config.pic_flags.sec != PI_SEC_DEFAULT) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
119 dotls_immediate = 0; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
120 port_no = htons(peer->p_hdr.info.config.pic_port ?: fd_g_config->cnf_port); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
121 } else { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
122 dotls_immediate = 1; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
123 port_no = htons(peer->p_hdr.info.config.pic_port ?: fd_g_config->cnf_port_tls); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
124 } |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
125 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
126 last_prio = &peer->p_connparams; |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
127 |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
128 /* Create TCP parameters unless specified otherwise */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
129 if (peer->p_hdr.info.config.pic_flags.pro4 != PI_P4_SCTP) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
130 for (li = peer->p_hdr.info.pi_endpoints.next; li != &peer->p_hdr.info.pi_endpoints; li = li->next) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
131 struct fd_endpoint * ep = (struct fd_endpoint *)li; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
132 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
133 CHECK_MALLOC( new = malloc(sizeof(struct next_conn)) ); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
134 memset(new, 0, sizeof(struct next_conn)); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
135 fd_list_init(&new->chain, new); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
136 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
137 new->proto = IPPROTO_TCP; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
138 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
139 memcpy( &new->ss, &ep->ss, sizeof(sSS) ); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
140 switch (new->ss.ss_family) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
141 case AF_INET: |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
142 new->sin.sin_port = port_no; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
143 break; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
144 case AF_INET6: |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
145 new->sin6.sin6_port = port_no; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
146 break; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
147 default: |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
148 free(new); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
149 continue; /* Move to the next endpoint */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
150 } |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
151 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
152 new->dotls = dotls_immediate; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
153 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
154 /* Add the new entry to the appropriate position (conf and disc go first) */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
155 if (ep->flags & (EP_FL_CONF | EP_FL_DISC)) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
156 fd_list_insert_after(last_prio, &new->chain); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
157 last_prio = &new->chain; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
158 } else { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
159 fd_list_insert_before(&peer->p_connparams, &new->chain); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
160 } |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
161 } |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
162 } |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
163 |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
164 /* Now, add the SCTP entry, if not disabled */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
165 #ifndef DISABLE_SCTP |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
166 if (peer->p_hdr.info.config.pic_flags.pro4 != PI_P4_TCP) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
167 struct next_conn * new; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
168 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
169 CHECK_MALLOC( new = malloc(sizeof(struct next_conn)) ); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
170 memset(new, 0, sizeof(struct next_conn)); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
171 fd_list_init(&new->chain, new); |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
172 |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
173 new->proto = IPPROTO_SCTP; |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
174 new->port = ntohs(port_no); /* back to host byte order... */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
175 new->dotls = dotls_immediate; |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
176 |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
177 /* Add the new entry to the appropriate position (depending on preferences) */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
178 if (peer->p_hdr.info.config.pic_flags.alg == PI_ALGPREF_TCP) { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
179 fd_list_insert_after(last_prio, &new->chain); |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
180 } else { |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
181 fd_list_insert_after(&peer->p_connparams, &new->chain); /* very first position */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
182 } |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
183 } |
39
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
184 #endif /* DISABLE_SCTP */ |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
185 |
d7535cf7bab5
Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
186 return FD_IS_LIST_EMPTY(&peer->p_connparams) ? EINVAL : 0; |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
187 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
188 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
189 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
190 /* The thread that attempts the connection */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
191 static void * connect_thr(void * arg) |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
192 { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
193 struct fd_peer * peer = arg; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
194 struct cnxctx * cnx = NULL; |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
195 struct next_conn * nc = NULL; |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
196 |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
197 TRACE_ENTRY("%p", arg); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
198 CHECK_PARAMS_DO( CHECK_PEER(peer), return NULL ); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
199 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
200 do { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
201 /* Rebuild the list if needed, if it is empty */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
202 if (FD_IS_LIST_EMPTY(&peer->p_connparams)) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
203 CHECK_FCT_DO( prepare_connection_list(peer), goto fatal_error ); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
204 if (FD_IS_LIST_EMPTY(&peer->p_connparams)) |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
205 /* Already logged and peer terminated */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
206 return NULL; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
207 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
208 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
209 /* Attempt connection to the first entry */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
210 nc = (struct next_conn *)(peer->p_connparams.next); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
211 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
212 switch (nc->proto) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
213 case IPPROTO_TCP: |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
214 cnx = fd_cnx_cli_connect_tcp((sSA *)&nc->ss, sSSlen(&nc->ss)); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
215 break; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
216 #ifndef DISABLE_SCTP |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
217 case IPPROTO_SCTP: |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
218 cnx = fd_cnx_cli_connect_sctp((peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_IP) ?: fd_g_config->cnf_flags.no_ip6, nc->port, &peer->p_hdr.info.pi_endpoints); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
219 break; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
220 #endif /* DISABLE_SCTP */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
221 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
222 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
223 if (cnx) |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
224 break; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
225 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
226 /* Pop these parameters and continue */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
227 failed_connection_attempt(peer); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
228 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
229 pthread_testcancel(); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
230 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
231 } while (!cnx); /* and until cancellation */ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
232 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
233 /* Now, we have an established connection in cnx */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
234 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
235 pthread_cleanup_push((void *)fd_cnx_destroy, cnx); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
236 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
237 /* Handshake if needed (secure port) */ |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
238 if (nc->dotls) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
239 CHECK_FCT_DO( fd_cnx_handshake(cnx, GNUTLS_CLIENT, peer->p_hdr.info.config.pic_priority, NULL), |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
240 { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
241 /* Handshake failed ... */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
242 fd_log_debug("TLS Handshake failed with peer '%s', resetting the connection\n", peer->p_hdr.info.pi_diamid); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
243 fd_cnx_destroy(cnx); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
244 empty_connection_list(peer); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
245 fd_ep_filter(&peer->p_hdr.info.pi_endpoints, EP_FL_CONF); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
246 return NULL; |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
247 } ); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
248 } |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
249 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
250 /* Upon success, generate FDEVP_CNX_ESTABLISHED */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
251 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ESTABLISHED, 0, cnx), goto fatal_error ); |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
252 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
253 pthread_cleanup_pop(0); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
254 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
255 return NULL; |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
256 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
257 fatal_error: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
258 /* Cleanup the connection */ |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
259 if (cnx) |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
260 fd_cnx_destroy(cnx); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
261 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
262 /* Generate a termination event */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
263 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
264 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
265 return NULL; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
266 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
267 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
268 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
269 /* Initiate a connection attempt to a remote peer */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
270 int fd_p_cnx_init(struct fd_peer * peer) |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
271 { |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
272 TRACE_ENTRY("%p", peer); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
273 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
274 /* Start the connect thread */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
275 CHECK_FCT( pthread_create(&peer->p_ini_thr, NULL, connect_thr, peer) ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
276 return 0; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
277 } |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
278 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
279 /* Cancel a connection attempt */ |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
280 void fd_p_cnx_abort(struct fd_peer * peer, int cleanup_all) |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
281 { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
282 TRACE_ENTRY("%p %d", peer, cleanup_all); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
283 CHECK_PARAMS_DO( CHECK_PEER(peer), return ); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
284 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
285 if (peer->p_ini_thr != (pthread_t)NULL) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
286 CHECK_FCT_DO( fd_thr_term(&peer->p_ini_thr), /* continue */); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
287 failed_connection_attempt(peer); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
288 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
289 |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
290 if (cleanup_all) { |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
291 empty_connection_list(peer); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
292 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
293 } |