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> |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 25 | #include <vnet/interface/tx_queue_funcs.h> |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 26 | #include <vnet/api_errno.h> |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 27 | #include <vnet/ethernet/ethernet.h> |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 28 | #include <vnet/ip/ip.h> |
| 29 | #include <vnet/fib/fib_table.h> |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 30 | #include <vnet/mfib/mfib_table.h> |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 31 | #include <vnet/l2/l2_vtr.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> |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 34 | #include <vlibapi/api_types.h> |
| 35 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 36 | #include <vnet/format_fns.h> |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 37 | #include <vnet/ip/ip_types_api.h> |
| 38 | #include <vnet/ethernet/ethernet_types_api.h> |
| 39 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 40 | #include <interface.api_enum.h> |
| 41 | #include <interface.api_types.h> |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 42 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 43 | #define REPLY_MSG_ID_BASE msg_id_base |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 44 | #include <vlibapi/api_helper_macros.h> |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 45 | |
| 46 | static u16 msg_id_base; |
| 47 | |
Dave Barach | f158661 | 2017-03-30 09:33:01 -0400 | [diff] [blame] | 48 | vpe_api_main_t vpe_api_main; |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 49 | |
Nathan Skrzypczak | fd0b399 | 2021-02-04 16:11:18 +0100 | [diff] [blame] | 50 | #define foreach_vpe_api_msg \ |
| 51 | _ (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \ |
| 52 | _ (SW_INTERFACE_SET_PROMISC, sw_interface_set_promisc) \ |
| 53 | _ (HW_INTERFACE_SET_MTU, hw_interface_set_mtu) \ |
| 54 | _ (SW_INTERFACE_SET_MTU, sw_interface_set_mtu) \ |
| 55 | _ (WANT_INTERFACE_EVENTS, want_interface_events) \ |
| 56 | _ (SW_INTERFACE_DUMP, sw_interface_dump) \ |
| 57 | _ (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \ |
| 58 | _ (SW_INTERFACE_SET_RX_MODE, sw_interface_set_rx_mode) \ |
| 59 | _ (SW_INTERFACE_RX_PLACEMENT_DUMP, sw_interface_rx_placement_dump) \ |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 60 | _ (SW_INTERFACE_TX_PLACEMENT_GET, sw_interface_tx_placement_get) \ |
Nathan Skrzypczak | fd0b399 | 2021-02-04 16:11:18 +0100 | [diff] [blame] | 61 | _ (SW_INTERFACE_SET_RX_PLACEMENT, sw_interface_set_rx_placement) \ |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 62 | _ (SW_INTERFACE_SET_TX_PLACEMENT, sw_interface_set_tx_placement) \ |
Nathan Skrzypczak | fd0b399 | 2021-02-04 16:11:18 +0100 | [diff] [blame] | 63 | _ (SW_INTERFACE_SET_TABLE, sw_interface_set_table) \ |
| 64 | _ (SW_INTERFACE_GET_TABLE, sw_interface_get_table) \ |
| 65 | _ (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \ |
| 66 | _ (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \ |
| 67 | _ (SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del) \ |
| 68 | _ (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, sw_interface_add_del_mac_address) \ |
| 69 | _ (SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address) \ |
| 70 | _ (SW_INTERFACE_GET_MAC_ADDRESS, sw_interface_get_mac_address) \ |
| 71 | _ (CREATE_VLAN_SUBIF, create_vlan_subif) \ |
| 72 | _ (CREATE_SUBIF, create_subif) \ |
| 73 | _ (DELETE_SUBIF, delete_subif) \ |
| 74 | _ (CREATE_LOOPBACK, create_loopback) \ |
| 75 | _ (CREATE_LOOPBACK_INSTANCE, create_loopback_instance) \ |
| 76 | _ (DELETE_LOOPBACK, delete_loopback) \ |
| 77 | _ (INTERFACE_NAME_RENUMBER, interface_name_renumber) \ |
| 78 | _ (COLLECT_DETAILED_INTERFACE_STATS, collect_detailed_interface_stats) \ |
| 79 | _ (SW_INTERFACE_SET_IP_DIRECTED_BROADCAST, \ |
| 80 | sw_interface_set_ip_directed_broadcast) \ |
| 81 | _ (SW_INTERFACE_ADDRESS_REPLACE_BEGIN, sw_interface_address_replace_begin) \ |
| 82 | _ (SW_INTERFACE_ADDRESS_REPLACE_END, sw_interface_address_replace_end) |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 83 | |
| 84 | static void |
| 85 | vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp) |
| 86 | { |
| 87 | vl_api_sw_interface_set_flags_reply_t *rmp; |
| 88 | vnet_main_t *vnm = vnet_get_main (); |
| 89 | int rv = 0; |
| 90 | clib_error_t *error; |
| 91 | u16 flags; |
| 92 | |
| 93 | VALIDATE_SW_IF_INDEX (mp); |
| 94 | |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 95 | flags = |
| 96 | ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ? |
| 97 | VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0; |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 98 | |
| 99 | error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags); |
| 100 | if (error) |
| 101 | { |
| 102 | rv = -1; |
| 103 | clib_error_report (error); |
| 104 | } |
| 105 | |
| 106 | BAD_SW_IF_INDEX_LABEL; |
| 107 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY); |
| 108 | } |
| 109 | |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 110 | static void |
Nathan Skrzypczak | fd0b399 | 2021-02-04 16:11:18 +0100 | [diff] [blame] | 111 | vl_api_sw_interface_set_promisc_t_handler ( |
| 112 | vl_api_sw_interface_set_promisc_t *mp) |
| 113 | { |
| 114 | vl_api_sw_interface_set_promisc_reply_t *rmp; |
| 115 | vnet_main_t *vnm = vnet_get_main (); |
| 116 | ethernet_main_t *em = ðernet_main; |
| 117 | int rv = 0; |
| 118 | ethernet_interface_t *eif; |
| 119 | vnet_sw_interface_t *swif; |
| 120 | u32 flags, sw_if_index; |
| 121 | |
| 122 | VALIDATE_SW_IF_INDEX (mp); |
| 123 | |
| 124 | sw_if_index = ntohl (mp->sw_if_index); |
| 125 | swif = vnet_get_sw_interface (vnm, sw_if_index); |
| 126 | eif = ethernet_get_interface (em, swif->hw_if_index); |
| 127 | if (!eif) |
| 128 | { |
| 129 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 130 | goto done; |
| 131 | } |
| 132 | |
| 133 | flags = mp->promisc_on ? ETHERNET_INTERFACE_FLAG_ACCEPT_ALL : 0; |
| 134 | rv = ethernet_set_flags (vnm, swif->hw_if_index, flags); |
| 135 | |
| 136 | done: |
| 137 | BAD_SW_IF_INDEX_LABEL; |
| 138 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_PROMISC_REPLY); |
| 139 | } |
| 140 | |
| 141 | static void |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 142 | 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] | 143 | { |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 144 | vl_api_hw_interface_set_mtu_reply_t *rmp; |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 145 | vnet_main_t *vnm = vnet_get_main (); |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 146 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 147 | u16 mtu = ntohs (mp->mtu); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 148 | ethernet_main_t *em = ðernet_main; |
Damjan Marion | 81bb6fc | 2022-01-16 22:47:55 +0100 | [diff] [blame] | 149 | clib_error_t *err; |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 150 | int rv = 0; |
| 151 | |
| 152 | VALIDATE_SW_IF_INDEX (mp); |
| 153 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 154 | vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); |
| 155 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 156 | { |
| 157 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 158 | goto bad_sw_if_index; |
| 159 | } |
| 160 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 161 | ethernet_interface_t *eif = ethernet_get_interface (em, si->hw_if_index); |
| 162 | |
| 163 | if (!eif) |
| 164 | { |
| 165 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 166 | goto bad_sw_if_index; |
| 167 | } |
| 168 | |
Damjan Marion | 81bb6fc | 2022-01-16 22:47:55 +0100 | [diff] [blame] | 169 | 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] | 170 | { |
Damjan Marion | 81bb6fc | 2022-01-16 22:47:55 +0100 | [diff] [blame] | 171 | rv = vnet_api_error (err); |
| 172 | clib_error_free (err); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 173 | goto bad_sw_if_index; |
| 174 | } |
| 175 | |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 176 | BAD_SW_IF_INDEX_LABEL; |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 177 | REPLY_MACRO (VL_API_HW_INTERFACE_SET_MTU_REPLY); |
| 178 | } |
| 179 | |
| 180 | static void |
| 181 | vl_api_sw_interface_set_mtu_t_handler (vl_api_sw_interface_set_mtu_t * mp) |
| 182 | { |
| 183 | vl_api_sw_interface_set_mtu_reply_t *rmp; |
| 184 | vnet_main_t *vnm = vnet_get_main (); |
| 185 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 186 | int rv = 0; |
| 187 | int i; |
| 188 | u32 per_protocol_mtu[VNET_N_MTU]; |
| 189 | |
| 190 | VALIDATE_SW_IF_INDEX (mp); |
| 191 | |
| 192 | for (i = 0; i < VNET_N_MTU; i++) |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 193 | { |
| 194 | per_protocol_mtu[i] = ntohl (mp->mtu[i]); |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 195 | } |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 196 | vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, per_protocol_mtu); |
| 197 | |
| 198 | BAD_SW_IF_INDEX_LABEL; |
Matus Fabian | d162f3d | 2016-12-05 01:05:35 -0800 | [diff] [blame] | 199 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY); |
| 200 | } |
| 201 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 202 | static void |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 203 | vl_api_sw_interface_set_ip_directed_broadcast_t_handler |
| 204 | (vl_api_sw_interface_set_ip_directed_broadcast_t * mp) |
| 205 | { |
| 206 | vl_api_sw_interface_set_ip_directed_broadcast_reply_t *rmp; |
| 207 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 208 | int rv = 0; |
| 209 | |
| 210 | VALIDATE_SW_IF_INDEX (mp); |
| 211 | |
| 212 | vnet_sw_interface_ip_directed_broadcast (vnet_get_main (), |
| 213 | sw_if_index, mp->enable); |
| 214 | |
| 215 | BAD_SW_IF_INDEX_LABEL; |
| 216 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_IP_DIRECTED_BROADCAST_REPLY); |
| 217 | } |
| 218 | |
| 219 | static void |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 220 | send_sw_interface_details (vpe_api_main_t * am, |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 221 | vl_api_registration_t * rp, |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 222 | vnet_sw_interface_t * swif, |
| 223 | u8 * interface_name, u32 context) |
| 224 | { |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 225 | vnet_hw_interface_t *hi = |
| 226 | vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index); |
Mohsin Kazmi | de312c2 | 2019-09-27 13:44:28 +0200 | [diff] [blame] | 227 | vnet_device_class_t *dev_class = |
| 228 | vnet_get_device_class (am->vnet_main, hi->dev_class_index); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 229 | |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 230 | vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp)); |
| 231 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 232 | 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] | 233 | mp->sw_if_index = ntohl (swif->sw_if_index); |
| 234 | mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 235 | |
| 236 | mp->flags |= (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
| 237 | IF_STATUS_API_FLAG_ADMIN_UP : 0; |
| 238 | mp->flags |= (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? |
| 239 | IF_STATUS_API_FLAG_LINK_UP : 0; |
| 240 | mp->flags = ntohl (mp->flags); |
| 241 | |
| 242 | switch (swif->type) |
| 243 | { |
| 244 | case VNET_SW_INTERFACE_TYPE_SUB: |
| 245 | mp->type = IF_API_TYPE_SUB; |
| 246 | break; |
| 247 | case VNET_SW_INTERFACE_TYPE_P2P: |
| 248 | mp->type = IF_API_TYPE_P2P; |
| 249 | break; |
| 250 | case VNET_SW_INTERFACE_TYPE_PIPE: |
| 251 | mp->type = IF_API_TYPE_PIPE; |
| 252 | break; |
| 253 | default: |
| 254 | mp->type = IF_API_TYPE_HARDWARE; |
| 255 | } |
| 256 | mp->type = ntohl (mp->type); |
| 257 | |
Neale Ranns | 8561e73 | 2021-07-21 13:29:58 +0000 | [diff] [blame] | 258 | mp->link_duplex = ntohl (((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >> |
| 259 | VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT)); |
Ole Troan | 8ee7251 | 2018-11-20 11:03:10 +0100 | [diff] [blame] | 260 | mp->link_speed = ntohl (hi->link_speed); |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame] | 261 | mp->link_mtu = ntohs (hi->max_frame_size - hi->frame_overhead); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 262 | mp->mtu[VNET_MTU_L3] = ntohl (swif->mtu[VNET_MTU_L3]); |
| 263 | mp->mtu[VNET_MTU_IP4] = ntohl (swif->mtu[VNET_MTU_IP4]); |
| 264 | mp->mtu[VNET_MTU_IP6] = ntohl (swif->mtu[VNET_MTU_IP6]); |
| 265 | mp->mtu[VNET_MTU_MPLS] = ntohl (swif->mtu[VNET_MTU_MPLS]); |
| 266 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 267 | mp->context = context; |
| 268 | |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 269 | strncpy ((char *) mp->interface_name, |
| 270 | (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1); |
| 271 | |
Mohsin Kazmi | de312c2 | 2019-09-27 13:44:28 +0200 | [diff] [blame] | 272 | if (dev_class && dev_class->name) |
| 273 | strncpy ((char *) mp->interface_dev_type, (char *) dev_class->name, |
| 274 | ARRAY_LEN (mp->interface_dev_type) - 1); |
| 275 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 276 | /* Send the L2 address for ethernet physical intfcs */ |
| 277 | if (swif->sup_sw_if_index == swif->sw_if_index |
| 278 | && hi->hw_class_index == ethernet_hw_interface_class.index) |
| 279 | { |
| 280 | ethernet_main_t *em = ethernet_get_main (am->vlib_main); |
| 281 | ethernet_interface_t *ei; |
| 282 | |
| 283 | ei = pool_elt_at_index (em->interfaces, hi->hw_instance); |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 284 | ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address.mac)); |
| 285 | mac_address_encode (&ei->address.mac, mp->l2_address); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 286 | } |
| 287 | else if (swif->sup_sw_if_index != swif->sw_if_index) |
| 288 | { |
| 289 | vnet_sub_interface_t *sub = &swif->sub; |
| 290 | mp->sub_id = ntohl (sub->id); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 291 | mp->sub_number_of_tags = |
| 292 | sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2; |
| 293 | mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id); |
| 294 | mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 295 | mp->sub_if_flags = |
| 296 | ntohl (sub->eth.raw_flags & SUB_IF_API_FLAG_MASK_VNET); |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 297 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 298 | |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 299 | /* vlan tag rewrite data */ |
| 300 | u32 vtr_op = L2_VTR_DISABLED; |
| 301 | u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 302 | |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 303 | if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index, |
| 304 | &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) |
| 305 | { |
| 306 | // error - default to disabled |
| 307 | mp->vtr_op = ntohl (L2_VTR_DISABLED); |
| 308 | clib_warning ("cannot get vlan tag rewrite for sw_if_index %d", |
| 309 | swif->sw_if_index); |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | mp->vtr_op = ntohl (vtr_op); |
| 314 | mp->vtr_push_dot1q = ntohl (vtr_push_dot1q); |
| 315 | mp->vtr_tag1 = ntohl (vtr_tag1); |
| 316 | mp->vtr_tag2 = ntohl (vtr_tag2); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 317 | } |
| 318 | |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 319 | /* pbb tag rewrite data */ |
Gabriel Ganne | f7f2a9f | 2017-03-06 15:19:40 +0100 | [diff] [blame] | 320 | ethernet_header_t eth_hdr; |
Alexander Chernavin | fdea5c6 | 2019-04-26 10:43:09 -0400 | [diff] [blame] | 321 | u32 pbb_vtr_op = L2_VTR_DISABLED; |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 322 | u16 outer_tag = 0; |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 323 | u16 b_vlanid = 0; |
| 324 | u32 i_sid = 0; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 325 | clib_memset (ð_hdr, 0, sizeof (eth_hdr)); |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 326 | |
| 327 | 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] | 328 | &pbb_vtr_op, &outer_tag, ð_hdr, &b_vlanid, &i_sid)) |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 329 | { |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 330 | mp->sub_if_flags |= ntohl (SUB_IF_API_FLAG_DOT1AH); |
| 331 | mac_address_encode ((mac_address_t *) eth_hdr.dst_address, mp->b_dmac); |
| 332 | 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] | 333 | mp->b_vlanid = b_vlanid; |
| 334 | mp->i_sid = i_sid; |
| 335 | } |
| 336 | |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 337 | u8 *tag = vnet_get_sw_interface_tag (vnet_get_main (), swif->sw_if_index); |
| 338 | if (tag) |
| 339 | strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 340 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 341 | vl_api_send_msg (rp, (u8 *) mp); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static void |
| 345 | vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp) |
| 346 | { |
| 347 | vpe_api_main_t *am = &vpe_api_main; |
| 348 | vnet_sw_interface_t *swif; |
| 349 | vnet_interface_main_t *im = &am->vnet_main->interface_main; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 350 | vl_api_registration_t *rp; |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 351 | u32 sw_if_index; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 352 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 353 | rp = vl_api_client_index_to_registration (mp->client_index); |
| 354 | |
| 355 | if (rp == 0) |
| 356 | { |
| 357 | clib_warning ("Client %d AWOL", mp->client_index); |
| 358 | return; |
| 359 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 360 | |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 361 | u8 *filter = 0, *name = 0; |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 362 | sw_if_index = ntohl (mp->sw_if_index); |
| 363 | |
Vratko Polak | b8591ac | 2019-04-23 12:26:44 +0200 | [diff] [blame] | 364 | 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] | 365 | { |
Vratko Polak | b8591ac | 2019-04-23 12:26:44 +0200 | [diff] [blame] | 366 | /* is it a valid sw_if_index? */ |
Neale Ranns | f5b0176 | 2019-06-14 08:26:21 +0000 | [diff] [blame] | 367 | if (!vnet_sw_if_index_is_api_valid (sw_if_index)) |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 368 | return; |
| 369 | |
| 370 | swif = vec_elt_at_index (im->sw_interfaces, sw_if_index); |
| 371 | |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 372 | vec_reset_length (name); |
| 373 | name = |
| 374 | format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main, |
| 375 | swif, 0); |
| 376 | send_sw_interface_details (am, rp, swif, name, mp->context); |
| 377 | vec_free (name); |
| 378 | return; |
| 379 | } |
| 380 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 381 | if (mp->name_filter_valid) |
| 382 | { |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 383 | filter = vl_api_from_api_to_new_vec (mp, &mp->name_filter); |
Aleksander Djuric | c12eae7 | 2019-10-31 14:35:21 +0300 | [diff] [blame] | 384 | vec_add1 (filter, 0); /* Ensure it's a C string for strcasecmp() */ |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 385 | } |
| 386 | |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 387 | char *strcasestr (char *, char *); /* lnx hdr file botch */ |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 388 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 389 | pool_foreach (swif, im->sw_interfaces) |
| 390 | { |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 391 | if (!vnet_swif_is_api_visible (swif)) |
| 392 | continue; |
| 393 | vec_reset_length(name); |
| 394 | name = format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main, |
| 395 | swif, 0); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 396 | |
Eyal Bari | 1c82cd4 | 2017-03-14 14:39:51 +0200 | [diff] [blame] | 397 | if (filter && !strcasestr((char *) name, (char *) filter)) |
| 398 | continue; |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 399 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 400 | send_sw_interface_details (am, rp, swif, name, mp->context); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 401 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 402 | /* *INDENT-ON* */ |
| 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 | |
| 811 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 812 | pool_foreach (reg, vam->interface_events_registrations) |
| 813 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 814 | vl_reg = vl_api_client_index_to_registration (reg->client_index); |
| 815 | if (vl_reg) |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 816 | 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] | 817 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 818 | /* *INDENT-ON* */ |
| 819 | } |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 820 | vec_reset_length (event_by_sw_if_index); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index, |
| 827 | u32 flags); |
| 828 | static clib_error_t *admin_up_down_function (vnet_main_t * vm, |
| 829 | u32 hw_if_index, u32 flags); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 830 | static clib_error_t *sw_interface_add_del_function (vnet_main_t * vm, |
| 831 | u32 sw_if_index, |
| 832 | u32 flags); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 833 | |
| 834 | /* *INDENT-OFF* */ |
| 835 | VLIB_REGISTER_NODE (link_state_process_node,static) = { |
| 836 | .function = link_state_process, |
| 837 | .type = VLIB_NODE_TYPE_PROCESS, |
| 838 | .name = "vpe-link-state-process", |
| 839 | }; |
| 840 | /* *INDENT-ON* */ |
| 841 | |
| 842 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function); |
| 843 | VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 844 | VNET_SW_INTERFACE_ADD_DEL_FUNCTION (sw_interface_add_del_function); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 845 | |
| 846 | static clib_error_t * |
| 847 | link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags) |
| 848 | { |
| 849 | vpe_api_main_t *vam = &vpe_api_main; |
| 850 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index); |
| 851 | |
| 852 | if (vam->link_state_process_up) |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 853 | { |
Alexander Chernavin | aa27dcb | 2019-11-06 09:58:18 -0500 | [diff] [blame] | 854 | enum api_events event = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? |
| 855 | API_LINK_STATE_UP_EVENT : |
| 856 | API_LINK_STATE_DOWN_EVENT); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 857 | vlib_process_signal_event (vam->vlib_main, |
| 858 | link_state_process_node.index, event, |
| 859 | hi->sw_if_index); |
| 860 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | static clib_error_t * |
| 865 | admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags) |
| 866 | { |
| 867 | vpe_api_main_t *vam = &vpe_api_main; |
| 868 | |
| 869 | /* |
| 870 | * Note: it's perfectly fair to set a subif admin up / admin down. |
| 871 | * Note the subtle distinction between this routine and the previous |
| 872 | * routine. |
| 873 | */ |
| 874 | if (vam->link_state_process_up) |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 875 | { |
Alexander Chernavin | aa27dcb | 2019-11-06 09:58:18 -0500 | [diff] [blame] | 876 | enum api_events event = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
| 877 | API_ADMIN_UP_EVENT : API_ADMIN_DOWN_EVENT); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 878 | vlib_process_signal_event (vam->vlib_main, |
| 879 | link_state_process_node.index, event, |
| 880 | sw_if_index); |
| 881 | } |
| 882 | return 0; |
| 883 | } |
| 884 | |
| 885 | static clib_error_t * |
| 886 | sw_interface_add_del_function (vnet_main_t * vm, u32 sw_if_index, u32 flags) |
| 887 | { |
| 888 | vpe_api_main_t *vam = &vpe_api_main; |
| 889 | |
| 890 | if (vam->link_state_process_up) |
| 891 | { |
| 892 | enum api_events event = |
| 893 | flags ? API_SW_INTERFACE_ADD_EVENT : API_SW_INTERFACE_DEL_EVENT; |
| 894 | vlib_process_signal_event (vam->vlib_main, |
| 895 | link_state_process_node.index, event, |
| 896 | sw_if_index); |
| 897 | } |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | static void vl_api_sw_interface_tag_add_del_t_handler |
| 902 | (vl_api_sw_interface_tag_add_del_t * mp) |
| 903 | { |
| 904 | vnet_main_t *vnm = vnet_get_main (); |
| 905 | vl_api_sw_interface_tag_add_del_reply_t *rmp; |
| 906 | int rv = 0; |
| 907 | u8 *tag; |
| 908 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 909 | |
| 910 | VALIDATE_SW_IF_INDEX (mp); |
| 911 | |
| 912 | if (mp->is_add) |
| 913 | { |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 914 | if (mp->tag[0] == 0) |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 915 | { |
| 916 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 917 | goto out; |
| 918 | } |
| 919 | |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 920 | mp->tag[ARRAY_LEN (mp->tag) - 1] = 0; |
| 921 | tag = format (0, "%s%c", mp->tag, 0); |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 922 | vnet_set_sw_interface_tag (vnm, tag, sw_if_index); |
| 923 | } |
| 924 | else |
| 925 | vnet_clear_sw_interface_tag (vnm, sw_if_index); |
| 926 | |
| 927 | BAD_SW_IF_INDEX_LABEL; |
| 928 | out: |
| 929 | REPLY_MACRO (VL_API_SW_INTERFACE_TAG_ADD_DEL_REPLY); |
| 930 | } |
| 931 | |
Matthew Smith | e0792fd | 2019-07-12 11:48:24 -0500 | [diff] [blame] | 932 | static void vl_api_sw_interface_add_del_mac_address_t_handler |
| 933 | (vl_api_sw_interface_add_del_mac_address_t * mp) |
| 934 | { |
| 935 | vl_api_sw_interface_add_del_mac_address_reply_t *rmp; |
| 936 | vnet_main_t *vnm = vnet_get_main (); |
| 937 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 938 | vnet_hw_interface_t *hi; |
| 939 | clib_error_t *error; |
| 940 | int rv = 0; |
| 941 | |
| 942 | VALIDATE_SW_IF_INDEX (mp); |
| 943 | |
| 944 | /* for subifs, the MAC should be changed on the actual hw if */ |
| 945 | hi = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 946 | error = vnet_hw_interface_add_del_mac_address (vnm, hi->hw_if_index, |
| 947 | mp->addr, mp->is_add); |
| 948 | if (error) |
| 949 | { |
| 950 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 951 | clib_error_report (error); |
| 952 | goto out; |
| 953 | } |
| 954 | |
| 955 | BAD_SW_IF_INDEX_LABEL; |
| 956 | out: |
| 957 | REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY); |
| 958 | } |
| 959 | |
Jon Loeliger | 10c273b | 2017-03-30 08:39:33 -0500 | [diff] [blame] | 960 | static void vl_api_sw_interface_set_mac_address_t_handler |
| 961 | (vl_api_sw_interface_set_mac_address_t * mp) |
| 962 | { |
| 963 | vl_api_sw_interface_set_mac_address_reply_t *rmp; |
| 964 | vnet_main_t *vnm = vnet_get_main (); |
| 965 | u32 sw_if_index = ntohl (mp->sw_if_index); |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 966 | vnet_sw_interface_t *si; |
Jon Loeliger | 10c273b | 2017-03-30 08:39:33 -0500 | [diff] [blame] | 967 | clib_error_t *error; |
| 968 | int rv = 0; |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 969 | mac_address_t mac; |
Jon Loeliger | 10c273b | 2017-03-30 08:39:33 -0500 | [diff] [blame] | 970 | |
| 971 | VALIDATE_SW_IF_INDEX (mp); |
| 972 | |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 973 | si = vnet_get_sw_interface (vnm, sw_if_index); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 974 | mac_address_decode (mp->mac_address, &mac); |
| 975 | error = |
| 976 | 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] | 977 | if (error) |
| 978 | { |
| 979 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 980 | clib_error_report (error); |
| 981 | goto out; |
| 982 | } |
| 983 | |
| 984 | BAD_SW_IF_INDEX_LABEL; |
| 985 | out: |
| 986 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_MAC_ADDRESS_REPLY); |
| 987 | } |
| 988 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 989 | static void vl_api_sw_interface_get_mac_address_t_handler |
| 990 | (vl_api_sw_interface_get_mac_address_t * mp) |
| 991 | { |
| 992 | vl_api_sw_interface_get_mac_address_reply_t *rmp; |
| 993 | vl_api_registration_t *reg; |
| 994 | vnet_main_t *vnm = vnet_get_main (); |
| 995 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 996 | vnet_sw_interface_t *si; |
| 997 | ethernet_interface_t *eth_if = 0; |
| 998 | int rv = 0; |
| 999 | |
| 1000 | VALIDATE_SW_IF_INDEX (mp); |
| 1001 | |
| 1002 | si = vnet_get_sup_sw_interface (vnm, sw_if_index); |
| 1003 | if (si->type == VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1004 | eth_if = ethernet_get_interface (ðernet_main, si->hw_if_index); |
| 1005 | |
| 1006 | BAD_SW_IF_INDEX_LABEL; |
| 1007 | |
| 1008 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1009 | if (!reg) |
| 1010 | return; |
| 1011 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1012 | rmp->_vl_msg_id = |
| 1013 | 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] | 1014 | rmp->context = mp->context; |
| 1015 | rmp->retval = htonl (rv); |
| 1016 | if (!rv && eth_if) |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1017 | mac_address_encode (ð_if->address.mac, rmp->mac_address); |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1018 | vl_api_send_msg (reg, (u8 *) rmp); |
| 1019 | } |
| 1020 | |
Steven Luong | f49734d | 2021-07-26 13:38:05 -0700 | [diff] [blame] | 1021 | static void |
| 1022 | vl_api_sw_interface_set_interface_name_t_handler ( |
| 1023 | vl_api_sw_interface_set_interface_name_t *mp) |
| 1024 | { |
| 1025 | vl_api_sw_interface_set_interface_name_reply_t *rmp; |
| 1026 | vnet_main_t *vnm = vnet_get_main (); |
| 1027 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1028 | vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1029 | clib_error_t *error; |
| 1030 | int rv = 0; |
| 1031 | |
| 1032 | if (mp->name[0] == 0) |
| 1033 | { |
| 1034 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1035 | goto out; |
| 1036 | } |
| 1037 | if (si == 0) |
| 1038 | { |
| 1039 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1040 | goto out; |
| 1041 | } |
| 1042 | |
| 1043 | error = vnet_rename_interface (vnm, si->hw_if_index, (char *) mp->name); |
| 1044 | if (error) |
| 1045 | { |
| 1046 | clib_error_free (error); |
| 1047 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1048 | } |
| 1049 | |
| 1050 | out: |
| 1051 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_INTERFACE_NAME_REPLY); |
| 1052 | } |
| 1053 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1054 | static void vl_api_sw_interface_set_rx_mode_t_handler |
| 1055 | (vl_api_sw_interface_set_rx_mode_t * mp) |
| 1056 | { |
| 1057 | vl_api_sw_interface_set_rx_mode_reply_t *rmp; |
| 1058 | vnet_main_t *vnm = vnet_get_main (); |
| 1059 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1060 | vnet_sw_interface_t *si; |
| 1061 | clib_error_t *error; |
| 1062 | int rv = 0; |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1063 | vnet_hw_if_rx_mode rx_mode; |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1064 | |
| 1065 | VALIDATE_SW_IF_INDEX (mp); |
| 1066 | |
| 1067 | si = vnet_get_sw_interface (vnm, sw_if_index); |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1068 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1069 | { |
| 1070 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1071 | goto bad_sw_if_index; |
| 1072 | } |
| 1073 | |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1074 | rx_mode = (vnet_hw_if_rx_mode) ntohl (mp->mode); |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1075 | error = set_hw_interface_change_rx_mode (vnm, si->hw_if_index, |
| 1076 | mp->queue_id_valid, |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1077 | ntohl (mp->queue_id), |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1078 | (vnet_hw_if_rx_mode) rx_mode); |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1079 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1080 | if (error) |
| 1081 | { |
| 1082 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 1083 | clib_error_report (error); |
| 1084 | goto out; |
| 1085 | } |
| 1086 | |
| 1087 | BAD_SW_IF_INDEX_LABEL; |
| 1088 | out: |
| 1089 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_MODE_REPLY); |
| 1090 | } |
| 1091 | |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1092 | static void |
| 1093 | send_interface_rx_placement_details (vpe_api_main_t * am, |
| 1094 | vl_api_registration_t * rp, |
| 1095 | u32 sw_if_index, u32 worker_id, |
| 1096 | u32 queue_id, u8 mode, u32 context) |
| 1097 | { |
| 1098 | vl_api_sw_interface_rx_placement_details_t *mp; |
| 1099 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1100 | clib_memset (mp, 0, sizeof (*mp)); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1101 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1102 | mp->_vl_msg_id = |
| 1103 | htons (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_RX_PLACEMENT_DETAILS); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1104 | mp->sw_if_index = htonl (sw_if_index); |
| 1105 | mp->queue_id = htonl (queue_id); |
| 1106 | mp->worker_id = htonl (worker_id); |
Jakub Grajciar | e30f1e9 | 2020-05-05 12:30:30 +0200 | [diff] [blame] | 1107 | mp->mode = htonl (mode); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1108 | mp->context = context; |
| 1109 | |
| 1110 | vl_api_send_msg (rp, (u8 *) mp); |
| 1111 | } |
| 1112 | |
| 1113 | static void vl_api_sw_interface_rx_placement_dump_t_handler |
| 1114 | (vl_api_sw_interface_rx_placement_dump_t * mp) |
| 1115 | { |
| 1116 | vnet_main_t *vnm = vnet_get_main (); |
| 1117 | vpe_api_main_t *am = &vpe_api_main; |
| 1118 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1119 | vl_api_registration_t *reg; |
| 1120 | |
| 1121 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1122 | if (!reg) |
| 1123 | return; |
| 1124 | |
| 1125 | if (sw_if_index == ~0) |
| 1126 | { |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1127 | vnet_hw_if_rx_queue_t **all_queues = 0; |
| 1128 | vnet_hw_if_rx_queue_t **qptr; |
| 1129 | vnet_hw_if_rx_queue_t *q; |
Nathan Skrzypczak | 455779f | 2021-02-15 14:48:33 +0100 | [diff] [blame] | 1130 | pool_foreach (q, vnm->interface_main.hw_if_rx_queues) |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1131 | vec_add1 (all_queues, q); |
| 1132 | 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] | 1133 | |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1134 | vec_foreach (qptr, all_queues) |
| 1135 | { |
| 1136 | u32 current_thread = qptr[0]->thread_index; |
| 1137 | u32 hw_if_index = qptr[0]->hw_if_index; |
| 1138 | vnet_hw_interface_t *hw_if = |
| 1139 | vnet_get_hw_interface (vnm, hw_if_index); |
| 1140 | send_interface_rx_placement_details ( |
| 1141 | am, reg, hw_if->sw_if_index, current_thread, qptr[0]->queue_id, |
| 1142 | qptr[0]->mode, mp->context); |
| 1143 | } |
| 1144 | vec_free (all_queues); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1145 | } |
| 1146 | else |
| 1147 | { |
| 1148 | int i; |
| 1149 | vnet_sw_interface_t *si; |
| 1150 | |
| 1151 | if (!vnet_sw_if_index_is_api_valid (sw_if_index)) |
| 1152 | { |
| 1153 | clib_warning ("sw_if_index %u does not exist", sw_if_index); |
| 1154 | goto bad_sw_if_index; |
| 1155 | } |
| 1156 | |
| 1157 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1158 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1159 | { |
| 1160 | clib_warning ("interface type is not HARDWARE! P2P, PIPE and SUB" |
| 1161 | " interfaces are not supported"); |
| 1162 | goto bad_sw_if_index; |
| 1163 | } |
| 1164 | |
| 1165 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, si->hw_if_index); |
| 1166 | |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1167 | for (i = 0; i < vec_len (hw->rx_queue_indices); i++) |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1168 | { |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1169 | vnet_hw_if_rx_queue_t *rxq = |
| 1170 | vnet_hw_if_get_rx_queue (vnm, hw->rx_queue_indices[i]); |
| 1171 | send_interface_rx_placement_details ( |
| 1172 | am, reg, hw->sw_if_index, rxq->thread_index, rxq->queue_id, |
| 1173 | rxq->mode, mp->context); |
Mohsin Kazmi | f0b42f4 | 2018-09-10 18:11:00 +0200 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | BAD_SW_IF_INDEX_LABEL; |
| 1178 | } |
| 1179 | |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1180 | static void vl_api_sw_interface_set_rx_placement_t_handler |
| 1181 | (vl_api_sw_interface_set_rx_placement_t * mp) |
| 1182 | { |
| 1183 | vl_api_sw_interface_set_rx_placement_reply_t *rmp; |
| 1184 | vnet_main_t *vnm = vnet_get_main (); |
| 1185 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1186 | vnet_sw_interface_t *si; |
| 1187 | clib_error_t *error = 0; |
| 1188 | int rv = 0; |
| 1189 | |
| 1190 | VALIDATE_SW_IF_INDEX (mp); |
| 1191 | |
| 1192 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1193 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1194 | { |
| 1195 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1196 | goto bad_sw_if_index; |
| 1197 | } |
| 1198 | |
| 1199 | error = set_hw_interface_rx_placement (si->hw_if_index, |
| 1200 | ntohl (mp->queue_id), |
| 1201 | ntohl (mp->worker_id), mp->is_main); |
| 1202 | if (error) |
| 1203 | { |
| 1204 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 1205 | clib_error_report (error); |
| 1206 | goto out; |
| 1207 | } |
| 1208 | |
| 1209 | BAD_SW_IF_INDEX_LABEL; |
| 1210 | out: |
| 1211 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_PLACEMENT_REPLY); |
| 1212 | } |
| 1213 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1214 | static void |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1215 | send_interface_tx_placement_details (vnet_hw_if_tx_queue_t **all_queues, |
| 1216 | u32 index, vl_api_registration_t *rp, |
Vratko Polak | 72c04bb | 2022-03-17 18:57:40 +0100 | [diff] [blame] | 1217 | u32 native_context) |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1218 | { |
| 1219 | vnet_main_t *vnm = vnet_get_main (); |
| 1220 | vl_api_sw_interface_tx_placement_details_t *rmp; |
| 1221 | u32 n_bits = 0, v = ~0; |
| 1222 | vnet_hw_if_tx_queue_t **q = vec_elt_at_index (all_queues, index); |
| 1223 | uword *bitmap = q[0]->threads; |
| 1224 | u32 hw_if_index = q[0]->hw_if_index; |
| 1225 | vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index); |
Vratko Polak | 72c04bb | 2022-03-17 18:57:40 +0100 | [diff] [blame] | 1226 | u32 context = clib_host_to_net_u32 (native_context); |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1227 | |
| 1228 | n_bits = clib_bitmap_count_set_bits (bitmap); |
| 1229 | u32 n = n_bits * sizeof (u32); |
| 1230 | |
Stanislav Zaikin | 139b2da | 2022-07-21 19:06:26 +0200 | [diff] [blame] | 1231 | REPLY_MACRO_DETAILS5_END (VL_API_SW_INTERFACE_TX_PLACEMENT_DETAILS, n, rp, |
| 1232 | context, ({ |
| 1233 | rmp->sw_if_index = hw_if->sw_if_index; |
| 1234 | rmp->queue_id = q[0]->queue_id; |
| 1235 | rmp->shared = q[0]->shared_queue; |
| 1236 | rmp->array_size = n_bits; |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1237 | |
Stanislav Zaikin | 139b2da | 2022-07-21 19:06:26 +0200 | [diff] [blame] | 1238 | v = clib_bitmap_first_set (bitmap); |
| 1239 | for (u32 i = 0; i < n_bits; i++) |
| 1240 | { |
| 1241 | rmp->threads[i] = v; |
| 1242 | v = clib_bitmap_next_set (bitmap, v + 1); |
| 1243 | } |
| 1244 | })); |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | static void |
| 1248 | vl_api_sw_interface_tx_placement_get_t_handler ( |
| 1249 | vl_api_sw_interface_tx_placement_get_t *mp) |
| 1250 | { |
| 1251 | vnet_main_t *vnm = vnet_get_main (); |
| 1252 | vl_api_sw_interface_tx_placement_get_reply_t *rmp = 0; |
| 1253 | vnet_hw_if_tx_queue_t **all_queues = 0; |
| 1254 | vnet_hw_if_tx_queue_t *q; |
| 1255 | u32 sw_if_index = mp->sw_if_index; |
| 1256 | i32 rv = 0; |
| 1257 | |
| 1258 | if (pool_elts (vnm->interface_main.hw_if_tx_queues) == 0) |
| 1259 | { |
| 1260 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 1261 | goto err; |
| 1262 | } |
| 1263 | |
| 1264 | if (sw_if_index == ~0) |
| 1265 | { |
| 1266 | pool_foreach (q, vnm->interface_main.hw_if_tx_queues) |
| 1267 | vec_add1 (all_queues, q); |
| 1268 | vec_sort_with_function (all_queues, vnet_hw_if_txq_cmp_cli_api); |
| 1269 | } |
| 1270 | else |
| 1271 | { |
| 1272 | u32 qi = ~0; |
| 1273 | vnet_sw_interface_t *si; |
| 1274 | |
| 1275 | if (!vnet_sw_if_index_is_api_valid (sw_if_index)) |
| 1276 | { |
| 1277 | clib_warning ("sw_if_index %u does not exist", sw_if_index); |
| 1278 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1279 | goto err; |
| 1280 | } |
| 1281 | |
| 1282 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1283 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1284 | { |
| 1285 | clib_warning ("interface type is not HARDWARE! P2P, PIPE and SUB" |
| 1286 | " interfaces are not supported"); |
| 1287 | rv = VNET_API_ERROR_INVALID_INTERFACE; |
| 1288 | goto err; |
| 1289 | } |
| 1290 | |
| 1291 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, si->hw_if_index); |
| 1292 | for (qi = 0; qi < vec_len (hw->tx_queue_indices); qi++) |
| 1293 | { |
| 1294 | q = vnet_hw_if_get_tx_queue (vnm, hw->tx_queue_indices[qi]); |
| 1295 | vec_add1 (all_queues, q); |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | REPLY_AND_DETAILS_VEC_MACRO_END (VL_API_SW_INTERFACE_TX_PLACEMENT_GET_REPLY, |
| 1300 | all_queues, mp, rmp, rv, ({ |
| 1301 | send_interface_tx_placement_details ( |
| 1302 | all_queues, cursor, rp, mp->context); |
| 1303 | })); |
| 1304 | |
| 1305 | vec_free (all_queues); |
| 1306 | return; |
| 1307 | |
| 1308 | err: |
| 1309 | REPLY_MACRO_END (VL_API_SW_INTERFACE_TX_PLACEMENT_GET_REPLY); |
| 1310 | } |
| 1311 | |
| 1312 | static void |
| 1313 | vl_api_sw_interface_set_tx_placement_t_handler ( |
| 1314 | vl_api_sw_interface_set_tx_placement_t *mp) |
| 1315 | { |
| 1316 | vl_api_sw_interface_set_tx_placement_reply_t *rmp; |
| 1317 | vnet_main_t *vnm = vnet_get_main (); |
| 1318 | u32 sw_if_index = mp->sw_if_index; |
| 1319 | vnet_sw_interface_t *si; |
| 1320 | uword *bitmap = 0; |
| 1321 | u32 queue_id = ~0; |
| 1322 | u32 size = 0; |
| 1323 | clib_error_t *error = 0; |
| 1324 | int rv = 0; |
| 1325 | |
| 1326 | VALIDATE_SW_IF_INDEX_END (mp); |
| 1327 | |
| 1328 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1329 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 1330 | { |
| 1331 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1332 | goto bad_sw_if_index; |
| 1333 | } |
| 1334 | |
| 1335 | size = mp->array_size; |
| 1336 | for (u32 i = 0; i < size; i++) |
| 1337 | { |
| 1338 | u32 thread_index = mp->threads[i]; |
| 1339 | bitmap = clib_bitmap_set (bitmap, thread_index, 1); |
| 1340 | } |
| 1341 | |
| 1342 | queue_id = mp->queue_id; |
| 1343 | rv = set_hw_interface_tx_queue (si->hw_if_index, queue_id, bitmap); |
| 1344 | |
| 1345 | switch (rv) |
| 1346 | { |
| 1347 | case VNET_API_ERROR_INVALID_VALUE: |
| 1348 | error = clib_error_return ( |
| 1349 | 0, "please specify valid thread(s) - last thread index %u", |
| 1350 | clib_bitmap_last_set (bitmap)); |
| 1351 | break; |
| 1352 | case VNET_API_ERROR_INVALID_QUEUE: |
| 1353 | error = clib_error_return ( |
| 1354 | 0, "unknown queue %u on interface %s", queue_id, |
| 1355 | vnet_get_hw_interface (vnet_get_main (), si->hw_if_index)->name); |
| 1356 | break; |
| 1357 | default: |
| 1358 | break; |
| 1359 | } |
| 1360 | |
| 1361 | if (error) |
| 1362 | { |
| 1363 | clib_error_report (error); |
| 1364 | goto out; |
| 1365 | } |
| 1366 | |
| 1367 | BAD_SW_IF_INDEX_LABEL; |
| 1368 | out: |
| 1369 | REPLY_MACRO_END (VL_API_SW_INTERFACE_SET_TX_PLACEMENT_REPLY); |
| 1370 | clib_bitmap_free (bitmap); |
| 1371 | } |
| 1372 | |
| 1373 | static void |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1374 | vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp) |
| 1375 | { |
| 1376 | vl_api_create_vlan_subif_reply_t *rmp; |
| 1377 | vnet_main_t *vnm = vnet_get_main (); |
| 1378 | u32 sw_if_index = (u32) ~ 0; |
| 1379 | vnet_hw_interface_t *hi; |
| 1380 | int rv = 0; |
| 1381 | u32 id; |
| 1382 | vnet_sw_interface_t template; |
| 1383 | uword *p; |
| 1384 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1385 | u64 sup_and_sub_key; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1386 | vl_api_registration_t *reg; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1387 | clib_error_t *error; |
| 1388 | |
| 1389 | VALIDATE_SW_IF_INDEX (mp); |
| 1390 | |
| 1391 | hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index)); |
| 1392 | |
| 1393 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
| 1394 | { |
| 1395 | rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED; |
| 1396 | goto out; |
| 1397 | } |
| 1398 | |
| 1399 | id = ntohl (mp->vlan_id); |
| 1400 | if (id == 0 || id > 4095) |
| 1401 | { |
| 1402 | rv = VNET_API_ERROR_INVALID_VLAN; |
| 1403 | goto out; |
| 1404 | } |
| 1405 | |
| 1406 | sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id; |
| 1407 | |
| 1408 | p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); |
| 1409 | if (p) |
| 1410 | { |
| 1411 | rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS; |
| 1412 | goto out; |
| 1413 | } |
| 1414 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1415 | clib_memset (&template, 0, sizeof (template)); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1416 | template.type = VNET_SW_INTERFACE_TYPE_SUB; |
Joe Zhou | 715f94e | 2019-03-06 23:05:32 -0800 | [diff] [blame] | 1417 | template.flood_class = VNET_FLOOD_CLASS_NORMAL; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1418 | template.sup_sw_if_index = hi->sw_if_index; |
| 1419 | template.sub.id = id; |
| 1420 | template.sub.eth.raw_flags = 0; |
| 1421 | template.sub.eth.flags.one_tag = 1; |
| 1422 | template.sub.eth.outer_vlan_id = id; |
| 1423 | template.sub.eth.flags.exact_match = 1; |
| 1424 | |
| 1425 | error = vnet_create_sw_interface (vnm, &template, &sw_if_index); |
| 1426 | if (error) |
| 1427 | { |
| 1428 | clib_error_report (error); |
| 1429 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 1430 | goto out; |
| 1431 | } |
| 1432 | |
| 1433 | u64 *kp = clib_mem_alloc (sizeof (*kp)); |
| 1434 | *kp = sup_and_sub_key; |
| 1435 | |
| 1436 | hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index); |
| 1437 | hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index); |
| 1438 | |
| 1439 | BAD_SW_IF_INDEX_LABEL; |
| 1440 | |
| 1441 | out: |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1442 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1443 | if (!reg) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1444 | return; |
| 1445 | |
| 1446 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1447 | 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] | 1448 | rmp->context = mp->context; |
| 1449 | rmp->retval = htonl (rv); |
| 1450 | rmp->sw_if_index = htonl (sw_if_index); |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1451 | vl_api_send_msg (reg, (u8 *) rmp); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | static void |
| 1455 | vl_api_create_subif_t_handler (vl_api_create_subif_t * mp) |
| 1456 | { |
| 1457 | vl_api_create_subif_reply_t *rmp; |
| 1458 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1459 | u32 sub_sw_if_index = ~0; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1460 | vnet_hw_interface_t *hi; |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1461 | int rv = 0; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1462 | |
| 1463 | VALIDATE_SW_IF_INDEX (mp); |
| 1464 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1465 | hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index)); |
| 1466 | |
| 1467 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1468 | rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED; |
| 1469 | else |
| 1470 | rv = vnet_create_sub_interface (ntohl (mp->sw_if_index), |
| 1471 | ntohl (mp->sub_id), |
| 1472 | ntohl (mp->sub_if_flags), |
| 1473 | ntohs (mp->inner_vlan_id), |
| 1474 | ntohs (mp->outer_vlan_id), |
| 1475 | &sub_sw_if_index); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1476 | |
| 1477 | BAD_SW_IF_INDEX_LABEL; |
| 1478 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1479 | /* *INDENT-OFF* */ |
| 1480 | REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY, |
| 1481 | ({ |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1482 | rmp->sw_if_index = ntohl(sub_sw_if_index); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1483 | })); |
| 1484 | /* *INDENT-ON* */ |
| 1485 | } |
| 1486 | |
| 1487 | static void |
| 1488 | vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp) |
| 1489 | { |
| 1490 | vl_api_delete_subif_reply_t *rmp; |
| 1491 | int rv; |
| 1492 | |
| 1493 | rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index)); |
| 1494 | |
| 1495 | REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY); |
| 1496 | } |
| 1497 | |
| 1498 | static void |
| 1499 | vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t * |
| 1500 | mp) |
| 1501 | { |
| 1502 | vl_api_interface_name_renumber_reply_t *rmp; |
| 1503 | int rv = 0; |
| 1504 | |
| 1505 | VALIDATE_SW_IF_INDEX (mp); |
| 1506 | |
| 1507 | rv = vnet_interface_name_renumber |
| 1508 | (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance)); |
| 1509 | |
| 1510 | BAD_SW_IF_INDEX_LABEL; |
| 1511 | |
| 1512 | REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY); |
| 1513 | } |
| 1514 | |
| 1515 | static void |
| 1516 | vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp) |
| 1517 | { |
| 1518 | vl_api_create_loopback_reply_t *rmp; |
| 1519 | u32 sw_if_index; |
| 1520 | int rv; |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1521 | mac_address_t mac; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1522 | |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1523 | mac_address_decode (mp->mac_address, &mac); |
| 1524 | rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac, 0, 0); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1525 | |
| 1526 | /* *INDENT-OFF* */ |
| 1527 | REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY, |
| 1528 | ({ |
| 1529 | rmp->sw_if_index = ntohl (sw_if_index); |
| 1530 | })); |
| 1531 | /* *INDENT-ON* */ |
| 1532 | } |
| 1533 | |
| 1534 | static void vl_api_create_loopback_instance_t_handler |
| 1535 | (vl_api_create_loopback_instance_t * mp) |
| 1536 | { |
| 1537 | vl_api_create_loopback_instance_reply_t *rmp; |
| 1538 | u32 sw_if_index; |
| 1539 | u8 is_specified = mp->is_specified; |
| 1540 | u32 user_instance = ntohl (mp->user_instance); |
| 1541 | int rv; |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1542 | mac_address_t mac; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1543 | |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1544 | mac_address_decode (mp->mac_address, &mac); |
| 1545 | rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac, |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1546 | is_specified, user_instance); |
| 1547 | |
| 1548 | /* *INDENT-OFF* */ |
| 1549 | REPLY_MACRO2(VL_API_CREATE_LOOPBACK_INSTANCE_REPLY, |
| 1550 | ({ |
| 1551 | rmp->sw_if_index = ntohl (sw_if_index); |
| 1552 | })); |
| 1553 | /* *INDENT-ON* */ |
| 1554 | } |
| 1555 | |
| 1556 | static void |
| 1557 | vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp) |
| 1558 | { |
| 1559 | vl_api_delete_loopback_reply_t *rmp; |
| 1560 | u32 sw_if_index; |
| 1561 | int rv; |
| 1562 | |
| 1563 | sw_if_index = ntohl (mp->sw_if_index); |
| 1564 | rv = vnet_delete_loopback_interface (sw_if_index); |
| 1565 | |
| 1566 | REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY); |
| 1567 | } |
| 1568 | |
Neale Ranns | 6f4a6be | 2018-03-16 16:26:21 -0700 | [diff] [blame] | 1569 | static void |
| 1570 | vl_api_collect_detailed_interface_stats_t_handler |
| 1571 | (vl_api_collect_detailed_interface_stats_t * mp) |
| 1572 | { |
| 1573 | vl_api_collect_detailed_interface_stats_reply_t *rmp; |
| 1574 | int rv = 0; |
| 1575 | |
Neale Ranns | 871dc42 | 2018-03-29 01:28:09 -0700 | [diff] [blame] | 1576 | rv = |
| 1577 | vnet_sw_interface_stats_collect_enable_disable (ntohl (mp->sw_if_index), |
| 1578 | mp->enable_disable); |
Neale Ranns | 6f4a6be | 2018-03-16 16:26:21 -0700 | [diff] [blame] | 1579 | |
| 1580 | REPLY_MACRO (VL_API_COLLECT_DETAILED_INTERFACE_STATS_REPLY); |
| 1581 | } |
| 1582 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 1583 | static void |
| 1584 | vl_api_sw_interface_address_replace_begin_t_handler |
| 1585 | (vl_api_sw_interface_address_replace_begin_t * mp) |
| 1586 | { |
| 1587 | vl_api_sw_interface_address_replace_begin_reply_t *rmp; |
| 1588 | int rv = 0; |
| 1589 | |
| 1590 | ip_interface_address_mark (); |
| 1591 | |
| 1592 | REPLY_MACRO (VL_API_SW_INTERFACE_ADDRESS_REPLACE_BEGIN_REPLY); |
| 1593 | } |
| 1594 | |
| 1595 | static void |
| 1596 | vl_api_sw_interface_address_replace_end_t_handler |
| 1597 | (vl_api_sw_interface_address_replace_end_t * mp) |
| 1598 | { |
| 1599 | vl_api_sw_interface_address_replace_end_reply_t *rmp; |
| 1600 | int rv = 0; |
| 1601 | |
| 1602 | ip_interface_address_sweep (); |
| 1603 | |
| 1604 | REPLY_MACRO (VL_API_SW_INTERFACE_ADDRESS_REPLACE_END_REPLY); |
| 1605 | } |
| 1606 | |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1607 | /* |
| 1608 | * vpe_api_hookup |
| 1609 | * Add vpe's API message handlers to the table. |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 1610 | * vlib has already mapped shared memory and |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1611 | * added the client registration handlers. |
| 1612 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 1613 | */ |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1614 | |
Dave Barach | 6d963c2 | 2016-12-05 09:50:05 -0500 | [diff] [blame] | 1615 | pub_sub_handler (interface_events, INTERFACE_EVENTS); |
| 1616 | |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1617 | #include <vnet/interface.api.c> |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1618 | static clib_error_t * |
| 1619 | interface_api_hookup (vlib_main_t * vm) |
| 1620 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1621 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1622 | |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1623 | /* |
| 1624 | * Set up the (msg_name, crc, message-id) table |
| 1625 | */ |
Filip Tehlar | 0577ff1 | 2021-06-27 00:18:57 +0000 | [diff] [blame] | 1626 | REPLY_MSG_ID_BASE = setup_message_id_table (); |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1627 | |
Ole Troan | 2ca88ff | 2022-01-27 16:25:43 +0100 | [diff] [blame] | 1628 | /* Mark these APIs as mp safe */ |
Damjan Marion | cada9eb | 2022-05-18 22:16:11 +0200 | [diff] [blame] | 1629 | vl_api_set_msg_thread_safe (am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_DUMP, |
| 1630 | 1); |
| 1631 | vl_api_set_msg_thread_safe ( |
| 1632 | am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_DETAILS, 1); |
| 1633 | vl_api_set_msg_thread_safe ( |
| 1634 | am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_TAG_ADD_DEL, 1); |
| 1635 | vl_api_set_msg_thread_safe ( |
| 1636 | 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] | 1637 | |
| 1638 | /* Do not replay VL_API_SW_INTERFACE_DUMP messages */ |
Damjan Marion | cada9eb | 2022-05-18 22:16:11 +0200 | [diff] [blame] | 1639 | vl_api_allow_msg_replay (am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_DUMP, |
| 1640 | 0); |
Ole Troan | 2ca88ff | 2022-01-27 16:25:43 +0100 | [diff] [blame] | 1641 | |
| 1642 | /* Mark these APIs as autoendian */ |
Damjan Marion | cada9eb | 2022-05-18 22:16:11 +0200 | [diff] [blame] | 1643 | vl_api_set_msg_autoendian ( |
| 1644 | am, REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_SET_TX_PLACEMENT, 1); |
| 1645 | vl_api_set_msg_autoendian ( |
| 1646 | 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] | 1647 | |
Dave Barach | aff7077 | 2016-10-31 11:59:07 -0400 | [diff] [blame] | 1648 | return 0; |
| 1649 | } |
| 1650 | |
| 1651 | VLIB_API_INIT_FUNCTION (interface_api_hookup); |
| 1652 | |
| 1653 | /* |
| 1654 | * fd.io coding-style-patch-verification: ON |
| 1655 | * |
| 1656 | * Local Variables: |
| 1657 | * eval: (c-set-style "gnu") |
| 1658 | * End: |
| 1659 | */ |