annotate waaad/peer-psm.c @ 416:5c5d72fd7f2a

Added more verbose information on connection message
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 16 Jun 2009 13:55:52 +0900
parents e86dba02630a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
371
e86dba02630a Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 351
diff changeset
5 * Copyright (c) 2009, WIDE Project and NICT *
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
618d0e5d7cb3 Completed peer module reorganization
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 *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
618d0e5d7cb3 Completed peer module reorganization
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 *
618d0e5d7cb3 Completed peer module reorganization
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 *
618d0e5d7cb3 Completed peer module reorganization
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 *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
618d0e5d7cb3 Completed peer module reorganization
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 *
618d0e5d7cb3 Completed peer module reorganization
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 *
618d0e5d7cb3 Completed peer module reorganization
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 *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /* Peers facility.
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37 *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 * This file contains the code of the peer state machine.
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 *
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 #include "waaad-internal.h"
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43 #include "peer-internal.h"
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 STATESTR_DEFINITION;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46
257
4b9688373710 New tests, many fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 247
diff changeset
47 #ifndef IN_WAAAD_TEST
4b9688373710 New tests, many fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 247
diff changeset
48 static
4b9688373710 New tests, many fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 247
diff changeset
49 #endif /* IN_WAAAD_TEST */
4b9688373710 New tests, many fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 247
diff changeset
50 void _psm_change_state(_peer_t * peer, _peer_state_t new);
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 static void _psm_reset_ts(_peer_t * peer, int add_random, int delay);
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
52 static void _psm_cleanup( _peer_t * peer );
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
53 static int _psm_answer_CEA_simple( _peer_t * peer, _pevent_t event, void * ev_data );
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
54 static int _psm_do_watchdog( _peer_t * peer, _pevent_t event, void * ev_data );
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
55
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
57 /* Election */
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
58 static int _psm_election( _peer_t * peer )
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
59 {
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
60 TRACE_ENTRY("%p(%s/%s)", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state));
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
61
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
62 /* Sanity check */
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
63 ASSERT( peer && peer->p_electdata );
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
64
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
65 /* Now compare the Diameter-Ids according to RFC:
226
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
66 The election is performed on the responder. The responder compares
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
67 the Origin-Host received in the CER with its own Origin-Host as two
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
68 streams of octets. If the local Origin-Host lexicographically
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
69 succeeds the received Origin-Host a Win-Election event is issued
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
70 locally. Diameter identities are in ASCII form therefore the lexical
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
71 comparison is consistent with DNS case insensitivity where octets
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
72 that fall in the ASCII range 'a' through 'z' MUST compare equally to
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
73 their upper-case counterparts between 'A' and 'Z'. See Appendix D
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
74 for interactions between the Diameter protocol and Internationalized
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
75 Domain Name (IDNs).
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
76
226
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
77 The winner of the election MUST close the connection it initiated.
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
78 Historically, maintaining the responder side of a connection was more
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
79 efficient than maintaining the initiator side. However, current
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
80 practices makes this distinction irrelevant.
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
81 */
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
82
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
83 if (strcasecmp(peer->p_electdata->peer->p_diamid, g_pconf->diameter_identity) < 0) {
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
84
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
85 /* WIN ELECTION */
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
86 _ev_incoming_t * inc = peer->p_electdata;
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
87 peer->p_electdata = NULL;
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
88
224
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
89 TRACE_DEBUG(FULL, "Election to peer '%s' was won, closing initiated connection...", peer->p_diamid);
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
90
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
91 /* Then process the receiver connection, as if it was a new one */
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
92 return _psm_answer_CEA_simple( peer, PEVENT_INCNX, inc );
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
93 }
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
94
226
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
95 TRACE_DEBUG(FULL, "Election to peer '%s' was lost, waiting for next events...", peer->p_diamid);
224
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
96
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
97 /* Election is lost, just wait for further events */
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
98 return 0;
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
99 }
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
100
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 /******************************************************************************/
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 /* The callbacks that are called when an event is received */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103 /******************************************************************************/
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 /* For events that we don't handle yet */
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
106 static int _psm_NOTSUP( _peer_t * peer, _pevent_t event, void * ev_data )
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 {
226
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
108 TRACE_DEBUG(INFO, "'%s' in state '%s', HANDLER FOR '%s' NOT IMPLEMENTED", peer->p_diamid, STATESTR(peer->p_state), EVENTSTR(event));
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
109 _psm_reset_ts(peer, 0, 5);
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113 /* callback that should never be called */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 static int _psm_assert( _peer_t * peer, _pevent_t event, void * ev_data )
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 TRACE_DEBUG(INFO, "Bad situation on peer state machine '%s'!!!", peer->p_diamid);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 ASSERT(0);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 return 2;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121 /* For events that are ignored */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
122 static int _psm_ignore( _peer_t * peer, _pevent_t event, void * ev_data )
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124 TRACE_DEBUG(FULL, "'%s' in state '%s', ignoring event '%s'...", peer->p_diamid, STATESTR(peer->p_state), EVENTSTR(event));
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
129 /* Restart the PSM from a clean state */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
130 static int _psm_reset( _peer_t * peer, _pevent_t event, void * ev_data )
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
132 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
133
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
134 /* Handle some simple events */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
135 if (event == PEVENT_SHUTDOWN)
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
136 peer->p_flags |= PEERFL_DISABLE_AFTER_SHUTDOWN;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
137
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
138 if (event == PEVENT_DESTROY)
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
139 peer->p_flags |= PEERFL_DESTROY_AFTER_SHUTDOWN;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
140
237
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
141
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
142 if (((peer->p_state == STATE_SUSPECT) && (event == PEVENT_TIMEOUT))
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
143 || (event == PEVENT_DISCONNECTED)
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
144 || (event == PEVENT_SND_FAILED)
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
145 || (event == PEVENT_TH_TERM_IN)
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
146 || (event == PEVENT_TH_TERM_OUT)
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
147 )
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
148 peer->p_flags |= PEERFL_CNX_PB;
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
149
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
150 /* All is done by just returning 1 here */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
151 return 1;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
152 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154 /* The lifetime of the peer entry is terminated, we must expire it or refresh it */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 static int _psm_expire( _peer_t * peer, _pevent_t event, void * ev_data )
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 /* @@ TODO */
226
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
160 TRACE_DEBUG(INFO, "Dynamic peers: Not implemented yet, will just destroy the peer now...");
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 return 2;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 /* Attempt a new connection */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 static int _psm_connect( _peer_t * peer, _pevent_t event, void * ev_data )
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 {
416
5c5d72fd7f2a Added more verbose information on connection message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 371
diff changeset
168 uint16_t port;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 CHECK_PARAMS_DO( peer->p_diamid, return 2 );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172
416
5c5d72fd7f2a Added more verbose information on connection message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 371
diff changeset
173 if (peer->p_addinfo.pa_ss.ss_family == AF_INET) {
5c5d72fd7f2a Added more verbose information on connection message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 371
diff changeset
174 port = ntohs( ((sSA4 *)(&peer->p_addinfo.pa_ss))->sin_port );
5c5d72fd7f2a Added more verbose information on connection message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 371
diff changeset
175 } else {
5c5d72fd7f2a Added more verbose information on connection message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 371
diff changeset
176 port = ntohs( ((sSA6 *)(&peer->p_addinfo.pa_ss))->sin6_port );
5c5d72fd7f2a Added more verbose information on connection message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 371
diff changeset
177 }
5c5d72fd7f2a Added more verbose information on connection message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 371
diff changeset
178
5c5d72fd7f2a Added more verbose information on connection message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 371
diff changeset
179 TRACE_DEBUG(INFO, "Connecting to peer '%s' on port '%s:%hd'...", peer->p_diamid, peer->p_addinfo.pa_proto == IPPROTO_SCTP ? "STCP" : "TCP", port);
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 /* go to STATE_WAITCNXACK state */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 _psm_change_state(peer, STATE_WAITCNXACK);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 /* Start a thread to attempt new connection. That thread will send an event upon success, or be canceled on timeout. */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 CHECK_FCT_DO( _peer_client_start(peer), return 1 );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 /* and re-arm the timer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188 _psm_reset_ts(peer, 0, CNX_TIMEOUT);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 /* Send a CER message */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 static int _psm_send_CER( _peer_t * peer, _pevent_t event, void * ev_data )
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 msg_t * cer = NULL;
202
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
197 _ev_connected_t * con_data = (_ev_connected_t *)ev_data;
224
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
198 int in_elec = 0;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201
202
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
202 /* We are called when we have been connected. do some sanity checks for debug */
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
203 ASSERT( event == PEVENT_CONNECTED );
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
204 ASSERT( con_data );
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
205 ASSERT( (peer->p_state == STATE_WAITCNXACK) || (peer->p_state == STATE_WAITCNXACK_ELEC) );
202
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
206
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
207 /* Initialize the connection data */
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
208 peer->p_sock = con_data->sock;
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
209 peer->p_ostr = con_data->ostr;
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
210 peer->p_istr = con_data->istr;
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
211 peer->p_curstr = 0;
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
212 SEC_SESS_INIT( &peer->p_sec_session, con_data->proto, peer, &peer->p_sock );
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
213
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
214 /* we don't need the event data anymore, free it */
301a35f95486 Added data to the CONNECTED event
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 201
diff changeset
215 free(ev_data);
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217 /* Start the communication threads */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
218 CHECK_FCT_DO( _peer_in_start(peer), return 1 );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219 CHECK_FCT_DO( _peer_out_start(peer), return 1 );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
220
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221 /* Create the CER message */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 CHECK_FCT_DO( _peer_cer_create(peer, &cer), return 2 );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224 /* Send the CER */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 CHECK_FCT_DO( meq_post( peer->p_out_q, cer ), return 1 );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226
224
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
227 in_elec = (peer->p_state == STATE_WAITCNXACK_ELEC);
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
228
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
229 /* go to next state */
224
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
230 _psm_change_state(peer, STATE_WAITCEA);
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
231
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232 /* and re-arm the timer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233 _psm_reset_ts(peer, 0, CEA_TIMEOUT);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
234
224
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
235 if (in_elec) {
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
236 /* DO election; we now have all needed information to proceed */
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
237 return _psm_election(peer);
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
238 }
0eabbea5e345 Debugging the election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 223
diff changeset
239
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
240 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
241 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
242
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
243 /* Received a CER, must check for common security and applications and answer */
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
244 static int _psm_answer_CEA_simple( _peer_t * peer, _pevent_t event, void * ev_data )
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
245 {
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
246 _ev_incoming_t * inc = (_ev_incoming_t *)ev_data;
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
247 msg_t * cea = NULL;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
248 uint32_t hbhid, eteid;
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
249
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
250 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
251
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
252 /* We are called when we have been connected. do some sanity checks for debug */
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
253 ASSERT( inc && VALIDATE_PEER(inc->peer) );
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
254 ASSERT( peer->p_sec_hdl == NULL );
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
255
237
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
256 /* Cleanup the peer */
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
257 _psm_cleanup( peer );
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
258 peer->p_flags |= PEERFL_RESPONDER;
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
259
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
260 /* Push two cancelation handlers to free the event data in case of we are cancelled */
306
b9b74d6ac29e Cleanup on cleanup functions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 292
diff changeset
261 pthread_cleanup_push( cleanup_buffer, inc );
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
262 pthread_cleanup_push( (void (*)(void *))_peer_struct_destroy, &inc->peer );
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
263
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
264 /* The inc->peer object already contains all parsed data from the received CER, copy this data into the main peer structure */
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
265 free(peer->p_realm); peer->p_realm = inc->peer->p_realm; inc->peer->p_realm = NULL;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
266 free(peer->p_peeraddr); peer->p_peeraddr = inc->peer->p_peeraddr;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
267 peer->p_peeraddr_sz = inc->peer->p_peeraddr_sz;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
268 inc->peer->p_peeraddr_sz = 0; inc->peer->p_peeraddr = NULL;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
269 free(peer->p_app_list); peer->p_app_list = inc->peer->p_app_list;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
270 peer->p_app_size = inc->peer->p_app_size;
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
271 peer->p_app_relay = inc->peer->p_app_relay;
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
272 inc->peer->p_app_size = 0; inc->peer->p_app_list = NULL;
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
273 inc->peer->p_app_relay = 0;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
274
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
275 peer->p_vendor = inc->peer->p_vendor;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
276 free(peer->p_prodname); peer->p_prodname = inc->peer->p_prodname; inc->peer->p_prodname = NULL;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
277 peer->p_firmrev = inc->peer->p_firmrev;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
278 peer->p_orstate = inc->peer->p_orstate;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
279
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
280 peer->p_sock = inc->peer->p_sock; inc->peer->p_sock = 0;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
281 peer->p_ostr = inc->peer->p_ostr;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
282 peer->p_istr = inc->peer->p_istr;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
283 peer->p_addinfo.pa_proto = inc->peer->p_addinfo.pa_proto;
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
284 peer->p_secmod = &_peer_secini_mod;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
285 SEC_SESS_INIT( &peer->p_sec_session, peer->p_addinfo.pa_proto, peer, &peer->p_sock );
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
286
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
287 hbhid = inc->hbh;
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
288 eteid = inc->ete;
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
289
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
290 /* Get a list of security modules that can handle the remote peer */
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
291 CHECK_FCT_DO( sec_getmodules(peer->p_diamid, (sSA *)&(inc->peer->p_addinfo.pa_ss), &inc->peer->p_sec_list), goto error );
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
292 while (! IS_LIST_EMPTY(&inc->peer->p_sec_list)) {
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
293 _sec_item_t * si = (_sec_item_t *)(inc->peer->p_sec_list.next);
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
294 uti_list_unlink(_LIST(si));
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
295
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
296 /* Was this module asked by the remote peer? */
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
297 if ((peer->p_sec_hdl == NULL) && ( _peer_struct_secid_check(inc->peer, ((sec_module_t *)(si->chain.o))->sec_insecid)) ) {
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
298 peer->p_sec_hdl = si->hdl;
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
299 /* peer->p_secmod will be changed *after* the CEA is sent */
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
300 } else {
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
301 CHECK_FCT_DO( sec_modunlink(si->hdl), /* continue */ );
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
302 }
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
303
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
304 free(si);
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
305 }
237
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
306 /* also free the saved security list stored locally, if any */
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
307 while ( ! IS_LIST_EMPTY( &peer->p_sec_list ) ) {
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
308 uti_list_t * next = peer->p_sec_list.next;
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
309 uti_list_unlink(next);
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
310 free(next);
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
311 }
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
312
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
313 /* From this point we don't need the inc anymore */
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
314 pthread_cleanup_pop(1);
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
315 pthread_cleanup_pop(1);
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
316
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
317 /* Create a CEA message */
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
318 CHECK_FCT_DO( _peer_cea_create( peer, &cea, eteid, hbhid ), goto error );
306
b9b74d6ac29e Cleanup on cleanup functions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 292
diff changeset
319 pthread_cleanup_push( cleanup_msg, cea );
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
320
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
321 /* At this point, if peer->p_sec_hdl is NULL, it means we have no common security, otherwise it points to our most prioritary common module */
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
322 if (peer->p_sec_hdl == NULL) {
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
323
247
adbc3782ba69 Routing module should be complete, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
324 CHECK_FCT_DO( msg_rescode_set( cea, "DIAMETER_NO_COMMON_SECURITY", NULL, NULL, 0 ), goto error );
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
325
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
326 /* send the message (the out thread is not running at this time) */
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
327 CHECK_FCT_DO( _peer_out_sendmsg( peer, cea ), goto error );
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
328
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
329 /* Free the message and the parsed data */
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
330 goto error;
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
331 }
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
332
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
333 /* Now check for a common application, or send NO_COMMON_APPLICATION message */
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
334 if (g_pconf->disable_relay && !peer->p_app_relay) {
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
335 int found = 0;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
336 int ix_loc = 0;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
337 int ix_rem = 0;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
338
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
339 /* Search at least one common application. Both arrays are ordered. */
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
340 while ((ix_loc < g_conf->supported_apps_nb) && (ix_rem < peer->p_app_size)) {
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
341 if (g_conf->supported_apps_list[ ix_loc ].a == peer->p_app_list[ ix_rem ].a) {
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
342 TRACE_DEBUG(INFO, "Found at least one common application with peer '%s': %u", peer->p_diamid, peer->p_app_list[ ix_rem ].a);
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
343 found = 1;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
344 break;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
345 }
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
346 if (g_conf->supported_apps_list[ ix_loc ].a < peer->p_app_list[ ix_rem ].a)
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
347 ix_loc++;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
348 else
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
349 ix_rem++;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
350 }
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
351
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
352 if (!found) {
247
adbc3782ba69 Routing module should be complete, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
353 CHECK_FCT_DO( msg_rescode_set( cea, "DIAMETER_NO_COMMON_APPLICATION", NULL, NULL, 0 ), goto error );
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
354
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
355 /* send the message (the out thread is not running at this time) */
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
356 CHECK_FCT_DO( _peer_out_sendmsg( peer, cea ), goto error );
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
357
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
358 /* Free the message and the parsed data */
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
359 goto error;
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
360 }
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
361 }
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
362
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
363 /* The CE is successful */
247
adbc3782ba69 Routing module should be complete, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
364 CHECK_FCT_DO( msg_rescode_set( cea, "DIAMETER_SUCCESS", NULL, NULL, 0 ), goto error );
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
365
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
366 /* Send the CEA */
290
5ed9c73c31cd Fixed debug levels, trace all incoming and outgoing messages with level of FULL
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 288
diff changeset
367 TRACE_DEBUG(FULL, "Sending CEA to '%s', status success", peer->p_diamid);
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
368 CHECK_FCT_DO( _peer_out_sendmsg( peer, cea ), goto error );
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
369
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
370 /* Free the CEA */
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
371 pthread_cleanup_pop(1);
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
372
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
373 /* now activate the security module and start the in/out threads */
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
374 CHECK_FCT( sec_getmodfromhdl(peer->p_sec_hdl, &peer->p_secmod) );
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
375
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
376 CHECK_FCT( _peer_in_start(peer) );
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
377 CHECK_FCT( _peer_out_start(peer) );
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
378
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
379 /* go to OPEN or REOPEN state */
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
380 /* This will also trig the security initialization. If TLS negotiation fails, an event will be trigged. */
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
381 if (peer->p_flags & PEERFL_CNX_PB) {
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
382
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
383 _psm_change_state(peer, STATE_REOPEN);
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
384
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
385 /* Now send a DWR */
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
386 return _psm_do_watchdog(peer, event, ev_data );
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
387
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
388 }
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
389
240
fb85b4e88ae3 Reset the timer after the cleanup
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 239
diff changeset
390 _psm_reset_ts(peer, 1, g_pconf->twtimer);
fb85b4e88ae3 Reset the timer after the cleanup
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 239
diff changeset
391
208
6d685e7ec213 Completed the code to send the CEA, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 207
diff changeset
392 _psm_change_state(peer, STATE_OPEN);
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
393
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
394 return 0;
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
395
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
396 error:
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
397 if (inc) {
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
398 if (inc->peer)
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
399 _peer_struct_destroy(&inc->peer);
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
400 free(inc);
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
401 inc = NULL;
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
402 }
207
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
403 if (cea) {
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
404 CHECK_FCT_DO( msg_free(cea, 1), /* continue */ );
6fe23eb0cd92 Changed incoming event format, added code to create CEA (unfinished), added code to set the result-code (unfinished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 204
diff changeset
405 }
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
406 return 1;
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
407 }
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
408
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
409 /* Received a CER on new connection that we reject */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
410 static int _psm_reject_incoming_CER( _peer_t * peer, _pevent_t event, void * ev_data )
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
411 {
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
412 _ev_incoming_t * inc = (_ev_incoming_t *)ev_data;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
413 msg_t * cea = NULL;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
414
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
415 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
416
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
417 ASSERT( event == PEVENT_INCNX );
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
418 ASSERT( inc && VALIDATE_PEER(inc->peer) );
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
419
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
420 /* Push two cancelation handlers to free the event data in case of we are cancelled */
306
b9b74d6ac29e Cleanup on cleanup functions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 292
diff changeset
421 pthread_cleanup_push( cleanup_buffer, inc );
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
422 pthread_cleanup_push( (void (*)(void *))_peer_struct_destroy, &inc->peer );
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
423
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
424 /* The inc->peer object already contains all parsed data from the received CER, copy this data into the main peer structure */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
425
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
426 /* Create a CEA message */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
427 CHECK_FCT_DO( _peer_cea_create( inc->peer, &cea, inc->ete, inc->hbh ), goto error );
306
b9b74d6ac29e Cleanup on cleanup functions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 292
diff changeset
428 pthread_cleanup_push( cleanup_msg, cea );
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
429
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
430 /* Now set the error code */
247
adbc3782ba69 Routing module should be complete, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
431 CHECK_FCT_DO( msg_rescode_set( cea, "DIAMETER_UNABLE_TO_COMPLY", NULL, NULL, 0 ), goto error );
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
432
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
433 /* send the message (the out thread is not running at this time) */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
434 CHECK_FCT_DO( _peer_out_sendmsg( inc->peer, cea ), goto error );
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
435
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
436 /* Free everything */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
437 pthread_cleanup_pop(1);
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
438 pthread_cleanup_pop(1);
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
439 pthread_cleanup_pop(1);
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
440
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
441 /* If we were in SUSPECT state, we may want to reset the peer now? Ignore for now ... */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
442
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
443 return 0;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
444
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
445 error:
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
446 if (inc) {
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
447 if (inc->peer)
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
448 _peer_struct_destroy(&inc->peer);
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
449 free(inc);
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
450 inc = NULL;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
451 }
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
452 if (cea) {
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
453 CHECK_FCT_DO( msg_free(cea, 1), /* continue */ );
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
454 }
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
455 return 1;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
456 }
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
457
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
458 /* Save incoming connection data for the upcoming election */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
459 static int _psm_incon_elect( _peer_t * peer, _pevent_t event, void * ev_data )
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
460 {
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
461 _ev_incoming_t * inc = (_ev_incoming_t *)ev_data;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
462
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
463 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
464
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
465 ASSERT( inc && VALIDATE_PEER(inc->peer) );
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
466
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
467 /* For now, just save the event data in the peer structure */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
468 ASSERT( peer->p_electdata == NULL );
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
469 peer->p_electdata = inc;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
470
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
471 /* And change state accordingly to previous state */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
472 ASSERT( (peer->p_state == STATE_WAITCNXACK) || (peer->p_state == STATE_WAITCEA) );
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
473
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
474 if (peer->p_state == STATE_WAITCEA) {
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
475 return _psm_election(peer);
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
476 }
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
477
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
478 _psm_change_state(peer, STATE_WAITCNXACK_ELEC);
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
479
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
480 return 0;
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
481 }
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
482
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
483 /* Timeout during election process, fallback to the responder side */
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
484 static int _psm_elect_timeout( _peer_t * peer, _pevent_t event, void * ev_data )
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
485 {
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
486 _ev_incoming_t * inc = peer->p_electdata;
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
487
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
488 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
489
226
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
490 if (inc == NULL) {
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
491 /* We have no responder-side connection, just reset the peer */
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
492 return _psm_reset(peer, event, ev_data);
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
493 }
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
494
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
495 peer->p_electdata = NULL;
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
496
237
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
497 /* Process as with a fresh incoming connection event */
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
498 return _psm_answer_CEA_simple( peer, PEVENT_INCNX, inc );
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
499 }
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
500
209
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
501 /* A message has been received while we were waiting for a CEA */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
502 static int _psm_receive_CEA( _peer_t * peer, _pevent_t event, void * ev_data )
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
503 {
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
504 msg_t * cea = NULL;
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
505
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
506 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
507
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
508 /* Do some sanity checks for debug */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
509 ASSERT( event == PEVENT_MSGRCVD );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
510 ASSERT( peer->p_state == STATE_WAITCEA );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
511 ASSERT( peer->p_sec_hdl == NULL );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
512
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
513 /* Retrieve the CEA from the incoming queue */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
514 CHECK_FCT_DO( meq_tryget(peer->p_in_q, &cea), return 1 );
306
b9b74d6ac29e Cleanup on cleanup functions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 292
diff changeset
515 pthread_cleanup_push( cleanup_msg, cea );
209
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
516
292
d40bbfcd07ef Fixed some additional debug messages and levels
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 290
diff changeset
517 TRACE_DEBUG(FULL, "Received this message from '%s':", peer->p_diamid);
d40bbfcd07ef Fixed some additional debug messages and levels
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 290
diff changeset
518 msg_dump_walk(FULL, cea);
d40bbfcd07ef Fixed some additional debug messages and levels
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 290
diff changeset
519
209
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
520 /* Check we can understand this message */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
521 CHECK_FCT_DO( msg_parse_dict(cea), goto no_cea );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
522
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
523 /* Check it is really a CEA */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
524 {
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
525 msg_data_t *mdata;
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
526
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
527 CHECK_FCT_DO( msg_data( cea, &mdata ), goto no_cea );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
528
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
529 if (mdata->msg_appl != 0) {
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
530 log_error("Received message with application %u while waiting for CEA, closing...\n", mdata->msg_appl);
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
531 goto no_cea;
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
532 }
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
533 if (mdata->msg_code != CC_CAPABILITIES_EXCHANGE) {
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
534 log_error("Received (%u) instead of CEA, closing...\n", mdata->msg_code);
209
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
535 goto no_cea;
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
536 }
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
537
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
538 /* Now check we support all mandatory AVPs */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
539 CHECK_FCT_DO( msg_parse_rules(cea, NULL), goto no_cea );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
540 }
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
541
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
542 /* Now parse the CEA. If an error occurs, the function returns an error and we will reset the PSM */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
543 CHECK_FCT_DO( _peer_cea_parse( cea, peer ), goto no_cea );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
544
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
545 /* Free the CEA */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
546 pthread_cleanup_pop(1);
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
547
231
ebd37fdf7a99 Added some verbosity
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 230
diff changeset
548 TRACE_DEBUG(FULL, "Stopping in/out threads with default sec module");
209
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
549 CHECK_FCT( _peer_in_stop(peer) );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
550 CHECK_FCT( _peer_out_stop(peer) );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
551
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
552 /* now activate the security module and start the in/out threads */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
553 CHECK_FCT( sec_getmodfromhdl(peer->p_sec_hdl, &peer->p_secmod) );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
554
231
ebd37fdf7a99 Added some verbosity
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 230
diff changeset
555 TRACE_DEBUG(FULL, "Starting in/out threads with correct sec module");
209
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
556 CHECK_FCT( _peer_in_start(peer) );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
557 CHECK_FCT( _peer_out_start(peer) );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
558
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
559 /* go to OPEN state */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
560 _psm_change_state(peer, STATE_OPEN);
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
561 /* This will also trig the security initialization. If TLS negotiation fails, an event will be trigged. */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
562
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
563 /* reset the timer for DWR: twtimer */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
564 _psm_reset_ts(peer, 1, g_pconf->twtimer);
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
565
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
566 return 0;
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
567
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
568 no_cea:
231
ebd37fdf7a99 Added some verbosity
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 230
diff changeset
569 TRACE_DEBUG(INFO, "Did not receive a CEA on initiated connection, resetting");
ebd37fdf7a99 Added some verbosity
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 230
diff changeset
570
209
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
571 if (cea) {
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
572 CHECK_FCT_DO( msg_free(cea, 1), /* continue */ );
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
573 }
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
574
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
575 return 1; /* will reset the peer */
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
576 }
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
577
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
578 /* A message has been received, we must handle application 0 and forward others to the routing module (we are in open state) */
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
579 static int _psm_receive_message( _peer_t * peer, _pevent_t event, void * ev_data )
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
580 {
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
581 msg_t * msg = NULL;
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
582 msg_data_t *mdata = NULL;
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
583
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
584 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
585
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
586 /* Do some sanity checks for debug */
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
587 ASSERT( event == PEVENT_MSGRCVD );
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
588
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
589 /* Retrieve the new message from the incoming queue */
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
590 CHECK_FCT_DO( meq_tryget(peer->p_in_q, &msg), return 1 );
306
b9b74d6ac29e Cleanup on cleanup functions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 292
diff changeset
591 pthread_cleanup_push( cleanup_msg, msg );
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
592
290
5ed9c73c31cd Fixed debug levels, trace all incoming and outgoing messages with level of FULL
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 288
diff changeset
593 TRACE_DEBUG(FULL, "Received this message from '%s':", peer->p_diamid);
5ed9c73c31cd Fixed debug levels, trace all incoming and outgoing messages with level of FULL
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 288
diff changeset
594 msg_dump_walk(FULL, msg);
5ed9c73c31cd Fixed debug levels, trace all incoming and outgoing messages with level of FULL
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 288
diff changeset
595
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
596 /* If the application id is not 0, or the message is proxyable, directly requeue in global incoming queue. */
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
597 CHECK_FCT_DO( msg_data( msg, &mdata ), goto error );
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
598 if ((mdata->msg_flags & CMD_FLAG_PROXIABLE) || (mdata->msg_appl != 0)) {
244
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
599 forward:
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
600
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
601 /* Save the source information with the message */
351
932ed12e1821 Add Route-Record AVP to answers as well
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 315
diff changeset
602 CHECK_FCT_DO( msg_source_set( msg, peer->p_diamid, peer->p_hash, /* mdata->msg_flags & CMD_FLAG_REQUEST */ /* we actually always add the route-record, even for answers */ 1 ),
244
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
603 {
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
604 CHECK_FCT_DO( msg_free(msg, 1), /* nothing */ );
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
605 goto error;
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
606 } );
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
607
1841789c4e97 Added code of the rt_in_th thread
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 243
diff changeset
608 /* Requeue in global queue */
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
609 CHECK_FCT_DO( meq_post(g_meq_incoming, msg), goto error );
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
610
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
611 goto end;
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
612 }
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
613
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
614 /* The application is Base Diameter Protocol, and the message is not proxyable, we must handle it in this PSM */
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
615
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
616 /* Check we can understand this message */
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
617 CHECK_FCT_DO( msg_parse_dict(msg),
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
618 {
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
619 log_error("A message with application 0 received from '%s' was not understood and dropped.\n", peer->p_diamid);
271
237d245fd336 Fixed some debug levels, add skeleton for new testcase
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 257
diff changeset
620 msg_dump_walk(0, msg);
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
621 goto error;
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
622 } );
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
623
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
624 /* Check that the message is conformant to our ABNF */
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
625 CHECK_FCT_DO( msg_parse_rules(msg, NULL),
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
626 {
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
627 TRACE_DEBUG(INFO, "TODO: retrieve the conflicting AVP and generate an error in case msg is a query");
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
628 log_error("A message with application 0 received from '%s' was not conforming to ABNF and dropped.\n", peer->p_diamid);
271
237d245fd336 Fixed some debug levels, add skeleton for new testcase
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 257
diff changeset
629 msg_dump_walk(0, msg);
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
630 msg_free(msg, 1);
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
631 goto end;
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
632 } );
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
633
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
634 switch (mdata->msg_code) {
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
635 case CC_CAPABILITIES_EXCHANGE:
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
636 /* We do not handle additional CER/CEA messages (no renegotiation). */
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
637 log_error("CER/CEA message received from peer '%s' in state %s (not supported), resetting connection...", peer->p_diamid, STATESTR(peer->p_state));
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
638 /* Note: the initial CER is received in server thread; the initial CEA is received in WAITCEA state in _psm_receive_CEA */
271
237d245fd336 Fixed some debug levels, add skeleton for new testcase
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 257
diff changeset
639 msg_dump_walk(0, msg);
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
640 goto error;
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
641
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
642 case CC_DISCONNECT_PEER:
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
643 if (mdata->msg_flags & CMD_FLAG_REQUEST) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
644 msg_t * dpa = NULL;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
645 int qlen = 0;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
646 /* We have received a DPR, check if we have any pending message and reply */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
647 /* Actually, we should also check that any message was sent recently according to RFC:
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
648
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
649 " Upon receipt of the message, the
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
650 Disconnect-Peer-Answer is returned, which SHOULD contain an error if
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
651 messages have recently been forwarded, and are likely in flight,
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
652 which would otherwise cause a race condition."
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
653
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
654 but checking we have no pending outgoing message is enough for the moment... */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
655 CHECK_FCT_DO( meq_length ( peer->p_out_q, &qlen ),
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
656 {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
657 /* The queue must be corrupt, better to reset the peer */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
658 goto error;
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
659 } );
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
660
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
661 /* Check the received DPR is valid */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
662 CHECK_FCT_DO( _peer_dpr_parse(msg, peer), goto error );
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
663
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
664 /* Now create the DPA */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
665 CHECK_FCT_DO( _peer_dpa_create(peer, &dpa, mdata->msg_eteid, mdata->msg_hbhid), goto error );
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
666
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
667 /* We can discard the incoming DPR, we don't need it anymore */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
668 msg_free(msg, 1);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
669
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
670 /* Set the error code according to the length of the out queue */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
671 if (qlen == 0) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
672 /* The queue was empty, ok to disconnect */
247
adbc3782ba69 Routing module should be complete, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
673 CHECK_FCT_DO( msg_rescode_set( dpa, "DIAMETER_SUCCESS", NULL, NULL, 0 ),
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
674 { msg_free(dpa, 1); return 1; } );
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
675 } else {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
676 /* The queue is not empty, refuse the disconnection */
247
adbc3782ba69 Routing module should be complete, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
677 CHECK_FCT_DO( msg_rescode_set( dpa, "DIAMETER_UNABLE_TO_COMPLY", "Pending message(s)", NULL, 0 ),
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
678 { msg_free(dpa, 1); return 1; } );
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
679 }
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
680
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
681 /* and queue the message for delivery */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
682 CHECK_FCT_DO( meq_post( peer->p_out_q, dpa ),
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
683 { msg_free(dpa, 1); return 1; } );
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
684
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
685 /* Now go to CLOSING state */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
686 _psm_change_state(peer, STATE_CLOSING);
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
687
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
688 } else {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
689 /* We received a DPA. Did we really ask for disconnection? */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
690 if ( ! (peer->p_flags & PEERFL_SHUTTING_DOWN)) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
691 log_error("Received DPA from '%s' but no DPR was sent, ignored", peer->p_diamid);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
692 msg_free(msg, 1);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
693 } else {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
694 /* The DPA was expected */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
695 int ret = 0;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
696
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
697 CHECK_FCT_DO(ret = _peer_dpa_parse(msg, peer), /* continue */);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
698
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
699 msg_free(msg, 1);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
700
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
701 if (ret == 0) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
702 /* The disconnection was accepted */
229
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
703 _psm_change_state(peer, STATE_CLOSING);
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
704 return 1;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
705 } else {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
706 /* The remote peer refused the disconnection... What should we do? */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
707
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
708 /* For the moment, just leave the connection open... we might force killing the peer later with a timeout */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
709 return 0;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
710 }
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
711 }
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
712 }
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
713 break;
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
714
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
715 case CC_DEVICE_WATCHDOG:
212
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
716 if (mdata->msg_flags & CMD_FLAG_REQUEST) {
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
717 msg_t * dwa = NULL;
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
718 /* We received a DWR, we must answer a DWA */
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
719
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
720 /* Check the received DWR is valid */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
721 CHECK_FCT_DO( _peer_dwr_parse(msg, peer), goto error );
212
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
722
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
723 /* Now create the DWA */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
724 CHECK_FCT_DO( _peer_dwa_create(peer, &dwa, mdata->msg_eteid, mdata->msg_hbhid), goto error );
212
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
725
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
726 /* We can discard the incoming DWR, we don't need it anymore */
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
727 msg_free(msg, 1);
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
728
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
729 /* Set the error code to OK */
247
adbc3782ba69 Routing module should be complete, to be tested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 246
diff changeset
730 CHECK_FCT_DO( msg_rescode_set( dwa, "DIAMETER_SUCCESS", NULL, NULL, 0 ),
212
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
731 { msg_free(dwa, 1); return 1; } );
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
732
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
733 /* and queue the message for delivery */
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
734 CHECK_FCT_DO( meq_post( peer->p_out_q, dwa ),
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
735 { msg_free(dwa, 1); return 1; } );
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
736
231
ebd37fdf7a99 Added some verbosity
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 230
diff changeset
737 TRACE_DEBUG(FULL, "DWA sent back");
ebd37fdf7a99 Added some verbosity
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 230
diff changeset
738
212
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
739 } else {
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
740 /* If we received a DWA, clear PEERFL_DW_PENDING */
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
741
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
742 CHECK_FCT_DO( _peer_dwa_parse(msg, peer),
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
743 { msg_free(msg, 1); return 1; } );
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
744
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
745 msg_free(msg, 1);
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
746
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
747 peer->p_flags &= ~PEERFL_DW_PENDING;
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
748
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
749 if ((peer->p_state == STATE_SUSPECT) || (peer->p_state == STATE_REOPEN)) {
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
750 int cnt = 1;
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
751
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
752 /* check the counter */
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
753 cnt += (peer->p_flags & PEERFL_DW_COUNTER_Hi) ? 2 : 0;
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
754 cnt += (peer->p_flags & PEERFL_DW_COUNTER_Lo) ? 1 : 0;
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
755
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
756 if (cnt < 4) {
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
757 /* Update the counter and send another DWR */
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
758 peer->p_flags &= ~ ( PEERFL_DW_COUNTER_Lo | PEERFL_DW_COUNTER_Hi );
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
759
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
760 if (cnt & 2)
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
761 peer->p_flags |= PEERFL_DW_COUNTER_Hi;
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
762 if (cnt & 1)
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
763 peer->p_flags |= PEERFL_DW_COUNTER_Lo;
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
764
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
765 return _psm_do_watchdog(peer, event, ev_data );
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
766 }
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
767
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
768 /* Ok, we exchanged 3 DWR/DWA without any timeout, the peer is responding properly */
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
769 _psm_change_state(peer, STATE_OPEN);
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
770 }
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
771
212
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
772 }
c1ae39dc809d Completed support for DWR/DWA, untested
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 211
diff changeset
773 break;
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
774
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
775
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
776 default:
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
777 TRACE_DEBUG(INFO, "Not supported in PSM: command code %u, dealing with it in routing thread", mdata->msg_code);
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
778 goto forward;
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
779 }
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
780 end:
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
781 /* reset the timer for DWR if needed: twtimer */
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
782 if (! (peer->p_flags & PEERFL_DW_PENDING)) {
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
783 _psm_reset_ts(peer, 1, g_pconf->twtimer);
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
784 }
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
785
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
786 return 0;
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
787 error:
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
788 /* empty line to make gcc happy... */;
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
789 pthread_cleanup_pop(1);
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
790 return 1;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
791 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
792
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
793
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
794 /* long time since data was received */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
795 static int _psm_do_watchdog( _peer_t * peer, _pevent_t event, void * ev_data )
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
796 {
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
797 int timer = 0;
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
798
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
799 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
800
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
801 /* Special case: if we are doing a shutdown of the peer, just really shutdown */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
802 if (peer->p_flags & PEERFL_SHUTTING_DOWN) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
803 TRACE_DEBUG(FULL, "Timeout while shutting down, reset the peer");
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
804 return 1;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
805 }
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
806
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
807 /* Have we already sent a DWR? */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
808 if (peer->p_flags & PEERFL_DW_PENDING) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
809 /* Ok, the remote peer did not answer in the given time, let's failover */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
810
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
811 /* Mark the peer as suspect. This also trigs a failover */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
812 _psm_change_state(peer, STATE_SUSPECT);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
813
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
814 timer = 2 * g_pconf->twtimer;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
815
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
816 } else {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
817 /* TwTimer has passed since last received message, so send a DWR to probe the cnx */
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
818 msg_t * dwr = NULL;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
819
211
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
820 /* Create the DWR message */
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
821 CHECK_FCT_DO( _peer_dwr_create(peer, &dwr), return 2 );
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
822
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
823 /* Send the DWR */
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
824 CHECK_FCT_DO( meq_post( peer->p_out_q, dwr ), return 1 );
a812567e69cc Added support to send DWR
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 209
diff changeset
825
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
826 /* Then arm the flag */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
827 peer->p_flags |= PEERFL_DW_PENDING;
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
828
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
829 timer = g_pconf->twtimer;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
830 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
831
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
832 /* and re-arm the timer */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
833 _psm_reset_ts(peer, 1, timer);
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
834
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
835 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
836 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
837
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
838
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
839 /* When the peer is requested to shutdown, send a DPR message. The reason may be passed as event data */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
840 static int _psm_send_DPR( _peer_t * peer, _pevent_t event, void * ev_data )
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
841 {
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
842 uint32_t cause = ACV_DC_REBOOTING;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
843 msg_t * dpr = NULL;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
844
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
845 TRACE_ENTRY("%p(%s/%s) %d(%s) %p", peer, peer->p_diamid ?: "null", STATESTR(peer->p_state), event, EVENTSTR(event), ev_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
846
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
847 TRACE_DEBUG(FULL, "Requesting clean disconnection to '%s'", peer->p_diamid);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
848
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
849 /* Set the flag PEERFL_SHUTTING_DOWN */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
850 peer->p_flags |= PEERFL_SHUTTING_DOWN;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
851
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
852 /* Set the flag PEERFL_DISABLE_AFTER_SHUTDOWN or PEERFL_DESTROY_AFTER_SHUTDOWN according to the event */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
853 if (event == PEVENT_SHUTDOWN) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
854 peer->p_flags |= PEERFL_DISABLE_AFTER_SHUTDOWN;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
855 }
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
856 if (event == PEVENT_DESTROY) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
857 peer->p_flags |= PEERFL_DESTROY_AFTER_SHUTDOWN;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
858 }
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
859
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
860 if (ev_data != NULL) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
861 /* set the value of "cause" according to the event data: ACV_DC_BUSY or ACV_DC_NOT_FRIEND */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
862 TRACE_DEBUG(INFO, "@@@Not supported yet");
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
863 }
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
864
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
865 /* Create the DPR message */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
866 CHECK_FCT_DO( _peer_dpr_create(peer, &dpr, cause), return 2 );
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
867
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
868 /* Send the DPR */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
869 CHECK_FCT_DO( meq_post( peer->p_out_q, dpr ), return 1 );
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
870
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
871 /* re-arm the timer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
872 _psm_reset_ts(peer, 0, DPR_TIMEOUT);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
873
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
874 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
875 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
876
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
877
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
878
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
879 /* The following matrix is the state machine. See following function for more details */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
880 static struct {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
881 int (*cb)(_peer_t * peer, _pevent_t event, void * ev_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
882 } PSM_ARRAY [ /* previous state */ ] [ /* incoming event */ PEVENT_MAX ] = {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
883 /* STATE_DISABLED */ { /* In this state, there is no PSM running, so any call here is erroneous */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
884 /* PEVENT_SHUTDOWN */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
885 /* PEVENT_DESTROY */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
886 /* PEVENT_EXPIRE */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
887 /* PEVENT_TIMEOUT */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
888 /* PEVENT_CONNECTED */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
889 /* PEVENT_MSGRCVD */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
890 /* PEVENT_INCNX */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
891 /* PEVENT_ASSOC_CHG */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
892 /* PEVENT_PEERADDR_CHG */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
893 /* PEVENT_REMOTE_ERR */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
894 /* PEVENT_DISCONNECTED */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
895 /* PEVENT_SND_FAILED */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
896 /* PEVENT_TH_TERM_IN */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
897 /* PEVENT_TH_TERM_OUT */ { _psm_assert }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
898 },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
899 /* STATE_OPEN */ {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
900 /* PEVENT_SHUTDOWN */ { _psm_send_DPR }, /* set flag PEERFL_DISABLE_AFTER_SHUTDOWN then initiate disconnection procedure */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
901 /* PEVENT_DESTROY */ { _psm_send_DPR }, /* set flag PEERFL_DESTROY_AFTER_SHUTDOWN then initiate disconnection procedure */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
902 /* PEVENT_EXPIRE */ { _psm_expire }, /* Handle dynamic peers end-of-lifetime */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
903 /* PEVENT_TIMEOUT */ { _psm_do_watchdog }, /* the handler may overwrite the next state to SUSPECT */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
904 /* PEVENT_CONNECTED */ { _psm_assert }, /* Did we initiate two connections?? */
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
905 /* PEVENT_MSGRCVD */ { _psm_receive_message }, /* Handle received messages */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
906 /* PEVENT_INCNX */ { _psm_reject_incoming_CER }, /* We must reject the new connection */
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
907 /* PEVENT_ASSOC_CHG */ { _psm_ignore }, /* I guess it will depend on the change... ignore for now */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
908 /* PEVENT_PEERADDR_CHG */ { _psm_NOTSUP }, /* Security issue? We may want to check the address change is compatible with advertised host-ip-addresses */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
909 /* PEVENT_REMOTE_ERR */ { _psm_NOTSUP }, /* should mark as SUSPECT and probe the cnx with DWR/DWA ? */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
910 /* PEVENT_DISCONNECTED */ { _psm_reset }, /* Cleanup open resources and reset the PSM */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
911 /* PEVENT_SND_FAILED */ { _psm_reset }, /* Cleanup open resources and reset the PSM */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
912 /* PEVENT_TH_TERM_IN */ { _psm_reset }, /* A serious error occurred in receiver thread: cleanup open resources and reset the PSM */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
913 /* PEVENT_TH_TERM_OUT */ { _psm_reset } /* A serious error occurred in sender thread: cleanup open resources and reset the PSM */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
914 },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
915 /* STATE_CLOSED */ {
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
916 /* PEVENT_SHUTDOWN */ { _psm_reset }, /* May force stopping reconnections */
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
917 /* PEVENT_DESTROY */ { _psm_reset },
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
918 /* PEVENT_EXPIRE */ { _psm_expire }, /* Handle dynamic peers end-of-lifetime */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
919 /* PEVENT_TIMEOUT */ { _psm_connect }, /* Timeout reached, it's time to attempt new connection */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
920 /* PEVENT_CONNECTED */ { _psm_assert }, /* This should never happen, but anyway we can ignore it */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
921 /* PEVENT_MSGRCVD */ { _psm_assert }, /* Assert for the moment, anyway we should be able to handle the message */
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
922 /* PEVENT_INCNX */ { _psm_answer_CEA_simple }, /* Answer a CEA and go to OPEN, or anwer an error */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
923 /* PEVENT_ASSOC_CHG */ { _psm_ignore },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
924 /* PEVENT_PEERADDR_CHG */ { _psm_ignore },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
925 /* PEVENT_REMOTE_ERR */ { _psm_ignore },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
926 /* PEVENT_DISCONNECTED */ { _psm_ignore }, /* This should never happen, but anyway we can ignore it */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
927 /* PEVENT_SND_FAILED */ { _psm_assert }, /* Of course send would fail on a closed peer... */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
928 /* PEVENT_TH_TERM_IN */ { _psm_assert },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
929 /* PEVENT_TH_TERM_OUT */ { _psm_assert }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
930 },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
931 /* STATE_CLOSING */ {
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
932 /* PEVENT_SHUTDOWN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
933 /* PEVENT_DESTROY */ { _psm_NOTSUP },
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
934 /* PEVENT_EXPIRE */ { _psm_expire },
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
935 /* PEVENT_TIMEOUT */ { _psm_reset },
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
936 /* PEVENT_CONNECTED */ { _psm_NOTSUP },
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
937 /* PEVENT_MSGRCVD */ { _psm_receive_message },
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
938 /* PEVENT_INCNX */ { _psm_reject_incoming_CER },
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
939 /* PEVENT_ASSOC_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
940 /* PEVENT_PEERADDR_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
941 /* PEVENT_REMOTE_ERR */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
942 /* PEVENT_DISCONNECTED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
943 /* PEVENT_SND_FAILED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
944 /* PEVENT_TH_TERM_IN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
945 /* PEVENT_TH_TERM_OUT */ { _psm_NOTSUP }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
946 },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
947 /* STATE_WAITCNXACK */ {
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
948 /* PEVENT_SHUTDOWN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
949 /* PEVENT_DESTROY */ { _psm_NOTSUP },
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
950 /* PEVENT_EXPIRE */ { _psm_expire },
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
951 /* PEVENT_TIMEOUT */ { _psm_reset }, /* The attempt failed, reset the PSM */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
952 /* PEVENT_CONNECTED */ { _psm_send_CER }, /* Send a CER */
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
953 /* PEVENT_MSGRCVD */ { _psm_NOTSUP },
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
954 /* PEVENT_INCNX */ { _psm_incon_elect }, /* We will have to handle an election */
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
955 /* PEVENT_ASSOC_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
956 /* PEVENT_PEERADDR_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
957 /* PEVENT_REMOTE_ERR */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
958 /* PEVENT_DISCONNECTED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
959 /* PEVENT_SND_FAILED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
960 /* PEVENT_TH_TERM_IN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
961 /* PEVENT_TH_TERM_OUT */ { _psm_NOTSUP }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
962 },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
963 /* STATE_WAITCNXACK_ELEC */ {
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
964 /* PEVENT_SHUTDOWN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
965 /* PEVENT_DESTROY */ { _psm_NOTSUP },
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
966 /* PEVENT_EXPIRE */ { _psm_expire },
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
967 /* PEVENT_TIMEOUT */ { _psm_elect_timeout }, /* initiated connection attempt failed, fallback to responder */
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
968 /* PEVENT_CONNECTED */ { _psm_send_CER },
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
969 /* PEVENT_MSGRCVD */ { _psm_NOTSUP },
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
970 /* PEVENT_INCNX */ { _psm_reject_incoming_CER },
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
971 /* PEVENT_ASSOC_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
972 /* PEVENT_PEERADDR_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
973 /* PEVENT_REMOTE_ERR */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
974 /* PEVENT_DISCONNECTED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
975 /* PEVENT_SND_FAILED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
976 /* PEVENT_TH_TERM_IN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
977 /* PEVENT_TH_TERM_OUT */ { _psm_NOTSUP }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
978 },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
979 /* STATE_WAITCEA */ {
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
980 /* PEVENT_SHUTDOWN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
981 /* PEVENT_DESTROY */ { _psm_NOTSUP },
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
982 /* PEVENT_EXPIRE */ { _psm_expire },
226
c73b91607715 Handle properly timeout in WAITCEA state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 224
diff changeset
983 /* PEVENT_TIMEOUT */ { _psm_elect_timeout }, /* Did not receive a CEA in the given time, reset the PSM or be responder */
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
984 /* PEVENT_CONNECTED */ { _psm_NOTSUP },
209
dd371bb37986 Added handler for incoming CEA; now peers can go to OPEN state in normal situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
985 /* PEVENT_MSGRCVD */ { _psm_receive_CEA },
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
986 /* PEVENT_INCNX */ { _psm_incon_elect }, /* We will have to handle an election */
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
987 /* PEVENT_ASSOC_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
988 /* PEVENT_PEERADDR_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
989 /* PEVENT_REMOTE_ERR */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
990 /* PEVENT_DISCONNECTED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
991 /* PEVENT_SND_FAILED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
992 /* PEVENT_TH_TERM_IN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
993 /* PEVENT_TH_TERM_OUT */ { _psm_NOTSUP }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
994 },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
995 /* STATE_SUSPECT */ {
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
996 /* PEVENT_SHUTDOWN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
997 /* PEVENT_DESTROY */ { _psm_NOTSUP },
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
998 /* PEVENT_EXPIRE */ { _psm_expire },
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
999 /* PEVENT_TIMEOUT */ { _psm_reset }, /* In this case, we must shutdown the connection */
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1000 /* PEVENT_CONNECTED */ { _psm_NOTSUP },
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1001 /* PEVENT_MSGRCVD */ { _psm_receive_message }, /* handle the received message */
237
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
1002 /* PEVENT_INCNX */ { _psm_answer_CEA_simple },
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1003 /* PEVENT_ASSOC_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1004 /* PEVENT_PEERADDR_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1005 /* PEVENT_REMOTE_ERR */ { _psm_NOTSUP },
232
65efaa0c849b Resolution for the deadlock
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 231
diff changeset
1006 /* PEVENT_DISCONNECTED */ { _psm_reset },
65efaa0c849b Resolution for the deadlock
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 231
diff changeset
1007 /* PEVENT_SND_FAILED */ { _psm_reset },
65efaa0c849b Resolution for the deadlock
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 231
diff changeset
1008 /* PEVENT_TH_TERM_IN */ { _psm_reset },
65efaa0c849b Resolution for the deadlock
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 231
diff changeset
1009 /* PEVENT_TH_TERM_OUT */ { _psm_reset }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1010 },
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1011 /* STATE_REOPEN */ {
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1012 /* PEVENT_SHUTDOWN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1013 /* PEVENT_DESTROY */ { _psm_NOTSUP },
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1014 /* PEVENT_EXPIRE */ { _psm_expire },
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1015 /* PEVENT_TIMEOUT */ { _psm_do_watchdog },
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1016 /* PEVENT_CONNECTED */ { _psm_NOTSUP },
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1017 /* PEVENT_MSGRCVD */ { _psm_receive_message },
222
b6eb2112a01f Added some support for election
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 219
diff changeset
1018 /* PEVENT_INCNX */ { _psm_reject_incoming_CER },
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1019 /* PEVENT_ASSOC_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1020 /* PEVENT_PEERADDR_CHG */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1021 /* PEVENT_REMOTE_ERR */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1022 /* PEVENT_DISCONNECTED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1023 /* PEVENT_SND_FAILED */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1024 /* PEVENT_TH_TERM_IN */ { _psm_NOTSUP },
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1025 /* PEVENT_TH_TERM_OUT */ { _psm_NOTSUP }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1026 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1027 };
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1028
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1029
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1030
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1031 /******************************************************************************/
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1032 /* Core of the state machine mechanism */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1033 /******************************************************************************/
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1034
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1035 /* Reset the timespec, optionally offset by random value */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1036 static void _psm_reset_ts(_peer_t * peer, int add_random, int delay)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1037 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1038 /* Initialize the timer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1039 CHECK_POSIX_DO( clock_gettime( CLOCK_REALTIME, &peer->p_ts ), ASSERT(0) );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1040
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1041 if (add_random) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1042 if (delay > 2)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1043 delay -= 2;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1044 else
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1045 delay = 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1046
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1047 /* Add a random value between 0 and 4sec */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1048 peer->p_ts.tv_sec += random() % 4;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1049 peer->p_ts.tv_nsec+= random() % 1000000000L;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1050 if (peer->p_ts.tv_nsec > 1000000000L) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1051 peer->p_ts.tv_nsec -= 1000000000L;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1052 peer->p_ts.tv_sec ++;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1053 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1054 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1055
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1056 peer->p_ts.tv_sec += delay;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1057
230
7cbe3396b122 Remove the additional delay for debug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 229
diff changeset
1058 #if 0
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1059 /* temporary for debug */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1060 peer->p_ts.tv_sec += 10;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1061 #endif
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1062 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1063
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1064 /* Wait for next event or timeout */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1065 static int _psm_wait_next_event(_peer_t * peer, _pevent_t * event, void ** ev_data)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1066 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1067 _pe_t * next;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1068 int ret = 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1069
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1070 *event = 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1071 if (ev_data)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1072 *ev_data = NULL;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1073
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1074 spurious:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1075 CHECK_POSIX_DO2( ret = pthread_cond_timedwait( &peer->p_condvar, &peer->p_lock, &peer->p_ts ),
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1076 ETIMEDOUT, *event = PEVENT_TIMEOUT,
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1077 return ret );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1078
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1079 if (!IS_LIST_EMPTY(&peer->p_events)) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1080 next = (_pe_t *) peer->p_events.next;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1081 uti_list_unlink(_LIST(next));
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1082 *event = next->event;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1083 if (ev_data)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1084 *ev_data = next->list.o;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1085 free(next);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1086 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1087
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1088 if (*event == 0)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1089 goto spurious;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1090
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1091 /* Very special case, it will actually probably never happen... */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1092 if ((peer->p_state == STATE_CLOSED) && (peer->p_flags & PEERFL_DISABLE_AFTER_SHUTDOWN) && (*event == PEVENT_TIMEOUT)) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1093 /* Wow... should probably never happen */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1094 TRACE_DEBUG(NONE, "The peer '%s' has been unused for more than one year ^^ (NO_TIMEOUT)", peer->p_diamid);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1095 /* Go back to sleep until next event */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1096 CHECK_POSIX_DO( ret = pthread_cond_wait( &peer->p_condvar, &peer->p_lock ),
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1097 return ret );
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1098 goto spurious;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1099 }
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1100
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1101 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1102 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1103
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1104 /* Change the security state of a peer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1105 static void _psm_change_state_sec(_peer_t * peer, _peer_state_t new)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1106 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1107 TRACE_ENTRY();
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1108
229
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1109 /* First, check if the peer is using the peer-sec-ini module or a real sec module */
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1110 if (peer->p_sec_hdl == NULL)
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1111 return;
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1112
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1113 if (peer->p_secmod->sec_state_change == NULL)
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1114 return;
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1115
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1116 /* For clean initialization, PSS_CLOSED->PSS_CONNECTED */
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1117 if ((
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1118 (new == STATE_OPEN)
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1119 || (new == STATE_REOPEN)
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1120 ) && (
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1121 ( peer->p_state == STATE_CLOSED )
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1122 || ( peer->p_state == STATE_WAITCNXACK_ELEC )
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1123 || ( peer->p_state == STATE_WAITCEA )
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1124 )) {
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1125 CHECK_FCT_DO( (*peer->p_secmod->sec_state_change)(
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1126 /* new state */ PSS_CONNECTED,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1127 /* old state */ PSS_CLOSED,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1128 /* session */ &peer->p_sec_session,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1129 /* private data */ &peer->p_ext_session),
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1130 /* Do nothing else than logging if it fails */ );
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1131 }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1132
229
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1133 if (new == STATE_CLOSED) {
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1134 if ( peer->p_state == STATE_CLOSING ) {
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1135 /* For clean termination, PSS_OPEN->PSS_CLOSING->PSS_CLOSED */
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1136 CHECK_FCT_DO( (*peer->p_secmod->sec_state_change)(
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1137 /* new state */ PSS_CLOSING,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1138 /* old state */ PSS_CONNECTED,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1139 /* session */ &peer->p_sec_session,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1140 /* private data */ &peer->p_ext_session),
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1141 /* Do nothing else than logging if it fails */ );
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1142 CHECK_FCT_DO( (*peer->p_secmod->sec_state_change)(
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1143 /* new state */ PSS_CLOSED,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1144 /* old state */ PSS_CLOSING,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1145 /* session */ &peer->p_sec_session,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1146 /* private data */ &peer->p_ext_session),
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1147 /* Do nothing else than logging if it fails */ );
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1148 } else {
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1149 /* For violent termination, PSS_OPEN->PSS_CLOSED */
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1150 CHECK_FCT_DO( (*peer->p_secmod->sec_state_change)(
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1151 /* new state */ PSS_CLOSED,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1152 /* old state */ PSS_CONNECTED,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1153 /* session */ &peer->p_sec_session,
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1154 /* private data */ &peer->p_ext_session),
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1155 /* Do nothing else than logging if it fails */ );
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1156 }
f821bb11131e Added state management for security modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 228
diff changeset
1157 }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1158
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1159 return;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1160 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1161
201
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1162 /* Cleanup the data when leaving a state */
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1163 static void _psm_cleanup_state(_peer_t * peer, _peer_state_t new)
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1164 {
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1165 TRACE_ENTRY();
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1166
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1167 /* Note: we are called only if the new state is different from the old one */
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1168
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1169 switch (peer->p_state) {
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1170 case STATE_DISABLED:
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1171 case STATE_CLOSED:
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1172 /* We have nothing to do */
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1173 break;
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1174
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1175 case STATE_REOPEN:
201
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1176 case STATE_OPEN:
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1177 /* We must failover any message */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1178 if (new != STATE_OPEN) {
239
ca4459bac73a Avoid deleting sent DWR when going to SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 237
diff changeset
1179 CHECK_FCT_DO( _peer_failover(peer, 0), /* continue */);
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1180 }
201
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1181
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1182 break;
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1183
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1184 case STATE_WAITCNXACK:
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1185 case STATE_WAITCNXACK_ELEC:
201
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1186 /* When we leave this state, we must stop the connection attempt, unless we are doing election */
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1187 if (new != STATE_WAITCNXACK_ELEC) {
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1188 CHECK_FCT_DO( _peer_client_stop(peer), /* continue */ );
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1189 }
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1190 break;
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1191
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1192 case STATE_WAITCEA:
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1193 /* When leaving this state, kill any incoming connection pending because of an election */
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1194 if (peer->p_electdata) {
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1195 _peer_struct_destroy(&peer->p_electdata->peer);
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1196 free(peer->p_electdata);
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1197 peer->p_electdata=NULL;
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1198 }
201
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1199 break;
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1200
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1201 case STATE_SUSPECT:
201
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1202 case STATE_CLOSING:
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1203 /* ??? */
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1204 break;
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1205 }
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1206
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1207 return;
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1208 }
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1209
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1210 /* Change the state of a peer */
257
4b9688373710 New tests, many fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 247
diff changeset
1211 #ifndef IN_WAAAD_TEST
4b9688373710 New tests, many fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 247
diff changeset
1212 static
4b9688373710 New tests, many fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 247
diff changeset
1213 #endif /* IN_WAAAD_TEST */
4b9688373710 New tests, many fixes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 247
diff changeset
1214 void _psm_change_state(_peer_t * peer, _peer_state_t new)
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1215 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1216 uti_list_t * prev;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1217
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1218 TRACE_DEBUG(FULL, "Peer '%s' state change: %s -> %s", peer->p_diamid, STATESTR(peer->p_state), STATESTR(new));
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1219
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1220 /* Only proceed if the state actually changed */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1221 if (peer->p_state == new)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1222 return;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1223
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1224 /* Now change the state in security module */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1225 _psm_change_state_sec(peer, new);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1226
201
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1227 /* Do any required cleanup when leaving the state */
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1228 _psm_cleanup_state(peer, new);
37dc37497b8c Added a function to cleanup when leaving a state in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 193
diff changeset
1229
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1230 /* change the state */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1231 peer->p_state = new;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1232
241
193574388534 Remove the CNX_PB flag after successful failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 240
diff changeset
1233 /* Ops on the flags */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1234 peer->p_flags &= ~ ( PEERFL_DW_COUNTER_Lo | PEERFL_DW_COUNTER_Hi );
241
193574388534 Remove the CNX_PB flag after successful failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 240
diff changeset
1235 if (peer->p_state == STATE_OPEN) {
193574388534 Remove the CNX_PB flag after successful failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 240
diff changeset
1236 peer->p_flags &= ~ PEERFL_CNX_PB;
193574388534 Remove the CNX_PB flag after successful failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 240
diff changeset
1237 }
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1238
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1239 /* Handle the "active" peers list */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1240 if (peer->p_state != STATE_OPEN) {
246
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1241 if (!IS_LIST_EMPTY(&peer->p_active)) {
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1242 CHECK_POSIX_DO( pthread_mutex_lock( &_peers_lists_mtx ), uti_event_send(WDE_ERROR) );
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1243 TRACE_DEBUG(FULL, "Peer '%s' removed from the list of active peers", peer->p_diamid);
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1244 uti_list_unlink( &peer->p_active );
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1245 CHECK_POSIX_DO( pthread_mutex_unlock( &_peers_lists_mtx ), uti_event_send(WDE_ERROR) );
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1246 }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1247 return;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1248 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1249
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1250 if (!IS_LIST_EMPTY(&peer->p_active))
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1251 return; /* we are already linked */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1252
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1253 /* Ok, we have to insert this peer into the active list */
246
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1254 CHECK_POSIX_DO( pthread_mutex_lock( &_peers_lists_mtx ), uti_event_send(WDE_ERROR) );
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1255
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1256 for (prev = &_peers_actives; prev->next != &_peers_actives; prev = prev->next) {
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1257 int cmp = 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1258 _peer_t * cur = _P(prev->next->o);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1259
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1260 if (cur->p_hash < peer->p_hash)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1261 continue;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1262
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1263 if (cur->p_hash > peer->p_hash)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1264 break;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1265
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1266 cmp = strcmp(cur->p_diamid, peer->p_diamid);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1267
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1268 if (cmp < 0)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1269 continue;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1270
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1271 if (cmp == 0) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1272 ASSERT(0);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1273 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1274
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1275 break;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1276 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1277
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1278 uti_list_insert_after(prev, &peer->p_active);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1279
246
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1280 CHECK_POSIX_DO( pthread_mutex_unlock( &_peers_lists_mtx ), uti_event_send(WDE_ERROR) );
13647ca6e0ad Progress on the routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 244
diff changeset
1281
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1282 TRACE_DEBUG(FULL, "Peer '%s' inserted in the list of active peers", peer->p_diamid);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1283
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1284 return;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1285 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1286
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1287 /* The peer state machine.
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1288
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1289 When this function is called, the peer is in a given state STATE_CUR and the timer p_ts is set.
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1290 The state machine waits for the next event (including expiry of p_ts) and handles this event.
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1291 It then eventually changes the state to STATE_NEW and resets the p_ts timer, then returns 0.
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1292 On important error, non-0 error code is returned.
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1293 */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1294 static int _psm_do(_peer_t * peer)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1295 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1296 _pevent_t event;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1297 void * event_data;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1298
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1299 TRACE_DEBUG(FULL, "PSM for peer '%s' state '%s', waiting next event...", peer->p_diamid, STATESTR(peer->p_state));
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1300
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1301 /* wait for the next event (or timeout). On error destroy the peer completly */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1302 CHECK_FCT_DO( _psm_wait_next_event(peer, &event, &event_data), return 2 );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1303
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1304 TRACE_DEBUG(FULL, "PSM for peer '%s' state '%s', received: '%s', processing...", peer->p_diamid, STATESTR(peer->p_state), EVENTSTR(event));
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1305
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1306 /* now call the PSM callback */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1307 return (*PSM_ARRAY[peer->p_state - 1][event - 1].cb)(peer, event, event_data);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1308 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1309
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1310 static void _psm_cleanup( _peer_t * peer )
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1311 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1312 /* Stop any children thread */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1313 CHECK_FCT_DO( _peer_client_stop(peer), /* continue */ );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1314 CHECK_FCT_DO( _peer_in_stop(peer), /* continue */ );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1315 CHECK_FCT_DO( _peer_out_stop(peer), /* continue */ );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1316
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1317 /* Close the socket if any */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1318 if (peer->p_sock) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1319 CHECK_SYS_DO( shutdown(peer->p_sock, SHUT_RDWR), /* continue */ );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1320 peer->p_sock = 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1321 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1322
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1323 /* Eat all pending events */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1324 _peer_events_reset(peer);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1325
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1326 /* Failover: requeue all sent messages and pending messages to the global outgoing queue */
239
ca4459bac73a Avoid deleting sent DWR when going to SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 237
diff changeset
1327 CHECK_FCT_DO( _peer_failover(peer, 0), /* continue */ );
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1328
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1329 /* The timespec is erased */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1330 memset( &peer->p_ts, 0, sizeof(struct timespec) );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1331
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1332 /* Reset the security module */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1333 _peer_struct_secmod_reset(peer);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1334
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1335 /* Reset application list */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1336 _peer_struct_appl_reset(peer);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1337
237
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
1338 /* keep only some of the flags */
d3502d7b3191 Handle reconnection when in SUSPECT state
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
1339 peer->p_flags &= PEERFL_CNX_PB;
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1340
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1341 return;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1342 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1343
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1344 /* In case of cancellation (i.e. PSM is terminated), go to DISABLED state, and unlock the peer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1345 static void cleanup_psm(void * arg)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1346 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1347 _peer_t * peer = _P(arg);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1348
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1349 TRACE_ENTRY("%p", arg);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1350
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1351 _psm_change_state(peer, STATE_DISABLED);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1352
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1353 _psm_cleanup(peer);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1354
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1355 CHECK_POSIX_DO( pthread_mutex_unlock( &peer->p_lock ), /* ignore error */ );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1356
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1357 return;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1358 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1359
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1360
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1361 /* The code of the p_psm_th thread */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1362 static void * _psm_th(void * arg)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1363 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1364 _peer_t * peer = (_peer_t *)arg;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1365 int ret = 0;
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1366 uint32_t flags =0;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1367
193
0e9d87ce40c7 Added thread names in debug traces for easier debug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 190
diff changeset
1368 THREAD_NAME_PEER( "PSM", peer );
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1369 TRACE_ENTRY( "%p", peer );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1370
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1371 /* Lock the peer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1372 CHECK_POSIX_DO( pthread_mutex_lock(&peer->p_lock), goto destroy_me );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1373
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1374 /* Go to closed state to signal that the PSM is running */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1375 _psm_change_state( peer, STATE_CLOSED );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1376
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1377 /* Check if the peer->p_sock is already defined, meaning we are receiver side */
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1378 if ( peer->p_flags & PEERFL_RESPONDER ) {
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1379 _psm_reset_ts(peer, 0, INCNX_TIMEOUT); /* This is just to check for errors, the event is generated before the PSM can acquire the lock */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1380
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1381 /* Just start the PSM then, the event will trig whatever behavior is expected */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1382 } else {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1383 /* We are initiating a connection to this peer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1384
236
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1385 /* We are handling a new peer, initialize the timer to a random value -- would be better to do this only at daemon startup... */
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1386 _psm_reset_ts(peer, 1, 0);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1387
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1388 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1389
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1390 psm:
236
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1391 /* First ,check that we will actually be able to communicate with the peer: we must have at least one security mechanism available */
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1392 CHECK_FCT_DO( sec_getmodules(peer->p_diamid, (sSA *)&(peer->p_addinfo.pa_ss),&peer->p_sec_list), goto destroy_me );
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1393
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1394 if (IS_LIST_EMPTY(&peer->p_sec_list)) {
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1395 log_error("No security extension is available to handle the peer '%s', peer is disabled.\n", peer->p_diamid);
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1396 goto disable_me;
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1397 }
5d409c5cf1c3 Fix assertion failed error in cer_cea
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 232
diff changeset
1398
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1399 /* the peer state machine main loop */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1400 while (1) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1401 pthread_cleanup_push( cleanup_psm, (void *)peer );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1402 ret = _psm_do(peer);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1403 pthread_cleanup_pop(0);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1404 switch (ret) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1405 case 0: /* no problem so far, continue to next event */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1406 continue;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1407
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1408 case 1: /* critical error, reset the peer state machine */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1409 goto reset;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1410
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1411 case 2: /* very critical error, destroy all peer data */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1412 default:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1413 goto destroy_me;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1414 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1415 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1416
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1417
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1418 reset:
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1419 /* The state is reinitialized to CLOSED */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1420 _psm_change_state(peer, STATE_CLOSED);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1421
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1422 /* Save the state of the flags */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1423 flags = peer->p_flags;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1424
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1425 /* Reset the peer object in a clean state */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1426 _psm_cleanup( peer );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1427
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1428 if (flags & PEERFL_DESTROY_AFTER_SHUTDOWN)
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1429 goto disable_me;
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1430
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1431 if (flags & PEERFL_DISABLE_AFTER_SHUTDOWN) {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1432 /* save this flag in the peer again */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1433 peer->p_flags |= PEERFL_DISABLE_AFTER_SHUTDOWN;
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1434
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1435 /* Reset the timer with a very large value */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1436 _psm_reset_ts(peer, 0, NO_TIMEOUT);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1437 } else {
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1438 /* We will re-attempt the connection regularly */
228
e5aeb56642e7 Added experimental support for failback
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
1439
219
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1440 /* Reset the timer */
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1441 _psm_reset_ts(peer, 1, g_pconf->tctimer);
c5b21282f2cf Added failover and partial DPR/DPA support
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
1442 }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1443
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1444 /* restart the PSM */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1445 goto psm;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1446
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1447 disable_me: /* the peer lock must be held */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1448 TRACE_DEBUG(INFO, "Disabling peer state machine for peer '%s'", peer->p_diamid);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1449
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1450 /* same as if the PSM is stopped from outside */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1451 cleanup_psm(peer);
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1452
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1453 goto autokill;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1454
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1455
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1456 destroy_me: /* the peer lock must not be held */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1457 /* An unrecoverable error occurred on this peer, we disable the PSM totally */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1458
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1459
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1460 autokill:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1461 peer->p_psm = (pthread_t)NULL;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1462 pthread_detach(pthread_self());
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1463
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1464 TRACE_DEBUG(INFO, "PSM tread is terminated.");
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1465 return NULL;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1466 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1467
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1468 /* Start the PSM for a peer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1469 /* mode:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1470 1 - start as initiator.
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1471 2 - start as responder. A PEVENT_INCNX event will be received soon.
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1472 */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1473 int _peer_psm_start(_peer_t * peer, int mode)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1474 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1475 CHECK_PARAMS( VALIDATE_PEER(peer) );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1476 CHECK_PARAMS( peer->p_state == STATE_DISABLED );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1477 CHECK_PARAMS( peer->p_psm == (pthread_t)NULL );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1478
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1479 switch (mode) {
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1480 case 1:
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1481 /* We are initiator */
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1482 peer->p_flags &= ~PEERFL_RESPONDER;
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1483 break;
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1484 case 2:
223
408106496938 Removed the unstable WAITRETURNS state; added the code for election mechanism
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 222
diff changeset
1485 /* We are responder */
204
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1486 peer->p_flags |= PEERFL_RESPONDER;
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1487 break;
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1488
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1489 default:
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1490 CHECK_PARAMS( mode && 0 );
d204bbc7eee5 Started handling of incoming CER -- tbc
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 202
diff changeset
1491 }
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1492
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1493 CHECK_POSIX( pthread_create( &peer->p_psm, NULL, _psm_th, peer ) );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1494
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1495 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1496 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1497
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1498 /* Stop the PSM for a peer */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1499 /* mode:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1500 0 - clean shutdown if possible (reason: Rebooting)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1501 1 - clean shutdown if possible (reason: busy)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1502 2 - clean shutdown if possible (reason: do not want to talk to you)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1503 -1 - violent shutdown (no message sent)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1504 */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1505 int _peer_psm_stop(_peer_t * peer, int mode)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1506 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1507 if (peer->p_psm == (pthread_t)NULL)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1508 return 0; /* the PSM is already stopped */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1509
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1510 switch (mode) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1511 case 0:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1512 case 1:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1513 case 2:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1514 /* Send a SHUTDOWN event to the peer with the reason asked */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1515 TRACE_DEBUG(INFO, "Clean shutdown not implemented yet...");
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1516
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1517 case -1:
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1518 default:
315
3cebe1c677ab Change build system to CMake (lots of changes)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 306
diff changeset
1519 TRACE_DEBUG(FULL, "Killing PSM %p", peer->p_psm);
243
6c66d4b26f27 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1520 return _thread_term(&peer->p_psm);
190
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1521 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1522
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1523 return EINVAL;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1524 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1525
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1526 /* Start the peers PSM */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1527 int _peer_psm_start_all(void)
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1528 {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1529 int i;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1530
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1531 TRACE_ENTRY( );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1532
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1533 /* Start all peer's state machine threads */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1534 for (i = 0; i < sizeof(_peer_hash) / sizeof(_peer_hash[0]); i++) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1535 uti_list_t * li;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1536
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1537 /* lock this line */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1538 CHECK_POSIX( pthread_mutex_lock( &_peer_hash[i].lock ) );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1539
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1540 /* For each peer in this line */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1541 for (li = _peer_hash[i].all.next; li != &_peer_hash[i].all; li = li->next) {
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1542
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1543 /* create the PSM */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1544 CHECK_FCT( _peer_psm_start( _P(li->o), 1 ) );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1545 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1546
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1547 /* unlock the line */
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1548 CHECK_POSIX( pthread_mutex_unlock( &_peer_hash[i].lock ) );
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1549
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1550 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1551
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1552 return 0;
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1553 }
618d0e5d7cb3 Completed peer module reorganization
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1554
"Welcome to our mercurial repository"