The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
session.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 *
16 */
17
18/**
19 * $Id: 2b9a7ac155faa8a27d7a52ab1939b396a94bab13 $
20 * @file src/listen/bfd/session.c
21 * @brief BFD Session handling
22 *
23 * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
24 */
25
26#include <freeradius-devel/util/debug.h>
27
28#include <freeradius-devel/util/time.h>
29#include <freeradius-devel/util/event.h>
30#include <freeradius-devel/util/base16.h>
31#include <freeradius-devel/util/md5.h>
32#include <freeradius-devel/util/rand.h>
33#include <freeradius-devel/util/sha1.h>
34#include <freeradius-devel/util/socket.h>
35#include <freeradius-devel/util/time.h>
36
37#include "session.h"
38
39static void bfd_sign(bfd_session_t *session, bfd_packet_t *bfd);
40static int bfd_authenticate(bfd_session_t *session, bfd_packet_t *bfd);
41static void bfd_control_packet_init(bfd_session_t *session, bfd_packet_t *bfd);
42
44
45static void bfd_start_packets(bfd_session_t *session);
46static void bfd_start_control(bfd_session_t *session);
47static int bfd_stop_control(bfd_session_t *session);
48static void bfd_set_timeout(bfd_session_t *session, fr_time_t when);
49static void bfd_arm_detection(bfd_session_t *session);
50
51/*
52 * Section 6.6. Demand mode is active on the local system when bfd.DemandMode is 1, and both
53 * systems say that the session is Up. The remote system then stops sending periodic packets, so
54 * the detection time does not run all the time. A Poll Sequence then checks the connectivity.
55 */
56static inline bool bfd_local_demand_active(bfd_session_t const *session)
57{
58 return session->demand_mode &&
59 (session->session_state == BFD_STATE_UP) &&
61}
62
63/*
64 * Section 6.6. Demand mode is active on the remote system when bfd.RemoteDemandMode is 1, and both
65 * systems say that the session is Up. The local system then stops sending periodic packets.
66 */
67static inline bool bfd_remote_demand_active(bfd_session_t const *session)
68{
69 return session->remote_demand_mode &&
70 (session->session_state == BFD_STATE_UP) &&
72}
73
74/*
75 * Wrapper to run a trigger.
76 *
77 * @todo - push the trigger name, and various other VPs to the worker side?
78 * we will need to define some other kind of fake packet to send to the process
79 * module.
80 */
82{
83#if 0
84 bfd_wrapper_t wrapper;
85 fr_io_track_t *track;
86
88 wrapper.state_change = change;
89 wrapper.session = session;
90
91 track = fr_master_io_track_alloc(session->listen, &session->client, &session->client.ipaddr, session->port,
92 &session->client.src_ipaddr, session->port);
93 if (!track) return;
94
95 (void) fr_network_sendto_worker(session->nr, session->listen, track, (uint8_t const *) &wrapper, sizeof(wrapper), fr_time());
96#endif
97}
98
107
108
109/*
110 * Stop polling for packets.
111 */
112static int bfd_stop_poll(bfd_session_t *session)
113{
114 if (!session->doing_poll) return 0;
115
116 session->doing_poll = false;
117
118 /*
119 * We tried to increase the min_tx during a polling
120 * sequence. That isn't kosher, so we instead waited
121 * until now.
122 */
123 if (fr_time_delta_unwrap(session->next_min_tx_interval) > 0) {
126 }
127
128 /*
129 * Already sending packets. Clear the poll bit and
130 * re-set the timers.
131 */
132 if (!session->remote_demand_mode) {
133 fr_assert(session->timeout_ev != NULL);
134 fr_assert(session->packet_ev != NULL);
135
136 bfd_stop_control(session);
137 bfd_start_control(session);
138 return 1;
139 }
140
141 /*
142 * Don't send packets on a timer when Demand mode is active on the remote system.
143 *
144 * If Demand mode is also active on the local system, the detection time runs only while we are
145 * polling.
146 */
147 if (bfd_local_demand_active(session)) FR_TIMER_DISARM(session->timeout_ev);
148
149 return bfd_stop_control(session);
150}
151
152/*
153 * Send an immediate response to a poll request.
154 *
155 * Note that this doesn't affect our "last_sent" timer.
156 * That's set only when we intend to send a packet.
157 */
158static void bfd_poll_response(bfd_session_t *session)
159{
160 bfd_packet_t bfd;
161
162 bfd_control_packet_init(session, &bfd);
163 bfd.poll = 0; /* Section 6.5 */
164 bfd.final = 1;
165
166 /*
167 * TO DO: rate limit poll responses.
168 */
169
170 bfd_sign(session, &bfd);
171
172 if (sendfromto(session->sockfd, &bfd, bfd.length, 0, 0,
173 (struct sockaddr *) &session->local_sockaddr, session->local_salen,
174 (struct sockaddr *) &session->remote_sockaddr, session->remote_salen) < 0) {
175 ERROR("Failed sending packet: %s", fr_syserror(errno));
176 bfd_session_admin_down(session);
177 }
178}
179
180/*
181 * Implement the requirements of RFC 5880 Section 6.8.6.
182 */
184{
186 uint32_t remote_required_min_rx, remote_desired_min_tx;
187
188 /*
189 *
190 * If the Your Discriminator field is nonzero, it MUST be used to
191 * select the session with which this BFD packet is associated. If
192 * no session is found, the packet MUST be discarded.
193 */
194 if ((bfd->your_disc != 0) && (bfd->your_disc != session->local_disc)) {
195 DEBUG("BFD %s peer %s packet has unexpected Your-Discriminator (got %08x, expected %08x",
196 session->server_name, session->client.shortname,
197 fr_nbo_to_uint32((void *) &bfd->your_disc),
198 fr_nbo_to_uint32((void *) &session->local_disc));
200 }
201
202 /*
203 * If the A bit is set and no authentication is in use (bfd.AuthType
204 * is zero), the packet MUST be discarded.
205 */
206 if (bfd->auth_present &&
207 (session->auth_type == BFD_AUTH_RESERVED)) {
208 DEBUG("BFD %s peer %s packet asked to authenticate an unauthenticated session.",
209 session->server_name, session->client.shortname);
211 }
212
213 /*
214 * If the A bit is clear and authentication is in use (bfd.AuthType
215 * is nonzero), the packet MUST be discarded.
216 */
217 if (!bfd->auth_present &&
218 (session->auth_type != BFD_AUTH_RESERVED)) {
219 DEBUG("BFD %s peer %s packet failed to authenticate an authenticated session.",
220 session->server_name, session->client.shortname);
222 }
223
224 /*
225 * If the A bit is set, the packet MUST be authenticated under the
226 * rules of section 6.7, based on the authentication type in use
227 * (bfd.AuthType). This may cause the packet to be discarded.
228 */
229 if (bfd->auth_present && !bfd_authenticate(session, bfd)) {
230 DEBUG("BFD %s peer %s authentication failed for packet",
231 session->server_name, session->client.shortname);
233 }
234
235 /*
236 * Set bfd.RemoteDiscr to the value of My Discriminator.
237 *
238 * Set bfd.RemoteState to the value of the State (Sta) field.
239 *
240 * Set bfd.RemoteDemandMode to the value of the Demand (D) bit.
241 */
242 session->remote_disc = bfd->my_disc;
243 session->remote_session_state = (bfd_session_state_t)bfd->state;
244 session->remote_demand_mode = bfd->demand;
245
246 /*
247 * The intervals are in network order on the wire. The session keeps them in host order.
248 */
249 remote_required_min_rx = fr_nbo_to_uint32((uint8_t const *) &bfd->required_min_rx_interval);
250 remote_desired_min_tx = fr_nbo_to_uint32((uint8_t const *) &bfd->desired_min_tx_interval);
251
252 /*
253 * Set bfd.RemoteMinRxInterval to the value of Required Min RX Interval. The RFC does not limit
254 * that value. Zero means that we don't send packets. A large value is how the peer slows us
255 * down.
256 */
257 session->remote_min_rx_interval = fr_time_delta_from_usec(remote_required_min_rx);
258
259 /*
260 * If the Required Min Echo RX Interval field is zero, the
261 * transmission of Echo packets, if any, MUST cease.
262 */
263 if (bfd->min_echo_rx_interval == 0) {
264#if 0
265 /*
266 * Echo packets are BFD packets with
267 * application-layer data echoed back to the
268 * sender. We don't do that.
269 */
270 bfd_stop_echo(session);
271#endif
272 }
273
274 /*
275 * If a Poll Sequence is being transmitted by the local system and
276 * the Final (F) bit in the received packet is set, the Poll Sequence
277 * MUST be terminated.
278 */
279 if (session->doing_poll && bfd->final) {
280 bfd_stop_poll(session);
281 }
282
283 /*
284 * Update transmit intervals as in 6.8.2
285 */
286
287 /*
288 * Update detection times as in 6.8.4. The detection time uses the Detect Mult of the
289 * remote system, which is it's promise for sent packet timers.
290 */
291 session->remote_detect_multi = bfd->detect_multi;
292
293 if (!bfd_local_demand_active(session)) {
294 if (fr_time_delta_gteq(session->required_min_rx_interval, fr_time_delta_from_usec(remote_desired_min_tx))) {
295 session->detection_time = session->required_min_rx_interval;
296 } else {
297 session->detection_time = fr_time_delta_from_usec(remote_desired_min_tx);
298 }
299 } else {
301 session->detection_time = session->desired_min_tx_interval;
302 } else {
303 session->detection_time = session->remote_min_rx_interval;
304 }
305 }
306
307 /*
308 * If bfd.SessionState is AdminDown
309 *
310 * Discard the packet.
311 */
312 if (session->session_state == BFD_STATE_ADMIN_DOWN) {
313 DEBUG("Discarding BFD packet (admin down)");
315 }
316
317 /*
318 * If received state is AdminDown
319 * If bfd.SessionState is not Down
320 * Set bfd.LocalDiag to 3 (Neighbor signaled session down)
321 * Set bfd.SessionState to Down
322 */
323 if (bfd->state == BFD_STATE_ADMIN_DOWN) {
324 if (session->session_state != BFD_STATE_DOWN) {
325 down:
326 session->local_diag = BFD_NEIGHBOR_DOWN;
327
328 DEBUG("BFD %s peer %s State %s -> DOWN (neighbour %s)",
329 session->server_name, session->client.shortname,
331 fr_bfd_packet_names[bfd->state]);
332 session->session_state = BFD_STATE_DOWN;
333 state_change = BFD_STATE_CHANGE_PEER_DOWN;
334 }
335
336 } else {
337 switch (session->session_state) {
338 case BFD_STATE_DOWN:
339 switch (bfd->state) {
340 case BFD_STATE_DOWN:
341 DEBUG("BFD %s peer %s State DOWN -> INIT (neighbor DOWN)",
342 session->server_name, session->client.shortname);
343 session->session_state = BFD_STATE_INIT;
344 state_change = BFD_STATE_CHANGE_INIT;
345 break;
346
347 case BFD_STATE_INIT:
348 DEBUG("BFD %s peer %s State DOWN -> UP (neighbor INIT)",
349 session->server_name, session->client.shortname);
350 session->session_state = BFD_STATE_UP;
351 state_change = BFD_STATE_CHANGE_UP;
352 break;
353
354 default: /* don't change anything */
355 break;
356 }
357 break;
358
359 case BFD_STATE_INIT:
360 switch (bfd->state) {
361 case BFD_STATE_INIT:
362 case BFD_STATE_UP:
363 DEBUG("BFD %s peer %s State INIT -> UP",
364 session->server_name, session->client.shortname);
365 session->session_state = BFD_STATE_UP;
366 state_change = BFD_STATE_CHANGE_UP;
367 break;
368
369 default: /* don't change anything */
370 break;
371 }
372 break;
373
374 case BFD_STATE_UP:
375 switch (bfd->state) {
376 case BFD_STATE_DOWN:
377 goto down;
378
379 default:
380 break;
381 }
382 break;
383
384 default:
385 DEBUG("Internal sanity check failed");
387 }
388 }
389
390 /*
391 * Section 6.8.3
392 *
393 * When bfd.SessionState is not Up, the system MUST set
394 * bfd.DesiredMinTxInterval to a value of not less than one second
395 * (1,000,000 microseconds). This is intended to ensure that the
396 * bandwidth consumed by BFD sessions that are not Up is negligible,
397 * particularly in the case where a neighbor may not be running BFD.
398 */
399 if ((state_change != BFD_STATE_CHANGE_NONE) && (session->session_state != BFD_STATE_UP)) {
401
402 /*
403 * The one second limit applies only while the session is not Up. Once the session is Up,
404 * go back to the configured value.
405 */
406 } else if (state_change == BFD_STATE_CHANGE_UP) {
408 }
409
410 /*
411 * Check if demand mode should be active (Section 6.6)
412 *
413 * If bfd.RemoteDemandMode is 1, bfd.SessionState is Up, and
414 * bfd.RemoteSessionState is Up, Demand mode is active on the remote
415 * system and the local system MUST cease the periodic transmission
416 * of BFD Control packets (see section 6.8.7).
417 *
418 * A Poll Sequence is not periodic transmission. It continues until the Final arrives.
419 */
420 if (bfd_remote_demand_active(session) && !session->doing_poll) {
421 DEBUG("BFD %s peer %s demand mode UP / UP, stopping packets",
422 session->server_name, session->client.shortname);
423 bfd_stop_control(session);
424 }
425
426 /*
427 * If bfd.RemoteDemandMode is 0, or bfd.SessionState is not Up, or
428 * bfd.RemoteSessionState is not Up, Demand mode is not active on the
429 * remote system and the local system MUST send periodic BFD Control
430 * packets.
431 */
432 if ((!session->remote_demand_mode) ||
433 (session->session_state != BFD_STATE_UP) ||
434 (session->remote_session_state != BFD_STATE_UP)) {
435 bfd_start_control(session);
436 }
437
438 /*
439 * If the Poll (P) bit is set, send a BFD Control packet to the
440 * remote system with the Poll (P) bit clear, and the Final (F) bit
441 * set (see section 6.8.7).
442 */
443 if (bfd->poll) {
444 bfd_poll_response(session);
445 }
446
447 /*
448 * If the packet was not discarded, it has been received for purposes
449 * of the Detection Time expiration rules in section 6.8.4.
450 */
451 session->last_recv = fr_time();
452
453 /*
454 * The other end is reducing the RX interval. Do that
455 * now.
456 */
457 if (fr_time_delta_lt(fr_time_delta_from_usec(remote_required_min_rx), session->remote_min_rx_interval) &&
458 !session->demand_mode) {
459 bfd_stop_control(session);
460 bfd_start_control(session);
461 }
462
463 /*
464 * @todo - warn about missing packets?
465 */
466#if 0
467 if ((session->detect_multi >= 2) && (fr_time_gt(session->last_recv, session->next_recv))) {
468 ...
469 }
470#endif
471
472 return state_change;
473}
474
475
476/*
477 * Requirements of 6.8.3
478 *
479 * Changes to:
480 *
481 * session->desired_min_tx_interval
482 * session->required_min_rx_interval
483 *
484 * mean we start polling.
485 */
486
487/*
488 * Verify and/or calculate passwords
489 */
490static void bfd_calc_simple(bfd_session_t *session, bfd_packet_t *bfd)
491{
492 bfd_auth_simple_t *simple = &bfd->auth.password;
493
494 fr_assert(session->secret_len <= sizeof(simple->password));
495
496 memcpy(simple->password, session->client.secret, session->secret_len);
497 simple->auth_len = 3 + session->secret_len;
498}
499
500static void bfd_auth_simple(bfd_session_t *session, bfd_packet_t *bfd)
501{
502 bfd_auth_simple_t *simple = &bfd->auth.password;
503
504 simple->auth_type = session->auth_type;
505 simple->auth_len = 3 + session->secret_len;
506 bfd->length = FR_BFD_HEADER_LENGTH + simple->auth_len;
507
508 simple->key_id = 0;
509
510 bfd_calc_simple(session, bfd);
511}
512
513/*
514 * Verify and/or calculate auth-type digests.
515 */
516static void bfd_calc_md5(bfd_session_t *session, bfd_packet_t *bfd)
517{
518 bfd_auth_md5_t *md5 = &bfd->auth.md5;
519
520 fr_assert(session->secret_len <= sizeof(md5->digest));
521 fr_assert(md5->auth_len == sizeof(*md5));
522
523 memset(md5->digest, 0, sizeof(md5->digest));
524 memcpy(md5->digest, session->client.secret, session->secret_len);
525
526 /*
527 * bfd_auth_md5() sets the length, and bfd_verify_md5()
528 * rejects packets with any other length.
529 */
530 fr_assert(bfd->length == (FR_BFD_HEADER_LENGTH + sizeof(*md5)));
531 fr_md5_calc(md5->digest, (const uint8_t *) bfd, FR_BFD_HEADER_LENGTH + sizeof(*md5));
532}
533
534
535static void bfd_auth_md5(bfd_session_t *session, bfd_packet_t *bfd)
536{
537 bfd_auth_md5_t *md5 = &bfd->auth.md5;
538
539 md5->auth_type = session->auth_type;
540 md5->auth_len = sizeof(*md5);
541 bfd->length = FR_BFD_HEADER_LENGTH + md5->auth_len;
542
543 md5->key_id = 0;
544 fr_nbo_from_uint32((uint8_t *) &md5->sequence_no, session->xmit_auth_seq++);
545
546 bfd_calc_md5(session, bfd);
547}
548
549static void bfd_calc_sha1(bfd_session_t *session, bfd_packet_t *bfd)
550{
551 fr_sha1_ctx ctx;
552 bfd_auth_sha1_t *sha1 = &bfd->auth.sha1;
553
554 fr_assert(session->secret_len <= sizeof(sha1->digest));
555 fr_assert(sha1->auth_len == sizeof(*sha1));
556
557 memset(sha1->digest, 0, sizeof(sha1->digest));
558 memcpy(sha1->digest, session->client.secret, session->secret_len);
559
560 fr_sha1_init(&ctx);
561 /*
562 * bfd_auth_sha1() sets the length, and bfd_verify_sha1()
563 * rejects packets with any other length.
564 */
565 fr_assert(bfd->length == (FR_BFD_HEADER_LENGTH + sizeof(*sha1)));
566 fr_sha1_update(&ctx, (const uint8_t *) bfd, FR_BFD_HEADER_LENGTH + sizeof(*sha1));
567 fr_sha1_final(sha1->digest, &ctx);
568}
569
570static void bfd_auth_sha1(bfd_session_t *session, bfd_packet_t *bfd)
571{
572 bfd_auth_sha1_t *sha1 = &bfd->auth.sha1;
573
574 sha1->auth_type = session->auth_type;
575 sha1->auth_len = sizeof(*sha1);
576 bfd->length = FR_BFD_HEADER_LENGTH + sha1->auth_len;
577
578 sha1->key_id = 0;
579 fr_nbo_from_uint32((uint8_t *) &sha1->sequence_no, session->xmit_auth_seq++);
580
581 bfd_calc_sha1(session, bfd);
582}
583
584/*
585 * Sections 6.7.3 and 6.7.4. The window is 3 times the Detect Mult field of the received packet. A
586 * meticulous type starts at the next number, and non-meticulous type allows the same number to repeat.
587 */
588static int bfd_verify_sequence(bfd_session_t *session, uint32_t sequence_no,
589 int meticulous, uint8_t detect_mult)
590{
591 uint32_t start, stop;
592
593 start = session->recv_auth_seq;
594 stop = start + 3 * detect_mult;
595
596 if (meticulous) {
597 start++;
598 }
599
600 if (start < stop) {
601 if ((sequence_no < start) ||
602 (sequence_no > stop)) {
603 return 0;
604 }
605
606 } else { /* start is ~2^32, stop is ~10 */
607 if ((sequence_no < start) &&
608 (sequence_no > stop)) {
609 return 0;
610 }
611 }
612
613 return 1;
614}
615
616static int bfd_verify_simple(bfd_session_t *session, bfd_packet_t *bfd)
617{
618 bfd_auth_simple_t *simple = &bfd->auth.password;
619
620 if ((size_t) simple->auth_len != (3 + session->secret_len)) return 0;
621
622 if (simple->key_id != 0) return 0;
623
624 return (fr_digest_cmp((uint8_t const *) session->client.secret, simple->password, session->secret_len) == 0);
625}
626
627static int bfd_verify_md5(bfd_session_t *session, bfd_packet_t *bfd)
628{
629 int rcode;
630 bfd_auth_md5_t *md5 = &bfd->auth.md5;
631 uint8_t digest[sizeof(md5->digest)];
632
633 if (md5->auth_len != sizeof(*md5)) return 0;
634
635 if (bfd->length != (FR_BFD_HEADER_LENGTH + sizeof(*md5))) return 0;
636
637 if (md5->key_id != 0) return 0;
638
639 memcpy(digest, md5->digest, sizeof(digest));
640
641 bfd_calc_md5(session, bfd);
642 rcode = fr_digest_cmp(digest, md5->digest, sizeof(digest));
643
644 memcpy(md5->digest, digest, sizeof(md5->digest)); /* pedantic */
645
646 if (rcode != 0) {
647 DEBUG("BFD %s peer %s MD5 Digest failed: **** RE-ENTER THE SECRET ON BOTH ENDS ****",
648 session->server_name, session->client.shortname);
649 return 0;
650 }
651
652 /*
653 * Do this AFTER the authentication instead of before!
654 */
655 if (!session->auth_seq_known) {
656 session->auth_seq_known = 1;
657
658 } else if (!bfd_verify_sequence(session, fr_nbo_to_uint32((uint8_t const *) &md5->sequence_no),
659 (md5->auth_type == BFD_AUTH_MET_KEYED_MD5), bfd->detect_multi)) {
660 DEBUG("MD5 sequence out of window");
661 return 0;
662 }
663
664 session->recv_auth_seq = fr_nbo_to_uint32((uint8_t const *) &md5->sequence_no);
665
666 return 1;
667}
668
669static int bfd_verify_sha1(bfd_session_t *session, bfd_packet_t *bfd)
670{
671 int rcode;
672 bfd_auth_sha1_t *sha1 = &bfd->auth.sha1;
673 uint8_t digest[sizeof(sha1->digest)];
674
675 if (sha1->auth_len != sizeof(*sha1)) return 0;
676
677 if (bfd->length != (FR_BFD_HEADER_LENGTH + sizeof(*sha1))) return 0;
678
679 if (sha1->key_id != 0) return 0;
680
681 memcpy(digest, sha1->digest, sizeof(digest));
682
683 bfd_calc_sha1(session, bfd);
684 rcode = fr_digest_cmp(digest, sha1->digest, sizeof(digest));
685
686 memcpy(sha1->digest, digest, sizeof(sha1->digest)); /* pedantic */
687
688 if (rcode != 0) {
689 DEBUG("BFD %s peer %s SHA1 Digest failed: **** RE-ENTER THE SECRET ON BOTH ENDS ****",
690 session->server_name, session->client.shortname);
691 return 0;
692 }
693
694 /*
695 * Do this AFTER the authentication instead of before!
696 */
697 if (!session->auth_seq_known) {
698 session->auth_seq_known = 1;
699
700 } else if (!bfd_verify_sequence(session, fr_nbo_to_uint32((uint8_t const *) &sha1->sequence_no),
701 (sha1->auth_type == BFD_AUTH_MET_KEYED_SHA1), bfd->detect_multi)) {
702 DEBUG("SHA1 sequence out of window");
703 return 0;
704 }
705
706 session->recv_auth_seq = fr_nbo_to_uint32((uint8_t const *) &sha1->sequence_no);
707
708 return 1;
709}
710
711static int bfd_authenticate(bfd_session_t *session, bfd_packet_t *bfd)
712{
713 /*
714 * Check the received auth_type against the configured auth_type. If they're different, then
715 * complain and discard the packet.
716 */
717 if (bfd->auth.basic.auth_type != session->auth_type) {
718 DEBUG("BFD %s peer %s packet has authentication type %u, expected %u",
719 session->server_name, session->client.shortname,
720 bfd->auth.basic.auth_type, session->auth_type);
721 return 0;
722 }
723
724 switch (bfd->auth.basic.auth_type) {
726 return 0;
727
728 case BFD_AUTH_SIMPLE:
729 return bfd_verify_simple(session, bfd);
730
733 return bfd_verify_md5(session, bfd);
734
737 return bfd_verify_sha1(session, bfd);
738 }
739
740 return 0;
741}
742
743
744static void bfd_sign(bfd_session_t *session, bfd_packet_t *bfd)
745{
746 if (bfd->auth_present) {
747 switch (session->auth_type) {
749 break;
750
751 case BFD_AUTH_SIMPLE:
752 bfd_auth_simple(session, bfd);
753 break;
754
757 bfd_auth_md5(session, bfd);
758 break;
759
762 bfd_auth_sha1(session, bfd);
763 break;
764 }
765 }
766}
767
768
769/*
770 * Initialize a control packet.
771 */
772static void bfd_control_packet_init(bfd_session_t *session, bfd_packet_t *bfd)
773{
774 memset(bfd, 0, sizeof(*bfd));
775
776 bfd->version = 1;
777 bfd->diag = session->local_diag;
778 bfd->state = session->session_state;
779 bfd->poll = 0; /* fixed by poll response */
780 bfd->final = 0; /* fixed by poll response */
781 bfd->control_plane_independent = 0;
782
783 bfd->auth_present = (session->auth_type != BFD_AUTH_RESERVED);
784
785 /*
786 * If we're UP / UP, signal that we've entered demand mode. The D bit tells the remote
787 * system to stop sending periodic packets. It does not stop ours.
788 */
789 bfd->demand = bfd_local_demand_active(session);
790
791 bfd->multipoint = 0;
792 bfd->detect_multi = session->detect_multi;
793 bfd->length = FR_BFD_HEADER_LENGTH;
794
795 bfd->my_disc = session->local_disc;
796 bfd->your_disc = session->remote_disc;
797
798 /*
799 * proto_bfd limits the intervals to 2s, which fits in the 32-bit wire fields.
800 */
801 fr_nbo_from_uint32((uint8_t *) &bfd->desired_min_tx_interval, (uint32_t) fr_time_delta_to_usec(session->desired_min_tx_interval));
802 fr_nbo_from_uint32((uint8_t *) &bfd->required_min_rx_interval, (uint32_t) fr_time_delta_to_usec(session->required_min_rx_interval));
803
804 fr_nbo_from_uint32((uint8_t *) &bfd->min_echo_rx_interval, (uint32_t) fr_time_delta_to_usec(session->my_min_echo_rx_interval)); /* not configurable, always 0 */
805}
806
807static void bfd_send_init(bfd_session_t *session, bfd_packet_t *bfd)
808{
809 bfd_control_packet_init(session, bfd);
810
811 bfd->poll = session->doing_poll;
812
813 /*
814 * Section 6.8.7. There are no more periodic packets when Demand mode is active on the
815 * remote system, except for the packets of a Poll Sequence. The Poll Sequence repeats
816 * until a Final arrives, or the detection time expires.
817 */
818 if (!bfd_remote_demand_active(session) || session->doing_poll) {
819 bfd_start_packets(session);
820 }
821
822 bfd_sign(session, bfd);
823}
824
825/*
826 * Send one BFD packet.
827 */
829{
830 bfd_session_t *session = ctx;
831 bfd_packet_t bfd;
832
833 bfd_send_init(session, &bfd);
834
835 DEBUG("BFD %s peer %s sending %s",
836 session->server_name, session->client.shortname, fr_bfd_packet_names[session->session_state]);
837
838 session->last_sent = fr_time();
839
840 if (sendfromto(session->sockfd, &bfd, bfd.length, 0, 0,
841 (struct sockaddr *) &session->local_sockaddr, session->local_salen,
842 (struct sockaddr *) &session->remote_sockaddr, session->remote_salen) < 0) {
843 ERROR("Failed sending packet: %s", fr_syserror(errno));
844 bfd_session_admin_down(session);
845 }
846}
847
848/*
849 * Send one BFD packet.
850 */
852{
853 bfd_session_t *session = ctx;
854 bfd_packet_t *bfd;
855 bfd_wrapper_t *wrapper;
856 fr_io_track_t *track;
858 uint8_t buffer[sizeof(bfd_wrapper_t) + sizeof(*bfd)];
859
860 wrapper = (bfd_wrapper_t *) buffer;
861 bfd = (bfd_packet_t *) wrapper->packet;
862
863 bfd_send_init(session, bfd);
864
865 session->last_sent = fr_time();
866
867 wrapper->type = BFD_WRAPPER_SEND_PACKET;
869 wrapper->session = session;
870
871 parent = talloc_parent(session->listen);
872 (void) talloc_get_type_abort(parent, fr_listen_instance_t);
873
874 track = fr_master_io_track_alloc(session->listen, &session->client, &session->client.ipaddr, session->port,
875 &session->client.src_ipaddr, session->port);
876 if (!track) return;
877
878 if (unlikely(fr_network_sendto_worker(session->nr, parent, track, (uint8_t const *) wrapper,
879 (wrapper->packet + bfd->length) - (uint8_t *) wrapper, fr_time()) < 0)) {
880 PERROR("Failed sending packet to worker");
881 }
882}
883
884/*
885 * Start sending packets.
886 */
887static void bfd_start_packets(bfd_session_t *session)
888{
889 uint64_t interval, base;
890 uint64_t jitter;
891 fr_timer_cb_t cb;
892
893 /*
894 * Reset the timers.
895 */
896 FR_TIMER_DISARM(session->packet_ev);
897
898 /*
899 * The other end doesn't want to receive control packets. So we stop sending them.
900 */
901 if (fr_time_delta_unwrap(session->remote_min_rx_interval) == 0) return;
902
905 } else {
906 interval = fr_time_delta_unwrap(session->remote_min_rx_interval);
907 }
908
909 /*
910 * If bfd.DetectMult is equal to 1, the interval between transmitted BFD
911 * Control packets MUST be no more than 90% of the negotiated
912 * transmission interval, and MUST be no less than 75% of the negotiated
913 * transmission interval. This is to ensure that, on the remote system,
914 * the calculated Detection Time does not pass prior to the receipt of
915 * the next BFD Control packet.
916 */
917 base = (interval * 3) / 4;
918 jitter = fr_rand(); /* 32-bit number */
919
920 if (session->detect_multi == 1) {
921 jitter *= 644245094; /* 15% of 2^32 */
922
923 } else {
924 jitter *= (1 << 30); /* 25% of 2^32 */
925 }
926
927 jitter >>= 32;
928 jitter *= interval;
929 jitter >>= 32;
930 interval = base;
931 interval += jitter;
932
933 if (!session->only_state_changes) {
935 } else {
936 cb = bfd_send_packet;
937 }
938
939 if (fr_timer_in(session, session->el->tl, &session->packet_ev,
940 fr_time_delta_wrap(interval),
941 false, cb, session) < 0) {
942 fr_assert("Failed to insert event" == NULL);
943 }
944}
945
946
947/*
948 * Start polling for the peer.
949 */
950static void bfd_start_poll(bfd_session_t *session)
951{
952 if (session->doing_poll) return;
953
954 /*
955 * Already sending packets. Reset the timers and set the
956 * poll bit.
957 */
958 if (!session->remote_demand_mode) {
959 bfd_stop_control(session);
960 }
961
962 session->doing_poll = true;
963 session->poll_start = fr_time();
964
965 /*
966 * Section 6.8.4. When Demand mode is active on the local system, the detection time
967 * starts when the Poll Sequence starts.
968 */
969 if (bfd_local_demand_active(session)) bfd_set_timeout(session, session->poll_start);
970
971 /*
972 * Send POLL packets, even if we're not sending CONTROL
973 * packets.
974 */
975 bfd_start_packets(session);
976}
977
978/*
979 * Timer functions
980 */
982{
983 /*
984 * Increasing the value: don't change it if we're already
985 * polling.
986 */
987 if (session->doing_poll &&
988 (session->session_state == BFD_STATE_UP) &&
990 session->next_min_tx_interval = value;
991 return;
992 }
993
994 /*
995 * Don't poll more than once per second.
996 */
997 if (session->session_state != BFD_STATE_UP) {
999 }
1000
1001 /*
1002 * If either bfd.DesiredMinTxInterval is changed or
1003 * bfd.RequiredMinRxInterval is changed, a Poll Sequence MUST be
1004 * initiated (see section 6.5). If the timing is such that a system
1005 * receiving a Poll Sequence wishes to change the parameters described
1006 * in this paragraph, the new parameter values MAY be carried in packets
1007 * with the Final (F) bit set, even if the Poll Sequence has not yet
1008 * been sent.
1009 */
1010
1011 session->desired_min_tx_interval = value;
1012
1013 /*
1014 * Already polling, don't change anything.
1015 */
1016 if (session->doing_poll) return;
1017
1018 bfd_stop_control(session);
1019 bfd_start_poll(session);
1020}
1021
1022
1023/*
1024 * We failed to see a packet.
1025 */
1027{
1028 bfd_session_t *session = ctx;
1029
1030 DEBUG("BFD %s peer %s TIMEOUT state %s",
1031 session->server_name, session->client.shortname,
1033
1034 /*
1035 * Section 6.8.4. If Demand mode is not active, and no packet arrived for the detection
1036 * time, an Init or Up session is Down.
1037 */
1038 if (!bfd_local_demand_active(session)) {
1039 switch (session->session_state) {
1040 case BFD_STATE_INIT:
1041 case BFD_STATE_UP:
1042 goto expired;
1043
1044 default:
1045 break;
1046 }
1047
1048 /*
1049 * If Demand mode is active, the detection time runs from the start of a Poll Sequence. If
1050 * that Poll Sequence is still running when the timer fires, the Poll got no Final.
1051 */
1052 } else if (session->doing_poll) {
1053 expired:
1054 DEBUG("BFD %s peer %s State <timeout> -> DOWN (control expired)",
1055 session->server_name, session->client.shortname);
1056 session->session_state = BFD_STATE_DOWN;
1057 session->local_diag = BFD_CTRL_EXPIRED;
1059
1061 }
1062
1063 session->remote_disc = 0;
1064
1065 if (session->detection_timeouts >= 2) {
1066 session->auth_seq_known = 0;
1067 }
1068
1069 session->detection_timeouts++;
1070
1071 /*
1072 * Demand mode is still active when the timer fired with no Poll Sequence, and then there is
1073 * nothing to time.
1074 */
1075 if (!bfd_local_demand_active(session)) bfd_set_timeout(session, now);
1076}
1077
1078/*
1079 * Section 6.8.4. The detection time starts when the last packet was received, unless Demand mode is
1080 * active on the local system. Then the remote system doesn't send periodic packets. A Poll Sequence
1081 * also has its own detection time.
1082 */
1083static inline void bfd_arm_detection(bfd_session_t *session)
1084{
1085 if (!bfd_local_demand_active(session)) {
1086 bfd_set_timeout(session, session->last_recv);
1087
1088 } else if (session->doing_poll) {
1089 bfd_set_timeout(session, session->poll_start);
1090
1091 } else {
1092 FR_TIMER_DISARM(session->timeout_ev);
1093 }
1094}
1095
1096/*
1097 * Set the timeout for when we've lost enough packets to be
1098 * worried.
1099 */
1100static void bfd_set_timeout(bfd_session_t *session, fr_time_t when)
1101{
1102 fr_time_t timeout;
1103 uint64_t delay;
1104
1105 delay = fr_time_delta_unwrap(session->detection_time);
1106
1107 /*
1108 * Section 6.8.4. In Demand mode, the detection time uses bfd.DetectMult. In other modes, the
1109 * remote system promises to send the packets, so the detection time uses the Detect Multi field
1110 * sent by the remote system.
1111 */
1112 delay *= bfd_local_demand_active(session) ? session->detect_multi : session->remote_detect_multi;
1113
1114 delay += fr_time_delta_unwrap(session->detection_time) / 2;
1115
1116 timeout = fr_time_add(when, fr_time_delta_wrap(delay));
1117
1118 if (fr_timer_at(session, session->el->tl, &session->timeout_ev,
1119 timeout, false, bfd_detection_timeout, session) < 0) {
1120 fr_assert("Failed to insert event" == NULL);
1121 }
1122}
1123
1124
1125/*
1126 * Start / stop control packets.
1127 */
1128
1129/*
1130 * Section 6.8.6 and 6.8.7. Cease the periodic transmission of BFD Control packets. This does not
1131 * touch the detection timer. The remote system may still be sending to us, and the detection timer
1132 * follows the rules of section 6.8.4.
1133 */
1135{
1136 FR_TIMER_DISARM(session->packet_ev);
1137 return 1;
1138}
1139
1141{
1142 /*
1143 * @todo - change our discriminator?
1144 */
1145
1146 /*
1147 * The peer asked us to stop sending periodic packets. We still receive its packets, so the
1148 * detection time still applies.
1149 */
1150 if (fr_time_delta_unwrap(session->remote_min_rx_interval) == 0) {
1151 bfd_arm_detection(session);
1152 return;
1153 }
1154
1155 /*
1156 * @todo - support passive. From 6.1:
1157 *
1158 * A system may take either an Active role or a Passive role in session
1159 * initialization. A system taking the Active role MUST send BFD
1160 * Control packets for a particular session, regardless of whether it
1161 * has received any BFD packets for that session. A system taking the
1162 * Passive role MUST NOT begin sending BFD packets for a particular
1163 * session until it has received a BFD packet for that session, and thus
1164 * has learned the remote system's discriminator value.
1165 */
1166 if ((session->remote_disc == 0) && session->passive) return;
1167
1168 /*
1169 * We were asked to go "up" when we were already "up"
1170 */
1171 if (session->remote_demand_mode &&
1172 (session->session_state == BFD_STATE_UP) &&
1173 (session->remote_session_state == BFD_STATE_UP) &&
1174 !session->doing_poll) {
1175 DEBUG("BFD %s peer %s warning: asked to start UP / UP ?",
1176 session->server_name, session->client.shortname);
1177 bfd_session_admin_down(session);
1178 return;
1179 }
1180
1181 bfd_arm_detection(session);
1182
1183 /*
1184 * Start sending packets.
1185 */
1186 bfd_start_packets(session);
1187}
1188
1189
1191{
1192 session->session_state = BFD_STATE_DOWN;
1193 session->local_disc = fr_rand();
1194 session->remote_disc = 0;
1195 session->local_diag = BFD_DIAG_NONE;
1198 session->remote_detect_multi = session->detect_multi; /* until we see a packet */
1199 session->remote_demand_mode = false;
1200 session->recv_auth_seq = 0;
1201 session->xmit_auth_seq = fr_rand();
1202 session->auth_seq_known = 0;
1203
1204 /*
1205 * Initialize the detection time.
1206 */
1207 if (!session->demand_mode) {
1208 session->detection_time = session->required_min_rx_interval;
1209 } else {
1210 session->detection_time = session->desired_min_tx_interval;
1211 }
1212
1213 return 0;
1214}
1215
1217{
1218 DEBUG("Starting BFD for %s", session->client.shortname);
1219
1220 fr_assert(session->el);
1221
1222 bfd_start_control(session);
1223}
static int const char char buffer[256]
Definition acutest.h:641
@ BFD_CTRL_EXPIRED
Definition bfd.h:42
@ BFD_DIAG_NONE
Definition bfd.h:41
@ BFD_NEIGHBOR_DOWN
Definition bfd.h:44
#define FR_BFD_HEADER_LENGTH
Definition bfd.h:141
@ BFD_AUTH_MET_KEYED_MD5
Definition bfd.h:56
@ BFD_AUTH_MET_KEYED_SHA1
Definition bfd.h:58
@ BFD_AUTH_SIMPLE
Definition bfd.h:54
@ BFD_AUTH_KEYED_SHA1
Definition bfd.h:57
@ BFD_AUTH_KEYED_MD5
Definition bfd.h:55
@ BFD_AUTH_RESERVED
Definition bfd.h:53
bfd_session_state_t
Definition bfd.h:33
@ BFD_STATE_DOWN
Definition bfd.h:35
@ BFD_STATE_INIT
Definition bfd.h:36
@ BFD_STATE_ADMIN_DOWN
Definition bfd.h:34
@ BFD_STATE_UP
Definition bfd.h:37
static bool stop
Definition radmin.c:68
#define unlikely(_x)
Definition build.h:492
#define UNUSED
Definition build.h:415
#define ERROR(fmt,...)
Definition dhcpclient.c:40
#define DEBUG(fmt,...)
Definition dhcpclient.c:38
Test enumeration values.
Definition dict_test.h:92
int fr_network_sendto_worker(fr_network_t *nr, fr_listen_instance_t *li, void *packet_ctx, uint8_t const *data, size_t data_len, fr_time_t recv_time)
Definition network.c:1032
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
Definition client.h:83
char const * secret
Secret PSK.
Definition client.h:90
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
Definition client.h:84
char const * shortname
Client nickname.
Definition client.h:88
#define PERROR(_fmt,...)
Definition log.h:233
#define fr_time()
Definition event.c:61
static int bfd_verify_simple(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:616
static int bfd_stop_control(bfd_session_t *session)
Definition session.c:1134
static int bfd_stop_poll(bfd_session_t *session)
Definition session.c:112
static void bfd_arm_detection(bfd_session_t *session)
Definition session.c:1083
static void bfd_auth_sha1(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:570
static void bfd_sign(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:744
static int bfd_verify_md5(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:627
static void bfd_poll_response(bfd_session_t *session)
Definition session.c:158
void bfd_session_start(bfd_session_t *session)
Definition session.c:1216
static void bfd_start_control(bfd_session_t *session)
Definition session.c:1140
static int bfd_verify_sha1(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:669
static void bfd_calc_md5(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:516
static bool bfd_local_demand_active(bfd_session_t const *session)
Definition session.c:56
static int bfd_verify_sequence(bfd_session_t *session, uint32_t sequence_no, int meticulous, uint8_t detect_mult)
Definition session.c:588
static int bfd_authenticate(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:711
static void bfd_start_poll(bfd_session_t *session)
Definition session.c:950
static void bfd_calc_simple(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:490
int bfd_session_init(bfd_session_t *session)
Definition session.c:1190
bfd_state_change_t bfd_session_process(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:183
static void bfd_auth_md5(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:535
static void bfd_send_init(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:807
static void bfd_detection_timeout(UNUSED fr_timer_list_t *tl, fr_time_t now, void *ctx)
Definition session.c:1026
static void bfd_unlang_send_packet(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *ctx)
Definition session.c:851
static bool bfd_remote_demand_active(bfd_session_t const *session)
Definition session.c:67
static void bfd_calc_sha1(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:549
static void bfd_trigger(UNUSED bfd_session_t *session, UNUSED bfd_state_change_t change)
Definition session.c:81
static void bfd_send_packet(UNUSED fr_timer_list_t *el, UNUSED fr_time_t now, void *ctx)
Definition session.c:828
static void bfd_start_packets(bfd_session_t *session)
Definition session.c:887
static void bfd_set_desired_min_tx_interval(bfd_session_t *session, fr_time_delta_t value)
Definition session.c:981
void bfd_session_admin_down(bfd_session_t *session)
Definition session.c:99
static void bfd_control_packet_init(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:772
static void bfd_set_timeout(bfd_session_t *session, fr_time_t when)
Definition session.c:1100
static void bfd_auth_simple(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:500
fr_listen_instance_t * listen
associated listener
Definition session.h:42
socklen_t local_salen
Definition session.h:52
uint32_t recv_auth_seq
their auth_seq number
Definition session.h:106
int sockfd
cached for laziness
Definition session.h:44
fr_time_delta_t my_min_echo_rx_interval
what we send for echo_rx_interval
Definition session.h:88
uint32_t remote_detect_multi
their detect_multi, used for the detection time in Asynchronous mode
Definition session.h:80
fr_timer_t * timeout_ev
when we time out for not receiving a packet
Definition session.h:57
struct sockaddr_storage remote_sockaddr
cached for laziness
Definition session.h:48
fr_time_t poll_start
when the Poll Sequence started, for the detection time in Demand mode
Definition session.h:97
size_t secret_len
doesn't change while we're running
Definition session.h:109
bool demand_mode
demand is "once session is up, stop sending packets"
Definition session.h:93
bool doing_poll
Definition session.h:96
bfd_state_change_t
Definition session.h:134
@ BFD_STATE_CHANGE_UP
we are going to UP
Definition session.h:140
@ BFD_STATE_CHANGE_TIMEOUT_DOWN
Definition session.h:141
@ BFD_STATE_CHANGE_INIT
we are going to INIT
Definition session.h:139
@ BFD_STATE_CHANGE_PEER_DOWN
the peer has signalled us that he's Down.
Definition session.h:138
@ BFD_STATE_CHANGE_INVALID
Definition session.h:135
@ BFD_STATE_CHANGE_ADMIN_DOWN
we are admin-down
Definition session.h:137
@ BFD_STATE_CHANGE_NONE
no state change
Definition session.h:136
bfd_session_state_t remote_session_state
their view of the session state
Definition session.h:64
fr_time_t last_recv
last received packet
Definition session.h:59
fr_time_delta_t required_min_rx_interval
intervals between receives
Definition session.h:84
socklen_t remote_salen
Definition session.h:49
bfd_session_state_t session_state
our view of the session state
Definition session.h:63
uint32_t local_disc
our session ID, which is unique to this session
Definition session.h:74
fr_time_t last_sent
the last time we sent a packet
Definition session.h:61
fr_client_t client
might as well reuse this, others need it
Definition session.h:29
uint32_t remote_disc
their session ID
Definition session.h:75
char const * server_name
our name
Definition session.h:33
bool only_state_changes
copied from proto_bfd_udp.c
Definition session.h:35
fr_timer_t * packet_ev
for when we next send a packet
Definition session.h:58
uint8_t packet[]
Definition session.h:148
uint16_t port
peer port where packets are sent to
Definition session.h:31
bfd_auth_type_t auth_type
what kind of authentication is used
Definition session.h:104
bfd_session_t * session
Definition session.h:147
@ BFD_WRAPPER_STATE_CHANGE
Definition session.h:131
@ BFD_WRAPPER_SEND_PACKET
Definition session.h:130
uint32_t detect_multi
Definition session.h:79
uint32_t xmit_auth_seq
our auth_seq number
Definition session.h:107
bool passive
active or passive role from RFC 5880 - unused
Definition session.h:114
fr_time_delta_t desired_min_tx_interval
intervals between transmits
Definition session.h:82
bool remote_demand_mode
their demand mode
Definition session.h:94
fr_time_delta_t configured_min_tx_interval
the configured value, restored when the session is Up
Definition session.h:83
fr_network_t * nr
network side of things
Definition session.h:46
bfd_state_change_t state_change
Definition session.h:146
int detection_timeouts
too many timeouts means !auth_seq_known
Definition session.h:112
struct sockaddr_storage local_sockaddr
cached for laziness
Definition session.h:51
fr_event_list_t * el
event list
Definition session.h:45
fr_time_delta_t next_min_tx_interval
how to update this when we're polling
Definition session.h:90
bool auth_seq_known
do we know the authentication sequence number?
Definition session.h:102
uint32_t type
Definition session.h:145
fr_time_t next_recv
when we next expect to receive a packet
Definition session.h:60
fr_time_delta_t detection_time
used to set ev_timeout
Definition session.h:111
bfd_diag_t local_diag
diagnostics for errors
Definition session.h:77
fr_time_delta_t remote_min_rx_interval
their min_rx_interval
Definition session.h:86
fr_io_track_t * fr_master_io_track_alloc(fr_listen_instance_t *li, fr_client_t *radclient, fr_ipaddr_t const *src_ipaddr, int src_port, fr_ipaddr_t const *dst_ipaddr, int dst_port)
Definition master.c:3554
unsigned int uint32_t
void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Perform a single digest operation on a single input buffer.
unsigned char uint8_t
int fr_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length)
Do a comparison of two authentication digests by comparing the FULL data.
Definition misc.c:516
static uint32_t fr_nbo_to_uint32(uint8_t const data[static sizeof(uint32_t)])
Read an unsigned 32bit integer from wire format (big endian)
Definition nbo.h:167
static void fr_nbo_from_uint32(uint8_t out[static sizeof(uint32_t)], uint32_t num)
Write out an unsigned 32bit integer in wire format (big endian)
Definition nbo.h:61
char const * fr_bfd_packet_names[FR_BFD_CODE_MAX]
Definition base.c:64
#define fr_assert(_expr)
Definition rad_assert.h:37
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:128
void fr_sha1_init(fr_sha1_ctx *context)
Definition sha1.c:93
void fr_sha1_final(uint8_t digest[static SHA1_DIGEST_LENGTH], fr_sha1_ctx *context)
Definition sha1.c:141
void fr_sha1_update(fr_sha1_ctx *context, uint8_t const *in, size_t len)
Definition sha1.c:105
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
Definition time.h:154
#define fr_time_delta_lt(_a, _b)
Definition time.h:285
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:599
#define fr_time_delta_wrap(_time)
Definition time.h:152
static int64_t fr_time_delta_to_usec(fr_time_delta_t delta)
Definition time.h:641
#define fr_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:196
static fr_cmp_ret_t fr_time_delta_cmp(fr_time_delta_t a, fr_time_delta_t b)
Compare two fr_time_delta_t values.
Definition time.h:948
#define fr_time_gt(_a, _b)
Definition time.h:237
#define fr_time_delta_gteq(_a, _b)
Definition time.h:284
static fr_time_delta_t fr_time_delta_from_usec(int64_t usec)
Definition time.h:577
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
An event timer list.
Definition timer.c:65
#define fr_timer_in(...)
Definition timer.h:87
void(* fr_timer_cb_t)(fr_timer_list_t *tl, fr_time_t now, void *uctx)
Called when a timer event fires.
Definition timer.h:75
#define FR_TIMER_DISARM(_ev)
Definition timer.h:91
#define fr_timer_at(...)
Definition timer.h:81
ssize_t sendfromto(int fd, void *buf, size_t len, int flags, int ifindex, struct sockaddr *from, socklen_t from_len, struct sockaddr *to, socklen_t to_len)
Send packet via a file descriptor, setting the src address and outbound interface.
Definition udpfromto.c:421
static fr_event_list_t * el
static fr_slen_t parent
Definition pair.h:864