diff options
author | Klement Sekera <klement.sekera@gmail.com> | 2022-02-14 20:19:28 +0000 |
---|---|---|
committer | Klement Sekera <klement.sekera@gmail.com> | 2022-02-14 20:19:28 +0000 |
commit | b59f63b0e71c879331280b721ec72ff0b4699540 (patch) | |
tree | 9f33dd3e0377dc7a657c2913c85ca250e8156fa2 /src | |
parent | be74504d2232ded435dc48d533d2c130595fea8c (diff) |
bfd: refactor code to fix misc warnings
This change fixes multiple unused parameter warnings, narrowing
conversion warnings and identical switch statement warnings.
Type: refactor
Signed-off-by: Klement Sekera <klement.sekera@gmail.com>
Change-Id: I4140e939c409ce06cc5aaaf5e1b042681f7ca448
Diffstat (limited to 'src')
-rw-r--r-- | src/vnet/bfd/bfd_main.c | 148 | ||||
-rw-r--r-- | src/vnet/bfd/bfd_main.h | 5 | ||||
-rw-r--r-- | src/vnet/bfd/bfd_udp.c | 88 |
3 files changed, 110 insertions, 131 deletions
diff --git a/src/vnet/bfd/bfd_main.c b/src/vnet/bfd/bfd_main.c index 530b2978068..23e3f0f02e9 100644 --- a/src/vnet/bfd/bfd_main.c +++ b/src/vnet/bfd/bfd_main.c @@ -172,7 +172,7 @@ bfd_set_poll_state (bfd_session_t * bs, bfd_poll_state_e state) } static void -bfd_recalc_tx_interval (bfd_main_t * bm, bfd_session_t * bs) +bfd_recalc_tx_interval (bfd_session_t *bs) { bs->transmit_interval_nsec = clib_max (bs->effective_desired_min_tx_nsec, bs->remote_min_rx_nsec); @@ -181,7 +181,7 @@ bfd_recalc_tx_interval (bfd_main_t * bm, bfd_session_t * bs) } static void -bfd_recalc_echo_tx_interval (bfd_main_t * bm, bfd_session_t * bs) +bfd_recalc_echo_tx_interval (bfd_session_t *bs) { bs->echo_transmit_interval_nsec = clib_max (bs->effective_desired_min_tx_nsec, bs->remote_min_echo_rx_nsec); @@ -240,7 +240,7 @@ bfd_calc_next_tx (bfd_main_t * bm, bfd_session_t * bs, u64 now) } static void -bfd_calc_next_echo_tx (bfd_main_t * bm, bfd_session_t * bs, u64 now) +bfd_calc_next_echo_tx (bfd_session_t *bs, u64 now) { bs->echo_tx_timeout_nsec = bs->echo_last_tx_nsec + bs->echo_transmit_interval_nsec; @@ -261,7 +261,7 @@ bfd_calc_next_echo_tx (bfd_main_t * bm, bfd_session_t * bs, u64 now) } static void -bfd_recalc_detection_time (bfd_main_t * bm, bfd_session_t * bs) +bfd_recalc_detection_time (bfd_session_t *bs) { if (bs->local_state == BFD_STATE_init || bs->local_state == BFD_STATE_up) { @@ -385,26 +385,24 @@ bfd_set_effective_desired_min_tx (bfd_main_t * bm, bs->effective_desired_min_tx_nsec = desired_min_tx_nsec; BFD_DBG ("Set effective desired min tx to " BFD_CLK_FMT, BFD_CLK_PRN (bs->effective_desired_min_tx_nsec)); - bfd_recalc_detection_time (bm, bs); - bfd_recalc_tx_interval (bm, bs); - bfd_recalc_echo_tx_interval (bm, bs); + bfd_recalc_detection_time (bs); + bfd_recalc_tx_interval (bs); + bfd_recalc_echo_tx_interval (bs); bfd_calc_next_tx (bm, bs, now); } static void -bfd_set_effective_required_min_rx (bfd_main_t * bm, - bfd_session_t * bs, - u64 required_min_rx_nsec) +bfd_set_effective_required_min_rx (bfd_session_t *bs, u64 required_min_rx_nsec) { bs->effective_required_min_rx_nsec = required_min_rx_nsec; BFD_DBG ("Set effective required min rx to " BFD_CLK_FMT, BFD_CLK_PRN (bs->effective_required_min_rx_nsec)); - bfd_recalc_detection_time (bm, bs); + bfd_recalc_detection_time (bs); } static void -bfd_set_remote_required_min_rx (bfd_main_t * bm, bfd_session_t * bs, - u64 now, u32 remote_required_min_rx_usec) +bfd_set_remote_required_min_rx (bfd_session_t *bs, + u32 remote_required_min_rx_usec) { if (bs->remote_min_rx_usec != remote_required_min_rx_usec) { @@ -412,14 +410,13 @@ bfd_set_remote_required_min_rx (bfd_main_t * bm, bfd_session_t * bs, bs->remote_min_rx_nsec = bfd_usec_to_nsec (remote_required_min_rx_usec); BFD_DBG ("Set remote min rx to " BFD_CLK_FMT, BFD_CLK_PRN (bs->remote_min_rx_nsec)); - bfd_recalc_detection_time (bm, bs); - bfd_recalc_tx_interval (bm, bs); + bfd_recalc_detection_time (bs); + bfd_recalc_tx_interval (bs); } } static void -bfd_set_remote_required_min_echo_rx (bfd_main_t * bm, bfd_session_t * bs, - u64 now, +bfd_set_remote_required_min_echo_rx (bfd_session_t *bs, u32 remote_required_min_echo_rx_usec) { if (bs->remote_min_echo_rx_usec != remote_required_min_echo_rx_usec) @@ -429,7 +426,7 @@ bfd_set_remote_required_min_echo_rx (bfd_main_t * bm, bfd_session_t * bs, bfd_usec_to_nsec (bs->remote_min_echo_rx_usec); BFD_DBG ("Set remote min echo rx to " BFD_CLK_FMT, BFD_CLK_PRN (bs->remote_min_echo_rx_nsec)); - bfd_recalc_echo_tx_interval (bm, bs); + bfd_recalc_echo_tx_interval (bs); } } @@ -450,8 +447,8 @@ bfd_session_start (bfd_main_t * bm, bfd_session_t * bs) BFD_DBG ("\nStarting session: %U", format_bfd_session, bs); vlib_log_info (bm->log_class, "start BFD session: %U", format_bfd_session_brief, bs); - bfd_set_effective_required_min_rx (bm, bs, bs->config_required_min_rx_nsec); - bfd_recalc_tx_interval (bm, bs); + bfd_set_effective_required_min_rx (bs, bs->config_required_min_rx_nsec); + bfd_recalc_tx_interval (bs); vlib_process_signal_event (bm->vlib_main, bm->bfd_process_node_index, BFD_EVENT_NEW_SESSION, bs->bs_idx); bfd_notify_listeners (bm, BFD_LISTEN_EVENT_CREATE, bs); @@ -651,8 +648,7 @@ bfd_on_state_change (bfd_main_t * bm, bfd_session_t * bs, u64 now, clib_max (bs->config_desired_min_tx_nsec, bm->default_desired_min_tx_nsec)); - bfd_set_effective_required_min_rx (bm, bs, - bs->config_required_min_rx_nsec); + bfd_set_effective_required_min_rx (bs, bs->config_required_min_rx_nsec); bfd_set_timer (bm, bs, now, handling_wakeup); break; case BFD_STATE_down: @@ -661,8 +657,7 @@ bfd_on_state_change (bfd_main_t * bm, bfd_session_t * bs, u64 now, clib_max (bs->config_desired_min_tx_nsec, bm->default_desired_min_tx_nsec)); - bfd_set_effective_required_min_rx (bm, bs, - bs->config_required_min_rx_nsec); + bfd_set_effective_required_min_rx (bs, bs->config_required_min_rx_nsec); bfd_set_timer (bm, bs, now, handling_wakeup); break; case BFD_STATE_init: @@ -676,7 +671,7 @@ bfd_on_state_change (bfd_main_t * bm, bfd_session_t * bs, u64 now, bs->config_desired_min_tx_nsec); if (BFD_POLL_NOT_NEEDED == bs->poll_state) { - bfd_set_effective_required_min_rx (bm, bs, + bfd_set_effective_required_min_rx (bs, bs->config_required_min_rx_nsec); } bfd_set_timer (bm, bs, now, handling_wakeup); @@ -694,8 +689,7 @@ bfd_on_state_change (bfd_main_t * bm, bfd_session_t * bs, u64 now, } 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) +bfd_on_config_change (bfd_main_t *bm, bfd_session_t *bs, u64 now) { /* * if remote demand mode is set and we need to do a poll, set the next @@ -706,7 +700,7 @@ bfd_on_config_change (vlib_main_t * vm, vlib_node_runtime_t * rt, { bs->tx_timeout_nsec = now; } - bfd_recalc_detection_time (bm, bs); + bfd_recalc_detection_time (bs); bfd_set_timer (bm, bs, now, 0); } @@ -861,8 +855,7 @@ bfd_is_echo_possible (bfd_session_t * bs) } static void -bfd_init_control_frame (bfd_main_t * bm, bfd_session_t * bs, - vlib_buffer_t * b) +bfd_init_control_frame (bfd_session_t *bs, vlib_buffer_t *b) { bfd_pkt_t *pkt = vlib_buffer_get_current (b); u32 bfd_length = 0; @@ -892,8 +885,7 @@ bfd_init_control_frame (bfd_main_t * bm, bfd_session_t * bs, } static void -bfd_send_echo (vlib_main_t * vm, vlib_node_runtime_t * rt, - bfd_main_t * bm, bfd_session_t * bs, u64 now) +bfd_send_echo (vlib_main_t *vm, bfd_main_t *bm, bfd_session_t *bs, u64 now) { if (!bfd_is_echo_possible (bs)) { @@ -936,7 +928,7 @@ bfd_send_echo (vlib_main_t * vm, vlib_node_runtime_t * rt, return; } bs->echo_last_tx_nsec = now; - bfd_calc_next_echo_tx (bm, bs, now); + bfd_calc_next_echo_tx (bs, now); } else { @@ -947,8 +939,7 @@ bfd_send_echo (vlib_main_t * vm, vlib_node_runtime_t * rt, } static void -bfd_send_periodic (vlib_main_t * vm, vlib_node_runtime_t * rt, - bfd_main_t * bm, bfd_session_t * bs, u64 now) +bfd_send_periodic (vlib_main_t *vm, bfd_main_t *bm, bfd_session_t *bs, u64 now) { if (!bs->remote_min_rx_usec && BFD_POLL_NOT_NEEDED == bs->poll_state) { @@ -980,7 +971,7 @@ bfd_send_periodic (vlib_main_t * vm, vlib_node_runtime_t * rt, } vlib_buffer_t *b = vlib_get_buffer (vm, bi); ASSERT (b->current_data == 0); - bfd_init_control_frame (bm, bs, b); + bfd_init_control_frame (bs, b); switch (bs->poll_state) { case BFD_POLL_NEEDED: @@ -1022,12 +1013,11 @@ bfd_send_periodic (vlib_main_t * vm, vlib_node_runtime_t * rt, } 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) +bfd_init_final_control_frame (vlib_main_t *vm, vlib_buffer_t *b, + bfd_session_t *bs) { BFD_DBG ("Send final control frame for bs_idx=%lu", bs->bs_idx); - bfd_init_control_frame (bm, bs, b); + bfd_init_control_frame (bs, b); bfd_pkt_set_final (vlib_buffer_get_current (b)); bfd_add_auth_section (vm, b, bs); u32 bi = vlib_get_buffer_index (vm, b); @@ -1069,7 +1059,7 @@ bfd_check_rx_timeout (vlib_main_t * vm, bfd_main_t * bm, bfd_session_t * bs, * since it is no longer required to maintain previous session state) * and then can transmit at its own rate. */ - bfd_set_remote_required_min_rx (bm, bs, now, 1); + bfd_set_remote_required_min_rx (bs, 1); } else if (bs->echo && bs->echo_last_rx_nsec + @@ -1082,21 +1072,19 @@ bfd_check_rx_timeout (vlib_main_t * vm, bfd_main_t * bm, bfd_session_t * bs, } void -bfd_on_timeout (vlib_main_t * vm, vlib_node_runtime_t * rt, bfd_main_t * bm, - bfd_session_t * bs, u64 now) +bfd_on_timeout (vlib_main_t *vm, bfd_main_t *bm, bfd_session_t *bs, u64 now) { BFD_DBG ("Timeout for bs_idx=%lu", bs->bs_idx); switch (bs->local_state) { case BFD_STATE_admin_down: - bfd_send_periodic (vm, rt, bm, bs, now); - break; + /* fallthrough */ case BFD_STATE_down: - bfd_send_periodic (vm, rt, bm, bs, now); + bfd_send_periodic (vm, bm, bs, now); break; case BFD_STATE_init: bfd_check_rx_timeout (vm, bm, bs, now, 1); - bfd_send_periodic (vm, rt, bm, bs, now); + bfd_send_periodic (vm, bm, bs, now); break; case BFD_STATE_up: bfd_check_rx_timeout (vm, bm, bs, now, 1); @@ -1108,16 +1096,15 @@ bfd_on_timeout (vlib_main_t * vm, vlib_node_runtime_t * rt, bfd_main_t * bm, bs->echo = 1; bs->echo_last_rx_nsec = now; bs->echo_tx_timeout_nsec = now; - bfd_set_effective_required_min_rx (bm, bs, - clib_max - (bm->min_required_min_rx_while_echo_nsec, - bs->config_required_min_rx_nsec)); + bfd_set_effective_required_min_rx ( + bs, clib_max (bm->min_required_min_rx_while_echo_nsec, + bs->config_required_min_rx_nsec)); bfd_set_poll_state (bs, BFD_POLL_NEEDED); } - bfd_send_periodic (vm, rt, bm, bs, now); + bfd_send_periodic (vm, bm, bs, now); if (bs->echo) { - bfd_send_echo (vm, rt, bm, bs, now); + bfd_send_echo (vm, bm, bs, now); } break; } @@ -1127,7 +1114,8 @@ bfd_on_timeout (vlib_main_t * vm, vlib_node_runtime_t * rt, bfd_main_t * bm, * bfd process node function */ static uword -bfd_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) +bfd_process (vlib_main_t *vm, CLIB_UNUSED (vlib_node_runtime_t *rt), + CLIB_UNUSED (vlib_frame_t *f)) { bfd_main_t *bm = &bfd_main; u32 *expired = 0; @@ -1168,7 +1156,9 @@ bfd_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) now + first_expires_in_ticks * bm->nsec_per_tw_tick; bm->bfd_process_next_wakeup_nsec = next_expire_nsec; bfd_unlock (bm); - timeout = (next_expire_nsec - now) * SEC_PER_NSEC; + ASSERT (next_expire_nsec - now <= UINT32_MAX); + // cast to u32 to avoid warning + timeout = (u32) (next_expire_nsec - now) * SEC_PER_NSEC; } BFD_DBG ("vlib_process_wait_for_event_or_clock(vm, %.09f)", timeout); @@ -1205,7 +1195,7 @@ bfd_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) { bfd_session_t *bs = pool_elt_at_index (bm->sessions, *session_index); - bfd_send_periodic (vm, rt, bm, bs, now); + bfd_send_periodic (vm, bm, bs, now); bfd_set_timer (bm, bs, now, 1); } else @@ -1224,7 +1214,7 @@ bfd_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) { bfd_session_t *bs = pool_elt_at_index (bm->sessions, *session_index); - bfd_on_config_change (vm, rt, bm, bs, now); + bfd_on_config_change (bm, bs, now); } else { @@ -1251,7 +1241,7 @@ bfd_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) { bfd_session_t *bs = pool_elt_at_index (bm->sessions, bs_idx); bs->tw_id = 0; /* timer is gone because it expired */ - bfd_on_timeout (vm, rt, bm, bs, now); + bfd_on_timeout (vm, bm, bs, now); bfd_set_timer (bm, bs, now, 1); } } @@ -1272,7 +1262,6 @@ bfd_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) /* * bfd process node declaration */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (bfd_process_node, static) = { .function = bfd_process, .type = VLIB_NODE_TYPE_PROCESS, @@ -1280,10 +1269,10 @@ VLIB_REGISTER_NODE (bfd_process_node, static) = { .n_next_nodes = 0, .next_nodes = {}, }; -/* *INDENT-ON* */ static clib_error_t * -bfd_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) +bfd_sw_interface_up_down (CLIB_UNUSED (vnet_main_t *vnm), + CLIB_UNUSED (u32 sw_if_index), u32 flags) { // bfd_main_t *bm = &bfd_main; // vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index); @@ -1297,7 +1286,8 @@ bfd_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (bfd_sw_interface_up_down); static clib_error_t * -bfd_hw_interface_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) +bfd_hw_interface_up_down (CLIB_UNUSED (vnet_main_t *vnm), + CLIB_UNUSED (u32 hw_if_index), u32 flags) { // bfd_main_t *bm = &bfd_main; if (flags & VNET_HW_INTERFACE_FLAG_LINK_UP) @@ -1581,8 +1571,8 @@ bfd_verify_pkt_auth_seq_num (vlib_main_t * vm, bfd_session_t * bs, static int bfd_verify_pkt_auth_key_sha1 (vlib_main_t *vm, const bfd_pkt_t *pkt, - u32 pkt_size, bfd_session_t *bs, u8 bfd_key_id, - bfd_auth_key_t *auth_key) + u32 pkt_size, CLIB_UNUSED (bfd_session_t *bs), + u8 bfd_key_id, bfd_auth_key_t *auth_key) { ASSERT (auth_key->auth_type == BFD_AUTH_TYPE_keyed_sha1 || auth_key->auth_type == BFD_AUTH_TYPE_meticulous_keyed_sha1); @@ -1667,18 +1657,14 @@ bfd_verify_pkt_auth_key (vlib_main_t * vm, const bfd_pkt_t * pkt, bfd_auth_type_str (auth_key->auth_type)); return 0; case BFD_AUTH_TYPE_simple_password: - vlib_log_err (bm->log_class, - "internal error, not implemented, unexpected auth_type=%d:%s", - auth_key->auth_type, - bfd_auth_type_str (auth_key->auth_type)); - return 0; + /* fallthrough */ case BFD_AUTH_TYPE_keyed_md5: /* fallthrough */ case BFD_AUTH_TYPE_meticulous_keyed_md5: - vlib_log_err - (bm->log_class, - "internal error, not implemented, unexpected auth_type=%d:%s", - auth_key->auth_type, bfd_auth_type_str (auth_key->auth_type)); + vlib_log_err ( + bm->log_class, + "internal error, not implemented, unexpected auth_type=%d:%s", + auth_key->auth_type, bfd_auth_type_str (auth_key->auth_type)); return 0; case BFD_AUTH_TYPE_keyed_sha1: /* fallthrough */ @@ -1839,11 +1825,9 @@ bfd_consume_pkt (vlib_main_t * vm, bfd_main_t * bm, const bfd_pkt_t * pkt, bs->remote_desired_min_tx_nsec = bfd_usec_to_nsec (clib_net_to_host_u32 (pkt->des_min_tx)); bs->remote_detect_mult = pkt->head.detect_mult; - bfd_set_remote_required_min_rx (bm, bs, now, - clib_net_to_host_u32 (pkt->req_min_rx)); - bfd_set_remote_required_min_echo_rx (bm, bs, now, - clib_net_to_host_u32 - (pkt->req_min_echo_rx)); + bfd_set_remote_required_min_rx (bs, clib_net_to_host_u32 (pkt->req_min_rx)); + bfd_set_remote_required_min_echo_rx ( + bs, clib_net_to_host_u32 (pkt->req_min_echo_rx)); if (bfd_pkt_get_final (pkt)) { if (BFD_POLL_IN_PROGRESS == bs->poll_state) @@ -1854,10 +1838,10 @@ bfd_consume_pkt (vlib_main_t * vm, bfd_main_t * bm, const bfd_pkt_t * pkt, { bfd_set_effective_desired_min_tx ( bm, bs, now, bs->config_desired_min_tx_nsec); - bfd_set_effective_required_min_rx (bm, bs, - clib_max (bs->echo * - bm->min_required_min_rx_while_echo_nsec, - bs->config_required_min_rx_nsec)); + bfd_set_effective_required_min_rx ( + bs, + clib_max (bs->echo * bm->min_required_min_rx_while_echo_nsec, + bs->config_required_min_rx_nsec)); } } else if (BFD_POLL_IN_PROGRESS_AND_QUEUED == bs->poll_state) diff --git a/src/vnet/bfd/bfd_main.h b/src/vnet/bfd/bfd_main.h index 0bdcfb87622..5e9f025c657 100644 --- a/src/vnet/bfd/bfd_main.h +++ b/src/vnet/bfd/bfd_main.h @@ -420,9 +420,8 @@ int bfd_verify_pkt_common (const bfd_pkt_t * pkt); int bfd_verify_pkt_auth (vlib_main_t * vm, const bfd_pkt_t * pkt, u16 pkt_size, bfd_session_t * bs); void bfd_event (bfd_main_t * bm, 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); +void bfd_init_final_control_frame (vlib_main_t *vm, vlib_buffer_t *b, + bfd_session_t *bs); u8 *format_bfd_session (u8 * s, va_list * args); u8 *format_bfd_session_brief (u8 * s, va_list * args); u8 *format_bfd_auth_key (u8 * s, va_list * args); diff --git a/src/vnet/bfd/bfd_udp.c b/src/vnet/bfd/bfd_udp.c index a58d9e2e1ca..d8fd4a10529 100644 --- a/src/vnet/bfd/bfd_udp.c +++ b/src/vnet/bfd/bfd_udp.c @@ -685,9 +685,8 @@ bfd_udp_find_session_by_api_input (u32 sw_if_index, static vnet_api_error_t bfd_api_verify_common (u32 sw_if_index, u32 desired_min_tx_usec, - u32 required_min_rx_usec, u8 detect_mult, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr) + u8 detect_mult, const ip46_address_t *local_addr, + const ip46_address_t *peer_addr) { bfd_udp_main_t *bum = &bfd_udp_main; vnet_api_error_t rv = @@ -781,10 +780,8 @@ bfd_udp_add_session (u32 sw_if_index, const ip46_address_t * local_addr, bfd_main_t *bm = &bfd_main; bfd_lock (bm); - vnet_api_error_t rv = - bfd_api_verify_common (sw_if_index, desired_min_tx_usec, - required_min_rx_usec, detect_mult, - local_addr, peer_addr); + vnet_api_error_t rv = bfd_api_verify_common ( + sw_if_index, desired_min_tx_usec, detect_mult, local_addr, peer_addr); if (!rv) rv = bfd_udp_add_and_start_session ( @@ -806,8 +803,7 @@ bfd_udp_upd_session (u32 sw_if_index, const ip46_address_t *local_addr, bfd_lock (bm); vnet_api_error_t rv = bfd_api_verify_common ( - sw_if_index, desired_min_tx_usec, required_min_rx_usec, detect_mult, - local_addr, peer_addr); + sw_if_index, desired_min_tx_usec, detect_mult, local_addr, peer_addr); if (!rv) { bfd_session_t *bs = NULL; @@ -1011,7 +1007,7 @@ bfd_udp4_find_headers (vlib_buffer_t * b, ip4_header_t ** ip4, { /* sanity check first */ const i32 start = vnet_buffer (b)->l3_hdr_offset; - if (start < 0 && start < sizeof (b->pre_data)) + if (start < -(signed) sizeof (b->pre_data)) { BFD_ERR ("Start of ip header is before pre_data, ignoring"); *ip4 = NULL; @@ -1080,8 +1076,7 @@ bfd_rpc_update_session (vlib_main_t * vm, u32 bs_idx, const bfd_pkt_t * pkt) } static bfd_udp_error_t -bfd_udp4_scan (vlib_main_t * vm, vlib_node_runtime_t * rt, - vlib_buffer_t * b, bfd_session_t ** bs_out) +bfd_udp4_scan (vlib_main_t *vm, vlib_buffer_t *b, bfd_session_t **bs_out) { const bfd_pkt_t *pkt = vlib_buffer_get_current (b); if (sizeof (*pkt) > b->current_length) @@ -1158,7 +1153,7 @@ bfd_udp6_find_headers (vlib_buffer_t * b, ip6_header_t ** ip6, { /* sanity check first */ const i32 start = vnet_buffer (b)->l3_hdr_offset; - if (start < 0 && start < sizeof (b->pre_data)) + if (start < -(signed) sizeof (b->pre_data)) { BFD_ERR ("Start of ip header is before pre_data, ignoring"); *ip6 = NULL; @@ -1222,8 +1217,7 @@ bfd_udp6_verify_transport (const ip6_header_t * ip6, } static bfd_udp_error_t -bfd_udp6_scan (vlib_main_t * vm, vlib_node_runtime_t * rt, - vlib_buffer_t * b, bfd_session_t ** bs_out) +bfd_udp6_scan (vlib_main_t *vm, vlib_buffer_t *b, bfd_session_t **bs_out) { const bfd_pkt_t *pkt = vlib_buffer_get_current (b); if (sizeof (*pkt) > b->current_length) @@ -1325,7 +1319,7 @@ bfd_udp_input (vlib_main_t * vm, vlib_node_runtime_t * rt, /* If this pkt is traced, snapshot the data */ if (b0->flags & VLIB_BUFFER_IS_TRACED) { - int len; + u64 len; t0 = vlib_add_trace (vm, rt, b0, sizeof (*t0)); len = (b0->current_length < sizeof (t0->data)) ? b0->current_length : sizeof (t0->data); @@ -1337,11 +1331,11 @@ bfd_udp_input (vlib_main_t * vm, vlib_node_runtime_t * rt, bfd_lock (bm); if (is_ipv6) { - error0 = bfd_udp6_scan (vm, rt, b0, &bs); + error0 = bfd_udp6_scan (vm, b0, &bs); } else { - error0 = bfd_udp4_scan (vm, rt, b0, &bs); + error0 = bfd_udp4_scan (vm, b0, &bs); } b0->error = rt->errors[error0]; @@ -1358,8 +1352,7 @@ bfd_udp_input (vlib_main_t * vm, vlib_node_runtime_t * rt, { b0->current_data = 0; b0->current_length = 0; - bfd_init_final_control_frame (vm, b0, bfd_udp_main.bfd_main, bs, - 0); + bfd_init_final_control_frame (vm, b0, bs); if (is_ipv6) { vlib_node_increment_counter (vm, bfd_udp6_input_node.index, @@ -1487,7 +1480,7 @@ bfd_udp_echo_input (vlib_main_t * vm, vlib_node_runtime_t * rt, /* If this pkt is traced, snapshot the data */ if (b0->flags & VLIB_BUFFER_IS_TRACED) { - int len; + u64 len; t0 = vlib_add_trace (vm, rt, b0, sizeof (*t0)); len = (b0->current_length < sizeof (t0->data)) ? b0->current_length : sizeof (t0->data); @@ -1607,38 +1600,41 @@ VLIB_REGISTER_NODE (bfd_udp_echo6_input_node, static) = { /* *INDENT-ON* */ static clib_error_t * -bfd_udp_sw_if_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_create) +bfd_udp_sw_if_add_del (CLIB_UNUSED (vnet_main_t *vnm), u32 sw_if_index, + u32 is_create) { - bfd_session_t **to_be_freed = NULL; + u32 *to_be_freed = NULL; bfd_udp_main_t *bum = &bfd_udp_main; BFD_DBG ("sw_if_add_del called, sw_if_index=%u, is_create=%u", sw_if_index, is_create); if (!is_create) { bfd_session_t *bs; - pool_foreach (bs, bfd_udp_main.bfd_main->sessions) - { - if (bs->transport != BFD_TRANSPORT_UDP4 && - bs->transport != BFD_TRANSPORT_UDP6) - { - continue; - } - if (bs->udp.key.sw_if_index != sw_if_index) - { - continue; - } - vec_add1 (to_be_freed, bs); - } - } - bfd_session_t **bs; - vec_foreach (bs, to_be_freed) - { - vlib_log_notice (bum->log_class, - "removal of sw_if_index=%u forces removal of bfd session " - "with bs_idx=%u", sw_if_index, (*bs)->bs_idx); - bfd_session_set_flags (vlib_get_main (), *bs, 0); - bfd_udp_del_session_internal (vlib_get_main (), *bs); - } + pool_foreach (bs, bum->bfd_main->sessions) + { + if (bs->transport != BFD_TRANSPORT_UDP4 && + bs->transport != BFD_TRANSPORT_UDP6) + { + continue; + } + if (bs->udp.key.sw_if_index != sw_if_index) + { + continue; + } + vec_add1 (to_be_freed, bs->bs_idx); + } + } + u32 *bs_idx; + vec_foreach (bs_idx, to_be_freed) + { + bfd_session_t *bs = pool_elt_at_index (bum->bfd_main->sessions, *bs_idx); + vlib_log_notice (bum->log_class, + "removal of sw_if_index=%u forces removal of bfd " + "session with bs_idx=%u", + sw_if_index, bs->bs_idx); + bfd_session_set_flags (vlib_get_main (), bs, 0); + bfd_udp_del_session_internal (vlib_get_main (), bs); + } return 0; } |