Mercurial > hg > freeDiameter
annotate libfdcore/peers.c @ 1517:9e233ef0b07e
Add 3GPP TS 29.283 V15.1.0 (2019-09)
Add AVPs:
- MCPTT-ID, UTF8String, code 4500, section 7.3.2
- Data-Identification, Grouped, code 4501, section 7.3.3
- Data-Identification-Prefix, Unsigned32, code 4502, section 7.3.11
- Data-Identification-Flags, Unsigned64, code 4503, section 7.3.12
- DPR-Flags, Unsigned32, code 4504, section 7.3.13
- DPA-Flags, Unsigned32, code 4505, section 7.3.14
- DUR-Flags, Unsigned32, code 4506, section 7.3.15
- DUA-Flags, Unsigned32, code 4507, section 7.3.16
- NDR-Flags, Unsigned32, code 4508, section 7.3.17
- NDA-Flags, Unsigned32, code 4509, section 7.3.18
- User-Data-Id, Unsigned32, code 4510, section 7.3.19
- MC-Service-User-Profile-Data, Grouped, code 4511, section 7.3.20
- Sequence-Number-29.283, Unsigned32, code 4512, section 7.3.21
- Data, Grouped, code 4513, section 7.3.22
- MCVideo-ID, UTF8String, code 4514, section 7.3.24
- MCData-ID, UTF8String, code 4515, section 7.3.25
Note: Name conflict with 3GPP TS 29.140 Sequence-Number (1107).
and 3GPP TS 29.329 Sequence-Number (716).
3GPP TS 29.140 V6.1.0 (2005-06) allocated Sequence-Number (1107).
3GPP TS 29.329 V10.0.0 (2010-09) CR 0163 added Sequence-Number (716).
3GPP TS 29.283 V13.1.0 (2016-06) allocated Sequence-Number (4512).
Fix: Sequence-Number (4512) renamed to Sequence-Number-29.283 (4512).
author | Luke Mewburn <luke@mewburn.net> |
---|---|
date | Thu, 09 Apr 2020 10:32:09 +1000 |
parents | 603a72c4bf6c |
children | 566bb46cc73f |
rev | line source |
---|---|
11
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
6576ef5e01eb
Added some support for peers
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:
738
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
11
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
928
5053f1abcf5d
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
917
diff
changeset
|
5 * Copyright (c) 2013, WIDE Project and NICT * |
11
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
6576ef5e01eb
Added some support for peers
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 * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
6576ef5e01eb
Added some support for peers
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 * |
6576ef5e01eb
Added some support for peers
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 * |
6576ef5e01eb
Added some support for peers
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 * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
6576ef5e01eb
Added some support for peers
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 * |
6576ef5e01eb
Added some support for peers
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 * |
6576ef5e01eb
Added some support for peers
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 * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
6576ef5e01eb
Added some support for peers
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:
649
diff
changeset
|
36 #include "fdcore-internal.h" |
11
6576ef5e01eb
Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
38 /* Global list of peers */ |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
39 struct fd_list fd_g_peers = FD_LIST_INITIALIZER(fd_g_peers); |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
40 pthread_rwlock_t fd_g_peers_rw = PTHREAD_RWLOCK_INITIALIZER; |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
41 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
42 /* List of active peers */ |
1395
603a72c4bf6c
peers.c: fix typo in comment
Thomas Klausner <tk@giga.or.at>
parents:
1238
diff
changeset
|
43 struct fd_list fd_g_activ_peers = FD_LIST_INITIALIZER(fd_g_activ_peers); /* peers linked by their p_actives ordered by p_diamid */ |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
44 pthread_rwlock_t fd_g_activ_peers_rw = PTHREAD_RWLOCK_INITIALIZER; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
45 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
46 /* List of validation callbacks (registered with fd_peer_validate_register) */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
47 static struct fd_list validators = FD_LIST_INITIALIZER(validators); /* list items are simple fd_list with "o" pointing to the callback */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
48 static pthread_rwlock_t validators_rw = PTHREAD_RWLOCK_INITIALIZER; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
49 |
12
418d2ce80dc8
Added support in configuration file for peers declaration
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
11
diff
changeset
|
50 |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
51 /* Alloc / reinit a peer structure. if *ptr is not NULL, it must already point to a valid struct fd_peer. */ |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
52 int fd_peer_alloc(struct fd_peer ** ptr) |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
53 { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
54 struct fd_peer *p; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
55 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
56 TRACE_ENTRY("%p", ptr); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
57 CHECK_PARAMS(ptr); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
58 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
59 if (*ptr) { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
60 p = *ptr; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
61 } else { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
62 CHECK_MALLOC( p = malloc(sizeof(struct fd_peer)) ); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
63 *ptr = p; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
64 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
65 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
66 /* Now initialize the content */ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
67 memset(p, 0, sizeof(struct fd_peer)); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
68 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
69 fd_list_init(&p->p_hdr.chain, p); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
70 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
71 fd_list_init(&p->p_hdr.info.pi_endpoints, p); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
72 fd_list_init(&p->p_hdr.info.runtime.pir_apps, p); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
73 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
74 p->p_eyec = EYEC_PEER; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
75 CHECK_POSIX( pthread_mutex_init(&p->p_state_mtx, NULL) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
76 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
77 fd_list_init(&p->p_actives, p); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
78 fd_list_init(&p->p_expiry, p); |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
749
diff
changeset
|
79 CHECK_FCT( fd_fifo_new(&p->p_tosend, 5) ); |
1207
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
80 CHECK_FCT( fd_fifo_new(&p->p_tofailover, 0) ); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
81 p->p_hbh = lrand48(); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
82 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
83 fd_list_init(&p->p_sr.srs, p); |
649
5e5d8152c229
Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
454
diff
changeset
|
84 fd_list_init(&p->p_sr.exp, p); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
85 CHECK_POSIX( pthread_mutex_init(&p->p_sr.mtx, NULL) ); |
649
5e5d8152c229
Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
454
diff
changeset
|
86 CHECK_POSIX( pthread_cond_init(&p->p_sr.cnd, NULL) ); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
87 |
48 | 88 fd_list_init(&p->p_connparams, p); |
89 | |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
90 return 0; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
91 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
92 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
93 /* Add a new peer entry */ |
947
cce5d4bace82
Make config file parameter const and convert another fprintf to TRACE_DEBUG_ERROR.
Thomas Klausner <tk@giga.or.at>
parents:
908
diff
changeset
|
94 int fd_peer_add ( struct peer_info * info, const char * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data ) |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
95 { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
96 struct fd_peer *p = NULL; |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
97 struct fd_list * li, *li_inf; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
98 int ret = 0; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
99 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
100 TRACE_ENTRY("%p %p %p %p", info, orig_dbg, cb, cb_data); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
101 CHECK_PARAMS(info && info->pi_diamid); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
102 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
103 if (info->config.pic_realm) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
104 if (!fd_os_is_valid_DiameterIdentity((os0_t)info->config.pic_realm, strlen(info->config.pic_realm))) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
105 TRACE_DEBUG(INFO, "'%s' is not a valid DiameterIdentity.", info->config.pic_realm); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
106 return EINVAL; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
107 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
108 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
109 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
110 /* Create a structure to contain the new peer information */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
111 CHECK_FCT( fd_peer_alloc(&p) ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
112 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
113 /* Copy the informations from the parameters received */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
114 p->p_hdr.info.pi_diamid = info->pi_diamid; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
115 CHECK_FCT( fd_os_validate_DiameterIdentity(&p->p_hdr.info.pi_diamid, &p->p_hdr.info.pi_diamidlen, 1) ); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
116 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
117 memcpy( &p->p_hdr.info.config, &info->config, sizeof(p->p_hdr.info.config) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
118 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
119 /* Duplicate the strings if provided */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
120 if (info->config.pic_realm) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
121 CHECK_MALLOC( p->p_hdr.info.config.pic_realm = strdup(info->config.pic_realm) ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
122 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
123 if (info->config.pic_priority) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
124 CHECK_MALLOC( p->p_hdr.info.config.pic_priority = strdup(info->config.pic_priority) ); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
125 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
126 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
127 /* Move the list of endpoints into the peer */ |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
128 if (info->pi_endpoints.next) |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
129 while (!FD_IS_LIST_EMPTY( &info->pi_endpoints ) ) { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
130 li = info->pi_endpoints.next; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
131 fd_list_unlink(li); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
132 fd_list_insert_before(&p->p_hdr.info.pi_endpoints, li); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
133 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
134 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
135 /* The internal data */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
136 if (orig_dbg) { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
137 CHECK_MALLOC( p->p_dbgorig = strdup(orig_dbg) ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
138 } else { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
139 CHECK_MALLOC( p->p_dbgorig = strdup("unspecified") ); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
140 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
141 p->p_cb = cb; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
142 p->p_cb_data = cb_data; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
143 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
144 /* Ok, now check if we don't already have an entry with the same Diameter Id, and insert this one */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
145 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_peers_rw) ); |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
146 li_inf = &fd_g_peers; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
147 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
148 struct fd_peer * next = (struct fd_peer *)li; |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
149 int cont; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
150 int cmp = fd_os_almostcasesrch( p->p_hdr.info.pi_diamid, p->p_hdr.info.pi_diamidlen, |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
151 next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen, |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
152 &cont ); |
743
5d529eb0ad33
Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
153 if (cmp > 0) |
5d529eb0ad33
Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
154 li_inf = li; /* it will come after this element, for sure */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
155 |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
156 if (cmp == 0) { |
743
5d529eb0ad33
Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
157 ret = EEXIST; /* we have a duplicate */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
158 break; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
159 } |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
160 if (!cont) |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
161 break; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
162 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
163 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
164 /* We can insert the new peer object */ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
165 if (! ret) |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
166 do { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
167 /* Update expiry list */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
168 CHECK_FCT_DO( ret = fd_p_expi_update( p ), break ); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
169 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
170 /* Insert the new element in the list */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
171 fd_list_insert_after( li_inf, &p->p_hdr.chain ); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
172 } while (0); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
173 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
174 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
175 if (ret) { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
176 CHECK_FCT( fd_peer_free(&p) ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
177 } else { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
178 CHECK_FCT( fd_psm_begin(p) ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
179 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
180 return ret; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
181 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
182 |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
183 /* Search for a peer */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
184 int fd_peer_getbyid( DiamId_t diamid, size_t diamidlen, int igncase, struct peer_hdr ** peer ) |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
185 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
186 struct fd_list * li; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
187 TRACE_ENTRY("%p %zd %d %p", diamid, diamidlen, igncase, peer); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
188 CHECK_PARAMS( diamid && diamidlen && peer ); |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
189 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
190 *peer = NULL; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
191 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
192 /* Search in the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
193 CHECK_POSIX( pthread_rwlock_rdlock(&fd_g_peers_rw) ); |
743
5d529eb0ad33
Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
194 if (igncase) { |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
195 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
196 struct fd_peer * next = (struct fd_peer *)li; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
197 int cmp, cont; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
198 cmp = fd_os_almostcasesrch( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen, &cont ); |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
199 if (cmp == 0) { |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
200 *peer = &next->p_hdr; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
201 break; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
202 } |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
203 if (!cont) |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
204 break; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
205 } |
743
5d529eb0ad33
Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
206 } else { |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
207 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
208 struct fd_peer * next = (struct fd_peer *)li; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
209 int cmp = fd_os_cmp( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen ); |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
210 if (cmp > 0) |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
211 continue; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
212 if (cmp == 0) |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
213 *peer = &next->p_hdr; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
214 break; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
215 } |
743
5d529eb0ad33
Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
216 } |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
217 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
218 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
219 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
220 } |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
221 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
222 |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
223 #define free_null( _v ) \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
224 if (_v) { \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
225 free(_v); \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
226 (_v) = NULL; \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
227 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
228 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
229 #define free_list( _l ) \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
230 while (!FD_IS_LIST_EMPTY(_l)) { \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
231 struct fd_list * __li = ((struct fd_list *)(_l))->next; \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
232 fd_list_unlink(__li); \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
233 free(__li); \ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
234 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
235 |
1207
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
236 /* Empty the lists of p_tosend, p_failover, and p_sentreq messages */ |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
237 void fd_peer_failover_msg(struct fd_peer * peer) |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
238 { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
239 struct msg *m; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
240 TRACE_ENTRY("%p", peer); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
241 CHECK_PARAMS_DO(CHECK_PEER(peer), return); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
242 |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
243 /* Requeue all messages in the "out" queue */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
244 while ( fd_fifo_tryget(peer->p_tosend, &m) == 0 ) { |
1201
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
245 /* but only if they are routable */ |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
246 if (fd_msg_is_routable(m)) { |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
247 fd_hook_call(HOOK_MESSAGE_FAILOVER, m, peer, NULL, fd_msg_pmdl_get(m)); |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
248 CHECK_FCT_DO(fd_fifo_post_noblock(fd_g_outgoing, (void *)&m), |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
249 { |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
250 /* fallback: destroy the message */ |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
251 fd_hook_call(HOOK_MESSAGE_DROPPED, m, NULL, "Internal error: unable to requeue this message during failover process", fd_msg_pmdl_get(m)); |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
252 CHECK_FCT_DO(fd_msg_free(m), /* What can we do more? */) |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
253 } ); |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
254 } else { |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
255 /* Just free it */ |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
256 /* fd_hook_call(HOOK_MESSAGE_DROPPED, m, NULL, "Non-routable message freed during handover", fd_msg_pmdl_get(m)); */ |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
257 CHECK_FCT_DO(fd_msg_free(m), /* What can we do more? */) |
d2608e47db28
Fix issue that can trigger an assert when failover occurs
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1188
diff
changeset
|
258 } |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
259 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
260 |
1207
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
261 /* Requeue all messages in the "failover" queue */ |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
262 while ( fd_fifo_tryget(peer->p_tofailover, &m) == 0 ) { |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
263 fd_hook_call(HOOK_MESSAGE_FAILOVER, m, peer, NULL, fd_msg_pmdl_get(m)); |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
264 CHECK_FCT_DO(fd_fifo_post_noblock(fd_g_outgoing, (void *)&m), |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
265 { |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
266 /* fallback: destroy the message */ |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
267 fd_hook_call(HOOK_MESSAGE_DROPPED, m, NULL, "Internal error: unable to requeue this message during failover process", fd_msg_pmdl_get(m)); |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
268 CHECK_FCT_DO(fd_msg_free(m), /* What can we do more? */) |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
269 } ); |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
270 } |
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
271 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
272 /* Requeue all routable sent requests */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
273 fd_p_sr_failover(&peer->p_sr); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
274 |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
275 /* Done */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
276 return; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
277 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
278 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
279 /* Describe the current connection */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
280 int fd_peer_cnx_proto_info(struct peer_hdr *peer, char * buf, size_t len) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
281 { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
282 struct fd_peer * p = (struct fd_peer *)peer; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
283 TRACE_ENTRY("%p %p %zd", peer, buf, len); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
284 CHECK_PARAMS(CHECK_PEER(peer) && buf && len); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
285 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
286 if (p->p_cnxctx) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
287 CHECK_FCT(fd_cnx_proto_info(p->p_cnxctx, buf, len)); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
288 } else if (p->p_receiver) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
289 CHECK_FCT(fd_cnx_proto_info(p->p_receiver, buf, len)); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
290 } else { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
291 snprintf(buf, len, "Not Connected"); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
292 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
293 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
294 return 0; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
295 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1185
diff
changeset
|
296 |
939
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
297 /* Return the value of srlist->cnt */ |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
298 int fd_peer_get_load_pending(struct peer_hdr *peer, long * to_receive, long * to_send) |
939
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
299 { |
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
300 struct fd_peer * p = (struct fd_peer *)peer; |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
301 TRACE_ENTRY("%p %p %p", peer, to_receive, to_send); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
302 CHECK_PARAMS(CHECK_PEER(peer)); |
939
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
303 |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
304 if (to_receive) { |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
305 CHECK_POSIX( pthread_mutex_lock(&p->p_sr.mtx) ); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
306 *to_receive = p->p_sr.cnt; |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
307 CHECK_POSIX( pthread_mutex_unlock(&p->p_sr.mtx) ); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
308 } |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
309 if (to_send) { |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
310 CHECK_POSIX( pthread_mutex_lock(&p->p_state_mtx) ); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
311 *to_send = p->p_reqin_count; |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
312 CHECK_POSIX( pthread_mutex_unlock(&p->p_state_mtx) ); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
313 } |
939
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
314 |
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
315 return 0; |
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
316 } |
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
317 |
1bc052ef961f
Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents:
933
diff
changeset
|
318 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
319 /* Destroy a structure once cleanups have been performed (fd_psm_abord, ...) */ |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
320 int fd_peer_free(struct fd_peer ** ptr) |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
321 { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
322 struct fd_peer *p; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
323 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
324 TRACE_ENTRY("%p", ptr); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
325 CHECK_PARAMS(ptr); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
326 p = *ptr; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
327 *ptr = NULL; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
328 CHECK_PARAMS(p); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
329 |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
330 CHECK_PARAMS( FD_IS_LIST_EMPTY(&p->p_hdr.chain) ); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
331 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
332 free_null(p->p_hdr.info.pi_diamid); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
333 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
334 free_null(p->p_hdr.info.config.pic_realm); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
335 free_null(p->p_hdr.info.config.pic_priority); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
336 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
337 free_null(p->p_hdr.info.runtime.pir_realm); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
338 free_null(p->p_hdr.info.runtime.pir_prodname); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
339 free_list( &p->p_hdr.info.runtime.pir_apps ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
340 |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
341 free_list( &p->p_hdr.info.pi_endpoints ); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
342 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
343 free_null(p->p_dbgorig); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
344 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
345 fd_list_unlink(&p->p_expiry); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
346 fd_list_unlink(&p->p_actives); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
347 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
348 CHECK_FCT_DO( fd_fifo_del(&p->p_tosend), /* continue */ ); |
1207
043b894b0511
Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
349 CHECK_FCT_DO( fd_fifo_del(&p->p_tofailover), /* continue */ ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
350 CHECK_POSIX_DO( pthread_mutex_destroy(&p->p_state_mtx), /* continue */); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
351 CHECK_POSIX_DO( pthread_mutex_destroy(&p->p_sr.mtx), /* continue */); |
649
5e5d8152c229
Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
454
diff
changeset
|
352 CHECK_POSIX_DO( pthread_cond_destroy(&p->p_sr.cnd), /* continue */); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
353 |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
354 /* If the callback is still around... */ |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
355 if (p->p_cb) |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
356 (*p->p_cb)(NULL, p->p_cb_data); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
357 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
358 /* Free the structure */ |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
359 free(p); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
360 return 0; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
361 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
362 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
363 /* Terminate peer module (destroy all peers, first gently, then violently) */ |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
364 int fd_peer_fini() |
12
418d2ce80dc8
Added support in configuration file for peers declaration
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
11
diff
changeset
|
365 { |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
366 struct fd_list * li; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
367 struct fd_list purge = FD_LIST_INITIALIZER(purge); /* Store zombie peers here */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
368 int list_empty; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
369 struct timespec wait_until, now; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
370 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
371 TRACE_ENTRY(); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
372 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
373 CHECK_FCT_DO(fd_p_expi_fini(), /* continue */); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
374 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
375 TRACE_DEBUG(INFO, "Sending terminate signal to all peer connections"); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
376 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
377 CHECK_FCT_DO( pthread_rwlock_wrlock(&fd_g_peers_rw), /* continue */ ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
378 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
379 struct fd_peer * peer = (struct fd_peer *)li->o; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
380 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
381 if (fd_peer_getstate(peer) != STATE_ZOMBIE) { |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
48
diff
changeset
|
382 CHECK_FCT_DO( fd_psm_terminate(peer, "REBOOTING"), /* continue */ ); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
383 } else { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
384 li = li->prev; /* to avoid breaking the loop */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
385 fd_list_unlink(&peer->p_hdr.chain); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
386 fd_list_insert_before(&purge, &peer->p_hdr.chain); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
387 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
388 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
389 list_empty = FD_IS_LIST_EMPTY(&fd_g_peers); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
390 CHECK_FCT_DO( pthread_rwlock_unlock(&fd_g_peers_rw), /* continue */ ); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
391 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
392 if (!list_empty) { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
393 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) ); |
1185
23695957bfc0
Don't block on peers shutdown when early errors
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
394 fd_psm_start(); /* just in case */ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
395 TRACE_DEBUG(INFO, "Waiting for connections shutdown... (%d sec max)", DPR_TIMEOUT + 1); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
396 wait_until.tv_sec = now.tv_sec + DPR_TIMEOUT + 1; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
397 wait_until.tv_nsec = now.tv_nsec; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
398 } |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
399 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
400 while ((!list_empty) && (TS_IS_INFERIOR(&now, &wait_until))) { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
401 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
402 /* Allow the PSM(s) to execute */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
403 usleep(100000); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
404 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
405 /* Remove zombie peers */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
406 CHECK_FCT_DO( pthread_rwlock_wrlock(&fd_g_peers_rw), /* continue */ ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
407 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
408 struct fd_peer * peer = (struct fd_peer *)li->o; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
409 if (fd_peer_getstate(peer) == STATE_ZOMBIE) { |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
410 li = li->prev; /* to avoid breaking the loop */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
411 fd_list_unlink(&peer->p_hdr.chain); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
412 fd_list_insert_before(&purge, &peer->p_hdr.chain); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
413 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
414 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
415 list_empty = FD_IS_LIST_EMPTY(&fd_g_peers); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
416 CHECK_FCT_DO( pthread_rwlock_unlock(&fd_g_peers_rw), /* continue */ ); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
417 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) ); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
418 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
419 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
420 if (!list_empty) { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
421 TRACE_DEBUG(INFO, "Forcing connections shutdown"); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
422 CHECK_FCT_DO( pthread_rwlock_wrlock(&fd_g_peers_rw), /* continue */ ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
423 while (!FD_IS_LIST_EMPTY(&fd_g_peers)) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
424 struct fd_peer * peer = (struct fd_peer *)(fd_g_peers.next->o); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
425 fd_psm_abord(peer); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
426 fd_list_unlink(&peer->p_hdr.chain); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
427 fd_list_insert_before(&purge, &peer->p_hdr.chain); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
428 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
429 CHECK_FCT_DO( pthread_rwlock_unlock(&fd_g_peers_rw), /* continue */ ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
430 } |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
431 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
432 /* Free memory objects of all peers */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
433 while (!FD_IS_LIST_EMPTY(&purge)) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
434 struct fd_peer * peer = (struct fd_peer *)(purge.next->o); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
435 fd_list_unlink(&peer->p_hdr.chain); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
436 fd_peer_free(&peer); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
437 } |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
438 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
439 /* Now empty the validators list */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
440 CHECK_FCT_DO( pthread_rwlock_wrlock(&validators_rw), /* continue */ ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
441 while (!FD_IS_LIST_EMPTY( &validators )) { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
442 struct fd_list * v = validators.next; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
443 fd_list_unlink(v); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
444 free(v); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
445 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
446 CHECK_FCT_DO( pthread_rwlock_unlock(&validators_rw), /* continue */ ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
447 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
448 return 0; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
449 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
450 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
451 /* Dump info of one peer */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
452 DECLARE_FD_DUMP_PROTOTYPE(fd_peer_dump, struct peer_hdr * p, int details) |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
453 { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
454 FD_DUMP_HANDLE_OFFSET(); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
455 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
456 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{peer}(@%p): ", p), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
457 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
458 if (!CHECK_PEER(p)) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
459 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL"), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
460 } else { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
461 struct fd_peer * peer = (struct fd_peer *)p; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
462 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
463 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s [%s, cnt:%ldsr,%ldpa]", peer->p_hdr.info.pi_diamid, STATE_STR(fd_peer_getstate(peer)), peer->p_sr.cnt, peer->p_reqin_count), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
464 if (details > 0) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
465 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " rlm:%s", peer->p_hdr.info.runtime.pir_realm ?: "<unknown>"), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
466 if (peer->p_hdr.info.runtime.pir_prodname) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
467 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " ['%s' %u]", peer->p_hdr.info.runtime.pir_prodname, peer->p_hdr.info.runtime.pir_firmrev), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
468 } |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
469 } |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
470 if (details > 1) { |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1113
diff
changeset
|
471 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " [from:%s] flags:%s%s%s%s%s%s%s%s lft:%ds", |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
472 peer->p_dbgorig ?: "unset", |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
473 peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_DEFAULT ? "-" : |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
474 (peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_IP ? "4" : "6"), |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
475 peer->p_hdr.info.config.pic_flags.pro4 == PI_P4_DEFAULT ? "-" : |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
476 (peer->p_hdr.info.config.pic_flags.pro4 == PI_P4_TCP ? "T" : "S"), |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
477 peer->p_hdr.info.config.pic_flags.alg ? "P" : "-", |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
478 peer->p_hdr.info.config.pic_flags.sec & PI_SEC_NONE ? "N" :"-", |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
479 peer->p_hdr.info.config.pic_flags.sec & PI_SEC_TLS_OLD ? "O" :"-", |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1113
diff
changeset
|
480 peer->p_hdr.info.config.pic_flags.sctpsec & PI_SCTPSEC_3436 ? "3" :"-", |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
481 peer->p_hdr.info.config.pic_flags.exp ? "E" : "-", |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
482 peer->p_hdr.info.config.pic_flags.persist ? "P" : "-", |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
483 peer->p_hdr.info.config.pic_lft), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
484 } |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
485 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
486 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
487 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
488 return *buf; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
489 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
490 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
491 /* Dump the list of peers */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
492 DECLARE_FD_DUMP_PROTOTYPE(fd_peer_dump_list, int details) |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
493 { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
494 struct fd_list * li; |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
495 FD_DUMP_HANDLE_OFFSET(); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
496 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
497 CHECK_FCT_DO( pthread_rwlock_rdlock(&fd_g_peers_rw), /* continue */ ); |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
498 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
499 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
500 CHECK_MALLOC_DO( fd_peer_dump(FD_DUMP_STD_PARAMS, (struct peer_hdr *)li->o, details), break); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
501 if (li->next != &fd_g_peers) { |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
502 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), break); |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
503 } |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
504 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
505 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
506 CHECK_FCT_DO( pthread_rwlock_unlock(&fd_g_peers_rw), /* continue */ ); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
507 return *buf; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
508 } |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
12
diff
changeset
|
509 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
510 static struct dict_object *avp_oh_model = NULL; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
511 static pthread_mutex_t cache_avp_lock = PTHREAD_MUTEX_INITIALIZER; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
512 |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
513 /* Handle an incoming CER request on a new connection */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
514 int fd_peer_handle_newCER( struct msg ** cer, struct cnxctx ** cnx ) |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
515 { |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
516 struct msg * msg; |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
517 struct avp *avp_oh; |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
518 struct avp_hdr * avp_hdr; |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
519 struct fd_list * li, *li_inf; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
520 int found = 0; |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
521 int ret = 0; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
522 struct fd_peer * peer; |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
523 struct cnx_incoming * ev_data; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
524 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
525 TRACE_ENTRY("%p %p", cer, cnx); |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
526 CHECK_PARAMS(cer && *cer && cnx && *cnx); |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
527 |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
528 msg = *cer; |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
529 |
749
2557127f3c8b
fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
743
diff
changeset
|
530 /* If needed, resolve the dictionary model for Origin-Host */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
531 CHECK_POSIX( pthread_mutex_lock(&cache_avp_lock) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
532 if (!avp_oh_model) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
533 avp_code_t code = AC_ORIGIN_HOST; |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
534 CHECK_FCT_DO( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE, &code, &avp_oh_model, ENOENT), |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
535 { LOG_E("Cannot find Origin-Host AVP definition in the dictionary!"); (void) pthread_mutex_unlock(&cache_avp_lock); return __ret__; } ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
536 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
537 CHECK_POSIX( pthread_mutex_unlock(&cache_avp_lock) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
538 |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
539 /* Find the Diameter Identity of the remote peer in the message */ |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
540 CHECK_FCT( fd_msg_search_avp ( msg, avp_oh_model, &avp_oh ) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
541 ASSERT(avp_oh); /* otherwise it should not have passed rules validation, right? */ |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
542 CHECK_FCT( fd_msg_avp_hdr ( avp_oh, &avp_hdr ) ); |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
543 |
749
2557127f3c8b
fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
743
diff
changeset
|
544 /* First, check if the Origin-Host value is valid */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
545 if (!fd_os_is_valid_DiameterIdentity(avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len)) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
546 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, cer, MSGFL_ANSW_ERROR ) ); |
827
a8ed055a9253
Fix name of the constant errors used for rescode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
767
diff
changeset
|
547 CHECK_FCT( fd_msg_rescode_set(*cer, "DIAMETER_INVALID_AVP_VALUE", |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
548 "Your Origin-Host contains invalid characters.", avp_oh, 1 ) ); |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
549 |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
550 fd_hook_call(HOOK_PEER_CONNECT_FAILED, *cer, NULL, "Received CER with invalid Origin-Host AVP", NULL); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
551 |
1238
8f9684264fe0
Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1207
diff
changeset
|
552 CHECK_FCT( fd_out_send(cer, *cnx, NULL, 0) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
553 return EINVAL; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
554 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
555 |
152
5b4c62560f22
Remove deadlock on rwlock upgrade unsupported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
137
diff
changeset
|
556 /* Search if we already have this peer id in our list. We take directly the write lock so that we don't need to upgrade if it is a new peer. |
5b4c62560f22
Remove deadlock on rwlock upgrade unsupported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
137
diff
changeset
|
557 * There is space for a small optimization here if needed. |
5b4c62560f22
Remove deadlock on rwlock upgrade unsupported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
137
diff
changeset
|
558 */ |
5b4c62560f22
Remove deadlock on rwlock upgrade unsupported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
137
diff
changeset
|
559 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_peers_rw) ); |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
560 |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
561 li_inf = &fd_g_peers; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
562 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
563 int cmp, cont; |
749
2557127f3c8b
fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
743
diff
changeset
|
564 peer = (struct fd_peer *)li; |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
565 cmp = fd_os_almostcasesrch( avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen, &cont ); |
749
2557127f3c8b
fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
743
diff
changeset
|
566 if (cmp > 0) { |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
567 li_inf = li; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
568 } |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
569 if (cmp == 0) { |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
570 found = 1; |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
571 break; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
572 } |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
573 if (!cont) |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
574 break; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
575 } |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
576 |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
577 if (!found) { |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
578 /* Create a new peer entry for this new remote peer */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
579 peer = NULL; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
580 CHECK_FCT_DO( ret = fd_peer_alloc(&peer), goto out ); |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
581 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
582 /* Set the peer Diameter Id and the responder flag parameters */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
583 CHECK_MALLOC_DO( peer->p_hdr.info.pi_diamid = os0dup(avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len), |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
584 { ret = ENOMEM; goto out; } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
585 peer->p_hdr.info.pi_diamidlen = avp_hdr->avp_value->os.len; |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
586 CHECK_MALLOC_DO( peer->p_dbgorig = strdup(fd_cnx_getid(*cnx)), { ret = ENOMEM; goto out; } ); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
587 peer->p_flags.pf_responder = 1; |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
153
diff
changeset
|
588 peer->p_flags.pf_delete = 1; |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
589 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
590 LOG_D("Created new peer object for incoming CER: %s", peer->p_hdr.info.pi_diamid); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
591 |
933
04f590da5821
Add cmake option DISABLE_PEER_EXPIRY to disable dynamic peer expiration mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents:
928
diff
changeset
|
592 #ifndef DISABLE_PEER_EXPIRY |
36 | 593 /* Set this peer to expire on inactivity */ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
594 peer->p_hdr.info.config.pic_flags.exp = PI_EXP_INACTIVE; |
175
7704fe55bb35
Added comment on expiry
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
163
diff
changeset
|
595 peer->p_hdr.info.config.pic_lft = 3600; /* 1 hour without any message |
7704fe55bb35
Added comment on expiry
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
163
diff
changeset
|
596 -- RFC3539 states that this must not be inferior to BRINGDOWN_INTERVAL = 5 minutes */ |
933
04f590da5821
Add cmake option DISABLE_PEER_EXPIRY to disable dynamic peer expiration mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents:
928
diff
changeset
|
597 |
749
2557127f3c8b
fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
743
diff
changeset
|
598 CHECK_FCT_DO( ret = fd_p_expi_update( peer ), goto out ); |
933
04f590da5821
Add cmake option DISABLE_PEER_EXPIRY to disable dynamic peer expiration mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents:
928
diff
changeset
|
599 #endif /* DISABLE_PEER_EXPIRY */ |
36 | 600 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
601 /* Insert the new peer in the list (the PSM will take care of setting the expiry after validation) */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
725
diff
changeset
|
602 fd_list_insert_after( li_inf, &peer->p_hdr.chain ); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
603 |
972 | 604 /* Start the PSM, which will receive the event below */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
605 CHECK_FCT_DO( ret = fd_psm_begin(peer), goto out ); |
163
547f30e9a8ae
Re-enable zombie peers on new connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
154
diff
changeset
|
606 } else { |
547f30e9a8ae
Re-enable zombie peers on new connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
154
diff
changeset
|
607 /* Check if the peer is in zombie state */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
608 if (fd_peer_getstate(peer) == STATE_ZOMBIE) { |
163
547f30e9a8ae
Re-enable zombie peers on new connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
154
diff
changeset
|
609 /* Re-activate the peer */ |
391
1042347401cc
Attempt to fix issue when zombie peers need a validator
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
610 if (peer->p_hdr.info.config.pic_flags.exp) |
1042347401cc
Attempt to fix issue when zombie peers need a validator
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
611 peer->p_flags.pf_responder = 1; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
612 CHECK_POSIX_DO( pthread_mutex_lock(&peer->p_state_mtx), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
613 peer->p_state = STATE_NEW; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
614 CHECK_POSIX_DO( pthread_mutex_unlock(&peer->p_state_mtx), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
615 peer->p_flags.pf_localterm = 0; |
163
547f30e9a8ae
Re-enable zombie peers on new connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
154
diff
changeset
|
616 CHECK_FCT_DO( ret = fd_psm_begin(peer), goto out ); |
547f30e9a8ae
Re-enable zombie peers on new connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
154
diff
changeset
|
617 } |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
618 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
619 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
620 /* Send the new connection event to the PSM */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
621 CHECK_MALLOC_DO( ev_data = malloc(sizeof(struct cnx_incoming)), { ret = ENOMEM; goto out; } ); |
908
ed611e15f744
Fix a few warnings, thank you Thomas again
Sebastien Decugis <sdecugis@freediameter.net>
parents:
837
diff
changeset
|
622 memset(ev_data, 0, sizeof(*ev_data)); |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
623 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
624 ev_data->cer = msg; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
625 ev_data->cnx = *cnx; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
626 ev_data->validate = !found; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
627 |
917
a2cf598607e6
Another place where ev_data was not dereferenced -- thanks Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents:
908
diff
changeset
|
628 CHECK_FCT_DO( ret = fd_event_send(peer->p_events, FDEVP_CNX_INCOMING, sizeof(*ev_data), ev_data), goto out ); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
629 |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
630 out: |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
631 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) ); |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
632 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
633 if (ret == 0) { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
634 /* Reset the "out" parameters, so that they are not cleanup on function return. */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
635 *cer = NULL; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
636 *cnx = NULL; |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
637 } else { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
638 char buf[1024]; |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
639 snprintf(buf, sizeof(buf), "An error occurred while processing new incoming CER: %s", strerror(ret)); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
640 fd_hook_call(HOOK_PEER_CONNECT_FAILED, *cer, NULL, buf, NULL); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
641 } |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
642 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
643 return ret; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
644 } |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
645 |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
646 /* Save a callback to accept / reject incoming unknown peers */ |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
647 int fd_peer_validate_register ( int (*peer_validate)(struct peer_info * /* info */, int * /* auth */, int (**cb2)(struct peer_info *)) ) |
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
648 { |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
649 struct fd_list * v; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
650 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
651 TRACE_ENTRY("%p", peer_validate); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
652 CHECK_PARAMS(peer_validate); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
653 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
654 /* Alloc a new entry */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
655 CHECK_MALLOC( v = malloc(sizeof(struct fd_list)) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
656 fd_list_init( v, peer_validate ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
657 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
658 /* Add at the beginning of the list */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
659 CHECK_FCT( pthread_rwlock_wrlock(&validators_rw) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
660 fd_list_insert_after(&validators, v); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
661 CHECK_FCT( pthread_rwlock_unlock(&validators_rw)); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
662 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
663 /* Done! */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
664 return 0; |
28
3628f7d2ba88
some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
665 } |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
666 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
667 /* Validate a peer by calling the callbacks in turn -- return 0 if the peer is validated, ! 0 in case of error (>0) or if the peer is rejected (-1) */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
668 int fd_peer_validate( struct fd_peer * peer ) |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
669 { |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
670 int ret = 0; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
671 struct fd_list * v; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
672 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
673 CHECK_FCT( pthread_rwlock_rdlock(&validators_rw) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
674 for (v = validators.next; v != &validators; v = v->next) { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
675 int auth = 0; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
676 pthread_cleanup_push(fd_cleanup_rwlock, &validators_rw); |
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:
688
diff
changeset
|
677 CHECK_FCT_DO( ret = ((int(*)(struct peer_info *, int *, int (**)(struct peer_info *)))(v->o)) (&peer->p_hdr.info, &auth, &peer->p_cb2), ); |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
678 pthread_cleanup_pop(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:
688
diff
changeset
|
679 if (ret) |
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:
688
diff
changeset
|
680 goto out; |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
681 if (auth) { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
682 ret = (auth > 0) ? 0 : -1; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
683 goto out; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
684 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
685 peer->p_cb2 = NULL; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
686 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
687 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
688 /* No callback has given a firm result, the default is to reject */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
689 ret = -1; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
690 out: |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
691 CHECK_FCT( pthread_rwlock_unlock(&validators_rw)); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
692 return ret; |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
693 } |