annotate libfdcore/p_cnx.c @ 1540:407e0a889c7e

SCTP ConnectPeer: sctp_bindx() to local endpoints When connecting to an SCTP peer using sctp_connectx() with local addresses configured with ListenOn, bind to the ListenOn addresses using sctp_bindx() so that the SCTP INIT only contains the configured local addresses, matching what is advertised in the CER, and disable SCTP_AUTO_ASCONF. If no local addresses are configured with ListenOn, the previous behaviour of sctp_connectx() and enable SCTP_AUTO_ASCONF is used.
author Luke Mewburn <luke@mewburn.net>
date Fri, 01 May 2020 18:20:33 +1000
parents 92f33e5ecb77
children 566bb46cc73f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
931
155d45d06530 Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 928
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
37
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
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 379
diff changeset
36 #include "fdcore-internal.h"
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
38
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
39 /* TODO: change the behavior to handle properly forced ordering at beginning & end of OPEN state */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
40
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 /* 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
42
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
43 struct next_conn {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
44 struct fd_list chain;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
45 int proto; /* Protocol of the next attempt */
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
46 union {
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
47 sSS ss; /* The address, only for TCP */
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
48 sSA4 sin;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
49 sSA6 sin6;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
50 };
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
51 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
52 int dotls; /* Handshake TLS after connection ? */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
53 };
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
54
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
55 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
56 {
50
dbba83bafd66 Fix small bug
thedoc@morbier.koganei.wide.ad.jp
parents: 49
diff changeset
57 /* Simply remove the first item in the list if not empty */
dbba83bafd66 Fix small bug
thedoc@morbier.koganei.wide.ad.jp
parents: 49
diff changeset
58 if (! FD_IS_LIST_EMPTY(&peer->p_connparams) ) {
dbba83bafd66 Fix small bug
thedoc@morbier.koganei.wide.ad.jp
parents: 49
diff changeset
59 struct fd_list * li = peer->p_connparams.next;
dbba83bafd66 Fix small bug
thedoc@morbier.koganei.wide.ad.jp
parents: 49
diff changeset
60 fd_list_unlink(li);
dbba83bafd66 Fix small bug
thedoc@morbier.koganei.wide.ad.jp
parents: 49
diff changeset
61 free(li);
dbba83bafd66 Fix small bug
thedoc@morbier.koganei.wide.ad.jp
parents: 49
diff changeset
62 }
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
63 }
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
64
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
65 static void empty_connection_list(struct fd_peer * peer)
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 /* Remove all items */
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
68 while (!FD_IS_LIST_EMPTY(&peer->p_connparams)) {
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
69 failed_connection_attempt(peer);
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
70 }
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
71 }
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
72
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
73 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
74 {
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
75 struct fd_list * li, *last_prio;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
76 struct next_conn * new;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
77
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
78 uint16_t port_no; /* network order */
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
79 int dotls_immediate;
1198
8c4dd4b693c6 Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1190
diff changeset
80 int count = 0;
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
81
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
82 TRACE_ENTRY("%p", peer);
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
83
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
84 /* Resolve peer address(es) if needed */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
85 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
86 struct addrinfo hints, *ai, *aip;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
87 int ret;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
88
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
89 memset(&hints, 0, sizeof(hints));
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
90 hints.ai_flags = AI_ADDRCONFIG;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
91 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
92 if (ret) {
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 931
diff changeset
93 TRACE_DEBUG(INFO, "Unable to resolve address for peer '%s' (%s), aborting", peer->p_hdr.info.pi_diamid, gai_strerror(ret));
370
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
94 if (ret != EAI_AGAIN)
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
95 fd_psm_terminate( peer, NULL );
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
96 return 0;
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
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
99 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
100 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
101 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
102 freeaddrinfo(ai);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
103 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
104
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
105 /* Remove addresses from unwanted family */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
106 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
107 CHECK_FCT( fd_ep_filter_family(
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
108 &peer->p_hdr.info.pi_endpoints,
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
109 (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
110 AF_INET
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
111 : AF_INET6));
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
112 }
370
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
113 if (fd_g_config->cnf_flags.no_ip4) {
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
114 CHECK_FCT( fd_ep_filter_family(
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
115 &peer->p_hdr.info.pi_endpoints,
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
116 AF_INET6));
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
117 }
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
118 if (fd_g_config->cnf_flags.no_ip6) {
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
119 CHECK_FCT( fd_ep_filter_family(
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
120 &peer->p_hdr.info.pi_endpoints,
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
121 AF_INET));
06692259d788 Enforce address family from config when connecting to a peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
122 }
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
123
1203
92f33e5ecb77 Do not attempt connecting to addresses advertised by the remote peer during CER/CEA. This creates issues when e.g. local addresses are advertized. Diameter RFC specifies that these addresses are for the purpose of validating the incoming packets, which is not very useful considering we have reliable lower layer (TLS or IPsec).
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
124 /* We don't use the alternate addresses that were sent by the remote peer */
92f33e5ecb77 Do not attempt connecting to addresses advertised by the remote peer during CER/CEA. This creates issues when e.g. local addresses are advertized. Diameter RFC specifies that these addresses are for the purpose of validating the incoming packets, which is not very useful considering we have reliable lower layer (TLS or IPsec).
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
125 CHECK_FCT( fd_ep_clearflags(&peer->p_hdr.info.pi_endpoints, EP_FL_ADV) );
92f33e5ecb77 Do not attempt connecting to addresses advertised by the remote peer during CER/CEA. This creates issues when e.g. local addresses are advertized. Diameter RFC specifies that these addresses are for the purpose of validating the incoming packets, which is not very useful considering we have reliable lower layer (TLS or IPsec).
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
126
92f33e5ecb77 Do not attempt connecting to addresses advertised by the remote peer during CER/CEA. This creates issues when e.g. local addresses are advertized. Diameter RFC specifies that these addresses are for the purpose of validating the incoming packets, which is not very useful considering we have reliable lower layer (TLS or IPsec).
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1198
diff changeset
127
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
128 /* 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
129 if (FD_IS_LIST_EMPTY(&peer->p_hdr.info.pi_endpoints)) {
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 931
diff changeset
130 TRACE_DEBUG(INFO, "No address %savailable to connect to peer '%s', aborting",
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
131 peer->p_hdr.info.config.pic_flags.pro3 ? "in the configured family " : "", peer->p_hdr.info.pi_diamid);
78
a58f0757c06a Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 70
diff changeset
132 fd_psm_terminate( peer, NULL );
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
133 return 0;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
134 }
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
135
1155
d00b5914351e Allow running freeDiameter without TLS credentials if the following conditions are verified:
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1136
diff changeset
136 /* Check if we are able to communicate with this peer */
d00b5914351e Allow running freeDiameter without TLS credentials if the following conditions are verified:
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1136
diff changeset
137 if (fd_g_config->cnf_sec_data.tls_disabled && ( peer->p_hdr.info.config.pic_flags.sec != PI_SEC_NONE)) {
d00b5914351e Allow running freeDiameter without TLS credentials if the following conditions are verified:
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1136
diff changeset
138 LOG_E("Peer '%s' not configured for No_TLS and TLS is locally disabled; giving up connection attempts",
d00b5914351e Allow running freeDiameter without TLS credentials if the following conditions are verified:
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1136
diff changeset
139 peer->p_hdr.info.pi_diamid);
d00b5914351e Allow running freeDiameter without TLS credentials if the following conditions are verified:
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1136
diff changeset
140 fd_psm_terminate( peer, NULL );
d00b5914351e Allow running freeDiameter without TLS credentials if the following conditions are verified:
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1136
diff changeset
141 return 0;
d00b5914351e Allow running freeDiameter without TLS credentials if the following conditions are verified:
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1136
diff changeset
142 }
d00b5914351e Allow running freeDiameter without TLS credentials if the following conditions are verified:
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1136
diff changeset
143
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
144 /* Cleanup any previous list */
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
145 empty_connection_list(peer);
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
146
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
147 /* Prepare the parameters */
372
2687aa506ef6 Enforce TLS_OLD mechanism from configuration
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 370
diff changeset
148 if ((peer->p_hdr.info.config.pic_flags.sec != PI_SEC_DEFAULT) || (fd_g_config->cnf_flags.tls_alg)) {
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
149 dotls_immediate = 0;
897
d8d0772586ad Use correct default port for outgoing connections even when local port is not the default one
Sebastien Decugis <sdecugis@freediameter.net>
parents: 765
diff changeset
150 port_no = htons(peer->p_hdr.info.config.pic_port ?: DIAMETER_PORT);
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
151 } else {
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
152 dotls_immediate = 1;
897
d8d0772586ad Use correct default port for outgoing connections even when local port is not the default one
Sebastien Decugis <sdecugis@freediameter.net>
parents: 765
diff changeset
153 port_no = htons(peer->p_hdr.info.config.pic_port ?: DIAMETER_SECURE_PORT);
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
154 }
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
155
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
156 last_prio = &peer->p_connparams;
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
157
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
158 /* Create TCP parameters unless specified otherwise */
64
bb45a8ffec77 Enforce configuration flags for new outgoing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 50
diff changeset
159 if ((!fd_g_config->cnf_flags.no_tcp) && (peer->p_hdr.info.config.pic_flags.pro4 != PI_P4_SCTP)) {
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
160 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
161 struct fd_endpoint * ep = (struct fd_endpoint *)li;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
162
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
163 CHECK_MALLOC( new = malloc(sizeof(struct next_conn)) );
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
164 memset(new, 0, sizeof(struct next_conn));
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
165 fd_list_init(&new->chain, new);
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
166
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
167 new->proto = IPPROTO_TCP;
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 memcpy( &new->ss, &ep->ss, sizeof(sSS) );
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
170 switch (new->ss.ss_family) {
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
171 case AF_INET:
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
172 new->sin.sin_port = port_no;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
173 break;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
174 case AF_INET6:
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
175 new->sin6.sin6_port = port_no;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
176 break;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
177 default:
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
178 free(new);
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
179 continue; /* Move to the next endpoint */
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
180 }
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
181
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
182 new->dotls = dotls_immediate;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
183
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
184 /* 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
185 if (ep->flags & (EP_FL_CONF | EP_FL_DISC)) {
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
186 fd_list_insert_after(last_prio, &new->chain);
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
187 last_prio = &new->chain;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
188 } else {
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
189 fd_list_insert_before(&peer->p_connparams, &new->chain);
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
190 }
1198
8c4dd4b693c6 Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1190
diff changeset
191 count++;
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
192 }
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
193 }
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
194
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
195 /* Now, add the SCTP entry, if not disabled */
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
196 #ifndef DISABLE_SCTP
64
bb45a8ffec77 Enforce configuration flags for new outgoing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 50
diff changeset
197 if ((!fd_g_config->cnf_flags.no_sctp) && (peer->p_hdr.info.config.pic_flags.pro4 != PI_P4_TCP)) {
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
198 struct next_conn * new;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
199
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
200 CHECK_MALLOC( new = malloc(sizeof(struct next_conn)) );
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
201 memset(new, 0, sizeof(struct next_conn));
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
202 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
203
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
204 new->proto = IPPROTO_SCTP;
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
205 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
206 new->dotls = dotls_immediate;
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
207
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
208 /* Add the new entry to the appropriate position (depending on preferences) */
374
8f4ae09bc7c3 Enforce the TCP preference from config also
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 372
diff changeset
209 if ((fd_g_config->cnf_flags.pr_tcp) || (peer->p_hdr.info.config.pic_flags.alg == PI_ALGPREF_TCP)) {
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
210 fd_list_insert_after(last_prio, &new->chain);
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
211 } else {
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
212 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
213 }
1198
8c4dd4b693c6 Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1190
diff changeset
214 count++;
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
215 }
39
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
216 #endif /* DISABLE_SCTP */
d7535cf7bab5 Added initiator connection logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 38
diff changeset
217
1198
8c4dd4b693c6 Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1190
diff changeset
218 LOG_D("Prepared %d sets of connection parameters to peer %s", count, peer->p_hdr.info.pi_diamid);
8c4dd4b693c6 Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1190
diff changeset
219
375
40507b3750da No need to return an error there
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 374
diff changeset
220 return 0;
38
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
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224 /* The thread that attempts the connection */
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 static void * connect_thr(void * arg)
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226 {
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227 struct fd_peer * peer = arg;
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 struct cnxctx * cnx = NULL;
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
229 struct next_conn * nc = NULL;
49
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
230 int rebuilt = 0;
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
231 int fatal_error=0;
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
233 TRACE_ENTRY("%p", arg);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
234 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
235
49
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
236 /* Set the thread name */
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
237 {
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
238 char buf[48];
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
239 snprintf(buf, sizeof(buf), "ConnTo:%s", peer->p_hdr.info.pi_diamid);
49
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
240 fd_log_threadname ( buf );
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
241 }
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
242
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
243 do {
49
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
244 /* Rebuild the list if needed, if it is empty -- but at most once */
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
245 if (FD_IS_LIST_EMPTY(&peer->p_connparams)) {
49
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
246 if (! rebuilt) {
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
247 CHECK_FCT_DO( fatal_error = prepare_connection_list(peer), goto out );
49
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
248 rebuilt ++;
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
249 }
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
250 if (FD_IS_LIST_EMPTY(&peer->p_connparams)) {
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
251 /* We encountered an error or we have looped over all the addresses of the peer. */
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
252 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, peer, "All connection attempts failed, will retry later", NULL);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
253
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
254 CHECK_FCT_DO( fatal_error = fd_event_send(peer->p_events, FDEVP_CNX_FAILED, 0, NULL), goto out );
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
255 return NULL;
49
204718b0fa54 Couple of fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
256 }
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
257 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
258
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
259 /* Attempt connection to the first entry */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
260 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
261
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
262 switch (nc->proto) {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
263 case IPPROTO_TCP:
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1203
diff changeset
264 /* TODO: use no_bind and first of cnf_endpoints of nc->ss.sa_family ? */
246
6418a188c1b5 getnameinfo is also more sensitive on freeBSD
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
265 cnx = fd_cnx_cli_connect_tcp((sSA *)&nc->ss, sSAlen(&nc->ss));
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
266 break;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
267 #ifndef DISABLE_SCTP
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
268 case IPPROTO_SCTP:
765
edbdb35a603f Fix a few compilation warning, some are still remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
269 cnx = fd_cnx_cli_connect_sctp((peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_IP) ? 1 : fd_g_config->cnf_flags.no_ip6,
1540
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1203
diff changeset
270 nc->port, &peer->p_hdr.info.pi_endpoints,
407e0a889c7e SCTP ConnectPeer: sctp_bindx() to local endpoints
Luke Mewburn <luke@mewburn.net>
parents: 1203
diff changeset
271 fd_g_config->cnf_flags.no_bind ? NULL : &fd_g_config->cnf_endpoints);
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
272 break;
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
273 #endif /* DISABLE_SCTP */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
274 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
275
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
276 if (cnx)
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
277 break;
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 /* Pop these parameters and continue */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
280 failed_connection_attempt(peer);
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 pthread_testcancel();
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
283
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
284 } while (!cnx); /* and until cancellation or all addresses attempted without success */
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
285
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
286 /* 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
287
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
288 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
289
219
e5bcc8c9322e Add hostname verification
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 136
diff changeset
290 /* Set the hostname in the connection, so that handshake verifies the remote identity */
e5bcc8c9322e Add hostname verification
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 136
diff changeset
291 fd_cnx_sethostname(cnx,peer->p_hdr.info.pi_diamid);
e5bcc8c9322e Add hostname verification
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 136
diff changeset
292
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
293 /* Handshake if needed (secure port) */
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
294 if (nc->dotls) {
1181
22de21feec64 Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1155
diff changeset
295 CHECK_FCT_DO( fd_cnx_handshake(cnx, GNUTLS_CLIENT,
1187
436e4342ecd0 Rollback to using TLS/SCTP in release 1.2.0. DTLS dev to happen in freeDiameter-dtls branch
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
296 ALGO_HANDSHAKE_3436,
1181
22de21feec64 Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1155
diff changeset
297 peer->p_hdr.info.config.pic_priority, NULL),
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
298 {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
299 /* Handshake failed ... */
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
300 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, peer, "TLS Handshake failed", NULL);
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
301 fd_cnx_destroy(cnx);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
302 empty_connection_list(peer);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
303 fd_ep_filter(&peer->p_hdr.info.pi_endpoints, EP_FL_CONF);
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
304 goto out_pop;
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
305 } );
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
306 LOG_A("%s: TLS handshake successful.", peer->p_hdr.info.pi_diamid);
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 39
diff changeset
307 } else {
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 39
diff changeset
308 /* Prepare to receive the next message */
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
309 CHECK_FCT_DO( fatal_error = fd_cnx_start_clear(cnx, 0), goto out_pop );
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
310 }
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
311
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
312 /* Upon success, generate FDEVP_CNX_ESTABLISHED */
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
313 CHECK_FCT_DO( fatal_error = fd_event_send(peer->p_events, FDEVP_CNX_ESTABLISHED, 0, cnx), );
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
314 out_pop:
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
315 ;
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
316 pthread_cleanup_pop(0);
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
317
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
318 out:
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
319
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
320 if (fatal_error) {
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
321
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
322 /* Cleanup the connection */
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
323 if (cnx)
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
324 fd_cnx_destroy(cnx);
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
325
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
326 /* Generate a termination event */
1190
6a1042d8075b Replace FDEV_TERMINATE events with calls to fd_core_shutdown to handle the core state properly
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1187
diff changeset
327 CHECK_FCT_DO(fd_core_shutdown(), );
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
328 }
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
329
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
330 return NULL;
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
331 }
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
332
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
333
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
334 /* 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
335 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
336 {
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
337 TRACE_ENTRY("%p", peer);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
338
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
339 /* Start the connect thread */
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
340 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
341 return 0;
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
342 }
38
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
343
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
344 /* Cancel a connection attempt */
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
345 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
346 {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
347 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
348 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
349
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
350 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
351 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
352 failed_connection_attempt(peer);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
353 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
354
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
355 if (cleanup_all) {
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
356 empty_connection_list(peer);
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
357 }
68c1890f7049 Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
358 }
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1181
diff changeset
359
"Welcome to our mercurial repository"