annotate libfdcore/peers.c @ 725:8b03c672261f

Fix a small bug in peers validation process
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 22 Feb 2011 15:50:45 +0900
parents 4ffbc9f1e922
children d666051658bd
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 * *
662
2e94ef0515d7 Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 658
diff changeset
5 * Copyright (c) 2011, 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 */
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
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);
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
79 CHECK_FCT( fd_fifo_new(&p->p_tosend) );
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
80 p->p_hbh = lrand48();
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
81
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
82 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
83 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
84 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
85 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
86
48
2b1cba7e949d Initialize list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
87 fd_list_init(&p->p_connparams, p);
2b1cba7e949d Initialize list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
88
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
89 return 0;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
90 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
91
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
92 /* Add a new peer entry */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
93 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
94 {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
95 struct fd_peer *p = NULL;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
96 struct fd_list * li;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
97 int ret = 0;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
98
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
99 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
100 CHECK_PARAMS(info && info->pi_diamid);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
101
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
102 if (info->config.pic_realm) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
103 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
104 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
105 return EINVAL;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
106 }
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
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
109 /* Create a structure to contain the new peer information */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
110 CHECK_FCT( fd_peer_alloc(&p) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
111
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
112 /* 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
113 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
114 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
115
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
116 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
117
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
118 /* Duplicate the strings if provided */
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
119 if (info->config.pic_realm) {
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
120 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
121 }
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
122 if (info->config.pic_priority) {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
123 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
124 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
125
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
126 /* Move the list of endpoints into the peer */
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
127 if (info->pi_endpoints.next)
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
128 while (!FD_IS_LIST_EMPTY( &info->pi_endpoints ) ) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
129 li = info->pi_endpoints.next;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
130 fd_list_unlink(li);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
131 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
132 }
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 /* The internal data */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
135 if (orig_dbg) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
136 CHECK_MALLOC( p->p_dbgorig = strdup(orig_dbg) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
137 } else {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
138 CHECK_MALLOC( p->p_dbgorig = strdup("unspecified") );
16
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 p->p_cb = cb;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
141 p->p_cb_data = cb_data;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
142
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
143 /* 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
144 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_peers_rw) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
145
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
146 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
147 struct fd_peer * next = (struct fd_peer *)li;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
148 int cmp = fd_os_almostcasecmp( p->p_hdr.info.pi_diamid, p->p_hdr.info.pi_diamidlen,
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
149 next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen );
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
150 if (cmp > 0)
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
151 continue;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
152 if (cmp == 0)
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
153 ret = EEXIST;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
154 break;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
155 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
156
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
157 /* 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
158 if (! ret)
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
159 do {
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
160 /* Update expiry list */
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
161 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
162
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
163 /* Insert the new element in the list */
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
164 fd_list_insert_before( li, &p->p_hdr.chain );
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
165 } while (0);
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
166
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
167 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
168 if (ret) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
169 CHECK_FCT( fd_peer_free(&p) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
170 } else {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
171 CHECK_FCT( fd_psm_begin(p) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
172 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
173 return ret;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
174 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
175
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
176 /* Search for a peer */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
177 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
178 {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
179 struct fd_list * li;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
180 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
181 CHECK_PARAMS( diamid && diamidlen && peer );
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
182
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
183 *peer = NULL;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
184
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
185 /* Search in the list */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
186 CHECK_POSIX( pthread_rwlock_rdlock(&fd_g_peers_rw) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
187 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
188 struct fd_peer * next = (struct fd_peer *)li;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
189 int cmp;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
190 if (igncase)
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
191 cmp = fd_os_almostcasecmp( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
192 else
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
193 cmp = fd_os_cmp( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen );
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
194 if (cmp > 0)
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
195 continue;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
196 if (cmp == 0)
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
197 *peer = &next->p_hdr;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
198 break;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
199 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
200 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
201
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
202 return 0;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
203 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
204
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
205
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
206 #define free_null( _v ) \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
207 if (_v) { \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
208 free(_v); \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
209 (_v) = NULL; \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
210 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
211
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
212 #define free_list( _l ) \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
213 while (!FD_IS_LIST_EMPTY(_l)) { \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
214 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
215 fd_list_unlink(__li); \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
216 free(__li); \
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
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
219 /* 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
220 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
221 {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
222 struct msg *m;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
223 TRACE_ENTRY("%p", peer);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
224 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
225
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
226 /* 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
227 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
228 CHECK_FCT_DO(fd_fifo_post(fd_g_outgoing, &m),
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
229 {
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
230 /* fallback: destroy the message */
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
231 fd_msg_log(FD_MSG_LOG_DROPPED, m, "Internal error: unable to requeue this message during failover process");
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
232 CHECK_FCT_DO(fd_msg_free(m), /* What can we do more? */)
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
233 } );
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
234 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
235
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
236 /* Requeue all routable sent requests */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
237 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
238
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
239 /* Done */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
240 return;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
241 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
242
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
243 /* 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
244 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
245 {
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
246 struct fd_peer *p;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
247
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
248 TRACE_ENTRY("%p", ptr);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
249 CHECK_PARAMS(ptr);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
250 p = *ptr;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
251 *ptr = NULL;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
252 CHECK_PARAMS(p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
253
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
254 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
255
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
256 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
257
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
258 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
259 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
260
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
261 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
262 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
263 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
264
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
265 free_list( &p->p_hdr.info.pi_endpoints );
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
266
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
267 free_null(p->p_dbgorig);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
268
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
269 fd_list_unlink(&p->p_expiry);
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
270 fd_list_unlink(&p->p_actives);
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
271
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
272 CHECK_FCT_DO( fd_fifo_del(&p->p_tosend), /* continue */ );
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
273 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
274 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
275 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
276
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
277 /* If the callback is still around... */
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
278 if (p->p_cb)
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
279 (*p->p_cb)(NULL, p->p_cb_data);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
280
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
281 /* Free the structure */
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
282 free(p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
283 return 0;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
284 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
285
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
286 /* 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
287 int fd_peer_fini()
12
418d2ce80dc8 Added support in configuration file for peers declaration
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 11
diff changeset
288 {
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
289 struct fd_list * li;
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
290 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
291 int list_empty;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
292 struct timespec wait_until, now;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
293
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
294 TRACE_ENTRY();
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
295
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
296 CHECK_FCT_DO(fd_p_expi_fini(), /* continue */);
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 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
299
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
300 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
301 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
302 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
303
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
304 if (fd_peer_getstate(peer) != STATE_ZOMBIE) {
78
a58f0757c06a Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 48
diff changeset
305 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
306 } else {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
307 li = li->prev; /* to avoid breaking the loop */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
308 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
309 fd_list_insert_before(&purge, &peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
310 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
311 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
312 list_empty = FD_IS_LIST_EMPTY(&fd_g_peers);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
313 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
314
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
315 if (!list_empty) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
316 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) );
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
317 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
318 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
319 wait_until.tv_nsec = now.tv_nsec;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
320 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
321
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
322 while ((!list_empty) && (TS_IS_INFERIOR(&now, &wait_until))) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
323
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
324 /* 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
325 usleep(100000);
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
326
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
327 /* Remove zombie peers */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
328 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
329 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
330 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
331 if (fd_peer_getstate(peer) == STATE_ZOMBIE) {
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
332 li = li->prev; /* to avoid breaking the loop */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
333 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
334 fd_list_insert_before(&purge, &peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
335 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
336 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
337 list_empty = FD_IS_LIST_EMPTY(&fd_g_peers);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
338 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
339 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) );
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
340 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
341
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
342 if (!list_empty) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
343 TRACE_DEBUG(INFO, "Forcing connections shutdown");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
344 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
345 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
346 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
347 fd_psm_abord(peer);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
348 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
349 fd_list_insert_before(&purge, &peer->p_hdr.chain);
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 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
352 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
353
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
354 /* Free memory objects of all peers */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
355 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
356 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
357 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
358 fd_peer_free(&peer);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
359 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
360
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
361 /* Now empty the validators list */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
362 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
363 while (!FD_IS_LIST_EMPTY( &validators )) {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
364 struct fd_list * v = validators.next;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
365 fd_list_unlink(v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
366 free(v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
367 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
368 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
369
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
370 return 0;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
371 }
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 /* Dump info of one peer */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
374 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
375 {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
376 if (peer->p_eyec != EYEC_PEER) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
377 fd_log_debug(" Invalid peer @ %p !\n", peer);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
378 return;
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
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
381 fd_log_debug("> %s\t%s", STATE_STR(fd_peer_getstate(peer)), peer->p_hdr.info.pi_diamid);
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
382 if (details > INFO) {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
383 fd_log_debug("\t(rlm:%s)", peer->p_hdr.info.runtime.pir_realm ?: "<unknown>");
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
384 if (peer->p_hdr.info.runtime.pir_prodname)
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
385 fd_log_debug("\t['%s' %u]", peer->p_hdr.info.runtime.pir_prodname, peer->p_hdr.info.runtime.pir_firmrev);
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
386 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
387 fd_log_debug("\n");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
388 if (details > FULL) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
389 /* Dump all info */
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
390 fd_log_debug("\tEntry origin : %s\n", peer->p_dbgorig?: "not set");
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
391 fd_log_debug("\tConfig flags : %s%s%s%s%s - %s%s%s\n",
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
392 peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_DEFAULT ? "" :
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
393 (peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_IP ? "IP." : "IPv6."),
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
394 peer->p_hdr.info.config.pic_flags.pro4 == PI_P4_DEFAULT ? "" :
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
395 (peer->p_hdr.info.config.pic_flags.pro4 == PI_P4_TCP ? "TCP." : "SCTP."),
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
396 peer->p_hdr.info.config.pic_flags.alg ? "PrefTCP." : "",
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
397 peer->p_hdr.info.config.pic_flags.sec & PI_SEC_NONE ? "NoTLSok" :"",
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
398 peer->p_hdr.info.config.pic_flags.sec & PI_SEC_TLS_OLD ? "OldTLS" :"",
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
399 peer->p_hdr.info.config.pic_flags.exp ? "Expire." : "",
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
400 peer->p_hdr.info.config.pic_flags.persist ? "Persist." : ""
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
401 );
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
402 fd_log_debug("\tLifetime : %d sec\n", peer->p_hdr.info.config.pic_lft);
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
403 }
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
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
406 /* Dump the list of peers */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
407 void fd_peer_dump_list(int details)
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
408 {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
409 struct fd_list * li;
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
410
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
411 fd_log_debug("Dumping list of peers :\n");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
412 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
413
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
414 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
415 struct fd_peer * np = (struct fd_peer *)li->o;
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
416 fd_peer_dump(np, details);
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
417 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
418
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
419 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
420 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
421
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
422 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
423 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
424
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
425 /* 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
426 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
427 {
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
428 struct msg * msg;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
429 struct avp *avp_oh;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
430 struct avp_hdr * avp_hdr;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
431 struct fd_list * li;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
432 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
433 int ret = 0;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
434 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
435 struct cnx_incoming * ev_data;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
436
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
437 TRACE_ENTRY("%p %p", cer, cnx);
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
438 CHECK_PARAMS(cer && *cer && cnx && *cnx);
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
439
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
440 msg = *cer;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
441
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
442 /* If needed, resolve the dictioanry model for Origin-Host */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
443 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
444 if (!avp_oh_model) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
445 avp_code_t code = AC_ORIGIN_HOST;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
446 int ret;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
447 CHECK_FCT_DO( ret = fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE, &code, &avp_oh_model, ENOENT),
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
448 { CHECK_POSIX( pthread_mutex_unlock(&cache_avp_lock) ); return ret; } );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
449 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
450 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
451
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
452 /* 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
453 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
454 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
455 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
456
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
457 /* First, check if the Origin-Host value */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
458 if (!fd_os_is_valid_DiameterIdentity(avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len)) {
725
8b03c672261f Fix a small bug in peers validation process
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
459 TRACE_DEBUG(INFO, "Received new CER with invalid Origin-Host");
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
460 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, cer, MSGFL_ANSW_ERROR ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
461 CHECK_FCT( fd_msg_rescode_set(*cer, "ER_DIAMETER_INVALID_AVP_VALUE",
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
462 "Your Origin-Host contains invalid characters.", avp_oh, 1 ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
463 CHECK_FCT( fd_out_send(cer, *cnx, NULL, FD_CNX_ORDERED) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
464 return EINVAL;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
465 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
466
152
5b4c62560f22 Remove deadlock on rwlock upgrade unsupported
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 137
diff changeset
467 /* 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
468 * 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
469 */
5b4c62560f22 Remove deadlock on rwlock upgrade unsupported
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 137
diff changeset
470 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
471
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
472 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
473 int cmp;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
474 peer = (struct fd_peer *)li->o;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
475 cmp = fd_os_almostcasecmp( avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen );
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
476 if (cmp > 0)
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
477 continue;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
478 if (cmp == 0)
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
479 found = 1;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
480 break;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
481 }
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
482
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
483 if (!found) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
484 /* 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
485 peer = NULL;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
486 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
487
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
488 /* 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
489 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
490 { ret = ENOMEM; goto out; } );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
491 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
492 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
493 peer->p_flags.pf_responder = 1;
154
4356de61174d Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 153
diff changeset
494 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
495
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
496 /* 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
497 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
498 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
499 -- RFC3539 states that this must not be inferior to BRINGDOWN_INTERVAL = 5 minutes */
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
500
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
501 /* 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
502 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
503
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
504 /* 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
505 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
506 } else {
547f30e9a8ae Re-enable zombie peers on new connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 154
diff changeset
507 /* 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
508 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
509 /* 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
510 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
511 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
512 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
513 peer->p_state = STATE_NEW;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
514 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
515 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
516 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
517 }
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
518 }
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
519
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
520 /* 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
521 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
522 memset(ev_data, 0, sizeof(ev_data));
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
523
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
524 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
525 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
526 ev_data->validate = !found;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
527
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
528 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
529
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
530 out:
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
531 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
532
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
533 if (ret == 0) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
534 /* 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
535 *cer = NULL;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
536 *cnx = NULL;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
537 }
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
538
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
539 return ret;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
540 }
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
541
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
542 /* Save a callback to accept / reject incoming unknown peers */
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
543 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
544 {
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
545 struct fd_list * v;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
546
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
547 TRACE_ENTRY("%p", peer_validate);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
548 CHECK_PARAMS(peer_validate);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
549
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
550 /* Alloc a new entry */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
551 CHECK_MALLOC( v = malloc(sizeof(struct fd_list)) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
552 fd_list_init( v, peer_validate );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
553
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
554 /* Add at the beginning of the list */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
555 CHECK_FCT( pthread_rwlock_wrlock(&validators_rw) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
556 fd_list_insert_after(&validators, v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
557 CHECK_FCT( pthread_rwlock_unlock(&validators_rw));
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
558
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
559 /* Done! */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
560 return 0;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
561 }
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
562
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
563 /* 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
564 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
565 {
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
566 int ret = 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
567 struct fd_list * v;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
568
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
569 CHECK_FCT( pthread_rwlock_rdlock(&validators_rw) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
570 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
571 int auth = 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
572 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
573 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
574 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
575 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
576 goto out;
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
577 if (auth) {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
578 ret = (auth > 0) ? 0 : -1;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
579 goto out;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
580 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
581 peer->p_cb2 = NULL;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
582 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
583
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
584 /* 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
585 ret = -1;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
586 out:
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
587 CHECK_FCT( pthread_rwlock_unlock(&validators_rw));
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
588 return ret;
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
589 }
"Welcome to our mercurial repository"