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