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