annotate libfdcore/peers.c @ 1186:56c36d1007b4

Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
author Sebastien Decugis <sdecugis@freediameter.net>
date Fri, 07 Jun 2013 18:48:34 +0800
parents 23695957bfc0
children f40de74bd1c7
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) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 738
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
11
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
928
5053f1abcf5d Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 917
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
11
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 649
diff changeset
36 #include "fdcore-internal.h"
11
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
38 /* Global list of peers */
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
39 struct fd_list fd_g_peers = FD_LIST_INITIALIZER(fd_g_peers);
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
40 pthread_rwlock_t fd_g_peers_rw = PTHREAD_RWLOCK_INITIALIZER;
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
41
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
42 /* List of active peers */
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);
767
c47c16436f71 Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 749
diff changeset
79 CHECK_FCT( fd_fifo_new(&p->p_tosend, 5) );
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 */
947
cce5d4bace82 Make config file parameter const and convert another fprintf to TRACE_DEBUG_ERROR.
Thomas Klausner <tk@giga.or.at>
parents: 908
diff changeset
93 int fd_peer_add ( struct peer_info * info, const char * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data )
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
94 {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
95 struct fd_peer *p = NULL;
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
96 struct fd_list * li, *li_inf;
16
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) );
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
145 li_inf = &fd_g_peers;
16
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;
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
148 int cont;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
149 int cmp = fd_os_almostcasesrch( p->p_hdr.info.pi_diamid, p->p_hdr.info.pi_diamidlen,
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
150 next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen,
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
151 &cont );
743
5d529eb0ad33 Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
152 if (cmp > 0)
5d529eb0ad33 Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
153 li_inf = li; /* it will come after this element, for sure */
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
154
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
155 if (cmp == 0) {
743
5d529eb0ad33 Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
156 ret = EEXIST; /* we have a duplicate */
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
157 break;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
158 }
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
159 if (!cont)
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
160 break;
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
161 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
162
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
163 /* 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
164 if (! ret)
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
165 do {
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
166 /* Update expiry list */
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
167 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
168
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
169 /* Insert the new element in the list */
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
170 fd_list_insert_after( li_inf, &p->p_hdr.chain );
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
171 } while (0);
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
172
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
173 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
174 if (ret) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
175 CHECK_FCT( fd_peer_free(&p) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
176 } else {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
177 CHECK_FCT( fd_psm_begin(p) );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
178 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
179 return ret;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
180 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
181
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
182 /* Search for a peer */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
183 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
184 {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
185 struct fd_list * li;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
186 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
187 CHECK_PARAMS( diamid && diamidlen && peer );
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
188
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
189 *peer = NULL;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
190
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
191 /* Search in the list */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
192 CHECK_POSIX( pthread_rwlock_rdlock(&fd_g_peers_rw) );
743
5d529eb0ad33 Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
193 if (igncase) {
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
194 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
195 struct fd_peer * next = (struct fd_peer *)li;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
196 int cmp, cont;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
197 cmp = fd_os_almostcasesrch( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen, &cont );
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
198 if (cmp == 0) {
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
199 *peer = &next->p_hdr;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
200 break;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
201 }
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
202 if (!cont)
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
203 break;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
204 }
743
5d529eb0ad33 Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
205 } else {
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
206 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
207 struct fd_peer * next = (struct fd_peer *)li;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
208 int cmp = fd_os_cmp( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen );
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
209 if (cmp > 0)
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
210 continue;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
211 if (cmp == 0)
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
212 *peer = &next->p_hdr;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
213 break;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
214 }
743
5d529eb0ad33 Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
215 }
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
216 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
217
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
218 return 0;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
219 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 78
diff changeset
220
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
221
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
222 #define free_null( _v ) \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
223 if (_v) { \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
224 free(_v); \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
225 (_v) = NULL; \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
226 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
227
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
228 #define free_list( _l ) \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
229 while (!FD_IS_LIST_EMPTY(_l)) { \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
230 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
231 fd_list_unlink(__li); \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
232 free(__li); \
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
233 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
234
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
235 /* 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
236 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
237 {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
238 struct msg *m;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
239 TRACE_ENTRY("%p", peer);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
240 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
241
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
242 /* 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
243 while ( fd_fifo_tryget(peer->p_tosend, &m) == 0 ) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
244 fd_hook_call(HOOK_MESSAGE_FAILOVER, m, peer, NULL, fd_msg_pmdl_get(m));
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
245 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
246 {
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
247 /* fallback: destroy the message */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
248 fd_hook_call(HOOK_MESSAGE_DROPPED, m, NULL, "Internal error: unable to requeue this message during failover process", fd_msg_pmdl_get(m));
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
249 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
250 } );
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
251 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
252
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
253 /* Requeue all routable sent requests */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
254 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
255
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
256 /* Done */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
257 return;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
258 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
259
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
260 /* Describe the current connection */
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
261 int fd_peer_cnx_proto_info(struct peer_hdr *peer, char * buf, size_t len)
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
262 {
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
263 struct fd_peer * p = (struct fd_peer *)peer;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
264 TRACE_ENTRY("%p %p %zd", peer, buf, len);
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
265 CHECK_PARAMS(CHECK_PEER(peer) && buf && len);
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
266
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
267 if (p->p_cnxctx) {
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
268 CHECK_FCT(fd_cnx_proto_info(p->p_cnxctx, buf, len));
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
269 } else if (p->p_receiver) {
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
270 CHECK_FCT(fd_cnx_proto_info(p->p_receiver, buf, len));
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
271 } else {
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
272 snprintf(buf, len, "Not Connected");
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
273 }
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
274
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
275 return 0;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
276 }
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
277
939
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
278 /* Return the value of srlist->cnt */
1010
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
279 int fd_peer_get_load_pending(struct peer_hdr *peer, long * to_receive, long * to_send)
939
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
280 {
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
281 struct fd_peer * p = (struct fd_peer *)peer;
1010
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
282 TRACE_ENTRY("%p %p %p", peer, to_receive, to_send);
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
283 CHECK_PARAMS(CHECK_PEER(peer));
939
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
284
1010
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
285 if (to_receive) {
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
286 CHECK_POSIX( pthread_mutex_lock(&p->p_sr.mtx) );
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
287 *to_receive = p->p_sr.cnt;
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
288 CHECK_POSIX( pthread_mutex_unlock(&p->p_sr.mtx) );
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
289 }
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
290 if (to_send) {
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
291 CHECK_POSIX( pthread_mutex_lock(&p->p_state_mtx) );
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
292 *to_send = p->p_reqin_count;
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
293 CHECK_POSIX( pthread_mutex_unlock(&p->p_state_mtx) );
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
294 }
939
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
295
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
296 return 0;
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
297 }
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
298
1bc052ef961f Add a function to access this counter
Sebastien Decugis <sdecugis@freediameter.net>
parents: 933
diff changeset
299
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
300 /* 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
301 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
302 {
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
303 struct fd_peer *p;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
304
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
305 TRACE_ENTRY("%p", ptr);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
306 CHECK_PARAMS(ptr);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
307 p = *ptr;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
308 *ptr = NULL;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
309 CHECK_PARAMS(p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
310
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
311 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
312
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
313 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
314
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
315 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
316 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
317
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
318 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
319 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
320 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
321
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
322 free_list( &p->p_hdr.info.pi_endpoints );
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
323
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
324 free_null(p->p_dbgorig);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
325
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
326 fd_list_unlink(&p->p_expiry);
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
327 fd_list_unlink(&p->p_actives);
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
328
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
329 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
330 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
331 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
332 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
333
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
334 /* If the callback is still around... */
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
335 if (p->p_cb)
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
336 (*p->p_cb)(NULL, p->p_cb_data);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
337
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
338 /* Free the structure */
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
339 free(p);
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
340 return 0;
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
341 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
342
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
343 /* 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
344 int fd_peer_fini()
12
418d2ce80dc8 Added support in configuration file for peers declaration
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 11
diff changeset
345 {
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
346 struct fd_list * li;
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
347 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
348 int list_empty;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
349 struct timespec wait_until, now;
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 TRACE_ENTRY();
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
352
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
353 CHECK_FCT_DO(fd_p_expi_fini(), /* continue */);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
354
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
355 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
356
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
357 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
358 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
359 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
360
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
361 if (fd_peer_getstate(peer) != STATE_ZOMBIE) {
78
a58f0757c06a Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 48
diff changeset
362 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
363 } else {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
364 li = li->prev; /* to avoid breaking the loop */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
365 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
366 fd_list_insert_before(&purge, &peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
367 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
368 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
369 list_empty = FD_IS_LIST_EMPTY(&fd_g_peers);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
370 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
371
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
372 if (!list_empty) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
373 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) );
1185
23695957bfc0 Don't block on peers shutdown when early errors
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1181
diff changeset
374 fd_psm_start(); /* just in case */
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
375 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
376 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
377 wait_until.tv_nsec = now.tv_nsec;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
378 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
379
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
380 while ((!list_empty) && (TS_IS_INFERIOR(&now, &wait_until))) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
381
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
382 /* 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
383 usleep(100000);
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
384
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
385 /* Remove zombie peers */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
386 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
387 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
388 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
389 if (fd_peer_getstate(peer) == STATE_ZOMBIE) {
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
390 li = li->prev; /* to avoid breaking the loop */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
391 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
392 fd_list_insert_before(&purge, &peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
393 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
394 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
395 list_empty = FD_IS_LIST_EMPTY(&fd_g_peers);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
396 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
397 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &now) );
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
398 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
399
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
400 if (!list_empty) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
401 TRACE_DEBUG(INFO, "Forcing connections shutdown");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
402 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
403 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
404 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
405 fd_psm_abord(peer);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
406 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
407 fd_list_insert_before(&purge, &peer->p_hdr.chain);
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 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
410 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
411
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
412 /* Free memory objects of all peers */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
413 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
414 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
415 fd_list_unlink(&peer->p_hdr.chain);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
416 fd_peer_free(&peer);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
417 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
418
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
419 /* Now empty the validators list */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
420 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
421 while (!FD_IS_LIST_EMPTY( &validators )) {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
422 struct fd_list * v = validators.next;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
423 fd_list_unlink(v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
424 free(v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
425 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
426 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
427
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
428 return 0;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
429 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
430
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
431 /* Dump info of one peer */
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
432 DECLARE_FD_DUMP_PROTOTYPE(fd_peer_dump, struct peer_hdr * p, int details)
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
433 {
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
434 FD_DUMP_HANDLE_OFFSET();
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
435
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
436 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{peer}(@%p): ", p), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
437
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
438 if (!CHECK_PEER(p)) {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
439 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL"), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
440 } else {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
441 struct fd_peer * peer = (struct fd_peer *)p;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
442
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
443 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s [%s, cnt:%ldsr,%ldpa]", peer->p_hdr.info.pi_diamid, STATE_STR(fd_peer_getstate(peer)), peer->p_sr.cnt, peer->p_reqin_count), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
444 if (details > 0) {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
445 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " rlm:%s", peer->p_hdr.info.runtime.pir_realm ?: "<unknown>"), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
446 if (peer->p_hdr.info.runtime.pir_prodname) {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
447 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " ['%s' %u]", peer->p_hdr.info.runtime.pir_prodname, peer->p_hdr.info.runtime.pir_firmrev), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
448 }
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
449 }
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
450 if (details > 1) {
1181
22de21feec64 Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
451 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " [from:%s] flags:%s%s%s%s%s%s%s%s lft:%ds",
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
452 peer->p_dbgorig ?: "unset",
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
453 peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_DEFAULT ? "-" :
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
454 (peer->p_hdr.info.config.pic_flags.pro3 == PI_P3_IP ? "4" : "6"),
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
455 peer->p_hdr.info.config.pic_flags.pro4 == PI_P4_DEFAULT ? "-" :
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
456 (peer->p_hdr.info.config.pic_flags.pro4 == PI_P4_TCP ? "T" : "S"),
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
457 peer->p_hdr.info.config.pic_flags.alg ? "P" : "-",
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
458 peer->p_hdr.info.config.pic_flags.sec & PI_SEC_NONE ? "N" :"-",
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
459 peer->p_hdr.info.config.pic_flags.sec & PI_SEC_TLS_OLD ? "O" :"-",
1181
22de21feec64 Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
460 peer->p_hdr.info.config.pic_flags.sctpsec & PI_SCTPSEC_3436 ? "3" :"-",
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
461 peer->p_hdr.info.config.pic_flags.exp ? "E" : "-",
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
462 peer->p_hdr.info.config.pic_flags.persist ? "P" : "-",
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
463 peer->p_hdr.info.config.pic_lft), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
464 }
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
465
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
466 }
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
467
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
468 return *buf;
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
469 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
470
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
471 /* Dump the list of peers */
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
472 DECLARE_FD_DUMP_PROTOTYPE(fd_peer_dump_list, int details)
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
473 {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
474 struct fd_list * li;
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
475 FD_DUMP_HANDLE_OFFSET();
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
476
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
477 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
478
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
479 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
480 CHECK_MALLOC_DO( fd_peer_dump(FD_DUMP_STD_PARAMS, (struct peer_hdr *)li->o, details), break);
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
481 if (li->next != &fd_g_peers) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
482 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), break);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
483 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
484 }
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
485
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
486 CHECK_FCT_DO( pthread_rwlock_unlock(&fd_g_peers_rw), /* continue */ );
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
487 return *buf;
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
488 }
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
489
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
490 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
491 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
492
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
493 /* 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
494 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
495 {
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
496 struct msg * msg;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
497 struct avp *avp_oh;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
498 struct avp_hdr * avp_hdr;
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
499 struct fd_list * li, *li_inf;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
500 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
501 int ret = 0;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
502 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
503 struct cnx_incoming * ev_data;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
504
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
505 TRACE_ENTRY("%p %p", cer, cnx);
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
506 CHECK_PARAMS(cer && *cer && cnx && *cnx);
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
507
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
508 msg = *cer;
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
509
749
2557127f3c8b fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 743
diff changeset
510 /* If needed, resolve the dictionary model for Origin-Host */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
511 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
512 if (!avp_oh_model) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
513 avp_code_t code = AC_ORIGIN_HOST;
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
514 CHECK_FCT_DO( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE, &code, &avp_oh_model, ENOENT),
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
515 { LOG_E("Cannot find Origin-Host AVP definition in the dictionary!"); (void) pthread_mutex_unlock(&cache_avp_lock); return __ret__; } );
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
516 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
517 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
518
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
519 /* 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
520 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
521 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
522 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
523
749
2557127f3c8b fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 743
diff changeset
524 /* First, check if the Origin-Host value is valid */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
525 if (!fd_os_is_valid_DiameterIdentity(avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len)) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
526 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, cer, MSGFL_ANSW_ERROR ) );
827
a8ed055a9253 Fix name of the constant errors used for rescode
Sebastien Decugis <sdecugis@freediameter.net>
parents: 767
diff changeset
527 CHECK_FCT( fd_msg_rescode_set(*cer, "DIAMETER_INVALID_AVP_VALUE",
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
528 "Your Origin-Host contains invalid characters.", avp_oh, 1 ) );
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
529
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
530 fd_hook_call(HOOK_PEER_CONNECT_FAILED, *cer, NULL, "Received CER with invalid Origin-Host AVP", NULL);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
531
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1185
diff changeset
532 CHECK_FCT( fd_out_send(cer, *cnx, NULL) );
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
533 return EINVAL;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
534 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
535
152
5b4c62560f22 Remove deadlock on rwlock upgrade unsupported
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 137
diff changeset
536 /* 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
537 * 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
538 */
5b4c62560f22 Remove deadlock on rwlock upgrade unsupported
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 137
diff changeset
539 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
540
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
541 li_inf = &fd_g_peers;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
542 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
543 int cmp, cont;
749
2557127f3c8b fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 743
diff changeset
544 peer = (struct fd_peer *)li;
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
545 cmp = fd_os_almostcasesrch( avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen, &cont );
749
2557127f3c8b fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 743
diff changeset
546 if (cmp > 0) {
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
547 li_inf = li;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
548 }
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
549 if (cmp == 0) {
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
550 found = 1;
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
551 break;
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
552 }
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
553 if (!cont)
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
554 break;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
555 }
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
556
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
557 if (!found) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
558 /* 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
559 peer = NULL;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
560 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
561
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
562 /* 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
563 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
564 { ret = ENOMEM; goto out; } );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
565 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
566 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
567 peer->p_flags.pf_responder = 1;
154
4356de61174d Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 153
diff changeset
568 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
569
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
570 LOG_D("Created new peer object for incoming CER: %s", peer->p_hdr.info.pi_diamid);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
571
933
04f590da5821 Add cmake option DISABLE_PEER_EXPIRY to disable dynamic peer expiration mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 928
diff changeset
572 #ifndef DISABLE_PEER_EXPIRY
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
573 /* 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
574 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
575 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
576 -- RFC3539 states that this must not be inferior to BRINGDOWN_INTERVAL = 5 minutes */
933
04f590da5821 Add cmake option DISABLE_PEER_EXPIRY to disable dynamic peer expiration mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 928
diff changeset
577
749
2557127f3c8b fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 743
diff changeset
578 CHECK_FCT_DO( ret = fd_p_expi_update( peer ), goto out );
933
04f590da5821 Add cmake option DISABLE_PEER_EXPIRY to disable dynamic peer expiration mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 928
diff changeset
579 #endif /* DISABLE_PEER_EXPIRY */
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
580
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
581 /* Insert the new peer in the list (the PSM will take care of setting the expiry after validation) */
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 725
diff changeset
582 fd_list_insert_after( li_inf, &peer->p_hdr.chain );
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
583
972
ce3cacbbccc9 Fix some typos.
Thomas Klausner <tk@giga.or.at>
parents: 968
diff changeset
584 /* Start the PSM, which will receive the event below */
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
585 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
586 } else {
547f30e9a8ae Re-enable zombie peers on new connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 154
diff changeset
587 /* 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
588 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
589 /* 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
590 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
591 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
592 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
593 peer->p_state = STATE_NEW;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
594 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
595 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
596 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
597 }
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
598 }
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
599
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
600 /* 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
601 CHECK_MALLOC_DO( ev_data = malloc(sizeof(struct cnx_incoming)), { ret = ENOMEM; goto out; } );
908
ed611e15f744 Fix a few warnings, thank you Thomas again
Sebastien Decugis <sdecugis@freediameter.net>
parents: 837
diff changeset
602 memset(ev_data, 0, sizeof(*ev_data));
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
603
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
604 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
605 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
606 ev_data->validate = !found;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
607
917
a2cf598607e6 Another place where ev_data was not dereferenced -- thanks Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 908
diff changeset
608 CHECK_FCT_DO( ret = fd_event_send(peer->p_events, FDEVP_CNX_INCOMING, sizeof(*ev_data), ev_data), goto out );
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
609
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
610 out:
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
611 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
612
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
613 if (ret == 0) {
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
614 /* 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
615 *cer = NULL;
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
616 *cnx = NULL;
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
617 } else {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
618 char buf[1024];
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
619 snprintf(buf, sizeof(buf), "An error occurred while processing new incoming CER: %s", strerror(ret));
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
620 fd_hook_call(HOOK_PEER_CONNECT_FAILED, *cer, NULL, buf, NULL);
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
621 }
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
622
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
623 return ret;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
624 }
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
625
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
626 /* Save a callback to accept / reject incoming unknown peers */
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
627 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
628 {
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
629 struct fd_list * v;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
630
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
631 TRACE_ENTRY("%p", peer_validate);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
632 CHECK_PARAMS(peer_validate);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
633
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
634 /* Alloc a new entry */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
635 CHECK_MALLOC( v = malloc(sizeof(struct fd_list)) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
636 fd_list_init( v, peer_validate );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
637
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
638 /* Add at the beginning of the list */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
639 CHECK_FCT( pthread_rwlock_wrlock(&validators_rw) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
640 fd_list_insert_after(&validators, v);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
641 CHECK_FCT( pthread_rwlock_unlock(&validators_rw));
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
642
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
643 /* Done! */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
644 return 0;
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
645 }
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
646
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
647 /* 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
648 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
649 {
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
650 int ret = 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
651 struct fd_list * v;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
652
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
653 CHECK_FCT( pthread_rwlock_rdlock(&validators_rw) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
654 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
655 int auth = 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
656 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
657 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
658 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
659 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
660 goto out;
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
661 if (auth) {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
662 ret = (auth > 0) ? 0 : -1;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
663 goto out;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
664 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
665 peer->p_cb2 = NULL;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
666 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
667
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
668 /* 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
669 ret = -1;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
670 out:
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
671 CHECK_FCT( pthread_rwlock_unlock(&validators_rw));
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 29
diff changeset
672 return ret;
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
673 }
"Welcome to our mercurial repository"