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