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