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