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