Mercurial > hg > freeDiameter
annotate libfdcore/p_dp.c @ 1562:6219359a36a9 default tip
Merge latest changes from proposed branch
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 21 Jun 2021 19:08:18 +0800 |
parents | 8f9684264fe0 |
children |
rev | line source |
---|---|
36 | 1 /********************************************************************************************************* |
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 | 4 * * |
1127
1af09cc156d6
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1119
diff
changeset
|
5 * Copyright (c) 2013, WIDE Project and NICT * |
36 | 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 | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
454
diff
changeset
|
36 #include "fdcore-internal.h" |
36 | 37 |
38 /* This file contains code to handle Disconnect Peer messages (DPR and DPA) */ | |
39 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
40 /* Delay to use before next reconnect attempt */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
41 int fd_p_dp_newdelay(struct fd_peer * peer) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
42 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
43 int delay = peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
44 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
45 switch (peer->p_hdr.info.runtime.pir_lastDC) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
46 case ACV_DC_REBOOTING: |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
47 default: |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
48 /* We use TcTimer to attempt reconnection */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
49 break; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
50 case ACV_DC_BUSY: |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
51 /* No need to hammer the overloaded peer */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
52 delay *= 10; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
53 break; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
54 case ACV_DC_NOT_FRIEND: |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
55 /* He does not want to speak to us... let's retry a *lot* later maybe */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
56 delay *= 200; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
57 break; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
58 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
59 return delay; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
60 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
61 |
36 | 62 /* Handle a received message */ |
40
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
63 int fd_p_dp_handle(struct msg ** msg, int req, struct fd_peer * peer) |
36 | 64 { |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
65 long to_receive, to_send; |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
66 TRACE_ENTRY("%p %d %p", msg, req, peer); |
36 | 67 |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
68 if (req) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
69 /* We received a DPR, save the Disconnect-Cause and go to CLOSING_GRACE or terminate the connection */ |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
70 struct avp * dc; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
71 |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
72 CHECK_FCT( fd_msg_search_avp ( *msg, fd_dict_avp_DC, &dc )); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
73 if (dc) { |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
74 struct avp_hdr * hdr; |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
75 CHECK_FCT( fd_msg_avp_hdr( dc, &hdr ) ); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
76 if (hdr->avp_value == NULL) { |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
77 /* This is a sanity check */ |
1119
79dd22145f52
Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1010
diff
changeset
|
78 LOG_F("BUG: Unset value in Disconnect-Cause in DPR"); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
79 ASSERT(0); /* To check if this really happens, and understand why... */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
80 } |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
81 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
82 /* save the cause */ |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
83 peer->p_hdr.info.runtime.pir_lastDC = hdr->avp_value->u32; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
84 } |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
85 if (TRACE_BOOL(INFO)) { |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
86 if (dc) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
87 struct dict_object * dictobj; |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
88 struct dict_enumval_request er; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
89 memset(&er, 0, sizeof(er)); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
90 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
91 /* prepare the request */ |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
92 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, fd_dict_avp_DC, &er.type_obj, ENOENT ) ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
93 er.search.enum_value.u32 = peer->p_hdr.info.runtime.pir_lastDC; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
94 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
95 /* Search the enum value */ |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
96 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &er, &dictobj, 0 ) ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
97 if (dictobj) { |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
98 CHECK_FCT( fd_dict_getval( dictobj, &er.search ) ); |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
740
diff
changeset
|
99 TRACE_DEBUG(INFO, "Peer '%s' sent a DPR with cause: %s", peer->p_hdr.info.pi_diamid, er.search.enum_name); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
100 } else { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
740
diff
changeset
|
101 TRACE_DEBUG(INFO, "Peer '%s' sent a DPR with unknown cause: %u", peer->p_hdr.info.pi_diamid, peer->p_hdr.info.runtime.pir_lastDC); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
102 } |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
103 } else { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
740
diff
changeset
|
104 TRACE_DEBUG(INFO, "Peer '%s' sent a DPR without Disconnect-Cause AVP", peer->p_hdr.info.pi_diamid); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
105 } |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
106 } |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
107 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
108 /* Now reply with a DPA */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
109 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) ); |
112
6a294d977878
Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
80
diff
changeset
|
110 CHECK_FCT( fd_msg_rescode_set( *msg, "DIAMETER_SUCCESS", NULL, NULL, 1 ) ); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
111 |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
112 /* Do we have pending exchanges with this peer? */ |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
113 CHECK_FCT( fd_peer_get_load_pending(&peer->p_hdr, &to_receive, &to_send) ); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
114 |
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
|
115 if ((to_receive == 0) && (to_send == 0)) { |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
116 /* No pending exchange, move to CLOSING directly */ |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
117 CHECK_FCT( fd_psm_change_state(peer, STATE_CLOSING) ); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
118 |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
119 /* Now send the DPA */ |
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
|
120 CHECK_FCT( fd_out_send( msg, NULL, peer, 0) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
121 |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
122 /* and move to CLOSED */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
123 fd_psm_cleanup(peer, 0); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
124 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
125 /* Reset the timer for next connection attempt -- we'll retry sooner or later depending on the disconnection cause */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
126 fd_psm_next_timeout(peer, 1, fd_p_dp_newdelay(peer)); |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
127 } else { |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
128 /* We have pending exchanges, we move to CLOSING_GRACE which allows exchanges of answers but |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
129 not new requests */ |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
130 CHECK_FCT( fd_psm_change_state(peer, STATE_CLOSING_GRACE) ); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
131 fd_psm_next_timeout(peer, 0, GRACE_TIMEOUT); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
132 |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
133 /* Now send the DPA */ |
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
|
134 CHECK_FCT( fd_out_send( msg, NULL, peer, 0) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
135 } |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
136 } else { |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
137 /* We received a DPA */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
138 int curstate = fd_peer_getstate(peer); |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
139 if (curstate != STATE_CLOSING_GRACE) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
140 TRACE_DEBUG(INFO, "Ignoring DPA received in state %s", STATE_STR(curstate)); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
141 } |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
142 |
79
d273a2ce19c8
Fix problem in DPR handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
143 /* In theory, we should control the Result-Code AVP. But since we will not go back to OPEN state here anyway, let's skip it */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
144 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
145 /* TODO("Control Result-Code in the DPA") */ |
79
d273a2ce19c8
Fix problem in DPR handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
146 CHECK_FCT_DO( fd_msg_free( *msg ), /* continue */ ); |
d273a2ce19c8
Fix problem in DPR handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
147 *msg = NULL; |
d273a2ce19c8
Fix problem in DPR handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
148 |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
149 /* Do we still have pending exchanges with this peer? */ |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
150 CHECK_FCT( fd_peer_get_load_pending(&peer->p_hdr, &to_receive, &to_send) ); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
151 if ((to_receive != 0) || (to_send != 0)) { |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
152 TRACE_DEBUG(INFO, "Received DPA but pending load: [%ld, %ld], giving grace delay before closing", to_receive, to_send); |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
153 fd_psm_next_timeout(peer, 0, GRACE_TIMEOUT); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
154 peer->p_flags.pf_localterm = 1; |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
155 } else { |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
156 /* otherwise, go to CLOSING state, the psm will handle terminating the connection */ |
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
157 CHECK_FCT( fd_psm_change_state(peer, STATE_CLOSING) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
158 } |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
159 } |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
160 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
161 return 0; |
36 | 162 } |
163 | |
164 /* Start disconnection of a peer: send DPR */ | |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
165 int fd_p_dp_initiate(struct fd_peer * peer, char * reason) |
36 | 166 { |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
167 struct msg * msg = NULL; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
168 struct dict_object * dictobj = NULL; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
169 struct avp * avp = NULL; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
170 struct dict_enumval_request er; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
171 union avp_value val; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
172 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
173 TRACE_ENTRY("%p %p", peer, reason); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
174 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
175 /* Create a new DWR instance */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
176 CHECK_FCT( fd_msg_new ( fd_dict_cmd_DPR, MSGFL_ALLOC_ETEID, &msg ) ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
177 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
178 /* Add the Origin information */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
179 CHECK_FCT( fd_msg_add_origin ( msg, 0 ) ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
180 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
181 /* Add the Disconnect-Cause */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
182 CHECK_FCT( fd_msg_avp_new ( fd_dict_avp_DC, 0, &avp ) ); |
36 | 183 |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
184 /* Search the value in the dictionary */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
185 memset(&er, 0, sizeof(er)); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
186 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, fd_dict_avp_DC, &er.type_obj, ENOENT ) ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
187 er.search.enum_name = reason ?: "REBOOTING"; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
188 CHECK_FCT_DO( fd_dict_search( fd_g_config->cnf_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &er, &dictobj, ENOENT ), { ASSERT(0); /* internal error: unknown reason */ } ); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
189 CHECK_FCT( fd_dict_getval( dictobj, &er.search ) ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
190 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
191 /* Set the value in the AVP */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
192 val.u32 = er.search.enum_value.u32; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
193 CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
194 CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp ) ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
195 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
196 /* Save the value also in the peer */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
197 peer->p_hdr.info.runtime.pir_lastDC = val.u32; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
198 |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
199 /* Update the peer state and timer */ |
1010
357c2f892d24
Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
200 CHECK_FCT( fd_psm_change_state(peer, STATE_CLOSING_GRACE) ); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
201 fd_psm_next_timeout(peer, 0, DPR_TIMEOUT); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
202 |
80 | 203 /* Now send the DPR 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
|
204 CHECK_FCT_DO( fd_out_send(&msg, NULL, peer, 0), /* ignore since we are on timeout anyway */ ); |
80 | 205 |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
40
diff
changeset
|
206 return 0; |
36 | 207 } |