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