Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * interface_api.c - vnet interface 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 | */ |
| 19 | |
Damjan Marion | 3d2f718 | 2023-09-06 21:18:18 +0200 | [diff] [blame] | 20 | #define _GNU_SOURCE |
| 21 | #include <string.h> |
| 22 | |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 23 | #include <vnet/vnet.h> |
| 24 | #include <vlibmemory/api.h> |
| 25 | |
| 26 | #include <vnet/interface.h> |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 27 | #include <vnet/interface/rx_queue_funcs.h> |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 28 | #include <vnet/interface/tx_queue_funcs.h> |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 29 | #include <vnet/api_errno.h> |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 30 | #include <vnet/ethernet/ethernet.h> |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 31 | #include <vnet/ip/ip.h> |
| 32 | #include <vnet/fib/fib_table.h> |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 33 | #include <vnet/mfib/mfib_table.h> |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 34 | #include <vnet/l2/l2_vtr.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 35 | #include <vnet/fib/fib_api.h> |
Neale Ranns | 358425b | 2017-02-20 09:42:36 -0800 | [diff] [blame] | 36 | #include <vnet/mfib/mfib_table.h> |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 37 | #include <vlibapi/api_types.h> |
| 38 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 39 | #include <vnet/format_fns.h> |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 40 | #include <vnet/ip/ip_types_api.h> |
| 41 | #include <vnet/ethernet/ethernet_types_api.h> |
| 42 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 43 | #include <interface.api_enum.h> |
| 44 | #include <interface.api_types.h> |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 45 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 46 | #define REPLY_MSG_ID_BASE msg_id_base |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 47 | #include <vlibapi/api_helper_macros.h> |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 48 | |
| 49 | static u16 msg_id_base; |
| 50 | |
Dave Barach | f158661 | 2017-03-30 09:33:01 -0400 | [diff] [blame] | 51 | vpe_api_main_t vpe_api_main; |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 52 | |
Nathan Skrzypczak | fd0b399 | 2021-02-04 16:11:18 +0100 | [diff] [blame] | 53 | #define foreach_vpe_api_msg \ |
| 54 | _ (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \ |
| 55 | _ (SW_INTERFACE_SET_PROMISC, sw_interface_set_promisc) \ |
| 56 | _ (HW_INTERFACE_SET_MTU, hw_interface_set_mtu) \ |
| 57 | _ (SW_INTERFACE_SET_MTU, sw_interface_set_mtu) \ |
| 58 | _ (WANT_INTERFACE_EVENTS, want_interface_events) \ |
| 59 | _ (SW_INTERFACE_DUMP, sw_interface_dump) \ |
| 60 | _ (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \ |
| 61 | _ (SW_INTERFACE_SET_RX_MODE, sw_interface_set_rx_mode) \ |
| 62 | _ (SW_INTERFACE_RX_PLACEMENT_DUMP, sw_interface_rx_placement_dump) \ |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 63 | _ (SW_INTERFACE_TX_PLACEMENT_GET, sw_interface_tx_placement_get) \ |
Nathan Skrzypczak | fd0b399 | 2021-02-04 16:11:18 +0100 | [diff] [blame] | 64 | _ (SW_INTERFACE_SET_RX_PLACEMENT, sw_interface_set_rx_placement) \ |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 65 | _ (SW_INTERFACE_SET_TX_PLACEMENT, sw_interface_set_tx_placement) \ |
Nathan Skrzypczak | fd0b399 | 2021-02-04 16:11:18 +0100 | [diff] [blame] | 66 | _ (SW_INTERFACE_SET_TABLE, sw_interface_set_table) \ |
| 67 | _ (SW_INTERFACE_GET_TABLE, sw_interface_get_table) \ |
| 68 | _ (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \ |
| 69 | _ (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \ |
| 70 | _ (SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del) \ |
| 71 | _ (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, sw_interface_add_del_mac_address) \ |
| 72 | _ (SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address) \ |
| 73 | _ (SW_INTERFACE_GET_MAC_ADDRESS, sw_interface_get_mac_address) \ |
| 74 | _ (CREATE_VLAN_SUBIF, create_vlan_subif) \ |
| 75 | _ (CREATE_SUBIF, create_subif) \ |
| 76 | _ (DELETE_SUBIF, delete_subif) \ |
| 77 | _ (CREATE_LOOPBACK, create_loopback) \ |
| 78 | _ (CREATE_LOOPBACK_INSTANCE, create_loopback_instance) \ |
| 79 | _ (DELETE_LOOPBACK, delete_loopback) \ |
| 80 | _ (INTERFACE_NAME_RENUMBER, interface_name_renumber) \ |
| 81 | _ (COLLECT_DETAILED_INTERFACE_STATS, collect_detailed_interface_stats) \ |
| 82 | _ (SW_INTERFACE_SET_IP_DIRECTED_BROADCAST, \ |
| 83 | sw_interface_set_ip_directed_broadcast) \ |
| 84 | _ (SW_INTERFACE_ADDRESS_REPLACE_BEGIN, sw_interface_address_replace_begin) \ |
| 85 | _ (SW_INTERFACE_ADDRESS_REPLACE_END, sw_interface_address_replace_end) |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 86 | |
| 87 | static void |
| 88 | vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp) |
| 89 | { |
| 90 | vl_api_sw_interface_set_flags_reply_t *rmp; |
| 91 | vnet_main_t *vnm = vnet_get_main (); |
| 92 | int rv = 0; |
| 93 | clib_error_t *error; |
| 94 | u16 flags; |
| 95 | |
| 96 | VALIDATE_SW_IF_INDEX (mp); |
| 97 | |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 98 | flags = |
| 99 | ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ? |
| 100 | VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0; |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 101 | |
| 102 | error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags); |
| 103 | if (error) |
| 104 | { |
| 105 | rv = -1; |
| 106 | clib_error_report (error); |
| 107 | } |
| 108 | |
| 109 | BAD_SW_IF_INDEX_LABEL; |
| 110 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY); |
| 111 | } |
| 112 | |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 113 | static void |
Nathan Skrzypczak | fd0b399 | 2021-02-04 16:11:18 +0100 | [diff] [blame] | 114 | vl_api_sw_interface_set_promisc_t_handler ( |
| 115 | vl_api_sw_interface_set_promisc_t *mp) |
| 116 | { |
| 117 | vl_api_sw_interface_set_promisc_reply_t *rmp; |
| 118 | vnet_main_t *vnm = vnet_get_main (); |
| 119 | ethernet_main_t *em = ðernet_main; |
| 120 | int rv = 0; |
| 121 | ethernet_interface_t *eif; |
| 122 | vnet_sw_interface_t *swif; |
| 123 | u32 flags, sw_if_index; |
| 124 | |
| 125 | VALIDATE_SW_IF_INDEX (mp); |
| 126 | |
| 127 | sw_if_index = ntohl (mp->sw_if_index); |
| 128 | swif = vnet_get_sw_interface (vnm, sw_if_index); |
| 129 | eif = ethernet_get_interface (em, swif->hw_if_index); |
| 130 | if (!eif) |
| 131 | { |
| 132 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 133 | goto done; |
| 134 | } |
| 135 | |
| 136 | flags = mp->promisc_on ? ETHERNET_INTERFACE_FLAG_ACCEPT_ALL : 0; |
| 137 | rv = ethernet_set_flags (vnm, swif->hw_if_index, flags); |
| 138 | |
| 139 | done: |
| 140 | BAD_SW_IF_INDEX_LABEL; |
| 141 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_PROMISC_REPLY); |
| 142 | } |
| 143 | |
| 144 | static void |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 145 | vl_api_hw_interface_set_mtu_t_handler (vl_api_hw_interface_set_mtu_t * mp) |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 146 | { |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 147 | vl_api_hw_interface_set_mtu_reply_t *rmp; |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 148 | vnet_main_t *vnm = vnet_get_main (); |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 149 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 150 | u16 mtu = ntohs (mp->mtu); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 151 | ethernet_main_t *em = ðernet_main; |
Damjan Marion | 81bb6fc | 2022-01-16 22:47:55 +0100 | [diff] [blame] | 152 | clib_error_t *err; |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 153 | int rv = 0; |
| 154 | |
| 155 | VALIDATE_SW_IF_INDEX (mp); |
| 156 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 157 | vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); |
| 158 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 159 | { |
| 160 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 161 | goto bad_sw_if_index; |
| 162 | } |
| 163 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 164 | ethernet_interface_t *eif = ethernet_get_interface (em, si->hw_if_index); |
| 165 | |
| 166 | if (!eif) |
| 167 | { |
| 168 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 169 | goto bad_sw_if_index; |
| 170 | } |
| 171 | |
Damjan Marion | 81bb6fc | 2022-01-16 22:47:55 +0100 | [diff] [blame] | 172 | if ((err = vnet_hw_interface_set_mtu (vnm, si->hw_if_index, mtu))) |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 173 | { |
Damjan Marion | 81bb6fc | 2022-01-16 22:47:55 +0100 | [diff] [blame] | 174 | rv = vnet_api_error (err); |
| 175 | clib_error_free (err); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 176 | goto bad_sw_if_index; |
| 177 | } |
| 178 | |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 179 | BAD_SW_IF_INDEX_LABEL; |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 180 | REPLY_MACRO (VL_API_HW_INTERFACE_SET_MTU_REPLY); |
| 181 | } |
| 182 | |
| 183 | static void |
| 184 | vl_api_sw_interface_set_mtu_t_handler (vl_api_sw_interface_set_mtu_t * mp) |
| 185 | { |
| 186 | vl_api_sw_interface_set_mtu_reply_t *rmp; |
| 187 | vnet_main_t *vnm = vnet_get_main (); |
| 188 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 189 | int rv = 0; |
| 190 | int i; |
| 191 | u32 per_protocol_mtu[VNET_N_MTU]; |
| 192 | |
| 193 | VALIDATE_SW_IF_INDEX (mp); |
| 194 | |
| 195 | for (i = 0; i < VNET_N_MTU; i++) |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 196 | { |
| 197 | per_protocol_mtu[i] = ntohl (mp->mtu[i]); |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 198 | } |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 199 | vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, per_protocol_mtu); |
| 200 | |
| 201 | BAD_SW_IF_INDEX_LABEL; |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 202 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY); |
| 203 | } |
| 204 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 205 | static void |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 206 | vl_api_sw_interface_set_ip_directed_broadcast_t_handler |
| 207 | (vl_api_sw_interface_set_ip_directed_broadcast_t * mp) |
| 208 | { |
| 209 | vl_api_sw_interface_set_ip_directed_broadcast_reply_t *rmp; |
| 210 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 211 | int rv = 0; |
| 212 | |
| 213 | VALIDATE_SW_IF_INDEX (mp); |
| 214 | |
| 215 | vnet_sw_interface_ip_directed_broadcast (vnet_get_main (), |
| 216 | sw_if_index, mp->enable); |
| 217 | |
| 218 | BAD_SW_IF_INDEX_LABEL; |
| 219 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_IP_DIRECTED_BROADCAST_REPLY); |
| 220 | } |
| 221 | |
| 222 | static void |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 223 | send_sw_interface_details (vpe_api_main_t * am, |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 224 | vl_api_registration_t * rp, |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 225 | vnet_sw_interface_t * swif, |
| 226 | u8 * interface_name, u32 context) |
| 227 | { |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 228 | vnet_hw_interface_t *hi = |
| 229 | vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index); |
Mohsin Kazmi | de312c2 | 2019-09-27 13:44:28 +0200 | [diff] [blame] | 230 | vnet_device_class_t *dev_class = |
| 231 | vnet_get_device_class (am->vnet_main, hi->dev_class_index); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 232 | |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 233 | vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp)); |
| 234 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 235 | mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_DETAILS); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 236 | mp->sw_if_index = ntohl (swif->sw_if_index); |
| 237 | mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 238 | |
| 239 | mp->flags |= (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
| 240 | IF_STATUS_API_FLAG_ADMIN_UP : 0; |
| 241 | mp->flags |= (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? |
| 242 | IF_STATUS_API_FLAG_LINK_UP : 0; |
| 243 | mp->flags = ntohl (mp->flags); |
| 244 | |
| 245 | switch (swif->type) |
| 246 | { |
| 247 | case VNET_SW_INTERFACE_TYPE_SUB: |
| 248 | mp->type = IF_API_TYPE_SUB; |
| 249 | break; |
| 250 | case VNET_SW_INTERFACE_TYPE_P2P: |
| 251 | mp->type = IF_API_TYPE_P2P; |
| 252 | break; |
| 253 | case VNET_SW_INTERFACE_TYPE_PIPE: |
| 254 | mp->type = IF_API_TYPE_PIPE; |
| 255 | break; |
| 256 | default: |
| 257 | mp->type = IF_API_TYPE_HARDWARE; |
| 258 | } |
| 259 | mp->type = ntohl (mp->type); |
| 260 | |
Neale Ranns | 8561e73 | 2021-07-21 13:29:58 +0000 | [diff] [blame] | 261 | mp->link_duplex = ntohl (((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >> |
| 262 | VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT)); |
Ole Troan | 8ee7251 | 2018-11-20 11:03:10 +0100 | [diff] [blame] | 263 | mp->link_speed = ntohl (hi->link_speed); |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame] | 264 | mp->link_mtu = ntohs (hi->max_frame_size - hi->frame_overhead); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 265 | mp->mtu[VNET_MTU_L3] = ntohl (swif->mtu[VNET_MTU_L3]); |
| 266 | mp->mtu[VNET_MTU_IP4] = ntohl (swif->mtu[VNET_MTU_IP4]); |
| 267 | mp->mtu[VNET_MTU_IP6] = ntohl (swif->mtu[VNET_MTU_IP6]); |
| 268 | mp->mtu[VNET_MTU_MPLS] = ntohl (swif->mtu[VNET_MTU_MPLS]); |
| 269 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 270 | mp->context = context; |
| 271 | |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 272 | strncpy ((char *) mp->interface_name, |
| 273 | (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1); |
| 274 | |
Mohsin Kazmi | de312c2 | 2019-09-27 13:44:28 +0200 | [diff] [blame] | 275 | if (dev_class && dev_class->name) |
| 276 | strncpy ((char *) mp->interface_dev_type, (char *) dev_class->name, |
| 277 | ARRAY_LEN (mp->interface_dev_type) - 1); |
| 278 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 279 | /* Send the L2 address for ethernet physical intfcs */ |
| 280 | if (swif->sup_sw_if_index == swif->sw_if_index |
| 281 | && hi->hw_class_index == ethernet_hw_interface_class.index) |
| 282 | { |
| 283 | ethernet_main_t *em = ethernet_get_main (am->vlib_main); |
| 284 | ethernet_interface_t *ei; |
| 285 | |
| 286 | ei = pool_elt_at_index (em->interfaces, hi->hw_instance); |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 287 | ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address.mac)); |
| 288 | mac_address_encode (&ei->address.mac, mp->l2_address); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 289 | } |
| 290 | else if (swif->sup_sw_if_index != swif->sw_if_index) |
| 291 | { |
| 292 | vnet_sub_interface_t *sub = &swif->sub; |
| 293 | mp->sub_id = ntohl (sub->id); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 294 | mp->sub_number_of_tags = |
| 295 | sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2; |
| 296 | mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id); |
| 297 | mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 298 | mp->sub_if_flags = |
| 299 | ntohl (sub->eth.raw_flags & SUB_IF_API_FLAG_MASK_VNET); |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 300 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 301 | |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 302 | /* vlan tag rewrite data */ |
| 303 | u32 vtr_op = L2_VTR_DISABLED; |
| 304 | u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 305 | |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 306 | if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index, |
| 307 | &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) |
| 308 | { |
| 309 | // error - default to disabled |
| 310 | mp->vtr_op = ntohl (L2_VTR_DISABLED); |
| 311 | clib_warning ("cannot get vlan tag rewrite for sw_if_index %d", |
| 312 | swif->sw_if_index); |
| 313 | } |
| 314 | else |
| 315 | { |
| 316 | mp->vtr_op = ntohl (vtr_op); |
| 317 | mp->vtr_push_dot1q = ntohl (vtr_push_dot1q); |
| 318 | mp->vtr_tag1 = ntohl (vtr_tag1); |
| 319 | mp->vtr_tag2 = ntohl (vtr_tag2); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 320 | } |
| 321 | |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 322 | /* pbb tag rewrite data */ |
Gabriel Ganne | f7f2a9f | 2017-03-06 15:19:40 +0100 | [diff] [blame] | 323 | ethernet_header_t eth_hdr; |
Alexander Chernavin | fdea5c6 | 2019-04-26 10:43:09 -0400 | [diff] [blame] | 324 | u32 pbb_vtr_op = L2_VTR_DISABLED; |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 325 | u16 outer_tag = 0; |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 326 | u16 b_vlanid = 0; |
| 327 | u32 i_sid = 0; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 328 | clib_memset (ð_hdr, 0, sizeof (eth_hdr)); |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 329 | |
| 330 | if (!l2pbb_get (am->vlib_main, am->vnet_main, swif->sw_if_index, |
Alexander Chernavin | fdea5c6 | 2019-04-26 10:43:09 -0400 | [diff] [blame] | 331 | &pbb_vtr_op, &outer_tag, ð_hdr, &b_vlanid, &i_sid)) |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 332 | { |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 333 | mp->sub_if_flags |= ntohl (SUB_IF_API_FLAG_DOT1AH); |
| 334 | mac_address_encode ((mac_address_t *) eth_hdr.dst_address, mp->b_dmac); |
| 335 | mac_address_encode ((mac_address_t *) eth_hdr.src_address, mp->b_smac); |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 336 | mp->b_vlanid = b_vlanid; |
| 337 | mp->i_sid = i_sid; |
| 338 | } |
| 339 | |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 340 | u8 *tag = vnet_get_sw_interface_tag (vnet_get_main (), swif->sw_if_index); |
| 341 | if (tag) |
| 342 | strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 343 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 344 | vl_api_send_msg (rp, (u8 *) mp); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static void |
| 348 | vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp) |
| 349 | { |
| 350 | vpe_api_main_t *am = &vpe_api_main; |
| 351 | vnet_sw_interface_t *swif; |
| 352 | vnet_interface_main_t *im = &am->vnet_main->interface_main; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 353 | vl_api_registration_t *rp; |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 354 | u32 sw_if_index; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 355 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 356 | rp = vl_api_client_index_to_registration (mp->client_index); |
| 357 | |
| 358 | if (rp == 0) |
| 359 | { |
| 360 | clib_warning ("Client %d AWOL", mp->client_index); |
| 361 | return; |
| 362 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 363 | |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 364 | u8 *filter = 0, *name = 0; |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 365 | sw_if_index = ntohl (mp->sw_if_index); |
| 366 | |
Vratko Polak | b8591ac | 2019-04-23 12:26:44 +0200 | [diff] [blame] | 367 | if (!mp->name_filter_valid && sw_if_index != ~0 && sw_if_index != 0) |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 368 | { |
Vratko Polak | b8591ac | 2019-04-23 12:26:44 +0200 | [diff] [blame] | 369 | /* is it a valid sw_if_index? */ |
Neale Ranns | f5b0176 | 2019-06-14 08:26:21 +0000 | [diff] [blame] | 370 | if (!vnet_sw_if_index_is_api_valid (sw_if_index)) |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 371 | return; |
| 372 | |
| 373 | swif = vec_elt_at_index (im->sw_interfaces, sw_if_index); |
| 374 | |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 375 | vec_reset_length (name); |
| 376 | name = |
| 377 | format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main, |
| 378 | swif, 0); |
| 379 | send_sw_interface_details (am, rp, swif, name, mp->context); |
| 380 | vec_free (name); |
| 381 | return; |
| 382 | } |
| 383 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 384 | if (mp->name_filter_valid) |
| 385 | { |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 386 | filter = vl_api_from_api_to_new_vec (mp, &mp->name_filter); |
Aleksander Djuric | c12eae7 | 2019-10-31 14:35:21 +0300 | [diff] [blame] | 387 | vec_add1 (filter, 0); /* Ensure it's a C string for strcasecmp() */ |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 388 | } |
| 389 | |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 390 | pool_foreach (swif, im->sw_interfaces) |
| 391 | { |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 392 | if (!vnet_swif_is_api_visible (swif)) |
| 393 | continue; |
| 394 | vec_reset_length(name); |
| 395 | name = format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main, |
| 396 | swif, 0); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 397 | |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 398 | if (filter && !strcasestr((char *) name, (char *) filter)) |
| 399 | continue; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 400 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 401 | send_sw_interface_details (am, rp, swif, name, mp->context); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 402 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 403 | |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 404 | vec_free (name); |
| 405 | vec_free (filter); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | static void |
| 409 | vl_api_sw_interface_add_del_address_t_handler |
| 410 | (vl_api_sw_interface_add_del_address_t * mp) |
| 411 | { |
| 412 | vlib_main_t *vm = vlib_get_main (); |
Jon Loeliger | 35ffa3e | 2017-09-28 13:54:16 -0500 | [diff] [blame] | 413 | vnet_main_t *vnm = vnet_get_main (); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 414 | vl_api_sw_interface_add_del_address_reply_t *rmp; |
| 415 | int rv = 0; |
| 416 | u32 is_del; |
Jon Loeliger | 35ffa3e | 2017-09-28 13:54:16 -0500 | [diff] [blame] | 417 | clib_error_t *error = 0; |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 418 | ip46_address_t address; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 419 | |
| 420 | VALIDATE_SW_IF_INDEX (mp); |
| 421 | |
| 422 | is_del = mp->is_add == 0; |
Jon Loeliger | 35ffa3e | 2017-09-28 13:54:16 -0500 | [diff] [blame] | 423 | vnm->api_errno = 0; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 424 | |
| 425 | if (mp->del_all) |
| 426 | ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index)); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 427 | else if (ip_address_decode (&mp->prefix.address, &address) == IP46_TYPE_IP6) |
Jon Loeliger | 35ffa3e | 2017-09-28 13:54:16 -0500 | [diff] [blame] | 428 | error = ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index), |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 429 | (void *) &address.ip6, |
| 430 | mp->prefix.len, is_del); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 431 | else |
Jon Loeliger | 35ffa3e | 2017-09-28 13:54:16 -0500 | [diff] [blame] | 432 | error = ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index), |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 433 | (void *) &address.ip4, |
| 434 | mp->prefix.len, is_del); |
Jon Loeliger | 35ffa3e | 2017-09-28 13:54:16 -0500 | [diff] [blame] | 435 | |
| 436 | if (error) |
| 437 | { |
| 438 | rv = vnm->api_errno; |
| 439 | clib_error_report (error); |
| 440 | goto done; |
| 441 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 442 | |
| 443 | BAD_SW_IF_INDEX_LABEL; |
| 444 | |
Jon Loeliger | 35ffa3e | 2017-09-28 13:54:16 -0500 | [diff] [blame] | 445 | done: |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 446 | REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY); |
| 447 | } |
| 448 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 449 | static void |
| 450 | vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp) |
| 451 | { |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 452 | vl_api_sw_interface_set_table_reply_t *rmp; |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 453 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 454 | u32 table_id = ntohl (mp->vrf_id); |
| 455 | int rv = 0; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 456 | |
| 457 | VALIDATE_SW_IF_INDEX (mp); |
| 458 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 459 | if (mp->is_ipv6) |
Nathan Skrzypczak | 275bd79 | 2021-09-17 17:29:14 +0200 | [diff] [blame] | 460 | rv = ip_table_bind (FIB_PROTOCOL_IP6, sw_if_index, table_id); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 461 | else |
Nathan Skrzypczak | 275bd79 | 2021-09-17 17:29:14 +0200 | [diff] [blame] | 462 | rv = ip_table_bind (FIB_PROTOCOL_IP4, sw_if_index, table_id); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 463 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 464 | BAD_SW_IF_INDEX_LABEL; |
| 465 | |
| 466 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY); |
| 467 | } |
| 468 | |
Nathan Skrzypczak | a424dd1 | 2021-08-20 15:53:43 +0200 | [diff] [blame] | 469 | void |
| 470 | fib_table_bind (fib_protocol_t fproto, u32 sw_if_index, u32 fib_index) |
| 471 | { |
| 472 | u32 table_id; |
| 473 | |
| 474 | table_id = fib_table_get_table_id (fib_index, fproto); |
| 475 | ASSERT (table_id != ~0); |
| 476 | |
| 477 | if (FIB_PROTOCOL_IP6 == fproto) |
| 478 | { |
| 479 | /* |
| 480 | * tell those that are interested that the binding is changing. |
| 481 | */ |
| 482 | ip6_table_bind_callback_t *cb; |
| 483 | vec_foreach (cb, ip6_main.table_bind_callbacks) |
| 484 | cb->function (&ip6_main, cb->function_opaque, |
| 485 | sw_if_index, |
| 486 | fib_index, |
| 487 | ip6_main.fib_index_by_sw_if_index[sw_if_index]); |
| 488 | |
| 489 | /* unlock currently assigned tables */ |
| 490 | if (0 != ip6_main.fib_index_by_sw_if_index[sw_if_index]) |
| 491 | fib_table_unlock (ip6_main.fib_index_by_sw_if_index[sw_if_index], |
| 492 | FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE); |
| 493 | |
| 494 | if (0 != table_id) |
| 495 | { |
| 496 | /* we need to lock the table now it's inuse */ |
| 497 | fib_table_lock (fib_index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE); |
| 498 | } |
| 499 | |
| 500 | ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | /* |
| 505 | * tell those that are interested that the binding is changing. |
| 506 | */ |
| 507 | ip4_table_bind_callback_t *cb; |
| 508 | vec_foreach (cb, ip4_main.table_bind_callbacks) |
| 509 | cb->function (&ip4_main, cb->function_opaque, |
| 510 | sw_if_index, |
| 511 | fib_index, |
| 512 | ip4_main.fib_index_by_sw_if_index[sw_if_index]); |
| 513 | |
| 514 | /* unlock currently assigned tables */ |
| 515 | if (0 != ip4_main.fib_index_by_sw_if_index[sw_if_index]) |
| 516 | fib_table_unlock (ip4_main.fib_index_by_sw_if_index[sw_if_index], |
| 517 | FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE); |
| 518 | |
| 519 | if (0 != table_id) |
| 520 | { |
| 521 | /* we need to lock the table now it's inuse */ |
| 522 | fib_index = fib_table_find_or_create_and_lock ( |
| 523 | FIB_PROTOCOL_IP4, table_id, FIB_SOURCE_INTERFACE); |
| 524 | } |
| 525 | |
| 526 | ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | void |
| 531 | mfib_table_bind (fib_protocol_t fproto, u32 sw_if_index, u32 mfib_index) |
| 532 | { |
| 533 | u32 table_id; |
| 534 | |
| 535 | table_id = mfib_table_get_table_id (mfib_index, fproto); |
| 536 | ASSERT (table_id != ~0); |
| 537 | |
| 538 | if (FIB_PROTOCOL_IP6 == fproto) |
| 539 | { |
| 540 | if (0 != ip6_main.mfib_index_by_sw_if_index[sw_if_index]) |
| 541 | mfib_table_unlock (ip6_main.mfib_index_by_sw_if_index[sw_if_index], |
| 542 | FIB_PROTOCOL_IP6, MFIB_SOURCE_INTERFACE); |
| 543 | |
| 544 | if (0 != table_id) |
| 545 | { |
| 546 | /* we need to lock the table now it's inuse */ |
| 547 | mfib_table_lock (mfib_index, FIB_PROTOCOL_IP6, |
| 548 | MFIB_SOURCE_INTERFACE); |
| 549 | } |
| 550 | |
| 551 | ip6_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index; |
| 552 | } |
| 553 | else |
| 554 | { |
| 555 | if (0 != ip4_main.mfib_index_by_sw_if_index[sw_if_index]) |
| 556 | mfib_table_unlock (ip4_main.mfib_index_by_sw_if_index[sw_if_index], |
| 557 | FIB_PROTOCOL_IP4, MFIB_SOURCE_INTERFACE); |
| 558 | |
| 559 | if (0 != table_id) |
| 560 | { |
| 561 | /* we need to lock the table now it's inuse */ |
| 562 | mfib_index = mfib_table_find_or_create_and_lock ( |
| 563 | FIB_PROTOCOL_IP4, table_id, MFIB_SOURCE_INTERFACE); |
| 564 | } |
| 565 | |
| 566 | ip4_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index; |
| 567 | } |
| 568 | } |
| 569 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 570 | int |
Nathan Skrzypczak | 275bd79 | 2021-09-17 17:29:14 +0200 | [diff] [blame] | 571 | ip_table_bind (fib_protocol_t fproto, u32 sw_if_index, u32 table_id) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 572 | { |
| 573 | CLIB_UNUSED (ip_interface_address_t * ia); |
| 574 | u32 fib_index, mfib_index; |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 575 | |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 576 | /* |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 577 | * This if table does not exist = error is what we want in the end. |
| 578 | */ |
Neale Ranns | 8f6dd32 | 2018-05-17 06:34:24 -0700 | [diff] [blame] | 579 | fib_index = fib_table_find (fproto, table_id); |
| 580 | mfib_index = mfib_table_find (fproto, table_id); |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 581 | |
Neale Ranns | 8f6dd32 | 2018-05-17 06:34:24 -0700 | [diff] [blame] | 582 | if (~0 == fib_index || ~0 == mfib_index) |
| 583 | { |
| 584 | return (VNET_API_ERROR_NO_SUCH_FIB); |
| 585 | } |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 586 | |
Nathan Skrzypczak | a424dd1 | 2021-08-20 15:53:43 +0200 | [diff] [blame] | 587 | /* |
| 588 | * If the interface already has in IP address, then a change int |
| 589 | * VRF is not allowed. The IP address applied must first be removed. |
| 590 | * We do not do that automatically here, since VPP has no knowledge |
| 591 | * of whether those subnets are valid in the destination VRF. |
| 592 | */ |
| 593 | /* clang-format off */ |
| 594 | foreach_ip_interface_address (FIB_PROTOCOL_IP6 == fproto ? |
| 595 | &ip6_main.lookup_main : &ip4_main.lookup_main, |
| 596 | ia, sw_if_index, |
| 597 | 1 /* honor unnumbered */ , |
| 598 | ({ |
| 599 | return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE); |
| 600 | })); |
| 601 | /* clang-format on */ |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 602 | |
Nathan Skrzypczak | a424dd1 | 2021-08-20 15:53:43 +0200 | [diff] [blame] | 603 | fib_table_bind (fproto, sw_if_index, fib_index); |
| 604 | mfib_table_bind (fproto, sw_if_index, mfib_index); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 605 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 606 | return (0); |
| 607 | } |
| 608 | |
Juraj Sloboda | dfc1923 | 2016-12-05 13:20:37 +0100 | [diff] [blame] | 609 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 610 | send_sw_interface_get_table_reply (vl_api_registration_t * reg, |
Juraj Sloboda | dfc1923 | 2016-12-05 13:20:37 +0100 | [diff] [blame] | 611 | u32 context, int retval, u32 vrf_id) |
| 612 | { |
| 613 | vl_api_sw_interface_get_table_reply_t *mp; |
| 614 | |
| 615 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 616 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 617 | mp->_vl_msg_id = |
| 618 | ntohs (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_GET_TABLE_REPLY); |
Juraj Sloboda | dfc1923 | 2016-12-05 13:20:37 +0100 | [diff] [blame] | 619 | mp->context = context; |
| 620 | mp->retval = htonl (retval); |
| 621 | mp->vrf_id = htonl (vrf_id); |
| 622 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 623 | vl_api_send_msg (reg, (u8 *) mp); |
Juraj Sloboda | dfc1923 | 2016-12-05 13:20:37 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static void |
| 627 | vl_api_sw_interface_get_table_t_handler (vl_api_sw_interface_get_table_t * mp) |
| 628 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 629 | vl_api_registration_t *reg; |
Juraj Sloboda | dfc1923 | 2016-12-05 13:20:37 +0100 | [diff] [blame] | 630 | fib_table_t *fib_table = 0; |
| 631 | u32 sw_if_index = ~0; |
| 632 | u32 fib_index = ~0; |
| 633 | u32 table_id = ~0; |
| 634 | fib_protocol_t fib_proto = FIB_PROTOCOL_IP4; |
| 635 | int rv = 0; |
| 636 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 637 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 638 | if (!reg) |
Juraj Sloboda | dfc1923 | 2016-12-05 13:20:37 +0100 | [diff] [blame] | 639 | return; |
| 640 | |
| 641 | VALIDATE_SW_IF_INDEX (mp); |
| 642 | |
| 643 | sw_if_index = ntohl (mp->sw_if_index); |
| 644 | |
| 645 | if (mp->is_ipv6) |
| 646 | fib_proto = FIB_PROTOCOL_IP6; |
| 647 | |
| 648 | fib_index = fib_table_get_index_for_sw_if_index (fib_proto, sw_if_index); |
| 649 | if (fib_index != ~0) |
| 650 | { |
| 651 | fib_table = fib_table_get (fib_index, fib_proto); |
| 652 | table_id = fib_table->ft_table_id; |
| 653 | } |
| 654 | |
| 655 | BAD_SW_IF_INDEX_LABEL; |
| 656 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 657 | send_sw_interface_get_table_reply (reg, mp->context, rv, table_id); |
Juraj Sloboda | dfc1923 | 2016-12-05 13:20:37 +0100 | [diff] [blame] | 658 | } |
| 659 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 660 | static void vl_api_sw_interface_set_unnumbered_t_handler |
| 661 | (vl_api_sw_interface_set_unnumbered_t * mp) |
| 662 | { |
| 663 | vl_api_sw_interface_set_unnumbered_reply_t *rmp; |
| 664 | int rv = 0; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 665 | vnet_main_t *vnm = vnet_get_main (); |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 666 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 667 | u32 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 668 | |
| 669 | /* |
| 670 | * The API message field names are backwards from |
| 671 | * the underlying data structure names. |
| 672 | * It's not worth changing them now. |
| 673 | */ |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 674 | if (!vnet_sw_interface_is_api_valid (vnm, unnumbered_sw_if_index)) |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 675 | { |
| 676 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 677 | goto done; |
| 678 | } |
| 679 | |
| 680 | /* Only check the "use loop0" field when setting the binding */ |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 681 | if (mp->is_add && !vnet_sw_interface_is_api_valid (vnm, sw_if_index)) |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 682 | { |
| 683 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2; |
| 684 | goto done; |
| 685 | } |
| 686 | |
Stanislav Zaikin | 328b5da | 2021-07-15 16:27:29 +0200 | [diff] [blame] | 687 | rv = vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index, |
| 688 | sw_if_index, mp->is_add); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 689 | done: |
| 690 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY); |
| 691 | } |
| 692 | |
| 693 | static void |
| 694 | vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t * |
| 695 | mp) |
| 696 | { |
| 697 | vl_api_sw_interface_clear_stats_reply_t *rmp; |
| 698 | |
| 699 | vnet_main_t *vnm = vnet_get_main (); |
| 700 | vnet_interface_main_t *im = &vnm->interface_main; |
| 701 | vlib_simple_counter_main_t *sm; |
| 702 | vlib_combined_counter_main_t *cm; |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 703 | int j, n_counters; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 704 | int rv = 0; |
| 705 | |
| 706 | if (mp->sw_if_index != ~0) |
| 707 | VALIDATE_SW_IF_INDEX (mp); |
| 708 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 709 | n_counters = vec_len (im->combined_sw_if_counters); |
| 710 | |
| 711 | for (j = 0; j < n_counters; j++) |
| 712 | { |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 713 | im = &vnm->interface_main; |
| 714 | cm = im->combined_sw_if_counters + j; |
| 715 | if (mp->sw_if_index == (u32) ~ 0) |
| 716 | vlib_clear_combined_counters (cm); |
| 717 | else |
| 718 | vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index)); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | n_counters = vec_len (im->sw_if_counters); |
| 722 | |
| 723 | for (j = 0; j < n_counters; j++) |
| 724 | { |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 725 | im = &vnm->interface_main; |
| 726 | sm = im->sw_if_counters + j; |
| 727 | if (mp->sw_if_index == (u32) ~ 0) |
| 728 | vlib_clear_simple_counters (sm); |
| 729 | else |
| 730 | vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index)); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | BAD_SW_IF_INDEX_LABEL; |
| 734 | |
| 735 | REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY); |
| 736 | } |
| 737 | |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 738 | /* |
| 739 | * Events used for sw_interface_events |
| 740 | */ |
| 741 | enum api_events |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 742 | { |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 743 | API_LINK_STATE_UP_EVENT = 1 << 1, |
| 744 | API_LINK_STATE_DOWN_EVENT = 1 << 2, |
| 745 | API_ADMIN_UP_EVENT = 1 << 3, |
| 746 | API_ADMIN_DOWN_EVENT = 1 << 4, |
| 747 | API_SW_INTERFACE_ADD_EVENT = 1 << 5, |
| 748 | API_SW_INTERFACE_DEL_EVENT = 1 << 6, |
| 749 | }; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 750 | |
| 751 | static void |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 752 | send_sw_interface_event (vpe_api_main_t * am, |
Neale Ranns | d292ab1 | 2017-08-15 12:29:48 -0700 | [diff] [blame] | 753 | vpe_client_registration_t * reg, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 754 | vl_api_registration_t * vl_reg, |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 755 | u32 sw_if_index, enum api_events events) |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 756 | { |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 757 | vl_api_sw_interface_event_t *mp; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 758 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 759 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 760 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 761 | mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_EVENT); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 762 | mp->sw_if_index = ntohl (sw_if_index); |
Neale Ranns | d292ab1 | 2017-08-15 12:29:48 -0700 | [diff] [blame] | 763 | mp->client_index = reg->client_index; |
| 764 | mp->pid = reg->client_pid; |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 765 | mp->flags = 0; |
| 766 | mp->flags |= (events & API_ADMIN_UP_EVENT) ? |
| 767 | IF_STATUS_API_FLAG_ADMIN_UP : 0; |
| 768 | mp->flags |= (events & API_LINK_STATE_UP_EVENT) ? |
| 769 | IF_STATUS_API_FLAG_LINK_UP : 0; |
| 770 | mp->flags = ntohl (mp->flags); |
| 771 | mp->deleted = events & API_SW_INTERFACE_DEL_EVENT ? true : false; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 772 | vl_api_send_msg (vl_reg, (u8 *) mp); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | static uword |
| 776 | link_state_process (vlib_main_t * vm, |
| 777 | vlib_node_runtime_t * rt, vlib_frame_t * f) |
| 778 | { |
| 779 | vpe_api_main_t *vam = &vpe_api_main; |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 780 | uword *event_by_sw_if_index = 0; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 781 | vpe_client_registration_t *reg; |
| 782 | int i; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 783 | vl_api_registration_t *vl_reg; |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 784 | uword event_type; |
| 785 | uword *event_data = 0; |
| 786 | u32 sw_if_index; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 787 | |
| 788 | vam->link_state_process_up = 1; |
| 789 | |
| 790 | while (1) |
| 791 | { |
| 792 | vlib_process_wait_for_event (vm); |
| 793 | |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 794 | /* Batch up events */ |
| 795 | while ((event_type = vlib_process_get_events (vm, &event_data)) != ~0) |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 796 | { |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 797 | for (i = 0; i < vec_len (event_data); i++) |
| 798 | { |
| 799 | sw_if_index = event_data[i]; |
| 800 | vec_validate_init_empty (event_by_sw_if_index, sw_if_index, 0); |
| 801 | event_by_sw_if_index[sw_if_index] |= event_type; |
| 802 | } |
| 803 | vec_reset_length (event_data); |
| 804 | } |
| 805 | |
| 806 | for (i = 0; i < vec_len (event_by_sw_if_index); i++) |
| 807 | { |
| 808 | if (event_by_sw_if_index[i] == 0) |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 809 | continue; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 810 | |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 811 | pool_foreach (reg, vam->interface_events_registrations) |
| 812 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 813 | vl_reg = vl_api_client_index_to_registration (reg->client_index); |
| 814 | if (vl_reg) |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 815 | send_sw_interface_event (vam, reg, vl_reg, i, event_by_sw_if_index[i]); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 816 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 817 | } |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 818 | vec_reset_length (event_by_sw_if_index); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index, |
| 825 | u32 flags); |
| 826 | static clib_error_t *admin_up_down_function (vnet_main_t * vm, |
| 827 | u32 hw_if_index, u32 flags); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 828 | static clib_error_t *sw_interface_add_del_function (vnet_main_t * vm, |
| 829 | u32 sw_if_index, |
| 830 | u32 flags); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 831 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 832 | VLIB_REGISTER_NODE (link_state_process_node,static) = { |
| 833 | .function = link_state_process, |
| 834 | .type = VLIB_NODE_TYPE_PROCESS, |
| 835 | .name = "vpe-link-state-process", |
| 836 | }; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 837 | |
| 838 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function); |
| 839 | VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 840 | VNET_SW_INTERFACE_ADD_DEL_FUNCTION (sw_interface_add_del_function); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 841 | |
| 842 | static clib_error_t * |
| 843 | link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags) |
| 844 | { |
| 845 | vpe_api_main_t *vam = &vpe_api_main; |
| 846 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index); |
| 847 | |
| 848 | if (vam->link_state_process_up) |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 849 | { |
Alexander Chernavin | aa27dcb | 2019-11-06 09:58:18 -0500 | [diff] [blame] | 850 | enum api_events event = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? |
| 851 | API_LINK_STATE_UP_EVENT : |
| 852 | API_LINK_STATE_DOWN_EVENT); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 853 | vlib_process_signal_event (vam->vlib_main, |
| 854 | link_state_process_node.index, event, |
| 855 | hi->sw_if_index); |
| 856 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static clib_error_t * |
| 861 | admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags) |
| 862 | { |
| 863 | vpe_api_main_t *vam = &vpe_api_main; |
| 864 | |
| 865 | /* |
| 866 | * Note: it's perfectly fair to set a subif admin up / admin down. |
| 867 | * Note the subtle distinction between this routine and the previous |
| 868 | * routine. |
| 869 | */ |
| 870 | if (vam->link_state_process_up) |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 871 | { |
Alexander Chernavin | aa27dcb | 2019-11-06 09:58:18 -0500 | [diff] [blame] | 872 | enum api_events event = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
| 873 | API_ADMIN_UP_EVENT : API_ADMIN_DOWN_EVENT); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 874 | vlib_process_signal_event (vam->vlib_main, |
| 875 | link_state_process_node.index, event, |
| 876 | sw_if_index); |
| 877 | } |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | static clib_error_t * |
| 882 | sw_interface_add_del_function (vnet_main_t * vm, u32 sw_if_index, u32 flags) |
| 883 | { |
| 884 | vpe_api_main_t *vam = &vpe_api_main; |
| 885 | |
| 886 | if (vam->link_state_process_up) |
| 887 | { |
| 888 | enum api_events event = |
| 889 | flags ? API_SW_INTERFACE_ADD_EVENT : API_SW_INTERFACE_DEL_EVENT; |
| 890 | vlib_process_signal_event (vam->vlib_main, |
| 891 | link_state_process_node.index, event, |
| 892 | sw_if_index); |
| 893 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | static void vl_api_sw_interface_tag_add_del_t_handler |
| 898 | (vl_api_sw_interface_tag_add_del_t * mp) |
| 899 | { |
| 900 | vnet_main_t *vnm = vnet_get_main (); |
| 901 | vl_api_sw_interface_tag_add_del_reply_t *rmp; |
| 902 | int rv = 0; |
| 903 | u8 *tag; |
| 904 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 905 | |
| 906 | VALIDATE_SW_IF_INDEX (mp); |
| 907 | |
| 908 | if (mp->is_add) |
| 909 | { |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 910 | if (mp->tag[0] == 0) |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 911 | { |
| 912 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 913 | goto out; |
| 914 | } |
| 915 | |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 916 | mp->tag[ARRAY_LEN (mp->tag) - 1] = 0; |
| 917 | tag = format (0, "%s%c", mp->tag, 0); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 918 | vnet_set_sw_interface_tag (vnm, tag, sw_if_index); |
| 919 | } |
| 920 | else |
| 921 | vnet_clear_sw_interface_tag (vnm, sw_if_index); |
| 922 | |
| 923 | BAD_SW_IF_INDEX_LABEL; |
| 924 | out: |
| 925 | REPLY_MACRO (VL_API_SW_INTERFACE_TAG_ADD_DEL_REPLY); |
| 926 | } |
| 927 | |
Matthew Smith | e0792fd | 2019-07-12 11:48:24 -0500 | [diff] [blame] | 928 | static void vl_api_sw_interface_add_del_mac_address_t_handler |
| 929 | (vl_api_sw_interface_add_del_mac_address_t * mp) |
| 930 | { |
| 931 | vl_api_sw_interface_add_del_mac_address_reply_t *rmp; |
| 932 | vnet_main_t *vnm = vnet_get_main (); |
| 933 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 934 | vnet_hw_interface_t *hi; |
| 935 | clib_error_t *error; |
| 936 | int rv = 0; |
| 937 | |
| 938 | VALIDATE_SW_IF_INDEX (mp); |
| 939 | |
| 940 | /* for subifs, the MAC should be changed on the actual hw if */ |
| 941 | hi = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 942 | error = vnet_hw_interface_add_del_mac_address (vnm, hi->hw_if_index, |
| 943 | mp->addr, mp->is_add); |
| 944 | if (error) |
| 945 | { |
| 946 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 947 | clib_error_report (error); |
| 948 | goto out; |
| 949 | } |
| 950 | |
| 951 | BAD_SW_IF_INDEX_LABEL; |
| 952 | out: |
| 953 | REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY); |
| 954 | } |
| 955 | |
Jon Loeliger | 10c273b | 2017-03-30 08:39:33 -0500 | [diff] [blame] | 956 | static void vl_api_sw_interface_set_mac_address_t_handler |
| 957 | (vl_api_sw_interface_set_mac_address_t * mp) |
| 958 | { |
| 959 | vl_api_sw_interface_set_mac_address_reply_t *rmp; |
| 960 | vnet_main_t *vnm = vnet_get_main (); |
| 961 | u32 sw_if_index = ntohl (mp->sw_if_index); |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 962 | vnet_sw_interface_t *si; |
Jon Loeliger | 10c273b | 2017-03-30 08:39:33 -0500 | [diff] [blame] | 963 | clib_error_t *error; |
| 964 | int rv = 0; |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 965 | mac_address_t mac; |
Jon Loeliger | 10c273b | 2017-03-30 08:39:33 -0500 | [diff] [blame] | 966 | |
| 967 | VALIDATE_SW_IF_INDEX (mp); |
| 968 | |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 969 | si = vnet_get_sw_interface (vnm, sw_if_index); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 970 | mac_address_decode (mp->mac_address, &mac); |
| 971 | error = |
| 972 | vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, (u8 *) & mac); |
Jon Loeliger | 10c273b | 2017-03-30 08:39:33 -0500 | [diff] [blame] | 973 | if (error) |
| 974 | { |
| 975 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 976 | clib_error_report (error); |
| 977 | goto out; |
| 978 | } |
| 979 | |
| 980 | BAD_SW_IF_INDEX_LABEL; |
| 981 | out: |
| 982 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_MAC_ADDRESS_REPLY); |
| 983 | } |
| 984 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 985 | static void vl_api_sw_interface_get_mac_address_t_handler |
| 986 | (vl_api_sw_interface_get_mac_address_t * mp) |
| 987 | { |
| 988 | vl_api_sw_interface_get_mac_address_reply_t *rmp; |
| 989 | vl_api_registration_t *reg; |
| 990 | vnet_main_t *vnm = vnet_get_main (); |
| 991 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 992 | vnet_sw_interface_t *si; |
| 993 | ethernet_interface_t *eth_if = 0; |
| 994 | int rv = 0; |
| 995 | |
| 996 | VALIDATE_SW_IF_INDEX (mp); |
| 997 | |
| 998 | si = vnet_get_sup_sw_interface (vnm, sw_if_index); |
| 999 | if (si->type == VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1000 | eth_if = ethernet_get_interface (ðernet_main, si->hw_if_index); |
| 1001 | |
| 1002 | BAD_SW_IF_INDEX_LABEL; |
| 1003 | |
| 1004 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1005 | if (!reg) |
| 1006 | return; |
| 1007 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1008 | rmp->_vl_msg_id = |
| 1009 | htons (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_GET_MAC_ADDRESS_REPLY); |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1010 | rmp->context = mp->context; |
| 1011 | rmp->retval = htonl (rv); |
| 1012 | if (!rv && eth_if) |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1013 | mac_address_encode (ð_if->address.mac, rmp->mac_address); |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1014 | vl_api_send_msg (reg, (u8 *) rmp); |
| 1015 | } |
| 1016 | |
Steven Luong | f49734d | 2021-07-26 13:38:05 -0700 | [diff] [blame] | 1017 | static void |
| 1018 | vl_api_sw_interface_set_interface_name_t_handler ( |
| 1019 | vl_api_sw_interface_set_interface_name_t *mp) |
| 1020 | { |
| 1021 | vl_api_sw_interface_set_interface_name_reply_t *rmp; |
| 1022 | vnet_main_t *vnm = vnet_get_main (); |
| 1023 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1024 | vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1025 | clib_error_t *error; |
| 1026 | int rv = 0; |
| 1027 | |
| 1028 | if (mp->name[0] == 0) |
| 1029 | { |
| 1030 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1031 | goto out; |
| 1032 | } |
| 1033 | if (si == 0) |
| 1034 | { |
| 1035 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1036 | goto out; |
| 1037 | } |
| 1038 | |
| 1039 | error = vnet_rename_interface (vnm, si->hw_if_index, (char *) mp->name); |
| 1040 | if (error) |
| 1041 | { |
| 1042 | clib_error_free (error); |
| 1043 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1044 | } |
| 1045 | |
| 1046 | out: |
| 1047 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_INTERFACE_NAME_REPLY); |
| 1048 | } |
| 1049 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1050 | static void vl_api_sw_interface_set_rx_mode_t_handler |
| 1051 | (vl_api_sw_interface_set_rx_mode_t * mp) |
| 1052 | { |
| 1053 | vl_api_sw_interface_set_rx_mode_reply_t *rmp; |
| 1054 | vnet_main_t *vnm = vnet_get_main (); |
| 1055 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1056 | vnet_sw_interface_t *si; |
| 1057 | clib_error_t *error; |
| 1058 | int rv = 0; |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1059 | vnet_hw_if_rx_mode rx_mode; |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1060 | |
| 1061 | VALIDATE_SW_IF_INDEX (mp); |
| 1062 | |
| 1063 | si = vnet_get_sw_interface (vnm, sw_if_index); |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1064 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1065 | { |
| 1066 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1067 | goto bad_sw_if_index; |
| 1068 | } |
| 1069 | |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1070 | rx_mode = (vnet_hw_if_rx_mode) ntohl (mp->mode); |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1071 | error = set_hw_interface_change_rx_mode (vnm, si->hw_if_index, |
| 1072 | mp->queue_id_valid, |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1073 | ntohl (mp->queue_id), |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1074 | (vnet_hw_if_rx_mode) rx_mode); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1075 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1076 | if (error) |
| 1077 | { |
| 1078 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 1079 | clib_error_report (error); |
| 1080 | goto out; |
| 1081 | } |
| 1082 | |
| 1083 | BAD_SW_IF_INDEX_LABEL; |
| 1084 | out: |
| 1085 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_MODE_REPLY); |
| 1086 | } |
| 1087 | |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1088 | static void |
| 1089 | send_interface_rx_placement_details (vpe_api_main_t * am, |
| 1090 | vl_api_registration_t * rp, |
| 1091 | u32 sw_if_index, u32 worker_id, |
| 1092 | u32 queue_id, u8 mode, u32 context) |
| 1093 | { |
| 1094 | vl_api_sw_interface_rx_placement_details_t *mp; |
| 1095 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1096 | clib_memset (mp, 0, sizeof (*mp)); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1097 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1098 | mp->_vl_msg_id = |
| 1099 | htons (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_RX_PLACEMENT_DETAILS); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1100 | mp->sw_if_index = htonl (sw_if_index); |
| 1101 | mp->queue_id = htonl (queue_id); |
| 1102 | mp->worker_id = htonl (worker_id); |
Jakub Grajciar | e30f1e9 | 2020-05-05 12:30:30 +0200 | [diff] [blame] | 1103 | mp->mode = htonl (mode); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1104 | mp->context = context; |
| 1105 | |
| 1106 | vl_api_send_msg (rp, (u8 *) mp); |
| 1107 | } |
| 1108 | |
| 1109 | static void vl_api_sw_interface_rx_placement_dump_t_handler |
| 1110 | (vl_api_sw_interface_rx_placement_dump_t * mp) |
| 1111 | { |
| 1112 | vnet_main_t *vnm = vnet_get_main (); |
| 1113 | vpe_api_main_t *am = &vpe_api_main; |
| 1114 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1115 | vl_api_registration_t *reg; |
| 1116 | |
| 1117 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1118 | if (!reg) |
| 1119 | return; |
| 1120 | |
| 1121 | if (sw_if_index == ~0) |
| 1122 | { |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1123 | vnet_hw_if_rx_queue_t **all_queues = 0; |
| 1124 | vnet_hw_if_rx_queue_t **qptr; |
| 1125 | vnet_hw_if_rx_queue_t *q; |
Nathan Skrzypczak | 455779f | 2021-02-15 14:48:33 +0100 | [diff] [blame] | 1126 | pool_foreach (q, vnm->interface_main.hw_if_rx_queues) |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1127 | vec_add1 (all_queues, q); |
| 1128 | vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1129 | |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1130 | vec_foreach (qptr, all_queues) |
| 1131 | { |
| 1132 | u32 current_thread = qptr[0]->thread_index; |
| 1133 | u32 hw_if_index = qptr[0]->hw_if_index; |
| 1134 | vnet_hw_interface_t *hw_if = |
| 1135 | vnet_get_hw_interface (vnm, hw_if_index); |
| 1136 | send_interface_rx_placement_details ( |
| 1137 | am, reg, hw_if->sw_if_index, current_thread, qptr[0]->queue_id, |
| 1138 | qptr[0]->mode, mp->context); |
| 1139 | } |
| 1140 | vec_free (all_queues); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1141 | } |
| 1142 | else |
| 1143 | { |
| 1144 | int i; |
| 1145 | vnet_sw_interface_t *si; |
| 1146 | |
| 1147 | if (!vnet_sw_if_index_is_api_valid (sw_if_index)) |
| 1148 | { |
| 1149 | clib_warning ("sw_if_index %u does not exist", sw_if_index); |
| 1150 | goto bad_sw_if_index; |
| 1151 | } |
| 1152 | |
| 1153 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1154 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1155 | { |
| 1156 | clib_warning ("interface type is not HARDWARE! P2P, PIPE and SUB" |
| 1157 | " interfaces are not supported"); |
| 1158 | goto bad_sw_if_index; |
| 1159 | } |
| 1160 | |
| 1161 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, si->hw_if_index); |
| 1162 | |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1163 | for (i = 0; i < vec_len (hw->rx_queue_indices); i++) |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1164 | { |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1165 | vnet_hw_if_rx_queue_t *rxq = |
| 1166 | vnet_hw_if_get_rx_queue (vnm, hw->rx_queue_indices[i]); |
| 1167 | send_interface_rx_placement_details ( |
| 1168 | am, reg, hw->sw_if_index, rxq->thread_index, rxq->queue_id, |
| 1169 | rxq->mode, mp->context); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | BAD_SW_IF_INDEX_LABEL; |
| 1174 | } |
| 1175 | |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1176 | static void vl_api_sw_interface_set_rx_placement_t_handler |
| 1177 | (vl_api_sw_interface_set_rx_placement_t * mp) |
| 1178 | { |
| 1179 | vl_api_sw_interface_set_rx_placement_reply_t *rmp; |
| 1180 | vnet_main_t *vnm = vnet_get_main (); |
| 1181 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1182 | vnet_sw_interface_t *si; |
| 1183 | clib_error_t *error = 0; |
| 1184 | int rv = 0; |
| 1185 | |
| 1186 | VALIDATE_SW_IF_INDEX (mp); |
| 1187 | |
| 1188 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1189 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1190 | { |
| 1191 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1192 | goto bad_sw_if_index; |
| 1193 | } |
| 1194 | |
| 1195 | error = set_hw_interface_rx_placement (si->hw_if_index, |
| 1196 | ntohl (mp->queue_id), |
| 1197 | ntohl (mp->worker_id), mp->is_main); |
| 1198 | if (error) |
| 1199 | { |
| 1200 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 1201 | clib_error_report (error); |
| 1202 | goto out; |
| 1203 | } |
| 1204 | |
| 1205 | BAD_SW_IF_INDEX_LABEL; |
| 1206 | out: |
| 1207 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_PLACEMENT_REPLY); |
| 1208 | } |
| 1209 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1210 | static void |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1211 | send_interface_tx_placement_details (vnet_hw_if_tx_queue_t **all_queues, |
| 1212 | u32 index, vl_api_registration_t *rp, |
Dave Wallace | 39c40fa | 2023-06-06 12:05:30 -0400 | [diff] [blame] | 1213 | u32 context) |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1214 | { |
| 1215 | vnet_main_t *vnm = vnet_get_main (); |
| 1216 | vl_api_sw_interface_tx_placement_details_t *rmp; |
| 1217 | u32 n_bits = 0, v = ~0; |
| 1218 | vnet_hw_if_tx_queue_t **q = vec_elt_at_index (all_queues, index); |
| 1219 | uword *bitmap = q[0]->threads; |
| 1220 | u32 hw_if_index = q[0]->hw_if_index; |
| 1221 | vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index); |
| 1222 | |
| 1223 | n_bits = clib_bitmap_count_set_bits (bitmap); |
| 1224 | u32 n = n_bits * sizeof (u32); |
| 1225 | |
Stanislav Zaikin | 139b2da | 2022-07-21 19:06:26 +0200 | [diff] [blame] | 1226 | REPLY_MACRO_DETAILS5_END (VL_API_SW_INTERFACE_TX_PLACEMENT_DETAILS, n, rp, |
| 1227 | context, ({ |
| 1228 | rmp->sw_if_index = hw_if->sw_if_index; |
| 1229 | rmp->queue_id = q[0]->queue_id; |
| 1230 | rmp->shared = q[0]->shared_queue; |
| 1231 | rmp->array_size = n_bits; |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1232 | |
Stanislav Zaikin | 139b2da | 2022-07-21 19:06:26 +0200 | [diff] [blame] | 1233 | v = clib_bitmap_first_set (bitmap); |
| 1234 | for (u32 i = 0; i < n_bits; i++) |
| 1235 | { |
| 1236 | rmp->threads[i] = v; |
| 1237 | v = clib_bitmap_next_set (bitmap, v + 1); |
| 1238 | } |
| 1239 | })); |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | static void |
| 1243 | vl_api_sw_interface_tx_placement_get_t_handler ( |
| 1244 | vl_api_sw_interface_tx_placement_get_t *mp) |
| 1245 | { |
| 1246 | vnet_main_t *vnm = vnet_get_main (); |
| 1247 | vl_api_sw_interface_tx_placement_get_reply_t *rmp = 0; |
| 1248 | vnet_hw_if_tx_queue_t **all_queues = 0; |
| 1249 | vnet_hw_if_tx_queue_t *q; |
| 1250 | u32 sw_if_index = mp->sw_if_index; |
| 1251 | i32 rv = 0; |
| 1252 | |
| 1253 | if (pool_elts (vnm->interface_main.hw_if_tx_queues) == 0) |
| 1254 | { |
| 1255 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 1256 | goto err; |
| 1257 | } |
| 1258 | |
| 1259 | if (sw_if_index == ~0) |
| 1260 | { |
| 1261 | pool_foreach (q, vnm->interface_main.hw_if_tx_queues) |
| 1262 | vec_add1 (all_queues, q); |
| 1263 | vec_sort_with_function (all_queues, vnet_hw_if_txq_cmp_cli_api); |
| 1264 | } |
| 1265 | else |
| 1266 | { |
| 1267 | u32 qi = ~0; |
| 1268 | vnet_sw_interface_t *si; |
| 1269 | |
| 1270 | if (!vnet_sw_if_index_is_api_valid (sw_if_index)) |
| 1271 | { |
| 1272 | clib_warning ("sw_if_index %u does not exist", sw_if_index); |
| 1273 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1274 | goto err; |
| 1275 | } |
| 1276 | |
| 1277 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1278 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1279 | { |
| 1280 | clib_warning ("interface type is not HARDWARE! P2P, PIPE and SUB" |
| 1281 | " interfaces are not supported"); |
| 1282 | rv = VNET_API_ERROR_INVALID_INTERFACE; |
| 1283 | goto err; |
| 1284 | } |
| 1285 | |
| 1286 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, si->hw_if_index); |
| 1287 | for (qi = 0; qi < vec_len (hw->tx_queue_indices); qi++) |
| 1288 | { |
| 1289 | q = vnet_hw_if_get_tx_queue (vnm, hw->tx_queue_indices[qi]); |
| 1290 | vec_add1 (all_queues, q); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | REPLY_AND_DETAILS_VEC_MACRO_END (VL_API_SW_INTERFACE_TX_PLACEMENT_GET_REPLY, |
| 1295 | all_queues, mp, rmp, rv, ({ |
| 1296 | send_interface_tx_placement_details ( |
| 1297 | all_queues, cursor, rp, mp->context); |
| 1298 | })); |
| 1299 | |
| 1300 | vec_free (all_queues); |
| 1301 | return; |
| 1302 | |
| 1303 | err: |
| 1304 | REPLY_MACRO_END (VL_API_SW_INTERFACE_TX_PLACEMENT_GET_REPLY); |
| 1305 | } |
| 1306 | |
| 1307 | static void |
| 1308 | vl_api_sw_interface_set_tx_placement_t_handler ( |
| 1309 | vl_api_sw_interface_set_tx_placement_t *mp) |
| 1310 | { |
| 1311 | vl_api_sw_interface_set_tx_placement_reply_t *rmp; |
| 1312 | vnet_main_t *vnm = vnet_get_main (); |
| 1313 | u32 sw_if_index = mp->sw_if_index; |
| 1314 | vnet_sw_interface_t *si; |
| 1315 | uword *bitmap = 0; |
| 1316 | u32 queue_id = ~0; |
| 1317 | u32 size = 0; |
| 1318 | clib_error_t *error = 0; |
| 1319 | int rv = 0; |
| 1320 | |
| 1321 | VALIDATE_SW_IF_INDEX_END (mp); |
| 1322 | |
| 1323 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1324 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1325 | { |
| 1326 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1327 | goto bad_sw_if_index; |
| 1328 | } |
| 1329 | |
| 1330 | size = mp->array_size; |
| 1331 | for (u32 i = 0; i < size; i++) |
| 1332 | { |
| 1333 | u32 thread_index = mp->threads[i]; |
| 1334 | bitmap = clib_bitmap_set (bitmap, thread_index, 1); |
| 1335 | } |
| 1336 | |
| 1337 | queue_id = mp->queue_id; |
| 1338 | rv = set_hw_interface_tx_queue (si->hw_if_index, queue_id, bitmap); |
| 1339 | |
| 1340 | switch (rv) |
| 1341 | { |
| 1342 | case VNET_API_ERROR_INVALID_VALUE: |
| 1343 | error = clib_error_return ( |
| 1344 | 0, "please specify valid thread(s) - last thread index %u", |
| 1345 | clib_bitmap_last_set (bitmap)); |
| 1346 | break; |
| 1347 | case VNET_API_ERROR_INVALID_QUEUE: |
| 1348 | error = clib_error_return ( |
| 1349 | 0, "unknown queue %u on interface %s", queue_id, |
| 1350 | vnet_get_hw_interface (vnet_get_main (), si->hw_if_index)->name); |
| 1351 | break; |
| 1352 | default: |
| 1353 | break; |
| 1354 | } |
| 1355 | |
| 1356 | if (error) |
| 1357 | { |
| 1358 | clib_error_report (error); |
| 1359 | goto out; |
| 1360 | } |
| 1361 | |
| 1362 | BAD_SW_IF_INDEX_LABEL; |
| 1363 | out: |
| 1364 | REPLY_MACRO_END (VL_API_SW_INTERFACE_SET_TX_PLACEMENT_REPLY); |
| 1365 | clib_bitmap_free (bitmap); |
| 1366 | } |
| 1367 | |
| 1368 | static void |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1369 | vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp) |
| 1370 | { |
| 1371 | vl_api_create_vlan_subif_reply_t *rmp; |
| 1372 | vnet_main_t *vnm = vnet_get_main (); |
| 1373 | u32 sw_if_index = (u32) ~ 0; |
| 1374 | vnet_hw_interface_t *hi; |
| 1375 | int rv = 0; |
| 1376 | u32 id; |
| 1377 | vnet_sw_interface_t template; |
| 1378 | uword *p; |
| 1379 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1380 | u64 sup_and_sub_key; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1381 | vl_api_registration_t *reg; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1382 | clib_error_t *error; |
| 1383 | |
| 1384 | VALIDATE_SW_IF_INDEX (mp); |
| 1385 | |
| 1386 | hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index)); |
| 1387 | |
| 1388 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
| 1389 | { |
| 1390 | rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED; |
| 1391 | goto out; |
| 1392 | } |
| 1393 | |
| 1394 | id = ntohl (mp->vlan_id); |
| 1395 | if (id == 0 || id > 4095) |
| 1396 | { |
| 1397 | rv = VNET_API_ERROR_INVALID_VLAN; |
| 1398 | goto out; |
| 1399 | } |
| 1400 | |
| 1401 | sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id; |
| 1402 | |
| 1403 | p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); |
| 1404 | if (p) |
| 1405 | { |
| 1406 | rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS; |
| 1407 | goto out; |
| 1408 | } |
| 1409 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1410 | clib_memset (&template, 0, sizeof (template)); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1411 | template.type = VNET_SW_INTERFACE_TYPE_SUB; |
Joe Zhou | 715f94e | 2019-03-06 23:05:32 -0800 | [diff] [blame] | 1412 | template.flood_class = VNET_FLOOD_CLASS_NORMAL; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1413 | template.sup_sw_if_index = hi->sw_if_index; |
| 1414 | template.sub.id = id; |
| 1415 | template.sub.eth.raw_flags = 0; |
| 1416 | template.sub.eth.flags.one_tag = 1; |
| 1417 | template.sub.eth.outer_vlan_id = id; |
| 1418 | template.sub.eth.flags.exact_match = 1; |
| 1419 | |
| 1420 | error = vnet_create_sw_interface (vnm, &template, &sw_if_index); |
| 1421 | if (error) |
| 1422 | { |
| 1423 | clib_error_report (error); |
| 1424 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 1425 | goto out; |
| 1426 | } |
| 1427 | |
| 1428 | u64 *kp = clib_mem_alloc (sizeof (*kp)); |
| 1429 | *kp = sup_and_sub_key; |
| 1430 | |
| 1431 | hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index); |
| 1432 | hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index); |
| 1433 | |
| 1434 | BAD_SW_IF_INDEX_LABEL; |
| 1435 | |
| 1436 | out: |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1437 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1438 | if (!reg) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1439 | return; |
| 1440 | |
| 1441 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1442 | rmp->_vl_msg_id = htons (REPLY_MSG_ID_BASE + VL_API_CREATE_VLAN_SUBIF_REPLY); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1443 | rmp->context = mp->context; |
| 1444 | rmp->retval = htonl (rv); |
| 1445 | rmp->sw_if_index = htonl (sw_if_index); |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1446 | vl_api_send_msg (reg, (u8 *) rmp); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | static void |
| 1450 | vl_api_create_subif_t_handler (vl_api_create_subif_t * mp) |
| 1451 | { |
| 1452 | vl_api_create_subif_reply_t *rmp; |
| 1453 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1454 | u32 sub_sw_if_index = ~0; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1455 | vnet_hw_interface_t *hi; |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1456 | int rv = 0; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1457 | |
| 1458 | VALIDATE_SW_IF_INDEX (mp); |
| 1459 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1460 | hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index)); |
| 1461 | |
| 1462 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1463 | rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED; |
| 1464 | else |
| 1465 | rv = vnet_create_sub_interface (ntohl (mp->sw_if_index), |
| 1466 | ntohl (mp->sub_id), |
| 1467 | ntohl (mp->sub_if_flags), |
| 1468 | ntohs (mp->inner_vlan_id), |
| 1469 | ntohs (mp->outer_vlan_id), |
| 1470 | &sub_sw_if_index); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1471 | |
| 1472 | BAD_SW_IF_INDEX_LABEL; |
| 1473 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1474 | REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY, |
| 1475 | ({ |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1476 | rmp->sw_if_index = ntohl(sub_sw_if_index); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1477 | })); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | static void |
| 1481 | vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp) |
| 1482 | { |
| 1483 | vl_api_delete_subif_reply_t *rmp; |
| 1484 | int rv; |
| 1485 | |
| 1486 | rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index)); |
| 1487 | |
| 1488 | REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY); |
| 1489 | } |
| 1490 | |
| 1491 | static void |
| 1492 | vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t * |
| 1493 | mp) |
| 1494 | { |
| 1495 | vl_api_interface_name_renumber_reply_t *rmp; |
| 1496 | int rv = 0; |
| 1497 | |
| 1498 | VALIDATE_SW_IF_INDEX (mp); |
| 1499 | |
| 1500 | rv = vnet_interface_name_renumber |
| 1501 | (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance)); |
| 1502 | |
| 1503 | BAD_SW_IF_INDEX_LABEL; |
| 1504 | |
| 1505 | REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY); |
| 1506 | } |
| 1507 | |
| 1508 | static void |
| 1509 | vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp) |
| 1510 | { |
| 1511 | vl_api_create_loopback_reply_t *rmp; |
| 1512 | u32 sw_if_index; |
| 1513 | int rv; |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1514 | mac_address_t mac; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1515 | |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1516 | mac_address_decode (mp->mac_address, &mac); |
| 1517 | rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac, 0, 0); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1518 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1519 | REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY, |
| 1520 | ({ |
| 1521 | rmp->sw_if_index = ntohl (sw_if_index); |
| 1522 | })); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | static void vl_api_create_loopback_instance_t_handler |
| 1526 | (vl_api_create_loopback_instance_t * mp) |
| 1527 | { |
| 1528 | vl_api_create_loopback_instance_reply_t *rmp; |
| 1529 | u32 sw_if_index; |
| 1530 | u8 is_specified = mp->is_specified; |
| 1531 | u32 user_instance = ntohl (mp->user_instance); |
| 1532 | int rv; |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1533 | mac_address_t mac; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1534 | |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1535 | mac_address_decode (mp->mac_address, &mac); |
| 1536 | rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac, |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1537 | is_specified, user_instance); |
| 1538 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1539 | REPLY_MACRO2(VL_API_CREATE_LOOPBACK_INSTANCE_REPLY, |
| 1540 | ({ |
| 1541 | rmp->sw_if_index = ntohl (sw_if_index); |
| 1542 | })); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | static void |
| 1546 | vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp) |
| 1547 | { |
| 1548 | vl_api_delete_loopback_reply_t *rmp; |
| 1549 | u32 sw_if_index; |
| 1550 | int rv; |
| 1551 | |
| 1552 | sw_if_index = ntohl (mp->sw_if_index); |
| 1553 | rv = vnet_delete_loopback_interface (sw_if_index); |
| 1554 | |
| 1555 | REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY); |
| 1556 | } |
| 1557 | |
Neale Ranns | 6f4a6be | 2018-03-16 16:26:21 -0700 | [diff] [blame] | 1558 | static void |
| 1559 | vl_api_collect_detailed_interface_stats_t_handler |
| 1560 | (vl_api_collect_detailed_interface_stats_t * mp) |
| 1561 | { |
| 1562 | vl_api_collect_detailed_interface_stats_reply_t *rmp; |
| 1563 | int rv = 0; |
| 1564 | |
Neale Ranns | 871dc42 | 2018-03-29 01:28:09 -0700 | [diff] [blame] | 1565 | rv = |
| 1566 | vnet_sw_interface_stats_collect_enable_disable (ntohl (mp->sw_if_index), |
| 1567 | mp->enable_disable); |
Neale Ranns | 6f4a6be | 2018-03-16 16:26:21 -0700 | [diff] [blame] | 1568 | |
| 1569 | REPLY_MACRO (VL_API_COLLECT_DETAILED_INTERFACE_STATS_REPLY); |
| 1570 | } |
| 1571 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 1572 | static void |
| 1573 | vl_api_sw_interface_address_replace_begin_t_handler |
| 1574 | (vl_api_sw_interface_address_replace_begin_t * mp) |
| 1575 | { |
| 1576 | vl_api_sw_interface_address_replace_begin_reply_t *rmp; |
| 1577 | int rv = 0; |
| 1578 | |
| 1579 | ip_interface_address_mark (); |
| 1580 | |
| 1581 | REPLY_MACRO (VL_API_SW_INTERFACE_ADDRESS_REPLACE_BEGIN_REPLY); |
| 1582 | } |
| 1583 | |
| 1584 | static void |
| 1585 | vl_api_sw_interface_address_replace_end_t_handler |
| 1586 | (vl_api_sw_interface_address_replace_end_t * mp) |
| 1587 | { |
| 1588 | vl_api_sw_interface_address_replace_end_reply_t *rmp; |
| 1589 | int rv = 0; |
| 1590 | |
| 1591 | ip_interface_address_sweep (); |
| 1592 | |
| 1593 | REPLY_MACRO (VL_API_SW_INTERFACE_ADDRESS_REPLACE_END_REPLY); |
| 1594 | } |
| 1595 | |
Maxime Peim | ddc16cf | 2023-01-13 08:04:55 +0000 | [diff] [blame] | 1596 | static void |
Maxime Peim | 3f40755 | 2023-07-03 17:45:51 +0200 | [diff] [blame] | 1597 | vl_api_pcap_set_filter_function_t_handler ( |
| 1598 | vl_api_pcap_set_filter_function_t *mp) |
| 1599 | { |
| 1600 | vnet_main_t *vnm = vnet_get_main (); |
| 1601 | vnet_pcap_t *pp = &vnm->pcap; |
| 1602 | vl_api_pcap_set_filter_function_reply_t *rmp; |
| 1603 | unformat_input_t input = { 0 }; |
| 1604 | vlib_is_packet_traced_fn_t *f; |
| 1605 | char *filter_name; |
| 1606 | int rv = 0; |
| 1607 | filter_name = vl_api_from_api_to_new_c_string (&mp->filter_function_name); |
| 1608 | unformat_init_cstring (&input, filter_name); |
| 1609 | if (unformat (&input, "%U", unformat_vlib_trace_filter_function, &f) == 0) |
| 1610 | { |
| 1611 | rv = -1; |
| 1612 | goto done; |
| 1613 | } |
| 1614 | |
| 1615 | pp->current_filter_function = f; |
| 1616 | |
| 1617 | done: |
| 1618 | unformat_free (&input); |
| 1619 | vec_free (filter_name); |
| 1620 | REPLY_MACRO (VL_API_PCAP_SET_FILTER_FUNCTION_REPLY); |
| 1621 | } |
| 1622 | |
| 1623 | static void |
Maxime Peim | ddc16cf | 2023-01-13 08:04:55 +0000 | [diff] [blame] | 1624 | vl_api_pcap_trace_on_t_handler (vl_api_pcap_trace_on_t *mp) |
| 1625 | { |
| 1626 | vl_api_pcap_trace_on_reply_t *rmp; |
| 1627 | unformat_input_t filename, drop_err_name; |
| 1628 | vnet_pcap_dispatch_trace_args_t capture_args; |
| 1629 | int rv = 0; |
| 1630 | |
| 1631 | VALIDATE_SW_IF_INDEX (mp); |
| 1632 | |
| 1633 | unformat_init_cstring (&filename, (char *) mp->filename); |
| 1634 | if (!unformat_user (&filename, unformat_vlib_tmpfile, |
| 1635 | &capture_args.filename)) |
| 1636 | { |
| 1637 | rv = VNET_API_ERROR_ILLEGAL_NAME; |
| 1638 | goto out; |
| 1639 | } |
| 1640 | |
| 1641 | capture_args.rx_enable = mp->capture_rx; |
| 1642 | capture_args.tx_enable = mp->capture_tx; |
| 1643 | capture_args.preallocate_data = mp->preallocate_data; |
| 1644 | capture_args.free_data = mp->free_data; |
| 1645 | capture_args.drop_enable = mp->capture_drop; |
| 1646 | capture_args.status = 0; |
| 1647 | capture_args.packets_to_capture = ntohl (mp->max_packets); |
| 1648 | capture_args.sw_if_index = ntohl (mp->sw_if_index); |
| 1649 | capture_args.filter = mp->filter; |
| 1650 | capture_args.max_bytes_per_pkt = ntohl (mp->max_bytes_per_packet); |
| 1651 | capture_args.drop_err = ~0; |
| 1652 | |
| 1653 | unformat_init_cstring (&drop_err_name, (char *) mp->error); |
| 1654 | unformat_user (&drop_err_name, unformat_vlib_error, vlib_get_main (), |
| 1655 | &capture_args.drop_err); |
| 1656 | |
| 1657 | rv = vnet_pcap_dispatch_trace_configure (&capture_args); |
| 1658 | |
| 1659 | BAD_SW_IF_INDEX_LABEL; |
| 1660 | |
| 1661 | out: |
| 1662 | unformat_free (&filename); |
| 1663 | unformat_free (&drop_err_name); |
| 1664 | |
| 1665 | REPLY_MACRO (VL_API_PCAP_TRACE_ON_REPLY); |
| 1666 | } |
| 1667 | |
| 1668 | static void |
| 1669 | vl_api_pcap_trace_off_t_handler (vl_api_pcap_trace_off_t *mp) |
| 1670 | { |
| 1671 | vl_api_pcap_trace_off_reply_t *rmp; |
| 1672 | vnet_pcap_dispatch_trace_args_t capture_args; |
| 1673 | int rv = 0; |
| 1674 | |
| 1675 | clib_memset (&capture_args, 0, sizeof (capture_args)); |
| 1676 | |
| 1677 | rv = vnet_pcap_dispatch_trace_configure (&capture_args); |
| 1678 | |
| 1679 | REPLY_MACRO (VL_API_PCAP_TRACE_OFF_REPLY); |
| 1680 | } |
| 1681 | |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1682 | /* |
| 1683 | * vpe_api_hookup |
| 1684 | * Add vpe's API message handlers to the table. |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 1685 | * vlib has already mapped shared memory and |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1686 | * added the client registration handlers. |
| 1687 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 1688 | */ |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1689 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 1690 | pub_sub_handler (interface_events, INTERFACE_EVENTS); |
| 1691 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1692 | #include <vnet/interface.api.c> |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1693 | static clib_error_t * |
| 1694 | interface_api_hookup (vlib_main_t * vm) |
| 1695 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1696 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1697 | |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1698 | /* |
| 1699 | * Set up the (msg_name, crc, message-id) table |
| 1700 | */ |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1701 | REPLY_MSG_ID_BASE = setup_message_id_table (); |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1702 | |
Ole Troan | 2ca88ff | 2022-01-27 16:25:43 +0100 | [diff] [blame] | 1703 | /* Mark these APIs as mp safe */ |
Damjan Marion | cada9eb | 2022-05-18 22:16:11 +0200 | [diff] [blame] | 1704 | vl_api_set_msg_thread_safe (am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_DUMP, |
| 1705 | 1); |
| 1706 | vl_api_set_msg_thread_safe ( |
| 1707 | am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_DETAILS, 1); |
| 1708 | vl_api_set_msg_thread_safe ( |
| 1709 | am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_TAG_ADD_DEL, 1); |
| 1710 | vl_api_set_msg_thread_safe ( |
| 1711 | am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_SET_INTERFACE_NAME, 1); |
Ole Troan | 2ca88ff | 2022-01-27 16:25:43 +0100 | [diff] [blame] | 1712 | |
| 1713 | /* Do not replay VL_API_SW_INTERFACE_DUMP messages */ |
Damjan Marion | cada9eb | 2022-05-18 22:16:11 +0200 | [diff] [blame] | 1714 | vl_api_allow_msg_replay (am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_DUMP, |
| 1715 | 0); |
Ole Troan | 2ca88ff | 2022-01-27 16:25:43 +0100 | [diff] [blame] | 1716 | |
| 1717 | /* Mark these APIs as autoendian */ |
Damjan Marion | cada9eb | 2022-05-18 22:16:11 +0200 | [diff] [blame] | 1718 | vl_api_set_msg_autoendian ( |
| 1719 | am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_SET_TX_PLACEMENT, 1); |
| 1720 | vl_api_set_msg_autoendian ( |
| 1721 | am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_TX_PLACEMENT_GET, 1); |
Ole Troan | 2ca88ff | 2022-01-27 16:25:43 +0100 | [diff] [blame] | 1722 | |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1723 | return 0; |
| 1724 | } |
| 1725 | |
| 1726 | VLIB_API_INIT_FUNCTION (interface_api_hookup); |
| 1727 | |
| 1728 | /* |
| 1729 | * fd.io coding-style-patch-verification: ON |
| 1730 | * |
| 1731 | * Local Variables: |
| 1732 | * eval: (c-set-style "gnu") |
| 1733 | * End: |
| 1734 | */ |