Debian Codegraph @

lib/freeDiameter-1.2.1/libfdcore/p_dw.c

raw symbols SCIP
1 /*********************************************************************************************************
2 * Software License Agreement (BSD License) *
3 * Author: Sebastien Decugis <[email protected]> *
4 * *
5 * Copyright (c) 2013, WIDE Project and NICT *
6 * All rights reserved. *
7 * *
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
9 * permitted provided that the following conditions are met: *
10 * *
11 * * Redistributions of source code must retain the above *
12 * copyright notice, this list of conditions and the *
13 * following disclaimer. *
14 * *
15 * * Redistributions in binary form must reproduce the above *
16 * copyright notice, this list of conditions and the *
17 * following disclaimer in the documentation and/or other *
18 * materials provided with the distribution. *
19 * *
20 * * Neither the name of the WIDE Project or NICT nor the *
21 * names of its contributors may be used to endorse or *
22 * promote products derived from this software without *
23 * specific prior written permission of WIDE Project and *
24 * NICT. *
25 * *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
34 *********************************************************************************************************/
35
36 #include "fdcore-internal.h"cxx . . $ `<file>/lib/freeDiameter-1.2.1/libfdcore/fdcore-internal.h`/
37
38 /* This file contains code to handle Device Watchdog messages (DWR and DWA) */
39
40 /* Check the value of Origin-State-Id is consistent in a DWR or DWA -- we return an error otherwise */
41 static int check_state_idcxx . . $ check_state_id(864a75bd4c25c5bf).(struct msgcxx . . $ msg# * msg, struct fd_peercxx . . $ fd_peer# * peer)
42 {
43 struct avpcxx . . $ avp# * osi;
44
45 /* Check if the request contains the Origin-State-Id */
46 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_msg_search_avp ( msg, fd_dict_avp_OSI, &osi ) );
47 if (osi) {
48 /* Check the value is consistent with the saved one */
49 struct avp_hdrcxx . . $ avp_hdr# * hdr;
50 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_msg_avp_hdr( osi, &hdr ) );
51 if (hdr->avp_valuecxx . . $ avp_hdr#avp_value. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
52 /* This is a sanity check */
53 LOG_Fcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:342:9`!("Ignored an Origin-State-Id AVP with unset value in DWR/DWA");
54 ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(0); /* To check if this really happens, and understand why... */
55 }
56
57 if (! peer->p_hdrcxx . . $ fd_peer#p_hdr..infocxx . . $ peer_hdr#info..runtimecxx . . $ peer_info#runtime..pir_orstatecxx . . $ peer_info#$anonymous_type_4#pir_orstate.) {
58 /* It was not already received in CER/CEA, save it now */
59 peer->p_hdrcxx . . $ fd_peer#p_hdr..infocxx . . $ peer_hdr#info..runtimecxx . . $ peer_info#runtime..pir_orstatecxx . . $ peer_info#$anonymous_type_4#pir_orstate. = hdr->avp_valuecxx . . $ avp_hdr#avp_value.->u32cxx . . $ avp_value#u32.;
60 }
61
62 if (peer->p_hdrcxx . . $ fd_peer#p_hdr..infocxx . . $ peer_hdr#info..runtimecxx . . $ peer_info#runtime..pir_orstatecxx . . $ peer_info#$anonymous_type_4#pir_orstate. != hdr->avp_valuecxx . . $ avp_hdr#avp_value.->u32cxx . . $ avp_value#u32.) {
63 TRACE_DEBUGcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:515:10`!(INFO, "Received a new Origin-State-Id from peer '%s'! (%x -> %x); resetting the connection.",
64 peer->p_hdr.info.pi_diamid,
65 peer->p_hdr.info.runtime.pir_orstate,
66 hdr->avp_value->u32 );
67 return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
68 }
69 }
70 return 0;
71 }
72
73 /* Create and send a DWR */
74 static int send_DWRcxx . . $ send_DWR(c8ea46e6cf1a23ee).(struct fd_peercxx . . $ fd_peer# * peer)
75 {
76 struct msgcxx . . $ msg# * msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
77
78 /* Create a new DWR instance */
79 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_msg_new ( fd_dict_cmd_DWR, MSGFL_ALLOC_ETEIDcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:2242:9`!, &msg ) );
80
81 /* Add the content of the message (only the origin) */
82 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_msg_add_origin ( msg, 1 ) );
83
84 /* Now send this message */
85 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_out_send(&msg, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, peer, 0) );
86
87 /* And mark the pending DW */
88 peer->p_flagscxx . . $ fd_peer#p_flags..pf_dw_pendingcxx . . $ fd_peer#$anonymous_type_0#pf_dw_pending. = 1;
89
90 return 0;
91 }
92
93 /* Handle an incoming message */
94 int fd_p_dw_handlecxx . . $ fd_p_dw_handle(cad7b1b331f4be06).(struct msgcxx . . $ msg# ** msg, int req, struct fd_peercxx . . $ fd_peer# * peer)
95 {
96 int reset_tmr = 0;
97
98 TRACE_ENTRYcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:374:9`!("%p %d %p", msg, req, peer);
99
100 /* Check the value of OSI for information */
101 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( check_state_id(*msg, peer) );
102
103 if (req) {
104 /* If we receive a DWR, send back a DWA */
105 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) );
106 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_msg_rescode_set( *msg, "DIAMETER_SUCCESS", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0 ) );
107 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_msg_add_origin ( *msg, 1 ) );
108 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_out_send( msg, peer->p_cnxctx, peer, 0) );
109
110 } else {
111 /* Discard the DWA */
112 CHECK_FCT_DOcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:587:10`!( fd_msg_free(*msg), /* continue */ );
113 *msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
114
115 /* And clear the pending DW flag */
116 peer->p_flagscxx . . $ fd_peer#p_flags..pf_dw_pendingcxx . . $ fd_peer#$anonymous_type_0#pf_dw_pending. = 0;
117 }
118
119 /* Now update timeout */
120 if (req) {
121 /* Update timeout only if we did not already send a DWR ourselves */
122 reset_tmr = !peer->p_flagscxx . . $ fd_peer#p_flags..pf_dw_pendingcxx . . $ fd_peer#$anonymous_type_0#pf_dw_pending.;
123 } else {
124 /* Reset the timer */
125 reset_tmr = 1;
126 }
127 if (reset_tmr) {
128 fd_psm_next_timeoutcxx . . $ fd_psm_next_timeout(b1c93fc10f1c629).(peer, 1, peer->p_hdrcxx . . $ fd_peer#p_hdr..infocxx . . $ peer_hdr#info..configcxx . . $ peer_info#config..pic_twtimercxx . . $ peer_info#$anonymous_type_2#pic_twtimer. ?: fd_g_configcxx . . $ fd_g_config.->cnf_timer_twcxx . . $ fd_config#cnf_timer_tw.);
129 }
130
131 /* If we are in REOPEN state, increment the counter */
132 if (fd_peer_getstatecxx . . $ `lib/freeDiameter-1.2.1/libfdcore/fdcore-internal.h:216:9`!(peer) == STATE_REOPENcxx . . $ STATE_REOPEN.) {
133 peer->p_flagscxx . . $ fd_peer#p_flags..pf_reopen_cntcxx . . $ fd_peer#$anonymous_type_0#pf_reopen_cnt. += 1;
134
135 if (peer->p_flagscxx . . $ fd_peer#p_flags..pf_reopen_cntcxx . . $ fd_peer#$anonymous_type_0#pf_reopen_cnt.) {
136 /* Send a new DWR */
137 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( send_DWR(peer) );
138 } else {
139 /* Move to OPEN state */
140 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_psm_change_state(peer, STATE_OPEN) );
141 }
142 }
143
144 return 0;
145 }
146
147 /* Handle a timeout in the PSM (OPEN or REOPEN state only) */
148 int fd_p_dw_timeoutcxx . . $ fd_p_dw_timeout(c8ea46e6cf1a23ee).(struct fd_peercxx . . $ fd_peer# * peer)
149 {
150 TRACE_ENTRYcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:374:9`!("%p", peer);
151
152 if (peer->p_flagscxx . . $ fd_peer#p_flags..pf_dw_pendingcxx . . $ fd_peer#$anonymous_type_0#pf_dw_pending.) {
153 /* We have sent a DWR and received no answer during TwTimer */
154 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( fd_psm_change_state(peer, STATE_SUSPECT) );
155 fd_psm_next_timeoutcxx . . $ fd_psm_next_timeout(b1c93fc10f1c629).(peer, 0, 2 * (peer->p_hdrcxx . . $ fd_peer#p_hdr..infocxx . . $ peer_hdr#info..configcxx . . $ peer_info#config..pic_twtimercxx . . $ peer_info#$anonymous_type_2#pic_twtimer. ?: fd_g_configcxx . . $ fd_g_config.->cnf_timer_twcxx . . $ fd_config#cnf_timer_tw.) );
156 } else {
157 /* The timeout has expired, send a DWR */
158 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( send_DWR(peer) );
159 fd_psm_next_timeoutcxx . . $ fd_psm_next_timeout(b1c93fc10f1c629).(peer, 0, peer->p_hdrcxx . . $ fd_peer#p_hdr..infocxx . . $ peer_hdr#info..configcxx . . $ peer_info#config..pic_twtimercxx . . $ peer_info#$anonymous_type_2#pic_twtimer. ?: fd_g_configcxx . . $ fd_g_config.->cnf_timer_twcxx . . $ fd_config#cnf_timer_tw. );
160 }
161
162 return 0;
163 }
164
165 /* Handle DW exchanges after the peer has come alive again */
166 int fd_p_dw_reopencxx . . $ fd_p_dw_reopen(c8ea46e6cf1a23ee).(struct fd_peercxx . . $ fd_peer# * peer)
167 {
168 TRACE_ENTRYcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:374:9`!("%p", peer);
169
170 peer->p_flagscxx . . $ fd_peer#p_flags..pf_reopen_cntcxx . . $ fd_peer#$anonymous_type_0#pf_reopen_cnt. = 1;
171 peer->p_flagscxx . . $ fd_peer#p_flags..pf_cnx_pbcxx . . $ fd_peer#$anonymous_type_0#pf_cnx_pb. = 0;
172 CHECK_FCTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:588:10`!( send_DWR(peer) );
173
174 return 0;
175 }
176
177