annotate libfdcore/p_dw.c @ 1327:82b386714795

Set callback data also when only setting expire callback (and not answer callback as well). It is used when calling the expire callback, so not setting it makes no sense.
author Thomas Klausner <tk@giga.or.at>
date Mon, 27 Nov 2017 15:21:20 +0100
parents 8f9684264fe0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
1127
1af09cc156d6 Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
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 *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
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 *
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 *
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 *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
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 *
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 *
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 *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 454
diff changeset
36 #include "fdcore-internal.h"
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 /* This file contains code to handle Device Watchdog messages (DWR and DWA) */
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
40 /* Check the value of Origin-State-Id is consistent in a DWR or DWA -- we return an error otherwise */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
41 static int check_state_id(struct msg * msg, struct fd_peer * peer)
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
42 {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
43 struct avp * osi;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
44
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
45 /* Check if the request contains the Origin-State-Id */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
46 CHECK_FCT( fd_msg_search_avp ( msg, fd_dict_avp_OSI, &osi ) );
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
47 if (osi) {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
48 /* Check the value is consistent with the saved one */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
49 struct avp_hdr * hdr;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
50 CHECK_FCT( fd_msg_avp_hdr( osi, &hdr ) );
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
51 if (hdr->avp_value == NULL) {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
52 /* This is a sanity check */
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
53 LOG_F("Ignored an Origin-State-Id AVP with unset value in DWR/DWA");
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
54 ASSERT(0); /* To check if this really happens, and understand why... */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
55 }
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
56
745
712c7bbf1016 Fix for bug on Origin-State-Id reported in http://lists.freediameter.net/pipermail/help/2011-May/000156.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
57 if (! peer->p_hdr.info.runtime.pir_orstate) {
712c7bbf1016 Fix for bug on Origin-State-Id reported in http://lists.freediameter.net/pipermail/help/2011-May/000156.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
58 /* It was not already received in CER/CEA, save it now */
712c7bbf1016 Fix for bug on Origin-State-Id reported in http://lists.freediameter.net/pipermail/help/2011-May/000156.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
59 peer->p_hdr.info.runtime.pir_orstate = hdr->avp_value->u32;
712c7bbf1016 Fix for bug on Origin-State-Id reported in http://lists.freediameter.net/pipermail/help/2011-May/000156.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
60 }
712c7bbf1016 Fix for bug on Origin-State-Id reported in http://lists.freediameter.net/pipermail/help/2011-May/000156.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
61
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
62 if (peer->p_hdr.info.runtime.pir_orstate != hdr->avp_value->u32) {
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 745
diff changeset
63 TRACE_DEBUG(INFO, "Received a new Origin-State-Id from peer '%s'! (%x -> %x); resetting the connection.",
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
64 peer->p_hdr.info.pi_diamid,
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
65 peer->p_hdr.info.runtime.pir_orstate,
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
66 hdr->avp_value->u32 );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
67 return EINVAL;
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
68 }
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
69 }
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
70 return 0;
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
71 }
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
72
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
73 /* Create and send a DWR */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
74 static int send_DWR(struct fd_peer * peer)
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
75 {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
76 struct msg * msg = NULL;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
77
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
78 /* Create a new DWR instance */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
79 CHECK_FCT( fd_msg_new ( fd_dict_cmd_DWR, MSGFL_ALLOC_ETEID, &msg ) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
80
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
81 /* Add the content of the message (only the origin) */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
82 CHECK_FCT( fd_msg_add_origin ( msg, 1 ) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
83
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
84 /* Now send this message */
1238
8f9684264fe0 Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
85 CHECK_FCT( fd_out_send(&msg, NULL, peer, 0) );
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
86
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
87 /* And mark the pending DW */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
88 peer->p_flags.pf_dw_pending = 1;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
89
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
90 return 0;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
91 }
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93 /* Handle an incoming message */
40
7e1deaa89540 Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 36
diff changeset
94 int fd_p_dw_handle(struct msg ** msg, int req, struct fd_peer * peer)
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95 {
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
96 int reset_tmr = 0;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
97
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
98 TRACE_ENTRY("%p %d %p", msg, req, peer);
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
99
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
100 /* Check the value of OSI for information */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
101 CHECK_FCT( check_state_id(*msg, peer) );
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
102
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
103 if (req) {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
104 /* If we receive a DWR, send back a DWA */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
105 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
106 CHECK_FCT( fd_msg_rescode_set( *msg, "DIAMETER_SUCCESS", NULL, NULL, 0 ) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
107 CHECK_FCT( fd_msg_add_origin ( *msg, 1 ) );
1238
8f9684264fe0 Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
108 CHECK_FCT( fd_out_send( msg, peer->p_cnxctx, peer, 0) );
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
109
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
110 } else {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
111 /* Discard the DWA */
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
112 CHECK_FCT_DO( fd_msg_free(*msg), /* continue */ );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
113 *msg = NULL;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
114
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
115 /* And clear the pending DW flag */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
116 peer->p_flags.pf_dw_pending = 0;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
117 }
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
119 /* Now update timeout */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
120 if (req) {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
121 /* Update timeout only if we did not already send a DWR ourselves */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
122 reset_tmr = !peer->p_flags.pf_dw_pending;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
123 } else {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
124 /* Reset the timer */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
125 reset_tmr = 1;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
126 }
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
127 if (reset_tmr) {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
128 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_twtimer ?: fd_g_config->cnf_timer_tw);
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
129 }
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
130
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
131 /* If we are in REOPEN state, increment the counter */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
132 if (fd_peer_getstate(peer) == STATE_REOPEN) {
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
133 peer->p_flags.pf_reopen_cnt += 1;
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
134
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
135 if (peer->p_flags.pf_reopen_cnt) {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
136 /* Send a new DWR */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
137 CHECK_FCT( send_DWR(peer) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
138 } else {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
139 /* Move to OPEN state */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
140 CHECK_FCT( fd_psm_change_state(peer, STATE_OPEN) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
141 }
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
142 }
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
143
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
144 return 0;
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 }
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
147 /* Handle a timeout in the PSM (OPEN or REOPEN state only) */
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148 int fd_p_dw_timeout(struct fd_peer * peer)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149 {
74
9dcb1bd11a07 Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 66
diff changeset
150 TRACE_ENTRY("%p", peer);
9dcb1bd11a07 Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 66
diff changeset
151
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
152 if (peer->p_flags.pf_dw_pending) {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
153 /* We have sent a DWR and received no answer during TwTimer */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
154 CHECK_FCT( fd_psm_change_state(peer, STATE_SUSPECT) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
155 fd_psm_next_timeout(peer, 0, 2 * (peer->p_hdr.info.config.pic_twtimer ?: fd_g_config->cnf_timer_tw) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
156 } else {
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
157 /* The timeout has expired, send a DWR */
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
158 CHECK_FCT( send_DWR(peer) );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
159 fd_psm_next_timeout(peer, 0, peer->p_hdr.info.config.pic_twtimer ?: fd_g_config->cnf_timer_tw );
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
160 }
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
162 return 0;
36
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 }
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 40
diff changeset
164
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 40
diff changeset
165 /* Handle DW exchanges after the peer has come alive again */
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 40
diff changeset
166 int fd_p_dw_reopen(struct fd_peer * peer)
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 40
diff changeset
167 {
74
9dcb1bd11a07 Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 66
diff changeset
168 TRACE_ENTRY("%p", peer);
9dcb1bd11a07 Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 66
diff changeset
169
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
170 peer->p_flags.pf_reopen_cnt = 1;
74
9dcb1bd11a07 Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 66
diff changeset
171 peer->p_flags.pf_cnx_pb = 0;
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
172 CHECK_FCT( send_DWR(peer) );
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 40
diff changeset
173
66
dcbd5b5ee55c Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 43
diff changeset
174 return 0;
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 40
diff changeset
175 }
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 40
diff changeset
176
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 40
diff changeset
177
"Welcome to our mercurial repository"