Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * bfd_api.c - bfd api |
| 4 | * |
| 5 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | *------------------------------------------------------------------ |
| 18 | */ |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 19 | /** |
| 20 | * @file |
| 21 | * @brief BFD binary API implementation |
| 22 | */ |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 23 | |
| 24 | #include <vnet/vnet.h> |
| 25 | #include <vlibmemory/api.h> |
| 26 | |
| 27 | #include <vnet/interface.h> |
| 28 | #include <vnet/api_errno.h> |
| 29 | #include <vnet/bfd/bfd_main.h> |
| 30 | #include <vnet/bfd/bfd_api.h> |
| 31 | |
| 32 | #include <vnet/vnet_msg_enum.h> |
| 33 | |
| 34 | #define vl_typedefs /* define message structures */ |
| 35 | #include <vnet/vnet_all_api_h.h> |
| 36 | #undef vl_typedefs |
| 37 | |
| 38 | #define vl_endianfun /* define message structures */ |
| 39 | #include <vnet/vnet_all_api_h.h> |
| 40 | #undef vl_endianfun |
| 41 | |
| 42 | /* instantiate all the print functions we know about */ |
| 43 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 44 | #define vl_printfun |
| 45 | #include <vnet/vnet_all_api_h.h> |
| 46 | #undef vl_printfun |
| 47 | |
| 48 | #include <vlibapi/api_helper_macros.h> |
| 49 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 50 | #define foreach_vpe_api_msg \ |
| 51 | _ (BFD_UDP_ADD, bfd_udp_add) \ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 52 | _ (BFD_UDP_MOD, bfd_udp_mod) \ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 53 | _ (BFD_UDP_DEL, bfd_udp_del) \ |
| 54 | _ (BFD_UDP_SESSION_DUMP, bfd_udp_session_dump) \ |
| 55 | _ (BFD_UDP_SESSION_SET_FLAGS, bfd_udp_session_set_flags) \ |
| 56 | _ (WANT_BFD_EVENTS, want_bfd_events) \ |
| 57 | _ (BFD_AUTH_SET_KEY, bfd_auth_set_key) \ |
| 58 | _ (BFD_AUTH_DEL_KEY, bfd_auth_del_key) \ |
| 59 | _ (BFD_AUTH_KEYS_DUMP, bfd_auth_keys_dump) \ |
| 60 | _ (BFD_UDP_AUTH_ACTIVATE, bfd_udp_auth_activate) \ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 61 | _ (BFD_UDP_AUTH_DEACTIVATE, bfd_udp_auth_deactivate) \ |
| 62 | _ (BFD_UDP_SET_ECHO_SOURCE, bfd_udp_set_echo_source) \ |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 63 | _ (BFD_UDP_DEL_ECHO_SOURCE, bfd_udp_del_echo_source) \ |
| 64 | _ (BFD_UDP_GET_ECHO_SOURCE, bfd_udp_get_echo_source) |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 65 | |
| 66 | pub_sub_handler (bfd_events, BFD_EVENTS); |
| 67 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 68 | #define BFD_UDP_API_PARAM_COMMON_CODE \ |
| 69 | ip46_address_t local_addr; \ |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 70 | clib_memset (&local_addr, 0, sizeof (local_addr)); \ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 71 | ip46_address_t peer_addr; \ |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 72 | clib_memset (&peer_addr, 0, sizeof (peer_addr)); \ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 73 | if (mp->is_ipv6) \ |
| 74 | { \ |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 75 | clib_memcpy_fast (&local_addr.ip6, mp->local_addr, sizeof (local_addr.ip6)); \ |
| 76 | clib_memcpy_fast (&peer_addr.ip6, mp->peer_addr, sizeof (peer_addr.ip6)); \ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 77 | } \ |
| 78 | else \ |
| 79 | { \ |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 80 | clib_memcpy_fast (&local_addr.ip4, mp->local_addr, sizeof (local_addr.ip4)); \ |
| 81 | clib_memcpy_fast (&peer_addr.ip4, mp->peer_addr, sizeof (peer_addr.ip4)); \ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | #define BFD_UDP_API_PARAM_FROM_MP(mp) \ |
| 85 | clib_net_to_host_u32 (mp->sw_if_index), &local_addr, &peer_addr |
| 86 | |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 87 | static void |
| 88 | vl_api_bfd_udp_add_t_handler (vl_api_bfd_udp_add_t * mp) |
| 89 | { |
| 90 | vl_api_bfd_udp_add_reply_t *rmp; |
| 91 | int rv; |
| 92 | |
| 93 | VALIDATE_SW_IF_INDEX (mp); |
| 94 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 95 | BFD_UDP_API_PARAM_COMMON_CODE; |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 96 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 97 | rv = bfd_udp_add_session (BFD_UDP_API_PARAM_FROM_MP (mp), |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 98 | clib_net_to_host_u32 (mp->desired_min_tx), |
| 99 | clib_net_to_host_u32 (mp->required_min_rx), |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 100 | mp->detect_mult, mp->is_authenticated, |
| 101 | clib_net_to_host_u32 (mp->conf_key_id), |
| 102 | mp->bfd_key_id); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 103 | |
| 104 | BAD_SW_IF_INDEX_LABEL; |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 105 | REPLY_MACRO (VL_API_BFD_UDP_ADD_REPLY); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static void |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 109 | vl_api_bfd_udp_mod_t_handler (vl_api_bfd_udp_mod_t * mp) |
| 110 | { |
| 111 | vl_api_bfd_udp_mod_reply_t *rmp; |
| 112 | int rv; |
| 113 | |
| 114 | VALIDATE_SW_IF_INDEX (mp); |
| 115 | |
| 116 | BFD_UDP_API_PARAM_COMMON_CODE; |
| 117 | |
| 118 | rv = bfd_udp_mod_session (BFD_UDP_API_PARAM_FROM_MP (mp), |
| 119 | clib_net_to_host_u32 (mp->desired_min_tx), |
| 120 | clib_net_to_host_u32 (mp->required_min_rx), |
| 121 | mp->detect_mult); |
| 122 | |
| 123 | BAD_SW_IF_INDEX_LABEL; |
| 124 | REPLY_MACRO (VL_API_BFD_UDP_MOD_REPLY); |
| 125 | } |
| 126 | |
| 127 | static void |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 128 | vl_api_bfd_udp_del_t_handler (vl_api_bfd_udp_del_t * mp) |
| 129 | { |
| 130 | vl_api_bfd_udp_del_reply_t *rmp; |
| 131 | int rv; |
| 132 | |
| 133 | VALIDATE_SW_IF_INDEX (mp); |
| 134 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 135 | BFD_UDP_API_PARAM_COMMON_CODE; |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 136 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 137 | rv = bfd_udp_del_session (BFD_UDP_API_PARAM_FROM_MP (mp)); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 138 | |
| 139 | BAD_SW_IF_INDEX_LABEL; |
| 140 | REPLY_MACRO (VL_API_BFD_UDP_DEL_REPLY); |
| 141 | } |
| 142 | |
| 143 | void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 144 | send_bfd_udp_session_details (vl_api_registration_t * reg, u32 context, |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 145 | bfd_session_t * bs) |
| 146 | { |
| 147 | if (bs->transport != BFD_TRANSPORT_UDP4 && |
| 148 | bs->transport != BFD_TRANSPORT_UDP6) |
| 149 | { |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | vl_api_bfd_udp_session_details_t *mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 154 | clib_memset (mp, 0, sizeof (*mp)); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 155 | mp->_vl_msg_id = ntohs (VL_API_BFD_UDP_SESSION_DETAILS); |
| 156 | mp->context = context; |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 157 | mp->state = bs->local_state; |
| 158 | bfd_udp_session_t *bus = &bs->udp; |
| 159 | bfd_udp_key_t *key = &bus->key; |
| 160 | mp->sw_if_index = clib_host_to_net_u32 (key->sw_if_index); |
| 161 | mp->is_ipv6 = !(ip46_address_is_ip4 (&key->local_addr)); |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 162 | if ((!bs->auth.is_delayed && bs->auth.curr_key) || |
| 163 | (bs->auth.is_delayed && bs->auth.next_key)) |
| 164 | { |
| 165 | mp->is_authenticated = 1; |
| 166 | } |
| 167 | if (bs->auth.is_delayed && bs->auth.next_key) |
| 168 | { |
| 169 | mp->bfd_key_id = bs->auth.next_bfd_key_id; |
| 170 | mp->conf_key_id = clib_host_to_net_u32 (bs->auth.next_key->conf_key_id); |
| 171 | } |
| 172 | else if (!bs->auth.is_delayed && bs->auth.curr_key) |
| 173 | { |
| 174 | mp->bfd_key_id = bs->auth.curr_bfd_key_id; |
| 175 | mp->conf_key_id = clib_host_to_net_u32 (bs->auth.curr_key->conf_key_id); |
| 176 | } |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 177 | if (mp->is_ipv6) |
| 178 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 179 | clib_memcpy_fast (mp->local_addr, &key->local_addr, |
| 180 | sizeof (key->local_addr)); |
| 181 | clib_memcpy_fast (mp->peer_addr, &key->peer_addr, |
| 182 | sizeof (key->peer_addr)); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 183 | } |
| 184 | else |
| 185 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 186 | clib_memcpy_fast (mp->local_addr, key->local_addr.ip4.data, |
| 187 | sizeof (key->local_addr.ip4.data)); |
| 188 | clib_memcpy_fast (mp->peer_addr, key->peer_addr.ip4.data, |
| 189 | sizeof (key->peer_addr.ip4.data)); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 192 | mp->required_min_rx = |
| 193 | clib_host_to_net_u32 (bs->config_required_min_rx_usec); |
| 194 | mp->desired_min_tx = clib_host_to_net_u32 (bs->config_desired_min_tx_usec); |
| 195 | mp->detect_mult = bs->local_detect_mult; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 196 | vl_api_send_msg (reg, (u8 *) mp); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void |
| 200 | bfd_event (bfd_main_t * bm, bfd_session_t * bs) |
| 201 | { |
| 202 | vpe_api_main_t *vam = &vpe_api_main; |
| 203 | vpe_client_registration_t *reg; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 204 | vl_api_registration_t *vl_reg; |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 205 | /* *INDENT-OFF* */ |
| 206 | pool_foreach (reg, vam->bfd_events_registrations, ({ |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 207 | vl_reg = vl_api_client_index_to_registration (reg->client_index); |
| 208 | if (vl_reg) |
| 209 | { |
| 210 | switch (bs->transport) |
| 211 | { |
| 212 | case BFD_TRANSPORT_UDP4: |
| 213 | /* fallthrough */ |
| 214 | case BFD_TRANSPORT_UDP6: |
| 215 | send_bfd_udp_session_details (vl_reg, 0, bs); |
| 216 | } |
| 217 | } |
| 218 | })); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 219 | /* *INDENT-ON* */ |
| 220 | } |
| 221 | |
| 222 | static void |
| 223 | vl_api_bfd_udp_session_dump_t_handler (vl_api_bfd_udp_session_dump_t * mp) |
| 224 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 225 | vl_api_registration_t *reg; |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 226 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 227 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 228 | if (!reg) |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 229 | return; |
| 230 | |
| 231 | bfd_session_t *bs = NULL; |
| 232 | /* *INDENT-OFF* */ |
| 233 | pool_foreach (bs, bfd_main.sessions, ({ |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 234 | if (bs->transport == BFD_TRANSPORT_UDP4 || |
| 235 | bs->transport == BFD_TRANSPORT_UDP6) |
| 236 | send_bfd_udp_session_details (reg, mp->context, bs); |
| 237 | })); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 238 | /* *INDENT-ON* */ |
| 239 | } |
| 240 | |
| 241 | static void |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 242 | vl_api_bfd_udp_session_set_flags_t_handler (vl_api_bfd_udp_session_set_flags_t |
| 243 | * mp) |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 244 | { |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 245 | vl_api_bfd_udp_session_set_flags_reply_t *rmp; |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 246 | int rv; |
| 247 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 248 | BFD_UDP_API_PARAM_COMMON_CODE; |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 249 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 250 | rv = bfd_udp_session_set_flags (BFD_UDP_API_PARAM_FROM_MP (mp), |
| 251 | mp->admin_up_down); |
| 252 | |
| 253 | REPLY_MACRO (VL_API_BFD_UDP_SESSION_SET_FLAGS_REPLY); |
| 254 | } |
| 255 | |
| 256 | static void |
| 257 | vl_api_bfd_auth_set_key_t_handler (vl_api_bfd_auth_set_key_t * mp) |
| 258 | { |
| 259 | vl_api_bfd_auth_set_key_reply_t *rmp; |
| 260 | int rv = bfd_auth_set_key (clib_net_to_host_u32 (mp->conf_key_id), |
| 261 | mp->auth_type, mp->key_len, mp->key); |
| 262 | |
| 263 | REPLY_MACRO (VL_API_BFD_AUTH_SET_KEY_REPLY); |
| 264 | } |
| 265 | |
| 266 | static void |
| 267 | vl_api_bfd_auth_del_key_t_handler (vl_api_bfd_auth_del_key_t * mp) |
| 268 | { |
| 269 | vl_api_bfd_auth_del_key_reply_t *rmp; |
| 270 | int rv = bfd_auth_del_key (clib_net_to_host_u32 (mp->conf_key_id)); |
| 271 | |
| 272 | REPLY_MACRO (VL_API_BFD_AUTH_DEL_KEY_REPLY); |
| 273 | } |
| 274 | |
| 275 | static void |
| 276 | vl_api_bfd_auth_keys_dump_t_handler (vl_api_bfd_auth_keys_dump_t * mp) |
| 277 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 278 | vl_api_registration_t *reg; |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 279 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 280 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 281 | if (!reg) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 282 | return; |
| 283 | |
| 284 | bfd_auth_key_t *key = NULL; |
| 285 | vl_api_bfd_auth_keys_details_t *rmp = NULL; |
| 286 | |
| 287 | /* *INDENT-OFF* */ |
| 288 | pool_foreach (key, bfd_main.auth_keys, ({ |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 289 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 290 | clib_memset (rmp, 0, sizeof (*rmp)); |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 291 | rmp->_vl_msg_id = ntohs (VL_API_BFD_AUTH_KEYS_DETAILS); |
| 292 | rmp->context = mp->context; |
| 293 | rmp->conf_key_id = clib_host_to_net_u32 (key->conf_key_id); |
| 294 | rmp->auth_type = key->auth_type; |
| 295 | rmp->use_count = clib_host_to_net_u32 (key->use_count); |
Florin Coras | f0c8a81 | 2018-01-15 01:17:29 -0800 | [diff] [blame] | 296 | vl_api_send_msg (reg, (u8 *)rmp); |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 297 | })); |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 298 | /* *INDENT-ON* */ |
| 299 | } |
| 300 | |
| 301 | static void |
| 302 | vl_api_bfd_udp_auth_activate_t_handler (vl_api_bfd_udp_auth_activate_t * mp) |
| 303 | { |
| 304 | vl_api_bfd_udp_auth_activate_reply_t *rmp; |
| 305 | int rv; |
| 306 | |
| 307 | VALIDATE_SW_IF_INDEX (mp); |
| 308 | |
| 309 | BFD_UDP_API_PARAM_COMMON_CODE; |
| 310 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 311 | rv = bfd_udp_auth_activate (BFD_UDP_API_PARAM_FROM_MP (mp), |
| 312 | clib_net_to_host_u32 (mp->conf_key_id), |
| 313 | mp->bfd_key_id, mp->is_delayed); |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 314 | |
| 315 | BAD_SW_IF_INDEX_LABEL; |
| 316 | REPLY_MACRO (VL_API_BFD_UDP_AUTH_ACTIVATE_REPLY); |
| 317 | } |
| 318 | |
| 319 | static void |
| 320 | vl_api_bfd_udp_auth_deactivate_t_handler (vl_api_bfd_udp_auth_deactivate_t * |
| 321 | mp) |
| 322 | { |
| 323 | vl_api_bfd_udp_auth_deactivate_reply_t *rmp; |
| 324 | int rv; |
| 325 | |
| 326 | VALIDATE_SW_IF_INDEX (mp); |
| 327 | |
| 328 | BFD_UDP_API_PARAM_COMMON_CODE; |
| 329 | |
| 330 | rv = |
| 331 | bfd_udp_auth_deactivate (BFD_UDP_API_PARAM_FROM_MP (mp), mp->is_delayed); |
| 332 | |
| 333 | BAD_SW_IF_INDEX_LABEL; |
| 334 | REPLY_MACRO (VL_API_BFD_UDP_AUTH_DEACTIVATE_REPLY); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 335 | } |
| 336 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 337 | static void |
| 338 | vl_api_bfd_udp_set_echo_source_t_handler (vl_api_bfd_udp_set_echo_source_t * |
| 339 | mp) |
| 340 | { |
| 341 | vl_api_bfd_udp_set_echo_source_reply_t *rmp; |
| 342 | int rv; |
| 343 | |
| 344 | VALIDATE_SW_IF_INDEX (mp); |
| 345 | |
| 346 | rv = bfd_udp_set_echo_source (clib_net_to_host_u32 (mp->sw_if_index)); |
| 347 | |
| 348 | BAD_SW_IF_INDEX_LABEL; |
| 349 | REPLY_MACRO (VL_API_BFD_UDP_SET_ECHO_SOURCE_REPLY); |
| 350 | } |
| 351 | |
| 352 | static void |
| 353 | vl_api_bfd_udp_del_echo_source_t_handler (vl_api_bfd_udp_del_echo_source_t * |
| 354 | mp) |
| 355 | { |
| 356 | vl_api_bfd_udp_del_echo_source_reply_t *rmp; |
| 357 | int rv; |
| 358 | |
| 359 | rv = bfd_udp_del_echo_source (); |
| 360 | |
| 361 | REPLY_MACRO (VL_API_BFD_UDP_DEL_ECHO_SOURCE_REPLY); |
| 362 | } |
| 363 | |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 364 | static void |
| 365 | vl_api_bfd_udp_get_echo_source_t_handler (vl_api_bfd_udp_get_echo_source_t * |
| 366 | mp) |
| 367 | { |
| 368 | vl_api_bfd_udp_get_echo_source_reply_t *rmp; |
| 369 | int rv = 0; |
| 370 | int is_set; |
| 371 | u32 sw_if_index; |
| 372 | int have_usable_ip4; |
| 373 | ip4_address_t ip4; |
| 374 | int have_usable_ip6; |
| 375 | ip6_address_t ip6; |
| 376 | |
| 377 | bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4, |
| 378 | &have_usable_ip6, &ip6); |
| 379 | |
| 380 | /* *INDENT-OFF* */ |
| 381 | REPLY_MACRO2 (VL_API_BFD_UDP_GET_ECHO_SOURCE_REPLY, |
| 382 | ({ |
| 383 | rmp->sw_if_index = ntohl (sw_if_index); |
| 384 | if (is_set) |
| 385 | { |
| 386 | rmp->is_set = 1; |
| 387 | rmp->sw_if_index = clib_host_to_net_u32 (sw_if_index); |
| 388 | if (have_usable_ip4) |
| 389 | { |
| 390 | rmp->have_usable_ip4 = 1; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 391 | clib_memcpy_fast (rmp->ip4_addr, &ip4, sizeof (ip4)); |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 392 | } |
| 393 | else |
| 394 | { |
| 395 | rmp->have_usable_ip4 = 0; |
| 396 | } |
| 397 | if (have_usable_ip6) |
| 398 | { |
| 399 | rmp->have_usable_ip6 = 1; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 400 | clib_memcpy_fast (rmp->ip6_addr, &ip6, sizeof (ip6)); |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 401 | } |
| 402 | else |
| 403 | { |
| 404 | rmp->have_usable_ip6 = 0; |
| 405 | } |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | rmp->is_set = 0; |
| 410 | rmp->have_usable_ip4 = 0; |
| 411 | rmp->have_usable_ip6 = 0; |
| 412 | } |
| 413 | })) |
| 414 | /* *INDENT-ON* */ |
| 415 | } |
| 416 | |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 417 | /* |
| 418 | * bfd_api_hookup |
| 419 | * Add vpe's API message handlers to the table. |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 420 | * vlib has already mapped shared memory and |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 421 | * added the client registration handlers. |
| 422 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 423 | */ |
| 424 | #define vl_msg_name_crc_list |
| 425 | #include <vnet/vnet_all_api_h.h> |
| 426 | #undef vl_msg_name_crc_list |
| 427 | |
| 428 | static void |
| 429 | setup_message_id_table (api_main_t * am) |
| 430 | { |
Klement Sekera | 10db26f | 2017-01-11 08:16:53 +0100 | [diff] [blame] | 431 | #define _(id, n, crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 432 | foreach_vl_msg_name_crc_bfd; |
| 433 | #undef _ |
| 434 | } |
| 435 | |
| 436 | static clib_error_t * |
| 437 | bfd_api_hookup (vlib_main_t * vm) |
| 438 | { |
| 439 | api_main_t *am = &api_main; |
| 440 | |
Klement Sekera | 10db26f | 2017-01-11 08:16:53 +0100 | [diff] [blame] | 441 | #define _(N, n) \ |
| 442 | vl_msg_api_set_handlers (VL_API_##N, #n, vl_api_##n##_t_handler, \ |
| 443 | vl_noop_handler, vl_api_##n##_t_endian, \ |
| 444 | vl_api_##n##_t_print, sizeof (vl_api_##n##_t), 1); |
Pavel Kotucek | 20d1232 | 2016-12-21 09:13:17 +0100 | [diff] [blame] | 445 | foreach_vpe_api_msg; |
| 446 | #undef _ |
| 447 | |
| 448 | /* |
| 449 | * Set up the (msg_name, crc, message-id) table |
| 450 | */ |
| 451 | setup_message_id_table (am); |
| 452 | |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | VLIB_API_INIT_FUNCTION (bfd_api_hookup); |
| 457 | |
| 458 | /* |
| 459 | * fd.io coding-style-patch-verification: ON |
| 460 | * |
| 461 | * Local Variables: |
| 462 | * eval: (c-set-style "gnu") |
| 463 | * End: |
| 464 | */ |