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