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