21 #include <openssl/sha.h> 25 #include <x86intrin.h> 42 #if defined(clib_crc32c_uses_intrinsics) && !defined (__i386__) 43 checksum = crc32_u64 (0, discriminator);
44 checksum = crc32_u64 (checksum, expire_time);
45 checksum = crc32_u64 (checksum, secret);
47 checksum =
clib_xxhash (discriminator ^ expire_time ^ secret);
72 s =
format (s,
"{auth-type=%u:%s, conf-key-id=%u, use-count=%u}, ",
124 BFD_DBG (
"set local_diag, bs_idx=%d: '%d:%s'", bs->
bs_idx, code,
151 return "BFD_POLL_" #x; 163 BFD_DBG (
"Setting poll state=%s, bs_idx=%u",
174 BFD_DBG (
"Recalculated transmit interval " BFD_CLK_FMT,
184 BFD_DBG (
"Recalculated echo transmit interval " BFD_CLK_FMT,
203 BFD_DBG (
"Missed %lu transmit events (now is %lu, calc " 204 "tx_timeout is %lu)",
222 BFD_DBG (
"Missed %lu transmit events (now is %lu, calc " 223 "tx_timeout is %lu)",
231 BFD_DBG (
"Next transmit in %lu clocks/%.02fs@%lu",
246 BFD_DBG (
"Missed %lu echo transmit events (now is %lu, calc tx_timeout " 253 BFD_DBG (
"Next echo transmit in %lu clocks/%.02fs@%lu",
268 BFD_DBG (
"Recalculated detection time %lu clocks/%.2fs",
291 if (tx_timeout && rx_timeout)
293 next =
clib_min (tx_timeout, rx_timeout);
307 BFD_DBG (
"bs_idx=%u, tx_timeout=%lu, echo_tx_timeout=%lu, rx_timeout=%lu, " 318 BFD_DBG (
"timing_wheel_insert(%p, %lu (%ld clocks/%.2fs in the " 325 if (!handling_wakeup)
337 u64 desired_min_tx_clocks)
340 BFD_DBG (
"Set effective desired min tx to " BFD_CLK_FMT,
351 u64 required_min_rx_clocks)
354 BFD_DBG (
"Set effective required min rx to " BFD_CLK_FMT,
361 u64 now,
u32 remote_required_min_rx_usec)
368 BFD_DBG (
"Set remote min rx to " BFD_CLK_FMT,
378 u32 remote_required_min_echo_rx_usec)
385 BFD_DBG (
"Set remote min echo rx to " BFD_CLK_FMT,
443 const bfd_pkt_t *pkt = (bfd_pkt_t *) t->
data;
446 s =
format (s,
"BFD v%u, diag=%u(%s), state=%u(%s),\n" 447 " flags=(P:%u, F:%u, C:%u, A:%u, D:%u, M:%u), " 448 "detect_mult=%u, length=%u\n",
458 if (t->
len >= sizeof (bfd_pkt_t) &&
459 pkt->head.length >= sizeof (bfd_pkt_t))
461 s =
format (s,
" my discriminator: %u\n",
462 clib_net_to_host_u32 (pkt->my_disc));
463 s =
format (s,
" your discriminator: %u\n",
464 clib_net_to_host_u32 (pkt->your_disc));
465 s =
format (s,
" desired min tx interval: %u\n",
466 clib_net_to_host_u32 (pkt->des_min_tx));
467 s =
format (s,
" required min rx interval: %u\n",
468 clib_net_to_host_u32 (pkt->req_min_rx));
469 s =
format (s,
" required min echo rx interval: %u",
470 clib_net_to_host_u32 (pkt->req_min_echo_rx));
472 if (t->
len >= sizeof (bfd_pkt_with_common_auth_t) &&
473 pkt->head.length >= sizeof (bfd_pkt_with_common_auth_t) &&
476 const bfd_pkt_with_common_auth_t *with_auth = (
void *) pkt;
477 const bfd_auth_common_t *common = &with_auth->common_auth;
478 s =
format (s,
"\n auth len: %u\n", common->len);
479 s =
format (s,
" auth type: %u:%s\n", common->type,
481 if (t->
len >= sizeof (bfd_pkt_with_sha1_auth_t) &&
482 pkt->head.length >= sizeof (bfd_pkt_with_sha1_auth_t) &&
483 (BFD_AUTH_TYPE_keyed_sha1 == common->type ||
484 BFD_AUTH_TYPE_meticulous_keyed_sha1 == common->type))
486 const bfd_pkt_with_sha1_auth_t *with_sha1 = (
void *) pkt;
487 const bfd_auth_sha1_t *sha1 = &with_sha1->sha1_auth;
488 s =
format (s,
" seq num: %u\n",
489 clib_net_to_host_u32 (sha1->seq_num));
490 s =
format (s,
" key id: %u\n", sha1->key_id);
492 sizeof (sha1->hash));
512 case BFD_STATE_admin_down:
574 case BFD_TRANSPORT_UDP4:
578 case BFD_TRANSPORT_UDP6:
590 case BFD_TRANSPORT_UDP4:
594 case BFD_TRANSPORT_UDP6:
607 case BFD_TRANSPORT_UDP4:
608 BFD_DBG (
"Transport bfd echo via udp4, bs_idx=%u", bs->
bs_idx);
611 case BFD_TRANSPORT_UDP6:
612 BFD_DBG (
"Transport bfd echo via udp6, bs_idx=%u", bs->
bs_idx);
624 case BFD_TRANSPORT_UDP4:
625 BFD_DBG (
"Transport bfd echo via udp4, bs_idx=%u", bs->
bs_idx);
628 case BFD_TRANSPORT_UDP6:
629 BFD_DBG (
"Transport bfd echo via udp6, bs_idx=%u", bs->
bs_idx);
641 bfd_auth_sha1_t *auth = &pkt->sha1_auth;
643 pkt->pkt.head.length +=
sizeof (*auth);
645 memset (auth, 0,
sizeof (*auth));
652 auth->type_len.len =
sizeof (bfd_auth_sha1_t);
661 unsigned char hash[
sizeof (auth->hash)];
662 SHA1 ((
unsigned char *) pkt,
sizeof (*pkt), hash);
676 case BFD_AUTH_TYPE_reserved:
678 case BFD_AUTH_TYPE_simple_password:
680 case BFD_AUTH_TYPE_keyed_md5:
682 case BFD_AUTH_TYPE_meticulous_keyed_md5:
683 clib_warning (
"Internal error, unexpected BFD auth type '%d'",
687 case BFD_AUTH_TYPE_keyed_sha1:
689 case BFD_AUTH_TYPE_meticulous_keyed_sha1:
690 bfd_add_sha1_auth_section (b, bs);
693 case BFD_AUTH_TYPE_keyed_sha1:
695 case BFD_AUTH_TYPE_meticulous_keyed_sha1:
696 clib_warning (
"Internal error, unexpected BFD auth type '%d'",
712 case BFD_TRANSPORT_UDP4:
714 case BFD_TRANSPORT_UDP6:
727 bfd_length =
sizeof (bfd_pkt_t);
728 memset (pkt, 0,
sizeof (*pkt));
733 pkt->head.length = bfd_length;
748 pkt->req_min_echo_rx = clib_host_to_net_u32 (1);
779 memset (pkt, 0,
sizeof (*pkt));
781 pkt->expire_time_clocks =
789 BFD_ERR (
"cannot send echo packet out, turning echo off");
796 BFD_ERR (
"cannot send echo packet out, turning echo off");
807 (
"No need to send echo packet now, now is %lu, tx_timeout is %lu",
818 BFD_DBG (
"Remote min rx interval is zero, not sending periodic control " 831 BFD_DBG (
"Remote demand is set, not sending periodic control frame");
855 case BFD_POLL_NEEDED:
856 if (now < bs->poll_state_start_or_timeout_clocks)
858 BFD_DBG (
"Cannot start a poll sequence yet, need to wait " 867 case BFD_POLL_IN_PROGRESS:
868 case BFD_POLL_IN_PROGRESS_AND_QUEUED:
870 BFD_DBG (
"Setting poll bit in packet, bs_idx=%u", bs->
bs_idx);
872 case BFD_POLL_NOT_NEEDED:
888 (
"No need to send control frame now, now is %lu, tx_timeout is %lu",
898 BFD_DBG (
"Send final control frame for bs_idx=%lu", bs->
bs_idx);
923 BFD_DBG (
"Rx timeout, session goes down");
940 BFD_DBG (
"Echo rx timeout, session goes down");
953 case BFD_STATE_admin_down:
969 BFD_DBG (
"Switching on echo function, bs_idx=%u", bs->
bs_idx);
996 uword event_type, *event_data = 0;
1005 BFD_DBG (
"timing_wheel_next_expiring_elt_time(%p) returns %lu",
1006 &bm->
wheel, next_expire);
1007 if ((
i64) next_expire < 0)
1009 BFD_DBG (
"wait for event without timeout");
1016 BFD_DBG (
"wait for event with timeout %.02f", timeout);
1019 BFD_DBG (
"negative timeout, already expired, skipping wait");
1048 BFD_DBG (
"Ignoring event for non-existent session index %u",
1049 (
u32) * event_data);
1061 BFD_DBG (
"Ignoring event for non-existent session index %u",
1062 (
u32) * event_data);
1069 BFD_DBG (
"advancing wheel, now is %lu", now);
1070 BFD_DBG (
"timing_wheel_advance (%p, %lu, %p, 0);", &bm->
wheel, now,
1077 const u32 bs_idx = *p;
1087 _vec_len (expired) = 0;
1091 _vec_len (event_data) = 0;
1105 .name =
"bfd-process",
1153 setbuf (stdout,
NULL);
1179 memset (result, 0,
sizeof (*result));
1182 const unsigned limit = 1000;
1183 unsigned counter = 0;
1187 if (counter > limit)
1189 clib_warning (
"Couldn't allocate unused session discriminator even " 1190 "after %u tries!", limit);
1251 BFD_ERR (
"BFD verification failed - unexpected version: '%d'",
1255 if (pkt->head.length < sizeof (bfd_pkt_t) ||
1257 pkt->head.length < sizeof (bfd_pkt_with_common_auth_t)))
1259 BFD_ERR (
"BFD verification failed - unexpected length: '%d' (auth " 1264 if (!pkt->head.detect_mult)
1266 BFD_ERR (
"BFD verification failed - unexpected detect-mult: '%d'",
1267 pkt->head.detect_mult);
1272 BFD_ERR (
"BFD verification failed - unexpected multipoint: '%d'",
1278 BFD_ERR (
"BFD verification failed - unexpected my-disc: '%d'",
1282 if (!pkt->your_disc)
1285 if (pkt_state != BFD_STATE_down && pkt_state != BFD_STATE_admin_down)
1287 BFD_ERR (
"BFD verification failed - unexpected state: '%s' " 1298 BFD_DBG (
"Switching authentication key from %U to %U for bs_idx=%u",
1314 if (BFD_AUTH_TYPE_meticulous_keyed_md5 == auth_type ||
1315 BFD_AUTH_TYPE_meticulous_keyed_sha1 == auth_type)
1324 u32 received_seq_num,
int is_meticulous)
1335 BFD_DBG (
"BFD peer unresponsive for %lu clocks, which is > 2 * " 1336 "detection_time=%u clocks, resetting remote_seq_number_known " 1344 const u32 max_u32 = 0xffffffff;
1363 if (received_seq_num > x &&
1364 received_seq_num < bs->auth.remote_seq_number + is_meticulous)
1367 (
"Recvd sequence number=%u out of ranges <0, %u>, <%u, %u>",
1368 received_seq_num, x,
1379 if (received_seq_num < min || received_seq_num > max)
1381 BFD_ERR (
"Recvd sequence number=%u out of range <%u, %u>",
1382 received_seq_num, min, max);
1396 auth_key->
auth_type == BFD_AUTH_TYPE_meticulous_keyed_sha1);
1398 u8 result[SHA_DIGEST_LENGTH];
1399 bfd_pkt_with_common_auth_t *with_common = (
void *) pkt;
1400 if (pkt_size <
sizeof (*with_common))
1402 BFD_ERR (
"Packet size too small to hold authentication common header");
1405 if (with_common->common_auth.type != auth_key->
auth_type)
1407 BFD_ERR (
"BFD auth type mismatch, packet auth=%d:%s doesn't match " 1408 "in-use auth=%d:%s",
1409 with_common->common_auth.type,
1414 bfd_pkt_with_sha1_auth_t *with_sha1 = (
void *) pkt;
1415 if (pkt_size <
sizeof (*with_sha1) ||
1416 with_sha1->sha1_auth.type_len.len <
sizeof (with_sha1->sha1_auth))
1419 (
"BFD size mismatch, payload size=%u, expected=%u, auth_len=%u, " 1420 "expected=%u", pkt_size,
sizeof (*with_sha1),
1421 with_sha1->sha1_auth.type_len.len, sizeof (with_sha1->sha1_auth));
1424 if (with_sha1->sha1_auth.key_id != bfd_key_id)
1427 (
"BFD key ID mismatch, packet key ID=%u doesn't match key ID=%u%s",
1428 with_sha1->sha1_auth.key_id, bfd_key_id,
1430 auth.
is_delayed ?
" (but a delayed auth change is scheduled)" :
"");
1434 if (!SHA1_Init (&ctx))
1440 if (!SHA1_Update (&ctx, with_sha1,
1441 sizeof (*with_sha1) -
sizeof (with_sha1->sha1_auth.hash)))
1443 BFD_ERR (
"SHA1_Update failed");
1446 if (!SHA1_Update (&ctx, auth_key->
key, sizeof (auth_key->
key)))
1448 BFD_ERR (
"SHA1_Update failed");
1451 if (!SHA1_Final (result, &ctx))
1453 BFD_ERR (
"SHA1_Final failed");
1456 if (0 == memcmp (result, with_sha1->sha1_auth.hash, SHA_DIGEST_LENGTH))
1460 BFD_ERR (
"SHA1 hash: %U doesn't match the expected value: %U",
1473 case BFD_AUTH_TYPE_reserved:
1474 clib_warning (
"Internal error, unexpected auth_type=%d:%s",
1478 case BFD_AUTH_TYPE_simple_password:
1480 (
"Internal error, not implemented, unexpected auth_type=%d:%s",
1483 case BFD_AUTH_TYPE_keyed_md5:
1485 case BFD_AUTH_TYPE_meticulous_keyed_md5:
1487 (
"Internal error, not implemented, unexpected auth_type=%d:%s",
1490 case BFD_AUTH_TYPE_keyed_sha1:
1492 case BFD_AUTH_TYPE_meticulous_keyed_sha1:
1496 const u32 seq_num = clib_net_to_host_u32 (((bfd_pkt_with_sha1_auth_t
1508 (
"Internal error, attempt to use SHA1 without SSL support");
1575 if (pkt_size >
sizeof (*pkt))
1577 BFD_ERR (
"BFD verification failed - unexpected packet size '%d' " 1578 "(auth not present)", pkt_size);
1604 if (!bs || (pkt->your_disc && pkt->your_disc != bs->
local_discr))
1618 ((bfd_pkt_with_common_auth_t *) (pkt))->common_auth.type;
1621 case BFD_AUTH_TYPE_reserved:
1623 case BFD_AUTH_TYPE_simple_password:
1625 case BFD_AUTH_TYPE_keyed_md5:
1627 case BFD_AUTH_TYPE_meticulous_keyed_md5:
1628 clib_warning (
"Internal error, unexpected auth_type=%d:%s",
1631 case BFD_AUTH_TYPE_keyed_sha1:
1633 case BFD_AUTH_TYPE_meticulous_keyed_sha1:
1636 bfd_pkt_with_sha1_auth_t *with_sha1 =
1637 (bfd_pkt_with_sha1_auth_t *) pkt;
1639 clib_net_to_host_u32 (with_sha1->sha1_auth.seq_num);
1641 BFD_DBG (
"Received sequence number %u",
1651 clib_net_to_host_u32 (pkt->req_min_rx));
1653 clib_net_to_host_u32
1654 (pkt->req_min_echo_rx));
1659 BFD_DBG (
"Poll sequence terminated, bs_idx=%u", bs->
bs_idx);
1669 else if (BFD_POLL_IN_PROGRESS_AND_QUEUED == bs->
poll_state)
1675 BFD_DBG (
"Next poll sequence can commence in " BFD_CLK_FMT,
1681 (
"Poll sequence terminated, but another is needed, bs_idx=%u",
1690 BFD_DBG (
"Session is admin-down, ignoring packet, bs_idx=%u",
1734 bfd_echo_pkt_t *pkt =
NULL;
1745 BFD_DBG (
"Scanning bfd echo packet, bs_idx=%d", bs->
bs_idx);
1749 if (checksum != pkt->checksum)
1751 BFD_DBG (
"Invalid echo packet, checksum mismatch");
1755 if (pkt->expire_time_clocks < now)
1757 BFD_DBG (
"Stale packet received, expire time %lu < now %lu",
1758 pkt->expire_time_clocks, now);
1772 s =
format (s,
"bs_idx=%u local-state=%s remote-state=%s\n" 1773 "%Ulocal-discriminator=%u remote-discriminator=%u\n" 1774 "%Ulocal-diag=%s echo-active=%s\n" 1775 "%Udesired-min-tx=%u required-min-rx=%u\n" 1776 "%Urequired-min-echo-rx=%u detect-mult=%u\n" 1777 "%Uremote-min-rx=%u remote-min-echo-rx=%u\n" 1778 "%Uremote-demand=%s poll-state=%s\n" 1779 "%Uauth: local-seq-num=%u remote-seq-num=%u\n" 1780 "%U is-delayed=%s\n" 1806 if (auth_type == BFD_AUTH_TYPE_keyed_sha1 ||
1807 auth_type == BFD_AUTH_TYPE_meticulous_keyed_sha1)
1816 u8 bfd_key_id,
u8 is_delayed)
1819 const uword *key_idx_p =
1823 clib_warning (
"Authentication key with config ID %u doesn't exist)",
1825 return VNET_API_ERROR_BFD_ENOENT;
1827 const uword key_idx = *key_idx_p;
1893 clib_warning (
"SSL missing, cannot deactivate BFD authentication");
1894 return VNET_API_ERROR_BFD_NOTSUPP;
1900 u32 desired_min_tx_usec,
1901 u32 required_min_rx_usec,
u8 detect_mult)
1910 case BFD_POLL_NOT_NEEDED:
1922 case BFD_POLL_NEEDED:
1923 case BFD_POLL_IN_PROGRESS_AND_QUEUED:
1929 case BFD_POLL_IN_PROGRESS:
1934 BFD_DBG (
"Poll in progress, queueing extra poll, bs_idx=%u",
1954 BFD_DBG (
"Ignore parameter change - no change, bs_idx=%u", bs->
bs_idx);
1961 const u8 * key_data)
1967 clib_warning (
"Invalid authentication key length for auth_type=%d:%s " 1968 "(key_len=%u, must be " 1969 "non-zero, expected max=%u)",
1972 return VNET_API_ERROR_INVALID_VALUE;
1976 clib_warning (
"Unsupported auth type=%d:%s", auth_type,
1978 return VNET_API_ERROR_BFD_NOTSUPP;
1985 const uword key_idx = *key_idx_p;
1989 clib_warning (
"Authentication key with conf ID %u in use by %u BFD " 1990 "session(s) - cannot modify",
1992 return VNET_API_ERROR_BFD_EINUSE;
2004 memset (auth_key->
key, 0, sizeof (auth_key->
key));
2008 clib_warning (
"SSL missing, cannot manipulate authentication keys");
2009 return VNET_API_ERROR_BFD_NOTSUPP;
2023 const uword key_idx = *key_idx_p;
2027 clib_warning (
"Authentication key with conf ID %u in use by %u BFD " 2028 "session(s) - cannot delete",
2030 return VNET_API_ERROR_BFD_EINUSE;
2033 memset (auth_key, 0,
sizeof (*auth_key));
2039 clib_warning (
"Authentication key with conf ID %u does not exist",
2041 return VNET_API_ERROR_BFD_ENOENT;
2045 clib_warning (
"SSL missing, cannot manipulate authentication keys");
2046 return VNET_API_ERROR_BFD_NOTSUPP;
VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION(bfd_hw_interface_up_down)
static u64 bfd_usec_to_clocks(const bfd_main_t *bm, u64 us)
static int bfd_transport_control_frame(vlib_main_t *vm, u32 bi, bfd_session_t *bs)
u8 bfd_pkt_get_auth_present(const bfd_pkt_t *pkt)
static void bfd_recalc_echo_tx_interval(bfd_main_t *bm, bfd_session_t *bs)
static void bfd_on_state_change(bfd_main_t *bm, bfd_session_t *bs, u64 now, int handling_wakeup)
bfd_session_t * bfd_get_session(bfd_main_t *bm, bfd_transport_e t)
bfd_notify_fn_t * listeners
A vector of callback notification functions.
#define hash_set(h, key, value)
bfd_auth_type_e auth_type
authentication type for this key
void bfd_consume_pkt(bfd_main_t *bm, const bfd_pkt_t *pkt, u32 bs_idx)
u8 curr_bfd_key_id
current key ID sent out in bfd packet
static uword random_default_seed(void)
Default random seed (unix/linux user-mode)
static void bfd_set_effective_required_min_rx(bfd_main_t *bm, bfd_session_t *bs, u64 required_min_rx_clocks)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
#define hash_unset(h, key)
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
void bfd_pkt_set_poll(bfd_pkt_t *pkt)
vnet_main_t * vnet_get_main(void)
void bfd_on_timeout(vlib_main_t *vm, vlib_node_runtime_t *rt, bfd_main_t *bm, bfd_session_t *bs, u64 now)
u32 * auth_key_by_conf_key_id
hashmap - index in pool auth_keys by conf_key_id
static void bfd_session_switch_auth_to_next(bfd_session_t *bs)
void timing_wheel_init(timing_wheel_t *w, u64 current_cpu_time, f64 cpu_clocks_per_second)
u8 bfd_pkt_get_diag_code(const bfd_pkt_t *pkt)
static uword bfd_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
bfd_session_t * bfd_find_session_by_disc(bfd_main_t *bm, u32 disc)
u8 * format_bfd_auth_key(u8 *s, va_list *args)
u64 timing_wheel_next_expiring_elt_time(timing_wheel_t *w)
u64 echo_last_rx_clocks
timestamp of last echo packet received
int bfd_verify_pkt_common(const bfd_pkt_t *pkt)
verify bfd packet - common checks
static void bfd_set_state(bfd_main_t *bm, bfd_session_t *bs, bfd_state_e new_state, int handling_wakeup)
u32 echo_secret
secret used for calculating/checking checksum of echo packets
bfd_diag_code_e local_diag
local diagnostics
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static u64 clib_cpu_time_now(void)
static u64 clib_xxhash(u64 key)
struct _vlib_node_registration vlib_node_registration_t
static void bfd_on_config_change(vlib_main_t *vm, vlib_node_runtime_t *rt, bfd_main_t *bm, bfd_session_t *bs, u64 now)
void bfd_put_session(bfd_main_t *bm, bfd_session_t *bs)
u64 last_tx_clocks
timestamp of last packet transmitted
u8 remote_seq_number_known
set to 1 if remote sequence number is known
static void bfd_set_remote_required_min_rx(bfd_main_t *bm, bfd_session_t *bs, u64 now, u32 remote_required_min_rx_usec)
unsigned bfd_auth_type_supported(bfd_auth_type_e auth_type)
#define VNET_HW_INTERFACE_FLAG_LINK_UP
static void bfd_add_transport_layer(vlib_main_t *vm, u32 bi, bfd_session_t *bs)
void bfd_init_final_control_frame(vlib_main_t *vm, vlib_buffer_t *b, bfd_main_t *bm, bfd_session_t *bs, int is_local)
u32 bfd_process_node_index
background process node index
u8 bfd_pkt_get_version(const bfd_pkt_t *pkt)
u64 remote_min_echo_rx_clocks
remote min echo rx interval (clocks)
void timing_wheel_insert(timing_wheel_t *w, u64 insert_cpu_time, u32 user_data)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
u64 effective_required_min_rx_clocks
effective required min rx interval (clocks)
u32 remote_seq_number
remote sequence number
int bfd_add_udp4_transport(vlib_main_t *vm, u32 bi, const bfd_session_t *bs, int is_echo)
timing_wheel_t wheel
timing wheel for scheduling timeouts
vnet_api_error_t bfd_auth_deactivate(bfd_session_t *bs, u8 is_delayed)
static int bfd_verify_pkt_auth_seq_num(bfd_session_t *bs, u32 received_seq_num, int is_meticulous)
u64 effective_desired_min_tx_clocks
effective desired min tx interval (clocks)
u32 bfd_clocks_to_usec(const bfd_main_t *bm, u64 clocks)
u8 key[20]
key data directly usable for bfd purposes - already padded with zeroes (so we don't need the actual l...
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
const char * bfd_poll_state_string(bfd_poll_state_e state)
u32 random_seed
for generating random numbers
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
int bfd_transport_udp4(vlib_main_t *vm, u32 bi, const struct bfd_session_s *bs)
transport packet over udpv4
u64 remote_min_rx_usec
remote min rx interval (microseconds)
u64 tx_timeout_clocks
next time at which to transmit a packet
void bfd_event(bfd_main_t *bm, bfd_session_t *bs)
u64 config_required_min_rx_clocks
configured required min rx interval (clocks)
bfd_auth_key_t * next_key
set to next key to use if delayed switch is enabled - in that case the key is switched when first inc...
static vlib_node_registration_t bfd_process_node
(constructor) VLIB_REGISTER_NODE (bfd_process_node)
static void bfd_set_poll_state(bfd_session_t *bs, bfd_poll_state_e state)
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
static void bfd_calc_next_echo_tx(bfd_main_t *bm, bfd_session_t *bs, u64 now)
bfd_session_t * bfd_find_session_by_idx(bfd_main_t *bm, uword bs_idx)
static u64 bfd_calc_echo_checksum(u32 discriminator, u64 expire_time, u32 secret)
u8 remote_demand
1 if remote system sets demand mode, 0 otherwise
bfd_session_t * sessions
pool of bfd sessions context data
bfd_auth_key_t * auth_keys
pool of authentication keys
bfd_transport_e transport
transport type for this session
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static clib_error_t * bfd_sw_interface_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
u16 current_length
Nbytes between current data and the end of this buffer.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
u32 remote_discr
remote discriminator
u64 default_desired_min_tx_clocks
default desired min tx in clocks
u64 echo_last_tx_clocks
timestamp of last echo packet transmitted
bfd_poll_state_e poll_state
state info regarding poll sequence
u8 bfd_pkt_get_control_plane_independent(const bfd_pkt_t *pkt)
f64 cpu_cps
cpu clocks per second
void bfd_pkt_set_auth_present(bfd_pkt_t *pkt)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define pool_put(P, E)
Free an object E in pool P.
u64 echo_tx_timeout_clocks
next time at which to transmit echo packet
static void bfd_set_diag(bfd_session_t *bs, bfd_diag_code_e code)
u8 local_detect_mult
configured detect multiplier
static int bfd_is_echo_possible(bfd_session_t *bs)
u64 last_rx_clocks
timestamp of last packet received
int bfd_transport_udp6(vlib_main_t *vm, u32 bi, const struct bfd_session_s *bs)
transport packet over udpv6
int bfd_add_udp6_transport(vlib_main_t *vm, u32 bi, const bfd_session_t *bs, int is_echo)
u8 bfd_pkt_get_final(const bfd_pkt_t *pkt)
void bfd_pkt_set_final(bfd_pkt_t *pkt)
static void bfd_notify_listeners(bfd_main_t *bm, bfd_listen_event_e event, const bfd_session_t *bs)
bfd_diag_code_e remote_diag
remote diagnostics
static void bfd_send_periodic(vlib_main_t *vm, vlib_node_runtime_t *rt, bfd_main_t *bm, bfd_session_t *bs, u64 now)
#define BFD_DEFAULT_DESIRED_MIN_TX_USEC
default, slow transmission interval for BFD packets, per spec at least 1s
void bfd_session_start(bfd_main_t *bm, bfd_session_t *bs)
const char * bfd_auth_type_str(bfd_auth_type_e auth_type)
u64 transmit_interval_clocks
transmit interval
u8 bfd_pkt_get_multipoint(const bfd_pkt_t *pkt)
static void bfd_set_effective_desired_min_tx(bfd_main_t *bm, bfd_session_t *bs, u64 now, u64 desired_min_tx_clocks)
static void bfd_recalc_tx_interval(bfd_main_t *bm, bfd_session_t *bs)
BFD protocol declarations.
u32 config_desired_min_tx_usec
configured desired min tx interval (microseconds)
u32 bfd_max_key_len_for_auth_type(bfd_auth_type_e auth_type)
get the maximum length of key data for given auth type
static void bfd_calc_next_tx(bfd_main_t *bm, bfd_session_t *bs, u64 now)
#define clib_warning(format, args...)
u8 * format_bfd_session(u8 *s, va_list *args)
#define clib_memcpy(a, b, c)
u32 * timing_wheel_advance(timing_wheel_t *w, u64 advance_cpu_time, u32 *expired_user_data, u64 *next_expiring_element_cpu_time)
const char * bfd_diag_code_string(bfd_diag_code_e diag)
static void bfd_add_auth_section(vlib_buffer_t *b, bfd_session_t *bs)
static int bfd_verify_pkt_auth_key_sha1(const bfd_pkt_t *pkt, u32 pkt_size, bfd_session_t *bs, u8 bfd_key_id, bfd_auth_key_t *auth_key)
u8 bfd_pkt_get_demand(const bfd_pkt_t *pkt)
vnet_api_error_t bfd_auth_activate(bfd_session_t *bs, u32 conf_key_id, u8 bfd_key_id, u8 is_delayed)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
static void bfd_set_remote_required_min_echo_rx(bfd_main_t *bm, bfd_session_t *bs, u64 now, u32 remote_required_min_echo_rx_usec)
u64 poll_state_start_or_timeout_clocks
helper for delayed poll sequence - marks either start of running poll sequence or timeout...
u64 detection_time_clocks
detection time
u8 * bfd_input_format_trace(u8 *s, va_list *args)
void bfd_pkt_set_version(bfd_pkt_t *pkt, int version)
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
static void bfd_recalc_detection_time(bfd_main_t *bm, bfd_session_t *bs)
u64 config_desired_min_tx_clocks
configured desired min tx interval (clocks)
int bfd_udp_is_echo_available(bfd_transport_e transport)
check if the bfd udp layer is echo-capable at this time
u8 echo
1 is echo function is active, 0 otherwise
u64 wheel_time_clocks
set to value of timer in timing wheel, 0 if never set
u64 remote_desired_min_tx_clocks
remote desired min tx interval (clocks)
vhost_vring_state_t state
u8 bfd_pkt_get_state(const bfd_pkt_t *pkt)
u32 local_discr
local discriminator
static f64 random_f64(u32 *seed)
Generate f64 random number in the interval [0,1].
bfd_hop_type_e hop_type
BFD hop type.
u32 conf_key_id
global configuration key ID
vnet_api_error_t bfd_auth_del_key(u32 conf_key_id)
delete existing authentication key
vlib_main_t * vlib_main
convenience variables
bfd_state_e local_state
session state
static int bfd_echo_add_transport_layer(vlib_main_t *vm, u32 bi, bfd_session_t *bs)
u32 * session_by_disc
hashmap - bfd session by discriminator
int bfd_consume_echo_pkt(bfd_main_t *bm, vlib_buffer_t *b)
vnet_api_error_t bfd_session_set_params(bfd_main_t *bm, bfd_session_t *bs, u32 desired_min_tx_usec, u32 required_min_rx_usec, u8 detect_mult)
void(* bfd_notify_fn_t)(bfd_listen_event_e, const bfd_session_t *)
session nitification call back function type
u64 echo_transmit_interval_clocks
transmit interval for echo packets
u32 local_seq_number
sequence number incremented occasionally or always (if meticulous)
void bfd_register_listener(bfd_notify_fn_t fn)
Register a callback function to receive session notifications.
u32 config_required_min_rx_usec
configured required min rx interval (microseconds)
static void bfd_set_timer(bfd_main_t *bm, bfd_session_t *bs, u64 now, int handling_wakeup)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void bfd_set_defaults(bfd_main_t *bm, bfd_session_t *bs)
u32 use_count
keeps track of how many sessions reference this key
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
u8 next_bfd_key_id
key ID to use when switched to next_key
static int bfd_verify_pkt_auth_key(const bfd_pkt_t *pkt, u32 pkt_size, bfd_session_t *bs, u8 bfd_key_id, bfd_auth_key_t *auth_key)
u8 bfd_pkt_get_poll(const bfd_pkt_t *pkt)
Linear Congruential Random Number Generator.
u32 bs_idx
index in bfd_main.sessions pool
static int bfd_transport_echo(vlib_main_t *vm, u32 bi, bfd_session_t *bs)
static u32 random_u32(u32 *seed)
32-bit random number generator
#define VLIB_REGISTER_NODE(x,...)
u64 remote_min_echo_rx_usec
remote min echo rx interval (microseconds)
vnet_api_error_t bfd_auth_set_key(u32 conf_key_id, u8 auth_type, u8 key_len, const u8 *key_data)
create or modify bfd authentication key
#define STRUCT_SIZE_OF(t, f)
#define vec_foreach(var, vec)
Vector iterator.
bfd_state_e remote_state
remote session state
const char * bfd_state_string(bfd_state_e state)
struct bfd_session_s::@47 auth
authentication information
u64 min_required_min_rx_while_echo_clocks
minimum required min rx while echo function is active - clocks
int bfd_verify_pkt_auth(const bfd_pkt_t *pkt, u16 pkt_size, bfd_session_t *bs)
verify bfd packet - authentication
static void vlib_buffer_free_one(vlib_main_t *vm, u32 buffer_index)
Free one buffer Shorthand to free a single buffer chain.
static int bfd_auth_type_is_meticulous(bfd_auth_type_e auth_type)
bfd_auth_key_t * curr_key
current key in use
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static void bfd_send_echo(vlib_main_t *vm, vlib_node_runtime_t *rt, bfd_main_t *bm, bfd_session_t *bs, u64 now)
void bfd_pkt_set_state(bfd_pkt_t *pkt, int value)
static clib_error_t * bfd_hw_interface_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
u8 remote_detect_mult
remote detect multiplier
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
void bfd_pkt_set_diag_code(bfd_pkt_t *pkt, int value)
#define BFD_REQUIRED_MIN_RX_USEC_WHILE_ECHO
minimum required min rx set locally when echo function is used, per spec should be set to at least 1s...
u64 remote_min_rx_clocks
remote min rx interval (clocks)
u8 is_delayed
set to 1 if delayed action is pending, which might be activation of authentication, change of key or deactivation
static clib_error_t * bfd_main_init(vlib_main_t *vm)
u64 wheel_inaccuracy
timing wheel inaccuracy, in clocks
static void bfd_init_control_frame(bfd_main_t *bm, bfd_session_t *bs, vlib_buffer_t *b)
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(bfd_sw_interface_up_down)
void bfd_session_set_flags(bfd_session_t *bs, u8 admin_up_down)
static void bfd_check_rx_timeout(bfd_main_t *bm, bfd_session_t *bs, u64 now, int handling_wakeup)