annotate freeDiameter/peers.c @ 34:0e2b57789361

Backup for the WE, some warnings remaining
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 30 Oct 2009 17:23:06 +0900
parents e6fcdf12b9a0
children 1498b3c7304c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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) *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
5 * Copyright (c) 2009, WIDE Project and NICT *
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
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 #include "fD.h"
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 */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
43 struct fd_list fd_g_activ_peers = FD_LIST_INITIALIZER(fd_g_activ_peers); /* peers linked by their p_actives oredered by p_diamid */
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
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
71 fd_list_init(&p->p_hdr.info.pi_endpoints, NULL);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
72 fd_list_init(&p->p_hdr.info.pi_apps, NULL);
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;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
75 fd_list_init(&p->p_expiry, p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
76 fd_list_init(&p->p_actives, p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
77 p->p_hbh = lrand48();
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
78 CHECK_FCT( fd_fifo_new(&p->p_events) );
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
79 CHECK_FCT( fd_fifo_new(&p->p_tosend) );
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
80 fd_list_init(&p->p_sr.srs, p);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
81 CHECK_POSIX( pthread_mutex_init(&p->p_sr.mtx, NULL) );
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
82
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
83 return 0;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
84 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
85
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
86 /* Add a new peer entry */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
87 int fd_peer_add ( struct peer_info * info, char * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data )
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
88 {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
89 struct fd_peer *p = NULL;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
90 struct fd_list * li;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
91 int ret = 0;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
92 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
93 CHECK_PARAMS(info && info->pi_diamid);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
94
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
95 /* Create a structure to contain the new peer information */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
96 CHECK_FCT( fd_peer_alloc(&p) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
97
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
98 /* Copy the informations from the parameters received */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
99 CHECK_MALLOC( p->p_hdr.info.pi_diamid = strdup(info->pi_diamid) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
100 if (info->pi_realm) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
101 CHECK_MALLOC( p->p_hdr.info.pi_realm = strdup(info->pi_realm) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
102 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
103
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
104 p->p_hdr.info.pi_flags.pro3 = info->pi_flags.pro3;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
105 p->p_hdr.info.pi_flags.pro4 = info->pi_flags.pro4;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
106 p->p_hdr.info.pi_flags.alg = info->pi_flags.alg;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
107 p->p_hdr.info.pi_flags.sec = info->pi_flags.sec;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
108 p->p_hdr.info.pi_flags.exp = info->pi_flags.exp;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
109
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
110 p->p_hdr.info.pi_lft = info->pi_lft;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
111 p->p_hdr.info.pi_port = info->pi_port;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
112 p->p_hdr.info.pi_tctimer = info->pi_tctimer;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
113 p->p_hdr.info.pi_twtimer = info->pi_twtimer;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
114
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
115 if (info->pi_sec_data.priority) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
116 CHECK_MALLOC( p->p_hdr.info.pi_sec_data.priority = strdup(info->pi_sec_data.priority) );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
117 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
118
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
119 /* Move the items from one list to the other */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
120 if (info->pi_endpoints.next)
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
121 while (!FD_IS_LIST_EMPTY( &info->pi_endpoints ) ) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
122 li = info->pi_endpoints.next;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
123 fd_list_unlink(li);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
124 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
125 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
126
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
127
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
128 /* The internal data */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
129 if (orig_dbg) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
130 CHECK_MALLOC( p->p_dbgorig = strdup(orig_dbg) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
131 } else {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
132 CHECK_MALLOC( p->p_dbgorig = strdup("unknown") );
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 p->p_cb = cb;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
135 p->p_cb_data = cb_data;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
136
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
137 /* 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
138 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_peers_rw) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
139
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
140 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
141 struct fd_peer * next = (struct fd_peer *)li;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
142 int cmp = strcasecmp( p->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamid );
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
143 if (cmp > 0)
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
144 continue;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
145 if (cmp == 0)
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
146 ret = EEXIST;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
147 break;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
148 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
149
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
150 /* We can insert the new peer object */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
151 if (! ret) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
152 /* Update expiry list */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
153 CHECK_FCT_DO( ret = fd_p_expi_update( p ), goto out );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
154
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
155 /* Insert the new element in the list */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
156 fd_list_insert_before( li, &p->p_hdr.chain );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
157 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
158
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
159 out:
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
160 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
161 if (ret) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
162 CHECK_FCT( fd_peer_free(&p) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
163 } else {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
164 CHECK_FCT( fd_psm_begin(p) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
165 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
166 return ret;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
167 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
168
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
169
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
170 #define free_null( _v ) \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
171 if (_v) { \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
172 free(_v); \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
173 (_v) = NULL; \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
174 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
175
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
176 #define free_list( _l ) \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
177 while (!FD_IS_LIST_EMPTY(_l)) { \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
178 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
179 fd_list_unlink(__li); \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
180 free(__li); \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
181 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
182
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
183 /* Empty the lists of p_tosend and p_sentreq messages */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
184 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
185 {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
186 struct msg *m;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
187 TRACE_ENTRY("%p", peer);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
188 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
189
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
190 /* 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
191 while ( fd_fifo_tryget(peer->p_tosend, &m) == 0 ) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
192 CHECK_FCT_DO(fd_fifo_post(fd_g_outgoing, &m),
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
193 /* fallback: destroy the message */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
194 CHECK_FCT_DO(fd_msg_free(m), /* What can we do more? */));
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
195 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
196
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
197 /* Requeue all routable sent requests */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
198 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
199
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
200 /* Done */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
201 return;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
202 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
203
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
204 /* Destroy a structure once all cleanups have been performed */
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
205 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
206 {
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
207 struct fd_peer *p;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
208 void * t;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
209
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
210 TRACE_ENTRY("%p", ptr);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
211 CHECK_PARAMS(ptr);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
212 p = *ptr;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
213 *ptr = NULL;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
214 CHECK_PARAMS(p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
215
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
216 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
217
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
218 free_null(p->p_hdr.info.pi_diamid);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
219 free_null(p->p_hdr.info.pi_realm);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
220 free_list( &p->p_hdr.info.pi_endpoints );
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
221 TODO("Free the security data if any ?");
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
222 free_null(p->p_hdr.info.pi_prodname);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
223 free_list( &p->p_hdr.info.pi_apps );
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
224
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
225 free_null(p->p_dbgorig);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
226 ASSERT(FD_IS_LIST_EMPTY(&p->p_expiry));
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
227 ASSERT(FD_IS_LIST_EMPTY(&p->p_actives));
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 CHECK_FCT( fd_thr_term(&p->p_psm) );
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
230 while ( fd_fifo_tryget(p->p_events, &t) == 0 ) {
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
231 struct fd_event * ev = t;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
232 TRACE_DEBUG(FULL, "Found event %d(%p) in queue of peer %p being destroyed", ev->code, ev->data, p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
233 free(ev);
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 CHECK_FCT( fd_fifo_del(&p->p_events) );
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
236
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
237 CHECK_FCT( fd_thr_term(&p->p_outthr) );
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
238
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
239 if (p->p_cnxctx) {
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
240 fd_cnx_destroy(p->p_cnxctx);
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
241 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
242
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
243 /* Requeue any remaining message into global structures if possible */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
244 fd_peer_failover_msg(p);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
245 CHECK_FCT_DO( fd_fifo_del(&p->p_tosend), /* continue */ );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
246 CHECK_POSIX_DO( pthread_mutex_destroy(&p->p_sr.mtx), /* continue */);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
247
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
248 /* If the callback is still around... */
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
249 if (p->p_cb)
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
250 (*p->p_cb)(NULL, p->p_cb_data);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
251
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
252 /* Free the structure */
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
253 free(p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
254 return 0;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
255 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
256
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
257 /* Terminate peer module (destroy all peers) */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
258 int fd_peer_fini()
12
418d2ce80dc8 Added support in configuration file for peers declaration
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 11
diff changeset
259 {
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
260 struct fd_list * li;
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
261 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
262 int list_empty;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
263 struct timespec wait_until, now;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
264
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
265 TRACE_ENTRY();
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
266
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
267 CHECK_FCT_DO(fd_p_expi_fini(), /* continue */);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
268
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
269 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
270
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
271 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
272 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
273 struct fd_peer * peer = (struct fd_peer *)li;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
274
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
275 if (peer->p_hdr.info.pi_state != STATE_ZOMBIE) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
276 CHECK_FCT_DO( fd_psm_terminate(peer), /* continue */ );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
277 } else {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
278 li = li->prev; /* to avoid breaking the loop */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
279 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
280 fd_list_insert_before(&purge, &peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
281 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
282 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
283 list_empty = FD_IS_LIST_EMPTY(&fd_g_peers);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
284 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
285
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
286 if (!list_empty) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
287 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
288 TRACE_DEBUG(INFO, "Waiting for connections shutdown... (%d sec max)", DPR_TIMEOUT);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
289 wait_until.tv_sec = now.tv_sec + DPR_TIMEOUT;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
290 wait_until.tv_nsec = now.tv_nsec;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
291 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
292
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
293 while ((!list_empty) && (TS_IS_INFERIOR(&now, &wait_until))) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
294
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
295 /* Allow the PSM(s) to execute */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
296 pthread_yield();
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
297
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
298 /* Remove zombie peers */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
299 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
300 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
301 struct fd_peer * peer = (struct fd_peer *)li;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
302 if (peer->p_hdr.info.pi_state == STATE_ZOMBIE) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
303 li = li->prev; /* to avoid breaking the loop */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
304 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
305 fd_list_insert_before(&purge, &peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
306 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
307 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
308 list_empty = FD_IS_LIST_EMPTY(&fd_g_peers);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
309 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
310 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) );
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
311 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
312
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
313 if (!list_empty) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
314 TRACE_DEBUG(INFO, "Forcing connections shutdown");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
315 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
316 while (!FD_IS_LIST_EMPTY(&fd_g_peers)) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
317 struct fd_peer * peer = (struct fd_peer *)(fd_g_peers.next);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
318 fd_psm_abord(peer);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
319 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
320 fd_list_insert_before(&purge, &peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
321 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
322 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
323 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
324
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
325 /* Free memory objects of all peers */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
326 while (!FD_IS_LIST_EMPTY(&purge)) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
327 struct fd_peer * peer = (struct fd_peer *)(purge.next);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
328 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
329 fd_peer_free(&peer);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
330 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
331
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
332 /* Now empty the validators list */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
333 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
334 while (!FD_IS_LIST_EMPTY( &validators )) {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
335 struct fd_list * v = validators.next;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
336 fd_list_unlink(v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
337 free(v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
338 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
339 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
340
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
341 return 0;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
342 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
343
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
344 /* Dump info of one peer */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
345 void fd_peer_dump(struct fd_peer * peer, int details)
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
346 {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
347 if (peer->p_eyec != EYEC_PEER) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
348 fd_log_debug(" Invalid peer @ %p !\n", peer);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
349 return;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
350 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
351
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
352 fd_log_debug("> %s\t%s", STATE_STR(peer->p_hdr.info.pi_state), peer->p_hdr.info.pi_diamid);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
353 if (details > INFO) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
354 fd_log_debug("\t(rlm:%s)", peer->p_hdr.info.pi_realm);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
355 if (peer->p_hdr.info.pi_prodname)
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
356 fd_log_debug("\t['%s' %u]", peer->p_hdr.info.pi_prodname, peer->p_hdr.info.pi_firmrev);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
357 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
358 fd_log_debug("\n");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
359 if (details > FULL) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
360 /* Dump all info */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
361 fd_log_debug("\tEntry origin : %s\n", peer->p_dbgorig);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
362 fd_log_debug("\tFlags : %s%s%s%s%s - %s%s%s\n",
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
363 peer->p_hdr.info.pi_flags.pro3 == PI_P3_DEFAULT ? "" :
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
364 (peer->p_hdr.info.pi_flags.pro3 == PI_P3_IP ? "IP." : "IPv6."),
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
365 peer->p_hdr.info.pi_flags.pro4 == PI_P4_DEFAULT ? "" :
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
366 (peer->p_hdr.info.pi_flags.pro4 == PI_P4_TCP ? "TCP." : "SCTP."),
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
367 peer->p_hdr.info.pi_flags.alg ? "PrefTCP." : "",
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
368 peer->p_hdr.info.pi_flags.sec == PI_SEC_DEFAULT ? "" :
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
369 (peer->p_hdr.info.pi_flags.sec == PI_SEC_NONE ? "IPSec." : "InbandTLS."),
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
370 peer->p_hdr.info.pi_flags.exp ? "Expire." : "",
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 16
diff changeset
371 peer->p_hdr.info.pi_flags.inband_none ? "InbandIPsec." : "",
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 16
diff changeset
372 peer->p_hdr.info.pi_flags.inband_tls ? "InbandTLS." : "",
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
373 peer->p_hdr.info.pi_flags.relay ? "Relay (0xffffff)" : "No relay"
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 fd_log_debug("\tLifetime : %d sec\n", peer->p_hdr.info.pi_lft);
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 TODO("Dump remaining useful information");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
378 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
379 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
380
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
381 /* Dump the list of peers */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
382 void fd_peer_dump_list(int details)
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
383 {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
384 struct fd_list * li;
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
385
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
386 fd_log_debug("Dumping list of peers :\n");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
387 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
388
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
389 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
390 struct fd_peer * np = (struct fd_peer *)li;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
391 fd_peer_dump(np, details);
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
392 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
393
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
394 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
395 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
396
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
397 /* 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
398 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
399 {
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
400 struct msg * msg;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
401 struct dict_object *avp_oh_model;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
402 avp_code_t code = AC_ORIGIN_HOST;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
403 struct avp *avp_oh;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
404 struct avp_hdr * avp_hdr;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
405 struct fd_list * li;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
406 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
407 int ret = 0;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
408 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
409 struct cnx_incoming * ev_data;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
410
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
411 TRACE_ENTRY("%p %p", cer, cnx);
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
412 CHECK_PARAMS(cer && *cer && cnx && *cnx);
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
413
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
414 msg = *cer;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
415
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
416 /* 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
417 CHECK_FCT( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE, &code, &avp_oh_model, ENOENT) );
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
418 CHECK_FCT( fd_msg_search_avp ( msg, avp_oh_model, &avp_oh ) );
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
419 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
420
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
421 /* Search if we already have this peer id in our list */
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
422 CHECK_POSIX( pthread_rwlock_rdlock(&fd_g_peers_rw) );
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
423
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
424 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
425 peer = (struct fd_peer *)li;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
426 int cmp = strncasecmp( avp_hdr->avp_value->os.data, peer->p_hdr.info.pi_diamid, avp_hdr->avp_value->os.len );
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
427 if (cmp > 0)
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
428 continue;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
429 if (cmp == 0)
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
430 found = 1;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
431 break;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
432 }
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
433
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
434 if (!found) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
435 /* 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
436 peer = NULL;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
437 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
438
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
439 /* Set the peer Diameter Id and the responder flag parameters */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
440 CHECK_MALLOC_DO( peer->p_hdr.info.pi_diamid = malloc(avp_hdr->avp_value->os.len + 1), { 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
441 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
442 peer->p_flags.pf_responder = 1;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
443
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
444 /* Upgrade the lock to write lock */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
445 CHECK_POSIX_DO( ret = pthread_rwlock_wrlock(&fd_g_peers_rw), goto out );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
446
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
447 /* Insert the new peer in the list (the PSM will take care of setting the expiry after validation) */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
448 fd_list_insert_before( li, &peer->p_hdr.chain );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
449
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
450 /* Release the write lock */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
451 CHECK_POSIX_DO( ret = pthread_rwlock_unlock(&fd_g_peers_rw), goto out );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
452
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
453 /* Start the PSM, which will receive the event bellow */
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
454 CHECK_FCT_DO( ret = fd_psm_begin(peer), goto out );
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
455 }
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
456
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
457 /* 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
458 CHECK_MALLOC_DO( ev_data = malloc(sizeof(struct cnx_incoming)), { 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
459 memset(ev_data, 0, sizeof(ev_data));
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
460
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
461 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
462 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
463 ev_data->validate = !found;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
464
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
465 CHECK_FCT_DO( ret = fd_event_send(peer->p_events, FDEVP_CNX_INCOMING, sizeof(ev_data), ev_data), goto out );
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
466
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
467 out:
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
468 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
469
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
470 if (ret == 0) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
471 /* 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
472 *cer = NULL;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
473 *cnx = NULL;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
474 }
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
475
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
476 return ret;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
477 }
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
478
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
479 /* Save a callback to accept / reject incoming unknown peers */
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
480 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
481 {
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
482 struct fd_list * v;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
483
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
484 TRACE_ENTRY("%p", peer_validate);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
485 CHECK_PARAMS(peer_validate);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
486
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
487 /* Alloc a new entry */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
488 CHECK_MALLOC( v = malloc(sizeof(struct fd_list)) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
489 fd_list_init( v, peer_validate );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
490
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
491 /* Add at the beginning of the list */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
492 CHECK_FCT( pthread_rwlock_wrlock(&validators_rw) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
493 fd_list_insert_after(&validators, v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
494 CHECK_FCT( pthread_rwlock_unlock(&validators_rw));
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
495
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
496 /* Done! */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
497 return 0;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
498 }
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
499
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
500 /* 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
501 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
502 {
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
503 int ret = 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
504 struct fd_list * v;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
505
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
506 CHECK_FCT( pthread_rwlock_rdlock(&validators_rw) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
507 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
508 int auth = 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
509 pthread_cleanup_push(fd_cleanup_rwlock, &validators_rw);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
510 CHECK_FCT_DO( ret = ((int(*)(struct peer_info *, int *, int (**)(struct peer_info *)))(v->o)) (&peer->p_hdr.info, &auth, &peer->p_cb2), goto out );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
511 pthread_cleanup_pop(0);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
512 if (auth) {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
513 ret = (auth > 0) ? 0 : -1;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
514 goto out;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
515 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
516 peer->p_cb2 = NULL;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
517 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
518
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
519 /* 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
520 ret = -1;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
521 out:
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
522 CHECK_FCT( pthread_rwlock_unlock(&validators_rw));
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
523 return ret;
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
524 }
"Welcome to our mercurial repository"