X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fbfd%2Fbfd_api.c;h=fcd66950114ec840c1306b448327cc59636aa41e;hb=2d3c7b9c;hp=af70f0ec2d59045011cd69b323f81bbc70f1b378;hpb=a57a970952be2c3403c57dd7a16cd3d73660ef79;p=vpp.git diff --git a/src/vnet/bfd/bfd_api.c b/src/vnet/bfd/bfd_api.c index af70f0ec2d5..fcd66950114 100644 --- a/src/vnet/bfd/bfd_api.c +++ b/src/vnet/bfd/bfd_api.c @@ -16,6 +16,10 @@ * limitations under the License. *------------------------------------------------------------------ */ +/** + * @file + * @brief BFD binary API implementation + */ #include #include @@ -54,7 +58,10 @@ _ (BFD_AUTH_DEL_KEY, bfd_auth_del_key) \ _ (BFD_AUTH_KEYS_DUMP, bfd_auth_keys_dump) \ _ (BFD_UDP_AUTH_ACTIVATE, bfd_udp_auth_activate) \ - _ (BFD_UDP_AUTH_DEACTIVATE, bfd_udp_auth_deactivate) + _ (BFD_UDP_AUTH_DEACTIVATE, bfd_udp_auth_deactivate) \ + _ (BFD_UDP_SET_ECHO_SOURCE, bfd_udp_set_echo_source) \ + _ (BFD_UDP_DEL_ECHO_SOURCE, bfd_udp_del_echo_source) \ + _ (BFD_UDP_GET_ECHO_SOURCE, bfd_udp_get_echo_source) pub_sub_handler (bfd_events, BFD_EVENTS); @@ -134,7 +141,7 @@ vl_api_bfd_udp_del_t_handler (vl_api_bfd_udp_del_t * mp) } void -send_bfd_udp_session_details (unix_shared_memory_queue_t * q, u32 context, +send_bfd_udp_session_details (vl_api_registration_t * reg, u32 context, bfd_session_t * bs) { if (bs->transport != BFD_TRANSPORT_UDP4 && @@ -152,6 +159,21 @@ send_bfd_udp_session_details (unix_shared_memory_queue_t * q, u32 context, bfd_udp_key_t *key = &bus->key; mp->sw_if_index = clib_host_to_net_u32 (key->sw_if_index); mp->is_ipv6 = !(ip46_address_is_ip4 (&key->local_addr)); + if ((!bs->auth.is_delayed && bs->auth.curr_key) || + (bs->auth.is_delayed && bs->auth.next_key)) + { + mp->is_authenticated = 1; + } + if (bs->auth.is_delayed && bs->auth.next_key) + { + mp->bfd_key_id = bs->auth.next_bfd_key_id; + mp->conf_key_id = clib_host_to_net_u32 (bs->auth.next_key->conf_key_id); + } + else if (!bs->auth.is_delayed && bs->auth.curr_key) + { + mp->bfd_key_id = bs->auth.curr_bfd_key_id; + mp->conf_key_id = clib_host_to_net_u32 (bs->auth.curr_key->conf_key_id); + } if (mp->is_ipv6) { clib_memcpy (mp->local_addr, &key->local_addr, @@ -170,7 +192,7 @@ send_bfd_udp_session_details (unix_shared_memory_queue_t * q, u32 context, clib_host_to_net_u32 (bs->config_required_min_rx_usec); mp->desired_min_tx = clib_host_to_net_u32 (bs->config_desired_min_tx_usec); mp->detect_mult = bs->local_detect_mult; - vl_msg_api_send_shmem (q, (u8 *) & mp); + vl_api_send_msg (reg, (u8 *) mp); } void @@ -178,41 +200,40 @@ bfd_event (bfd_main_t * bm, bfd_session_t * bs) { vpe_api_main_t *vam = &vpe_api_main; vpe_client_registration_t *reg; - unix_shared_memory_queue_t *q; + vl_api_registration_t *vl_reg; /* *INDENT-OFF* */ pool_foreach (reg, vam->bfd_events_registrations, ({ - q = vl_api_client_index_to_input_queue (reg->client_index); - if (q) - { - switch (bs->transport) - { - case BFD_TRANSPORT_UDP4: - /* fallthrough */ - case BFD_TRANSPORT_UDP6: - send_bfd_udp_session_details (q, 0, bs); - } - } - })); + vl_reg = vl_api_client_index_to_registration (reg->client_index); + if (vl_reg) + { + switch (bs->transport) + { + case BFD_TRANSPORT_UDP4: + /* fallthrough */ + case BFD_TRANSPORT_UDP6: + send_bfd_udp_session_details (vl_reg, 0, bs); + } + } + })); /* *INDENT-ON* */ } static void vl_api_bfd_udp_session_dump_t_handler (vl_api_bfd_udp_session_dump_t * mp) { - unix_shared_memory_queue_t *q; - - q = vl_api_client_index_to_input_queue (mp->client_index); + vl_api_registration_t *reg; - if (q == 0) + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) return; bfd_session_t *bs = NULL; /* *INDENT-OFF* */ pool_foreach (bs, bfd_main.sessions, ({ - if (bs->transport == BFD_TRANSPORT_UDP4 || - bs->transport == BFD_TRANSPORT_UDP6) - send_bfd_udp_session_details (q, mp->context, bs); - })); + if (bs->transport == BFD_TRANSPORT_UDP4 || + bs->transport == BFD_TRANSPORT_UDP6) + send_bfd_udp_session_details (reg, mp->context, bs); + })); /* *INDENT-ON* */ } @@ -253,11 +274,10 @@ vl_api_bfd_auth_del_key_t_handler (vl_api_bfd_auth_del_key_t * mp) static void vl_api_bfd_auth_keys_dump_t_handler (vl_api_bfd_auth_keys_dump_t * mp) { - unix_shared_memory_queue_t *q; + vl_api_registration_t *reg; - q = vl_api_client_index_to_input_queue (mp->client_index); - - if (q == 0) + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) return; bfd_auth_key_t *key = NULL; @@ -265,15 +285,15 @@ vl_api_bfd_auth_keys_dump_t_handler (vl_api_bfd_auth_keys_dump_t * mp) /* *INDENT-OFF* */ pool_foreach (key, bfd_main.auth_keys, ({ - rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_BFD_AUTH_KEYS_DETAILS); - rmp->context = mp->context; - rmp->conf_key_id = clib_host_to_net_u32 (key->conf_key_id); - rmp->auth_type = key->auth_type; - rmp->use_count = clib_host_to_net_u32 (key->use_count); - vl_msg_api_send_shmem (q, (u8 *)&rmp); - })); + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_BFD_AUTH_KEYS_DETAILS); + rmp->context = mp->context; + rmp->conf_key_id = clib_host_to_net_u32 (key->conf_key_id); + rmp->auth_type = key->auth_type; + rmp->use_count = clib_host_to_net_u32 (key->use_count); + vl_api_send_msg (reg, (u8 *)rmp); + })); /* *INDENT-ON* */ } @@ -287,10 +307,9 @@ vl_api_bfd_udp_auth_activate_t_handler (vl_api_bfd_udp_auth_activate_t * mp) BFD_UDP_API_PARAM_COMMON_CODE; - rv = - bfd_udp_auth_activate (BFD_UDP_API_PARAM_FROM_MP (mp), - clib_net_to_host_u32 (mp->conf_key_id), - mp->bfd_key_id, mp->is_delayed); + rv = bfd_udp_auth_activate (BFD_UDP_API_PARAM_FROM_MP (mp), + clib_net_to_host_u32 (mp->conf_key_id), + mp->bfd_key_id, mp->is_delayed); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_BFD_UDP_AUTH_ACTIVATE_REPLY); @@ -314,6 +333,86 @@ vl_api_bfd_udp_auth_deactivate_t_handler (vl_api_bfd_udp_auth_deactivate_t * REPLY_MACRO (VL_API_BFD_UDP_AUTH_DEACTIVATE_REPLY); } +static void +vl_api_bfd_udp_set_echo_source_t_handler (vl_api_bfd_udp_set_echo_source_t * + mp) +{ + vl_api_bfd_udp_set_echo_source_reply_t *rmp; + int rv; + + VALIDATE_SW_IF_INDEX (mp); + + rv = bfd_udp_set_echo_source (clib_net_to_host_u32 (mp->sw_if_index)); + + BAD_SW_IF_INDEX_LABEL; + REPLY_MACRO (VL_API_BFD_UDP_SET_ECHO_SOURCE_REPLY); +} + +static void +vl_api_bfd_udp_del_echo_source_t_handler (vl_api_bfd_udp_del_echo_source_t * + mp) +{ + vl_api_bfd_udp_del_echo_source_reply_t *rmp; + int rv; + + rv = bfd_udp_del_echo_source (); + + REPLY_MACRO (VL_API_BFD_UDP_DEL_ECHO_SOURCE_REPLY); +} + +static void +vl_api_bfd_udp_get_echo_source_t_handler (vl_api_bfd_udp_get_echo_source_t * + mp) +{ + vl_api_bfd_udp_get_echo_source_reply_t *rmp; + int rv = 0; + int is_set; + u32 sw_if_index; + int have_usable_ip4; + ip4_address_t ip4; + int have_usable_ip6; + ip6_address_t ip6; + + bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4, + &have_usable_ip6, &ip6); + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_BFD_UDP_GET_ECHO_SOURCE_REPLY, + ({ + rmp->sw_if_index = ntohl (sw_if_index); + if (is_set) + { + rmp->is_set = 1; + rmp->sw_if_index = clib_host_to_net_u32 (sw_if_index); + if (have_usable_ip4) + { + rmp->have_usable_ip4 = 1; + clib_memcpy (rmp->ip4_addr, &ip4, sizeof (ip4)); + } + else + { + rmp->have_usable_ip4 = 0; + } + if (have_usable_ip6) + { + rmp->have_usable_ip6 = 1; + clib_memcpy (rmp->ip6_addr, &ip6, sizeof (ip6)); + } + else + { + rmp->have_usable_ip6 = 0; + } + } + else + { + rmp->is_set = 0; + rmp->have_usable_ip4 = 0; + rmp->have_usable_ip6 = 0; + } + })) + /* *INDENT-ON* */ +} + /* * bfd_api_hookup * Add vpe's API message handlers to the table.