blob: 3448c6037b77ef51d825c6b4e7f3c2af4cf0f99c [file] [log] [blame]
Dave Barachaff70772016-10-31 11:59:07 -04001/*
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 Fabiand162f3d2016-12-05 01:05:35 -080025#include <vnet/ethernet/ethernet.h>
Dave Barach6d963c22016-12-05 09:50:05 -050026#include <vnet/ip/ip.h>
27#include <vnet/fib/fib_table.h>
Neale Ranns4008ac92017-02-13 23:20:04 -080028#include <vnet/mfib/mfib_table.h>
Dave Barach6d963c22016-12-05 09:50:05 -050029#include <vnet/l2/l2_vtr.h>
Dave Barachaff70772016-10-31 11:59:07 -040030#include <vnet/vnet_msg_enum.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050031#include <vnet/fib/fib_api.h>
Neale Ranns358425b2017-02-20 09:42:36 -080032#include <vnet/mfib/mfib_table.h>
Dave Barachaff70772016-10-31 11:59:07 -040033
Jakub Grajciar053204a2019-03-18 13:17:53 +010034#include <vlibapi/api_types.h>
35
36#include <vnet/ip/ip_types_api.h>
37#include <vnet/ethernet/ethernet_types_api.h>
38
Dave Barachaff70772016-10-31 11:59:07 -040039#define vl_typedefs /* define message structures */
40#include <vnet/vnet_all_api_h.h>
41#undef vl_typedefs
42
43#define vl_endianfun /* define message structures */
44#include <vnet/vnet_all_api_h.h>
45#undef vl_endianfun
46
47/* instantiate all the print functions we know about */
48#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
49#define vl_printfun
50#include <vnet/vnet_all_api_h.h>
51#undef vl_printfun
52
53#include <vlibapi/api_helper_macros.h>
Dave Barachf1586612017-03-30 09:33:01 -040054vpe_api_main_t vpe_api_main;
Dave Barachaff70772016-10-31 11:59:07 -040055
Dave Barach6d963c22016-12-05 09:50:05 -050056#define foreach_vpe_api_msg \
57_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
Ole Troand7231612018-06-07 10:17:57 +020058_(HW_INTERFACE_SET_MTU, hw_interface_set_mtu) \
Dave Barach6d963c22016-12-05 09:50:05 -050059_(SW_INTERFACE_SET_MTU, sw_interface_set_mtu) \
60_(WANT_INTERFACE_EVENTS, want_interface_events) \
61_(SW_INTERFACE_DUMP, sw_interface_dump) \
Dave Barach6d963c22016-12-05 09:50:05 -050062_(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
Stevenad8015b2017-10-29 22:10:46 -070063_(SW_INTERFACE_SET_RX_MODE, sw_interface_set_rx_mode) \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +020064_(SW_INTERFACE_RX_PLACEMENT_DUMP, sw_interface_rx_placement_dump) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +020065_(SW_INTERFACE_SET_RX_PLACEMENT, sw_interface_set_rx_placement) \
Dave Barach6d963c22016-12-05 09:50:05 -050066_(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
Juraj Slobodadfc19232016-12-05 13:20:37 +010067_(SW_INTERFACE_GET_TABLE, sw_interface_get_table) \
Dave Barach6d963c22016-12-05 09:50:05 -050068_(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
69_(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
Jon Loeliger10c273b2017-03-30 08:39:33 -050070_(SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del) \
Neale Rannsb8d44812017-11-10 06:53:54 -080071_(SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address) \
Juraj Slobodac0374232018-02-01 15:18:49 +010072_(SW_INTERFACE_GET_MAC_ADDRESS, sw_interface_get_mac_address) \
Neale Rannsb8d44812017-11-10 06:53:54 -080073_(CREATE_VLAN_SUBIF, create_vlan_subif) \
74_(CREATE_SUBIF, create_subif) \
75_(DELETE_SUBIF, delete_subif) \
76_(CREATE_LOOPBACK, create_loopback) \
77_(CREATE_LOOPBACK_INSTANCE, create_loopback_instance) \
78_(DELETE_LOOPBACK, delete_loopback) \
Neale Ranns6f4a6be2018-03-16 16:26:21 -070079_(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
Neale Ranns1855b8e2018-07-11 10:31:26 -070080_(COLLECT_DETAILED_INTERFACE_STATS, collect_detailed_interface_stats) \
81_(SW_INTERFACE_SET_IP_DIRECTED_BROADCAST, \
82 sw_interface_set_ip_directed_broadcast)
Dave Barachaff70772016-10-31 11:59:07 -040083
84static void
85vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
86{
87 vl_api_sw_interface_set_flags_reply_t *rmp;
88 vnet_main_t *vnm = vnet_get_main ();
89 int rv = 0;
90 clib_error_t *error;
91 u16 flags;
92
93 VALIDATE_SW_IF_INDEX (mp);
94
Jakub Grajciar053204a2019-03-18 13:17:53 +010095 flags =
96 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
97 VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
Dave Barachaff70772016-10-31 11:59:07 -040098
99 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
100 if (error)
101 {
102 rv = -1;
103 clib_error_report (error);
104 }
105
106 BAD_SW_IF_INDEX_LABEL;
107 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
108}
109
Matus Fabiand162f3d2016-12-05 01:05:35 -0800110static void
Ole Troand7231612018-06-07 10:17:57 +0200111vl_api_hw_interface_set_mtu_t_handler (vl_api_hw_interface_set_mtu_t * mp)
Matus Fabiand162f3d2016-12-05 01:05:35 -0800112{
Ole Troand7231612018-06-07 10:17:57 +0200113 vl_api_hw_interface_set_mtu_reply_t *rmp;
Matus Fabiand162f3d2016-12-05 01:05:35 -0800114 vnet_main_t *vnm = vnet_get_main ();
Matus Fabiand162f3d2016-12-05 01:05:35 -0800115 u32 sw_if_index = ntohl (mp->sw_if_index);
116 u16 mtu = ntohs (mp->mtu);
Damjan Marionfe7d4a22018-04-13 19:43:39 +0200117 ethernet_main_t *em = &ethernet_main;
Matus Fabiand162f3d2016-12-05 01:05:35 -0800118 int rv = 0;
119
120 VALIDATE_SW_IF_INDEX (mp);
121
Damjan Marionfe7d4a22018-04-13 19:43:39 +0200122 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
123 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
124 {
125 rv = VNET_API_ERROR_INVALID_VALUE;
126 goto bad_sw_if_index;
127 }
128
129 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, si->hw_if_index);
130 ethernet_interface_t *eif = ethernet_get_interface (em, si->hw_if_index);
131
132 if (!eif)
133 {
134 rv = VNET_API_ERROR_FEATURE_DISABLED;
135 goto bad_sw_if_index;
136 }
137
138 if (mtu < hi->min_supported_packet_bytes)
139 {
140 rv = VNET_API_ERROR_INVALID_VALUE;
141 goto bad_sw_if_index;
142 }
143
144 if (mtu > hi->max_supported_packet_bytes)
145 {
146 rv = VNET_API_ERROR_INVALID_VALUE;
147 goto bad_sw_if_index;
148 }
149
150 vnet_hw_interface_set_mtu (vnm, si->hw_if_index, mtu);
Matus Fabiand162f3d2016-12-05 01:05:35 -0800151
152 BAD_SW_IF_INDEX_LABEL;
Ole Troand7231612018-06-07 10:17:57 +0200153 REPLY_MACRO (VL_API_HW_INTERFACE_SET_MTU_REPLY);
154}
155
156static void
157vl_api_sw_interface_set_mtu_t_handler (vl_api_sw_interface_set_mtu_t * mp)
158{
159 vl_api_sw_interface_set_mtu_reply_t *rmp;
160 vnet_main_t *vnm = vnet_get_main ();
161 u32 sw_if_index = ntohl (mp->sw_if_index);
162 int rv = 0;
163 int i;
164 u32 per_protocol_mtu[VNET_N_MTU];
165
166 VALIDATE_SW_IF_INDEX (mp);
167
168 for (i = 0; i < VNET_N_MTU; i++)
169 per_protocol_mtu[i] = ntohl (mp->mtu[i]);
170
171 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, per_protocol_mtu);
172
173 BAD_SW_IF_INDEX_LABEL;
Matus Fabiand162f3d2016-12-05 01:05:35 -0800174 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY);
175}
176
Dave Barach6d963c22016-12-05 09:50:05 -0500177static void
Neale Ranns1855b8e2018-07-11 10:31:26 -0700178 vl_api_sw_interface_set_ip_directed_broadcast_t_handler
179 (vl_api_sw_interface_set_ip_directed_broadcast_t * mp)
180{
181 vl_api_sw_interface_set_ip_directed_broadcast_reply_t *rmp;
182 u32 sw_if_index = ntohl (mp->sw_if_index);
183 int rv = 0;
184
185 VALIDATE_SW_IF_INDEX (mp);
186
187 vnet_sw_interface_ip_directed_broadcast (vnet_get_main (),
188 sw_if_index, mp->enable);
189
190 BAD_SW_IF_INDEX_LABEL;
191 REPLY_MACRO (VL_API_SW_INTERFACE_SET_IP_DIRECTED_BROADCAST_REPLY);
192}
193
194static void
Dave Barach6d963c22016-12-05 09:50:05 -0500195send_sw_interface_details (vpe_api_main_t * am,
Dave Barach59b25652017-09-10 15:04:27 -0400196 vl_api_registration_t * rp,
Dave Barach6d963c22016-12-05 09:50:05 -0500197 vnet_sw_interface_t * swif,
198 u8 * interface_name, u32 context)
199{
Eyal Bari1c82cd42017-03-14 14:39:51 +0200200 vnet_hw_interface_t *hi =
201 vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
Dave Barach6d963c22016-12-05 09:50:05 -0500202
Ole Troane5ff5a32019-08-23 22:55:18 +0200203 vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
204 clib_memset (mp, 0, sizeof (*mp));
Dave Barach6d963c22016-12-05 09:50:05 -0500205 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
206 mp->sw_if_index = ntohl (swif->sw_if_index);
207 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
Jakub Grajciar053204a2019-03-18 13:17:53 +0100208
209 mp->flags |= (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
210 IF_STATUS_API_FLAG_ADMIN_UP : 0;
211 mp->flags |= (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
212 IF_STATUS_API_FLAG_LINK_UP : 0;
213 mp->flags = ntohl (mp->flags);
214
215 switch (swif->type)
216 {
217 case VNET_SW_INTERFACE_TYPE_SUB:
218 mp->type = IF_API_TYPE_SUB;
219 break;
220 case VNET_SW_INTERFACE_TYPE_P2P:
221 mp->type = IF_API_TYPE_P2P;
222 break;
223 case VNET_SW_INTERFACE_TYPE_PIPE:
224 mp->type = IF_API_TYPE_PIPE;
225 break;
226 default:
227 mp->type = IF_API_TYPE_HARDWARE;
228 }
229 mp->type = ntohl (mp->type);
230
Dave Barach6d963c22016-12-05 09:50:05 -0500231 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
232 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
Ole Troan8ee72512018-11-20 11:03:10 +0100233 mp->link_speed = ntohl (hi->link_speed);
Damjan Marionfe7d4a22018-04-13 19:43:39 +0200234 mp->link_mtu = ntohs (hi->max_packet_bytes);
Ole Troand7231612018-06-07 10:17:57 +0200235 mp->mtu[VNET_MTU_L3] = ntohl (swif->mtu[VNET_MTU_L3]);
236 mp->mtu[VNET_MTU_IP4] = ntohl (swif->mtu[VNET_MTU_IP4]);
237 mp->mtu[VNET_MTU_IP6] = ntohl (swif->mtu[VNET_MTU_IP6]);
238 mp->mtu[VNET_MTU_MPLS] = ntohl (swif->mtu[VNET_MTU_MPLS]);
239
Dave Barach6d963c22016-12-05 09:50:05 -0500240 mp->context = context;
241
Ole Troane5ff5a32019-08-23 22:55:18 +0200242 strncpy ((char *) mp->interface_name,
243 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
244
Dave Barach6d963c22016-12-05 09:50:05 -0500245 /* Send the L2 address for ethernet physical intfcs */
246 if (swif->sup_sw_if_index == swif->sw_if_index
247 && hi->hw_class_index == ethernet_hw_interface_class.index)
248 {
249 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
250 ethernet_interface_t *ei;
251
252 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
253 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
Jakub Grajciar053204a2019-03-18 13:17:53 +0100254 mac_address_encode ((mac_address_t *) ei->address, mp->l2_address);
Dave Barach6d963c22016-12-05 09:50:05 -0500255 }
256 else if (swif->sup_sw_if_index != swif->sw_if_index)
257 {
258 vnet_sub_interface_t *sub = &swif->sub;
259 mp->sub_id = ntohl (sub->id);
Dave Barach6d963c22016-12-05 09:50:05 -0500260 mp->sub_number_of_tags =
261 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
262 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
263 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
Jakub Grajciar053204a2019-03-18 13:17:53 +0100264 mp->sub_if_flags =
265 ntohl (sub->eth.raw_flags & SUB_IF_API_FLAG_MASK_VNET);
Dave Barach6d963c22016-12-05 09:50:05 -0500266
Jakub Grajciar053204a2019-03-18 13:17:53 +0100267 /* vlan tag rewrite data */
268 u32 vtr_op = L2_VTR_DISABLED;
269 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
Dave Barach6d963c22016-12-05 09:50:05 -0500270
Jakub Grajciar053204a2019-03-18 13:17:53 +0100271 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
272 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
273 {
274 // error - default to disabled
275 mp->vtr_op = ntohl (L2_VTR_DISABLED);
276 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
277 swif->sw_if_index);
278 }
279 else
280 {
281 mp->vtr_op = ntohl (vtr_op);
282 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
283 mp->vtr_tag1 = ntohl (vtr_tag1);
284 mp->vtr_tag2 = ntohl (vtr_tag2);
285 }
Dave Barach6d963c22016-12-05 09:50:05 -0500286 }
287
Pavel Kotucek65e84572017-01-16 17:01:56 +0100288 /* pbb tag rewrite data */
Gabriel Gannef7f2a9f2017-03-06 15:19:40 +0100289 ethernet_header_t eth_hdr;
Alexander Chernavinfdea5c62019-04-26 10:43:09 -0400290 u32 pbb_vtr_op = L2_VTR_DISABLED;
Pavel Kotucek65e84572017-01-16 17:01:56 +0100291 u16 outer_tag = 0;
Pavel Kotucek65e84572017-01-16 17:01:56 +0100292 u16 b_vlanid = 0;
293 u32 i_sid = 0;
Dave Barachb7b92992018-10-17 10:38:51 -0400294 clib_memset (&eth_hdr, 0, sizeof (eth_hdr));
Pavel Kotucek65e84572017-01-16 17:01:56 +0100295
296 if (!l2pbb_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
Alexander Chernavinfdea5c62019-04-26 10:43:09 -0400297 &pbb_vtr_op, &outer_tag, &eth_hdr, &b_vlanid, &i_sid))
Pavel Kotucek65e84572017-01-16 17:01:56 +0100298 {
Jakub Grajciar053204a2019-03-18 13:17:53 +0100299 mp->sub_if_flags |= ntohl (SUB_IF_API_FLAG_DOT1AH);
300 mac_address_encode ((mac_address_t *) eth_hdr.dst_address, mp->b_dmac);
301 mac_address_encode ((mac_address_t *) eth_hdr.src_address, mp->b_smac);
Pavel Kotucek65e84572017-01-16 17:01:56 +0100302 mp->b_vlanid = b_vlanid;
303 mp->i_sid = i_sid;
304 }
305
Ole Troane5ff5a32019-08-23 22:55:18 +0200306 u8 *tag = vnet_get_sw_interface_tag (vnet_get_main (), swif->sw_if_index);
307 if (tag)
308 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
Dave Barach6d963c22016-12-05 09:50:05 -0500309
Florin Corase86a8ed2018-01-05 03:20:25 -0800310 vl_api_send_msg (rp, (u8 *) mp);
Dave Barach6d963c22016-12-05 09:50:05 -0500311}
312
313static void
314vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
315{
316 vpe_api_main_t *am = &vpe_api_main;
317 vnet_sw_interface_t *swif;
318 vnet_interface_main_t *im = &am->vnet_main->interface_main;
Dave Barach59b25652017-09-10 15:04:27 -0400319 vl_api_registration_t *rp;
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700320 u32 sw_if_index;
Dave Barach6d963c22016-12-05 09:50:05 -0500321
Dave Barach59b25652017-09-10 15:04:27 -0400322 rp = vl_api_client_index_to_registration (mp->client_index);
323
324 if (rp == 0)
325 {
326 clib_warning ("Client %d AWOL", mp->client_index);
327 return;
328 }
Dave Barach6d963c22016-12-05 09:50:05 -0500329
Eyal Bari1c82cd42017-03-14 14:39:51 +0200330 u8 *filter = 0, *name = 0;
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700331 sw_if_index = ntohl (mp->sw_if_index);
332
Vratko Polakb8591ac2019-04-23 12:26:44 +0200333 if (!mp->name_filter_valid && sw_if_index != ~0 && sw_if_index != 0)
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700334 {
Vratko Polakb8591ac2019-04-23 12:26:44 +0200335 /* is it a valid sw_if_index? */
Neale Rannsf5b01762019-06-14 08:26:21 +0000336 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700337 return;
338
339 swif = vec_elt_at_index (im->sw_interfaces, sw_if_index);
340
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700341 vec_reset_length (name);
342 name =
343 format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main,
344 swif, 0);
345 send_sw_interface_details (am, rp, swif, name, mp->context);
346 vec_free (name);
347 return;
348 }
349
Dave Barach6d963c22016-12-05 09:50:05 -0500350 if (mp->name_filter_valid)
351 {
Jakub Grajciar053204a2019-03-18 13:17:53 +0100352 filter =
Ole Troane5ff5a32019-08-23 22:55:18 +0200353 format (0, ".*%s", vl_api_string_len (&mp->name_filter),
354 vl_api_from_api_string (&mp->name_filter), 0);
Dave Barach6d963c22016-12-05 09:50:05 -0500355 }
356
Eyal Bari1c82cd42017-03-14 14:39:51 +0200357 char *strcasestr (char *, char *); /* lnx hdr file botch */
Dave Barach6d963c22016-12-05 09:50:05 -0500358 /* *INDENT-OFF* */
359 pool_foreach (swif, im->sw_interfaces,
360 ({
Eyal Bari1c82cd42017-03-14 14:39:51 +0200361 if (!vnet_swif_is_api_visible (swif))
362 continue;
363 vec_reset_length(name);
364 name = format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main,
365 swif, 0);
Dave Barach6d963c22016-12-05 09:50:05 -0500366
Eyal Bari1c82cd42017-03-14 14:39:51 +0200367 if (filter && !strcasestr((char *) name, (char *) filter))
368 continue;
Dave Barach6d963c22016-12-05 09:50:05 -0500369
Dave Barach59b25652017-09-10 15:04:27 -0400370 send_sw_interface_details (am, rp, swif, name, mp->context);
Dave Barach6d963c22016-12-05 09:50:05 -0500371 }));
372 /* *INDENT-ON* */
373
Eyal Bari1c82cd42017-03-14 14:39:51 +0200374 vec_free (name);
375 vec_free (filter);
Dave Barach6d963c22016-12-05 09:50:05 -0500376}
377
378static void
379 vl_api_sw_interface_add_del_address_t_handler
380 (vl_api_sw_interface_add_del_address_t * mp)
381{
382 vlib_main_t *vm = vlib_get_main ();
Jon Loeliger35ffa3e2017-09-28 13:54:16 -0500383 vnet_main_t *vnm = vnet_get_main ();
Dave Barach6d963c22016-12-05 09:50:05 -0500384 vl_api_sw_interface_add_del_address_reply_t *rmp;
385 int rv = 0;
386 u32 is_del;
Jon Loeliger35ffa3e2017-09-28 13:54:16 -0500387 clib_error_t *error = 0;
Jakub Grajciar053204a2019-03-18 13:17:53 +0100388 ip46_address_t address;
Dave Barach6d963c22016-12-05 09:50:05 -0500389
390 VALIDATE_SW_IF_INDEX (mp);
391
392 is_del = mp->is_add == 0;
Jon Loeliger35ffa3e2017-09-28 13:54:16 -0500393 vnm->api_errno = 0;
Dave Barach6d963c22016-12-05 09:50:05 -0500394
395 if (mp->del_all)
396 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
Jakub Grajciar053204a2019-03-18 13:17:53 +0100397 else if (ip_address_decode (&mp->prefix.address, &address) == IP46_TYPE_IP6)
Jon Loeliger35ffa3e2017-09-28 13:54:16 -0500398 error = ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
Jakub Grajciar053204a2019-03-18 13:17:53 +0100399 (void *) &address.ip6,
400 mp->prefix.len, is_del);
Dave Barach6d963c22016-12-05 09:50:05 -0500401 else
Jon Loeliger35ffa3e2017-09-28 13:54:16 -0500402 error = ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
Jakub Grajciar053204a2019-03-18 13:17:53 +0100403 (void *) &address.ip4,
404 mp->prefix.len, is_del);
Jon Loeliger35ffa3e2017-09-28 13:54:16 -0500405
406 if (error)
407 {
408 rv = vnm->api_errno;
409 clib_error_report (error);
410 goto done;
411 }
Dave Barach6d963c22016-12-05 09:50:05 -0500412
413 BAD_SW_IF_INDEX_LABEL;
414
Jon Loeliger35ffa3e2017-09-28 13:54:16 -0500415done:
Dave Barach6d963c22016-12-05 09:50:05 -0500416 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
417}
418
Dave Barach6d963c22016-12-05 09:50:05 -0500419static void
420vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
421{
Dave Barach6d963c22016-12-05 09:50:05 -0500422 vl_api_sw_interface_set_table_reply_t *rmp;
Neale Ranns15002542017-09-10 04:39:11 -0700423 u32 sw_if_index = ntohl (mp->sw_if_index);
424 u32 table_id = ntohl (mp->vrf_id);
425 int rv = 0;
Dave Barach6d963c22016-12-05 09:50:05 -0500426
427 VALIDATE_SW_IF_INDEX (mp);
428
Dave Barach6d963c22016-12-05 09:50:05 -0500429 if (mp->is_ipv6)
Neale Ranns15002542017-09-10 04:39:11 -0700430 rv = ip_table_bind (FIB_PROTOCOL_IP6, sw_if_index, table_id, 1);
Dave Barach6d963c22016-12-05 09:50:05 -0500431 else
Neale Ranns15002542017-09-10 04:39:11 -0700432 rv = ip_table_bind (FIB_PROTOCOL_IP4, sw_if_index, table_id, 1);
Dave Barach6d963c22016-12-05 09:50:05 -0500433
Dave Barach6d963c22016-12-05 09:50:05 -0500434 BAD_SW_IF_INDEX_LABEL;
435
436 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
437}
438
Neale Ranns15002542017-09-10 04:39:11 -0700439int
440ip_table_bind (fib_protocol_t fproto,
Neale Ranns6b3a8ef2017-09-11 10:34:33 -0700441 u32 sw_if_index, u32 table_id, u8 is_api)
Neale Ranns15002542017-09-10 04:39:11 -0700442{
443 CLIB_UNUSED (ip_interface_address_t * ia);
444 u32 fib_index, mfib_index;
445 fib_source_t src;
446 mfib_source_t msrc;
447
448 if (is_api)
449 {
450 src = FIB_SOURCE_API;
451 msrc = MFIB_SOURCE_API;
452 }
453 else
454 {
455 src = FIB_SOURCE_CLI;
456 msrc = MFIB_SOURCE_CLI;
457 }
458
Florin Corasd0a59722017-10-15 17:41:21 +0000459 /*
Florin Corasd0a59722017-10-15 17:41:21 +0000460 * This if table does not exist = error is what we want in the end.
461 */
Neale Ranns8f6dd322018-05-17 06:34:24 -0700462 fib_index = fib_table_find (fproto, table_id);
463 mfib_index = mfib_table_find (fproto, table_id);
Florin Corasd0a59722017-10-15 17:41:21 +0000464
Neale Ranns8f6dd322018-05-17 06:34:24 -0700465 if (~0 == fib_index || ~0 == mfib_index)
466 {
467 return (VNET_API_ERROR_NO_SUCH_FIB);
468 }
Florin Corasd0a59722017-10-15 17:41:21 +0000469
Neale Ranns15002542017-09-10 04:39:11 -0700470 if (FIB_PROTOCOL_IP6 == fproto)
471 {
472 /*
473 * If the interface already has in IP address, then a change int
474 * VRF is not allowed. The IP address applied must first be removed.
475 * We do not do that automatically here, since VPP has no knowledge
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700476 * of whether those subnets are valid in the destination VRF.
Neale Ranns15002542017-09-10 04:39:11 -0700477 */
478 /* *INDENT-OFF* */
479 foreach_ip_interface_address (&ip6_main.lookup_main,
480 ia, sw_if_index,
481 1 /* honor unnumbered */ ,
482 ({
483 return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE);
484 }));
485 /* *INDENT-ON* */
486
487 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
488 vec_validate (ip6_main.mfib_index_by_sw_if_index, sw_if_index);
489
490 /*
491 * tell those that are interested that the binding is changing.
492 */
493 ip6_table_bind_callback_t *cb;
494 vec_foreach (cb, ip6_main.table_bind_callbacks)
495 cb->function (&ip6_main, cb->function_opaque,
496 sw_if_index,
497 fib_index,
498 ip6_main.fib_index_by_sw_if_index[sw_if_index]);
499
500 if (0 == table_id)
501 {
502 /* reset back to default */
503 if (0 != ip6_main.fib_index_by_sw_if_index[sw_if_index])
504 fib_table_unlock (ip6_main.fib_index_by_sw_if_index[sw_if_index],
505 FIB_PROTOCOL_IP6, src);
506 if (0 != ip6_main.mfib_index_by_sw_if_index[sw_if_index])
507 mfib_table_unlock (ip6_main.mfib_index_by_sw_if_index
508 [sw_if_index], FIB_PROTOCOL_IP6, msrc);
509
510 }
511 else
512 {
513 /* we need to lock the table now it's inuse */
514 fib_table_lock (fib_index, FIB_PROTOCOL_IP6, src);
515 mfib_table_lock (mfib_index, FIB_PROTOCOL_IP6, msrc);
516 }
517
518 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
519 ip6_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index;
520 }
521 else
522 {
523 /*
524 * If the interface already has in IP address, then a change int
525 * VRF is not allowed. The IP address applied must first be removed.
526 * We do not do that automatically here, since VPP has no knowledge
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700527 * of whether those subnets are valid in the destination VRF.
Neale Ranns15002542017-09-10 04:39:11 -0700528 */
529 /* *INDENT-OFF* */
530 foreach_ip_interface_address (&ip4_main.lookup_main,
531 ia, sw_if_index,
532 1 /* honor unnumbered */ ,
533 ({
534 return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE);
535 }));
536 /* *INDENT-ON* */
537
538 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
539 vec_validate (ip4_main.mfib_index_by_sw_if_index, sw_if_index);
540
541 /*
542 * tell those that are interested that the binding is changing.
543 */
544 ip4_table_bind_callback_t *cb;
545 vec_foreach (cb, ip4_main.table_bind_callbacks)
546 cb->function (&ip4_main, cb->function_opaque,
547 sw_if_index,
548 fib_index,
549 ip4_main.fib_index_by_sw_if_index[sw_if_index]);
550
551 if (0 == table_id)
552 {
553 /* reset back to default */
554 if (0 != ip4_main.fib_index_by_sw_if_index[sw_if_index])
555 fib_table_unlock (ip4_main.fib_index_by_sw_if_index[sw_if_index],
556 FIB_PROTOCOL_IP4, src);
557 if (0 != ip4_main.mfib_index_by_sw_if_index[sw_if_index])
558 mfib_table_unlock (ip4_main.mfib_index_by_sw_if_index
559 [sw_if_index], FIB_PROTOCOL_IP4, msrc);
560
561 }
562 else
563 {
564 /* we need to lock the table now it's inuse */
565 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
566 table_id, src);
567
568 mfib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
569 table_id, msrc);
570 }
571
572 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
573 ip4_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index;
574 }
575
Neale Ranns15002542017-09-10 04:39:11 -0700576 return (0);
577}
578
Juraj Slobodadfc19232016-12-05 13:20:37 +0100579static void
Florin Coras6c4dae22018-01-09 06:39:23 -0800580send_sw_interface_get_table_reply (vl_api_registration_t * reg,
Juraj Slobodadfc19232016-12-05 13:20:37 +0100581 u32 context, int retval, u32 vrf_id)
582{
583 vl_api_sw_interface_get_table_reply_t *mp;
584
585 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400586 clib_memset (mp, 0, sizeof (*mp));
Juraj Slobodadfc19232016-12-05 13:20:37 +0100587 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_GET_TABLE_REPLY);
588 mp->context = context;
589 mp->retval = htonl (retval);
590 mp->vrf_id = htonl (vrf_id);
591
Florin Coras6c4dae22018-01-09 06:39:23 -0800592 vl_api_send_msg (reg, (u8 *) mp);
Juraj Slobodadfc19232016-12-05 13:20:37 +0100593}
594
595static void
596vl_api_sw_interface_get_table_t_handler (vl_api_sw_interface_get_table_t * mp)
597{
Florin Coras6c4dae22018-01-09 06:39:23 -0800598 vl_api_registration_t *reg;
Juraj Slobodadfc19232016-12-05 13:20:37 +0100599 fib_table_t *fib_table = 0;
600 u32 sw_if_index = ~0;
601 u32 fib_index = ~0;
602 u32 table_id = ~0;
603 fib_protocol_t fib_proto = FIB_PROTOCOL_IP4;
604 int rv = 0;
605
Florin Coras6c4dae22018-01-09 06:39:23 -0800606 reg = vl_api_client_index_to_registration (mp->client_index);
607 if (!reg)
Juraj Slobodadfc19232016-12-05 13:20:37 +0100608 return;
609
610 VALIDATE_SW_IF_INDEX (mp);
611
612 sw_if_index = ntohl (mp->sw_if_index);
613
614 if (mp->is_ipv6)
615 fib_proto = FIB_PROTOCOL_IP6;
616
617 fib_index = fib_table_get_index_for_sw_if_index (fib_proto, sw_if_index);
618 if (fib_index != ~0)
619 {
620 fib_table = fib_table_get (fib_index, fib_proto);
621 table_id = fib_table->ft_table_id;
622 }
623
624 BAD_SW_IF_INDEX_LABEL;
625
Florin Coras6c4dae22018-01-09 06:39:23 -0800626 send_sw_interface_get_table_reply (reg, mp->context, rv, table_id);
Juraj Slobodadfc19232016-12-05 13:20:37 +0100627}
628
Dave Barach6d963c22016-12-05 09:50:05 -0500629static void vl_api_sw_interface_set_unnumbered_t_handler
630 (vl_api_sw_interface_set_unnumbered_t * mp)
631{
632 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
633 int rv = 0;
Dave Barach6d963c22016-12-05 09:50:05 -0500634 vnet_main_t *vnm = vnet_get_main ();
Eyal Bari1c82cd42017-03-14 14:39:51 +0200635 u32 sw_if_index = ntohl (mp->sw_if_index);
636 u32 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
Dave Barach6d963c22016-12-05 09:50:05 -0500637
638 /*
639 * The API message field names are backwards from
640 * the underlying data structure names.
641 * It's not worth changing them now.
642 */
Eyal Bari1c82cd42017-03-14 14:39:51 +0200643 if (!vnet_sw_interface_is_api_valid (vnm, unnumbered_sw_if_index))
Dave Barach6d963c22016-12-05 09:50:05 -0500644 {
645 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
646 goto done;
647 }
648
649 /* Only check the "use loop0" field when setting the binding */
Eyal Bari1c82cd42017-03-14 14:39:51 +0200650 if (mp->is_add && !vnet_sw_interface_is_api_valid (vnm, sw_if_index))
Dave Barach6d963c22016-12-05 09:50:05 -0500651 {
652 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
653 goto done;
654 }
655
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700656 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
657 sw_if_index, mp->is_add);
Dave Barach6d963c22016-12-05 09:50:05 -0500658done:
659 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
660}
661
662static void
663vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
664 mp)
665{
666 vl_api_sw_interface_clear_stats_reply_t *rmp;
667
668 vnet_main_t *vnm = vnet_get_main ();
669 vnet_interface_main_t *im = &vnm->interface_main;
670 vlib_simple_counter_main_t *sm;
671 vlib_combined_counter_main_t *cm;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400672 int j, n_counters;
Dave Barach6d963c22016-12-05 09:50:05 -0500673 int rv = 0;
674
675 if (mp->sw_if_index != ~0)
676 VALIDATE_SW_IF_INDEX (mp);
677
Dave Barach6d963c22016-12-05 09:50:05 -0500678 n_counters = vec_len (im->combined_sw_if_counters);
679
680 for (j = 0; j < n_counters; j++)
681 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400682 im = &vnm->interface_main;
683 cm = im->combined_sw_if_counters + j;
684 if (mp->sw_if_index == (u32) ~ 0)
685 vlib_clear_combined_counters (cm);
686 else
687 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
Dave Barach6d963c22016-12-05 09:50:05 -0500688 }
689
690 n_counters = vec_len (im->sw_if_counters);
691
692 for (j = 0; j < n_counters; j++)
693 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400694 im = &vnm->interface_main;
695 sm = im->sw_if_counters + j;
696 if (mp->sw_if_index == (u32) ~ 0)
697 vlib_clear_simple_counters (sm);
698 else
699 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
Dave Barach6d963c22016-12-05 09:50:05 -0500700 }
701
702 BAD_SW_IF_INDEX_LABEL;
703
704 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
705}
706
Ole Troan2e1c8962019-04-10 09:44:23 +0200707/*
708 * Events used for sw_interface_events
709 */
710enum api_events
Dave Barach6d963c22016-12-05 09:50:05 -0500711{
Ole Troan2e1c8962019-04-10 09:44:23 +0200712 API_LINK_STATE_UP_EVENT = 1 << 1,
713 API_LINK_STATE_DOWN_EVENT = 1 << 2,
714 API_ADMIN_UP_EVENT = 1 << 3,
715 API_ADMIN_DOWN_EVENT = 1 << 4,
716 API_SW_INTERFACE_ADD_EVENT = 1 << 5,
717 API_SW_INTERFACE_DEL_EVENT = 1 << 6,
718};
Dave Barach6d963c22016-12-05 09:50:05 -0500719
720static void
Neale Rannsa07bd702017-08-07 07:53:49 -0700721send_sw_interface_event (vpe_api_main_t * am,
Neale Rannsd292ab12017-08-15 12:29:48 -0700722 vpe_client_registration_t * reg,
Florin Coras6c4dae22018-01-09 06:39:23 -0800723 vl_api_registration_t * vl_reg,
Ole Troan2e1c8962019-04-10 09:44:23 +0200724 u32 sw_if_index, enum api_events events)
Dave Barach6d963c22016-12-05 09:50:05 -0500725{
Neale Rannsa07bd702017-08-07 07:53:49 -0700726 vl_api_sw_interface_event_t *mp;
Dave Barach6d963c22016-12-05 09:50:05 -0500727
Dave Barach6d963c22016-12-05 09:50:05 -0500728 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400729 clib_memset (mp, 0, sizeof (*mp));
Neale Rannsa07bd702017-08-07 07:53:49 -0700730 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_EVENT);
Ole Troan2e1c8962019-04-10 09:44:23 +0200731 mp->sw_if_index = ntohl (sw_if_index);
Neale Rannsd292ab12017-08-15 12:29:48 -0700732 mp->client_index = reg->client_index;
733 mp->pid = reg->client_pid;
Jakub Grajciar053204a2019-03-18 13:17:53 +0100734 mp->flags = 0;
735 mp->flags |= (events & API_ADMIN_UP_EVENT) ?
736 IF_STATUS_API_FLAG_ADMIN_UP : 0;
737 mp->flags |= (events & API_LINK_STATE_UP_EVENT) ?
738 IF_STATUS_API_FLAG_LINK_UP : 0;
739 mp->flags = ntohl (mp->flags);
740 mp->deleted = events & API_SW_INTERFACE_DEL_EVENT ? true : false;
Florin Coras6c4dae22018-01-09 06:39:23 -0800741 vl_api_send_msg (vl_reg, (u8 *) mp);
Dave Barach6d963c22016-12-05 09:50:05 -0500742}
743
744static uword
745link_state_process (vlib_main_t * vm,
746 vlib_node_runtime_t * rt, vlib_frame_t * f)
747{
748 vpe_api_main_t *vam = &vpe_api_main;
Ole Troan2e1c8962019-04-10 09:44:23 +0200749 uword *event_by_sw_if_index = 0;
Dave Barach6d963c22016-12-05 09:50:05 -0500750 vpe_client_registration_t *reg;
751 int i;
Florin Coras6c4dae22018-01-09 06:39:23 -0800752 vl_api_registration_t *vl_reg;
Ole Troan2e1c8962019-04-10 09:44:23 +0200753 uword event_type;
754 uword *event_data = 0;
755 u32 sw_if_index;
Dave Barach6d963c22016-12-05 09:50:05 -0500756
757 vam->link_state_process_up = 1;
758
759 while (1)
760 {
761 vlib_process_wait_for_event (vm);
762
Ole Troan2e1c8962019-04-10 09:44:23 +0200763 /* Batch up events */
764 while ((event_type = vlib_process_get_events (vm, &event_data)) != ~0)
Dave Barach6d963c22016-12-05 09:50:05 -0500765 {
Ole Troan2e1c8962019-04-10 09:44:23 +0200766 for (i = 0; i < vec_len (event_data); i++)
767 {
768 sw_if_index = event_data[i];
769 vec_validate_init_empty (event_by_sw_if_index, sw_if_index, 0);
770 event_by_sw_if_index[sw_if_index] |= event_type;
771 }
772 vec_reset_length (event_data);
773 }
774
775 for (i = 0; i < vec_len (event_by_sw_if_index); i++)
776 {
777 if (event_by_sw_if_index[i] == 0)
Dave Barach6d963c22016-12-05 09:50:05 -0500778 continue;
Dave Barach6d963c22016-12-05 09:50:05 -0500779
780 /* *INDENT-OFF* */
781 pool_foreach(reg, vam->interface_events_registrations,
782 ({
Florin Coras6c4dae22018-01-09 06:39:23 -0800783 vl_reg = vl_api_client_index_to_registration (reg->client_index);
784 if (vl_reg)
Ole Troan2e1c8962019-04-10 09:44:23 +0200785 send_sw_interface_event (vam, reg, vl_reg, i, event_by_sw_if_index[i]);
Dave Barach6d963c22016-12-05 09:50:05 -0500786 }));
787 /* *INDENT-ON* */
788 }
Ole Troan2e1c8962019-04-10 09:44:23 +0200789 vec_reset_length (event_by_sw_if_index);
Dave Barach6d963c22016-12-05 09:50:05 -0500790 }
791
792 return 0;
793}
794
795static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
796 u32 flags);
797static clib_error_t *admin_up_down_function (vnet_main_t * vm,
798 u32 hw_if_index, u32 flags);
Ole Troan2e1c8962019-04-10 09:44:23 +0200799static clib_error_t *sw_interface_add_del_function (vnet_main_t * vm,
800 u32 sw_if_index,
801 u32 flags);
Dave Barach6d963c22016-12-05 09:50:05 -0500802
803/* *INDENT-OFF* */
804VLIB_REGISTER_NODE (link_state_process_node,static) = {
805 .function = link_state_process,
806 .type = VLIB_NODE_TYPE_PROCESS,
807 .name = "vpe-link-state-process",
808};
809/* *INDENT-ON* */
810
811VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
812VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
Ole Troan2e1c8962019-04-10 09:44:23 +0200813VNET_SW_INTERFACE_ADD_DEL_FUNCTION (sw_interface_add_del_function);
Dave Barach6d963c22016-12-05 09:50:05 -0500814
815static clib_error_t *
816link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
817{
818 vpe_api_main_t *vam = &vpe_api_main;
819 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
820
821 if (vam->link_state_process_up)
Ole Troan2e1c8962019-04-10 09:44:23 +0200822 {
823 enum api_events event =
824 flags ? API_LINK_STATE_UP_EVENT : API_LINK_STATE_DOWN_EVENT;
825 vlib_process_signal_event (vam->vlib_main,
826 link_state_process_node.index, event,
827 hi->sw_if_index);
828 }
Dave Barach6d963c22016-12-05 09:50:05 -0500829 return 0;
830}
831
832static clib_error_t *
833admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
834{
835 vpe_api_main_t *vam = &vpe_api_main;
836
837 /*
838 * Note: it's perfectly fair to set a subif admin up / admin down.
839 * Note the subtle distinction between this routine and the previous
840 * routine.
841 */
842 if (vam->link_state_process_up)
Ole Troan2e1c8962019-04-10 09:44:23 +0200843 {
844 enum api_events event =
845 flags ? API_ADMIN_UP_EVENT : API_ADMIN_DOWN_EVENT;
846 vlib_process_signal_event (vam->vlib_main,
847 link_state_process_node.index, event,
848 sw_if_index);
849 }
850 return 0;
851}
852
853static clib_error_t *
854sw_interface_add_del_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
855{
856 vpe_api_main_t *vam = &vpe_api_main;
857
858 if (vam->link_state_process_up)
859 {
860 enum api_events event =
861 flags ? API_SW_INTERFACE_ADD_EVENT : API_SW_INTERFACE_DEL_EVENT;
862 vlib_process_signal_event (vam->vlib_main,
863 link_state_process_node.index, event,
864 sw_if_index);
865 }
Dave Barach6d963c22016-12-05 09:50:05 -0500866 return 0;
867}
868
869static void vl_api_sw_interface_tag_add_del_t_handler
870 (vl_api_sw_interface_tag_add_del_t * mp)
871{
872 vnet_main_t *vnm = vnet_get_main ();
873 vl_api_sw_interface_tag_add_del_reply_t *rmp;
874 int rv = 0;
875 u8 *tag;
876 u32 sw_if_index = ntohl (mp->sw_if_index);
877
878 VALIDATE_SW_IF_INDEX (mp);
879
880 if (mp->is_add)
881 {
Ole Troane5ff5a32019-08-23 22:55:18 +0200882 if (mp->tag[0] == 0)
Dave Barach6d963c22016-12-05 09:50:05 -0500883 {
884 rv = VNET_API_ERROR_INVALID_VALUE;
885 goto out;
886 }
887
Ole Troane5ff5a32019-08-23 22:55:18 +0200888 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
889 tag = format (0, "%s%c", mp->tag, 0);
Dave Barach6d963c22016-12-05 09:50:05 -0500890 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
891 }
892 else
893 vnet_clear_sw_interface_tag (vnm, sw_if_index);
894
895 BAD_SW_IF_INDEX_LABEL;
896out:
897 REPLY_MACRO (VL_API_SW_INTERFACE_TAG_ADD_DEL_REPLY);
898}
899
Jon Loeliger10c273b2017-03-30 08:39:33 -0500900static void vl_api_sw_interface_set_mac_address_t_handler
901 (vl_api_sw_interface_set_mac_address_t * mp)
902{
903 vl_api_sw_interface_set_mac_address_reply_t *rmp;
904 vnet_main_t *vnm = vnet_get_main ();
905 u32 sw_if_index = ntohl (mp->sw_if_index);
Neale Rannsd867a7c2017-10-04 02:29:07 -0700906 vnet_sw_interface_t *si;
Jon Loeliger10c273b2017-03-30 08:39:33 -0500907 clib_error_t *error;
908 int rv = 0;
Jakub Grajciar053204a2019-03-18 13:17:53 +0100909 mac_address_t mac;
Jon Loeliger10c273b2017-03-30 08:39:33 -0500910
911 VALIDATE_SW_IF_INDEX (mp);
912
Neale Rannsd867a7c2017-10-04 02:29:07 -0700913 si = vnet_get_sw_interface (vnm, sw_if_index);
Jakub Grajciar053204a2019-03-18 13:17:53 +0100914 mac_address_decode (mp->mac_address, &mac);
915 error =
916 vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, (u8 *) & mac);
Jon Loeliger10c273b2017-03-30 08:39:33 -0500917 if (error)
918 {
919 rv = VNET_API_ERROR_UNIMPLEMENTED;
920 clib_error_report (error);
921 goto out;
922 }
923
924 BAD_SW_IF_INDEX_LABEL;
925out:
926 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MAC_ADDRESS_REPLY);
927}
928
Juraj Slobodac0374232018-02-01 15:18:49 +0100929static void vl_api_sw_interface_get_mac_address_t_handler
930 (vl_api_sw_interface_get_mac_address_t * mp)
931{
932 vl_api_sw_interface_get_mac_address_reply_t *rmp;
933 vl_api_registration_t *reg;
934 vnet_main_t *vnm = vnet_get_main ();
935 u32 sw_if_index = ntohl (mp->sw_if_index);
936 vnet_sw_interface_t *si;
937 ethernet_interface_t *eth_if = 0;
938 int rv = 0;
939
940 VALIDATE_SW_IF_INDEX (mp);
941
942 si = vnet_get_sup_sw_interface (vnm, sw_if_index);
943 if (si->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
944 eth_if = ethernet_get_interface (&ethernet_main, si->hw_if_index);
945
946 BAD_SW_IF_INDEX_LABEL;
947
948 reg = vl_api_client_index_to_registration (mp->client_index);
949 if (!reg)
950 return;
951 rmp = vl_msg_api_alloc (sizeof (*rmp));
952 rmp->_vl_msg_id = htons (VL_API_SW_INTERFACE_GET_MAC_ADDRESS_REPLY);
953 rmp->context = mp->context;
954 rmp->retval = htonl (rv);
955 if (!rv && eth_if)
Jakub Grajciar053204a2019-03-18 13:17:53 +0100956 mac_address_encode ((mac_address_t *) eth_if->address, rmp->mac_address);
Juraj Slobodac0374232018-02-01 15:18:49 +0100957 vl_api_send_msg (reg, (u8 *) rmp);
958}
959
Stevenad8015b2017-10-29 22:10:46 -0700960static void vl_api_sw_interface_set_rx_mode_t_handler
961 (vl_api_sw_interface_set_rx_mode_t * mp)
962{
963 vl_api_sw_interface_set_rx_mode_reply_t *rmp;
964 vnet_main_t *vnm = vnet_get_main ();
965 u32 sw_if_index = ntohl (mp->sw_if_index);
966 vnet_sw_interface_t *si;
967 clib_error_t *error;
968 int rv = 0;
969
970 VALIDATE_SW_IF_INDEX (mp);
971
972 si = vnet_get_sw_interface (vnm, sw_if_index);
Mohsin Kazmi54f7c512018-08-23 18:28:11 +0200973 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
974 {
975 rv = VNET_API_ERROR_INVALID_VALUE;
976 goto bad_sw_if_index;
977 }
978
Stevenad8015b2017-10-29 22:10:46 -0700979 error = set_hw_interface_change_rx_mode (vnm, si->hw_if_index,
980 mp->queue_id_valid,
Jakub Grajciar053204a2019-03-18 13:17:53 +0100981 ntohl (mp->queue_id),
982 (vnet_hw_interface_rx_mode)
983 mp->mode);
984
Stevenad8015b2017-10-29 22:10:46 -0700985 if (error)
986 {
987 rv = VNET_API_ERROR_UNIMPLEMENTED;
988 clib_error_report (error);
989 goto out;
990 }
991
992 BAD_SW_IF_INDEX_LABEL;
993out:
994 REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_MODE_REPLY);
995}
996
Mohsin Kazmif0b42f42018-09-10 18:11:00 +0200997static void
998send_interface_rx_placement_details (vpe_api_main_t * am,
999 vl_api_registration_t * rp,
1000 u32 sw_if_index, u32 worker_id,
1001 u32 queue_id, u8 mode, u32 context)
1002{
1003 vl_api_sw_interface_rx_placement_details_t *mp;
1004 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04001005 clib_memset (mp, 0, sizeof (*mp));
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02001006
1007 mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_RX_PLACEMENT_DETAILS);
1008 mp->sw_if_index = htonl (sw_if_index);
1009 mp->queue_id = htonl (queue_id);
1010 mp->worker_id = htonl (worker_id);
1011 mp->mode = mode;
1012 mp->context = context;
1013
1014 vl_api_send_msg (rp, (u8 *) mp);
1015}
1016
1017static void vl_api_sw_interface_rx_placement_dump_t_handler
1018 (vl_api_sw_interface_rx_placement_dump_t * mp)
1019{
1020 vnet_main_t *vnm = vnet_get_main ();
1021 vpe_api_main_t *am = &vpe_api_main;
1022 u32 sw_if_index = ntohl (mp->sw_if_index);
1023 vl_api_registration_t *reg;
1024
1025 reg = vl_api_client_index_to_registration (mp->client_index);
1026 if (!reg)
1027 return;
1028
1029 if (sw_if_index == ~0)
1030 {
1031 vnet_device_input_runtime_t *rt;
1032 vnet_device_and_queue_t *dq;
1033 vlib_node_t *pn = vlib_get_node_by_name (am->vlib_main,
1034 (u8 *) "device-input");
1035 uword si;
1036 int index = 0;
1037
1038 /* *INDENT-OFF* */
1039 foreach_vlib_main (({
1040 clib_bitmap_foreach (si, pn->sibling_bitmap,
1041 ({
1042 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1043 vec_foreach (dq, rt->devices_and_queues)
1044 {
1045 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm,
1046 dq->hw_if_index);
1047 send_interface_rx_placement_details (am, reg, hw->sw_if_index, index,
1048 dq->queue_id, dq->mode, mp->context);
1049 }
1050 }));
1051 index++;
1052 }));
1053 /* *INDENT-ON* */
1054 }
1055 else
1056 {
1057 int i;
1058 vnet_sw_interface_t *si;
1059
1060 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
1061 {
1062 clib_warning ("sw_if_index %u does not exist", sw_if_index);
1063 goto bad_sw_if_index;
1064 }
1065
1066 si = vnet_get_sw_interface (vnm, sw_if_index);
1067 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
1068 {
1069 clib_warning ("interface type is not HARDWARE! P2P, PIPE and SUB"
1070 " interfaces are not supported");
1071 goto bad_sw_if_index;
1072 }
1073
1074 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, si->hw_if_index);
1075
1076 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1077 {
1078 send_interface_rx_placement_details (am, reg, hw->sw_if_index,
1079 hw->input_node_thread_index_by_queue
1080 [i], i,
1081 hw->rx_mode_by_queue[i],
1082 mp->context);
1083 }
1084 }
1085
1086 BAD_SW_IF_INDEX_LABEL;
1087}
1088
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001089static void vl_api_sw_interface_set_rx_placement_t_handler
1090 (vl_api_sw_interface_set_rx_placement_t * mp)
1091{
1092 vl_api_sw_interface_set_rx_placement_reply_t *rmp;
1093 vnet_main_t *vnm = vnet_get_main ();
1094 u32 sw_if_index = ntohl (mp->sw_if_index);
1095 vnet_sw_interface_t *si;
1096 clib_error_t *error = 0;
1097 int rv = 0;
1098
1099 VALIDATE_SW_IF_INDEX (mp);
1100
1101 si = vnet_get_sw_interface (vnm, sw_if_index);
1102 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
1103 {
1104 rv = VNET_API_ERROR_INVALID_VALUE;
1105 goto bad_sw_if_index;
1106 }
1107
1108 error = set_hw_interface_rx_placement (si->hw_if_index,
1109 ntohl (mp->queue_id),
1110 ntohl (mp->worker_id), mp->is_main);
1111 if (error)
1112 {
1113 rv = VNET_API_ERROR_UNIMPLEMENTED;
1114 clib_error_report (error);
1115 goto out;
1116 }
1117
1118 BAD_SW_IF_INDEX_LABEL;
1119out:
1120 REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_PLACEMENT_REPLY);
1121}
1122
Neale Rannsb8d44812017-11-10 06:53:54 -08001123static void
1124vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1125{
1126 vl_api_create_vlan_subif_reply_t *rmp;
1127 vnet_main_t *vnm = vnet_get_main ();
1128 u32 sw_if_index = (u32) ~ 0;
1129 vnet_hw_interface_t *hi;
1130 int rv = 0;
1131 u32 id;
1132 vnet_sw_interface_t template;
1133 uword *p;
1134 vnet_interface_main_t *im = &vnm->interface_main;
1135 u64 sup_and_sub_key;
Florin Coras6c4dae22018-01-09 06:39:23 -08001136 vl_api_registration_t *reg;
Neale Rannsb8d44812017-11-10 06:53:54 -08001137 clib_error_t *error;
1138
1139 VALIDATE_SW_IF_INDEX (mp);
1140
1141 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1142
1143 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1144 {
1145 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1146 goto out;
1147 }
1148
1149 id = ntohl (mp->vlan_id);
1150 if (id == 0 || id > 4095)
1151 {
1152 rv = VNET_API_ERROR_INVALID_VLAN;
1153 goto out;
1154 }
1155
1156 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1157
1158 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1159 if (p)
1160 {
1161 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1162 goto out;
1163 }
1164
Dave Barachb7b92992018-10-17 10:38:51 -04001165 clib_memset (&template, 0, sizeof (template));
Neale Rannsb8d44812017-11-10 06:53:54 -08001166 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Joe Zhou715f94e2019-03-06 23:05:32 -08001167 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Neale Rannsb8d44812017-11-10 06:53:54 -08001168 template.sup_sw_if_index = hi->sw_if_index;
1169 template.sub.id = id;
1170 template.sub.eth.raw_flags = 0;
1171 template.sub.eth.flags.one_tag = 1;
1172 template.sub.eth.outer_vlan_id = id;
1173 template.sub.eth.flags.exact_match = 1;
1174
1175 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1176 if (error)
1177 {
1178 clib_error_report (error);
1179 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1180 goto out;
1181 }
1182
1183 u64 *kp = clib_mem_alloc (sizeof (*kp));
1184 *kp = sup_and_sub_key;
1185
1186 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1187 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1188
1189 BAD_SW_IF_INDEX_LABEL;
1190
1191out:
Florin Coras6c4dae22018-01-09 06:39:23 -08001192 reg = vl_api_client_index_to_registration (mp->client_index);
1193 if (!reg)
Neale Rannsb8d44812017-11-10 06:53:54 -08001194 return;
1195
1196 rmp = vl_msg_api_alloc (sizeof (*rmp));
1197 rmp->_vl_msg_id = htons (VL_API_CREATE_VLAN_SUBIF_REPLY);
1198 rmp->context = mp->context;
1199 rmp->retval = htonl (rv);
1200 rmp->sw_if_index = htonl (sw_if_index);
Florin Coras6c4dae22018-01-09 06:39:23 -08001201 vl_api_send_msg (reg, (u8 *) rmp);
Neale Rannsb8d44812017-11-10 06:53:54 -08001202}
1203
1204static void
1205vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1206{
1207 vl_api_create_subif_reply_t *rmp;
1208 vnet_main_t *vnm = vnet_get_main ();
1209 u32 sw_if_index = ~0;
1210 int rv = 0;
1211 u32 sub_id;
1212 vnet_sw_interface_t *si;
1213 vnet_hw_interface_t *hi;
1214 vnet_sw_interface_t template;
1215 uword *p;
1216 vnet_interface_main_t *im = &vnm->interface_main;
1217 u64 sup_and_sub_key;
1218 clib_error_t *error;
1219
1220 VALIDATE_SW_IF_INDEX (mp);
1221
1222 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1223 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1224
1225 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1226 {
1227 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1228 goto out;
1229 }
1230
1231 sw_if_index = si->sw_if_index;
1232 sub_id = ntohl (mp->sub_id);
1233
1234 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1235
1236 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1237 if (p)
1238 {
1239 if (CLIB_DEBUG > 0)
1240 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1241 sw_if_index, sub_id);
1242 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1243 goto out;
1244 }
1245
Dave Barachb7b92992018-10-17 10:38:51 -04001246 clib_memset (&template, 0, sizeof (template));
Neale Rannsb8d44812017-11-10 06:53:54 -08001247 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Joe Zhou715f94e2019-03-06 23:05:32 -08001248 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Neale Rannsb8d44812017-11-10 06:53:54 -08001249 template.sup_sw_if_index = sw_if_index;
1250 template.sub.id = sub_id;
Jakub Grajciar053204a2019-03-18 13:17:53 +01001251 template.sub.eth.raw_flags = ntohl (mp->sub_if_flags);
Neale Rannsb8d44812017-11-10 06:53:54 -08001252 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1253 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1254
1255 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1256 if (error)
1257 {
1258 clib_error_report (error);
1259 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1260 goto out;
1261 }
1262
1263 u64 *kp = clib_mem_alloc (sizeof (*kp));
1264 *kp = sup_and_sub_key;
1265
1266 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1267 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1268
1269 BAD_SW_IF_INDEX_LABEL;
1270
1271out:
1272
1273 /* *INDENT-OFF* */
1274 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1275 ({
1276 rmp->sw_if_index = ntohl(sw_if_index);
1277 }));
1278 /* *INDENT-ON* */
1279}
1280
1281static void
1282vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
1283{
1284 vl_api_delete_subif_reply_t *rmp;
1285 int rv;
1286
1287 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
1288
1289 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
1290}
1291
1292static void
1293vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1294 mp)
1295{
1296 vl_api_interface_name_renumber_reply_t *rmp;
1297 int rv = 0;
1298
1299 VALIDATE_SW_IF_INDEX (mp);
1300
1301 rv = vnet_interface_name_renumber
1302 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1303
1304 BAD_SW_IF_INDEX_LABEL;
1305
1306 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1307}
1308
1309static void
1310vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1311{
1312 vl_api_create_loopback_reply_t *rmp;
1313 u32 sw_if_index;
1314 int rv;
Jakub Grajciar053204a2019-03-18 13:17:53 +01001315 mac_address_t mac;
Neale Rannsb8d44812017-11-10 06:53:54 -08001316
Jakub Grajciar053204a2019-03-18 13:17:53 +01001317 mac_address_decode (mp->mac_address, &mac);
1318 rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac, 0, 0);
Neale Rannsb8d44812017-11-10 06:53:54 -08001319
1320 /* *INDENT-OFF* */
1321 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1322 ({
1323 rmp->sw_if_index = ntohl (sw_if_index);
1324 }));
1325 /* *INDENT-ON* */
1326}
1327
1328static void vl_api_create_loopback_instance_t_handler
1329 (vl_api_create_loopback_instance_t * mp)
1330{
1331 vl_api_create_loopback_instance_reply_t *rmp;
1332 u32 sw_if_index;
1333 u8 is_specified = mp->is_specified;
1334 u32 user_instance = ntohl (mp->user_instance);
1335 int rv;
Jakub Grajciar053204a2019-03-18 13:17:53 +01001336 mac_address_t mac;
Neale Rannsb8d44812017-11-10 06:53:54 -08001337
Jakub Grajciar053204a2019-03-18 13:17:53 +01001338 mac_address_decode (mp->mac_address, &mac);
1339 rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac,
Neale Rannsb8d44812017-11-10 06:53:54 -08001340 is_specified, user_instance);
1341
1342 /* *INDENT-OFF* */
1343 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_INSTANCE_REPLY,
1344 ({
1345 rmp->sw_if_index = ntohl (sw_if_index);
1346 }));
1347 /* *INDENT-ON* */
1348}
1349
1350static void
1351vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1352{
1353 vl_api_delete_loopback_reply_t *rmp;
1354 u32 sw_if_index;
1355 int rv;
1356
1357 sw_if_index = ntohl (mp->sw_if_index);
1358 rv = vnet_delete_loopback_interface (sw_if_index);
1359
1360 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1361}
1362
Neale Ranns6f4a6be2018-03-16 16:26:21 -07001363static void
1364 vl_api_collect_detailed_interface_stats_t_handler
1365 (vl_api_collect_detailed_interface_stats_t * mp)
1366{
1367 vl_api_collect_detailed_interface_stats_reply_t *rmp;
1368 int rv = 0;
1369
Neale Ranns871dc422018-03-29 01:28:09 -07001370 rv =
1371 vnet_sw_interface_stats_collect_enable_disable (ntohl (mp->sw_if_index),
1372 mp->enable_disable);
Neale Ranns6f4a6be2018-03-16 16:26:21 -07001373
1374 REPLY_MACRO (VL_API_COLLECT_DETAILED_INTERFACE_STATS_REPLY);
1375}
1376
Dave Barachaff70772016-10-31 11:59:07 -04001377/*
1378 * vpe_api_hookup
1379 * Add vpe's API message handlers to the table.
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001380 * vlib has already mapped shared memory and
Dave Barachaff70772016-10-31 11:59:07 -04001381 * added the client registration handlers.
1382 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1383 */
1384#define vl_msg_name_crc_list
Dave Barachb5e8a772016-12-06 12:04:42 -05001385#include <vnet/interface.api.h>
Dave Barachaff70772016-10-31 11:59:07 -04001386#undef vl_msg_name_crc_list
1387
1388static void
1389setup_message_id_table (api_main_t * am)
1390{
1391#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1392 foreach_vl_msg_name_crc_interface;
1393#undef _
1394}
1395
Dave Barach6d963c22016-12-05 09:50:05 -05001396pub_sub_handler (interface_events, INTERFACE_EVENTS);
1397
Dave Barachaff70772016-10-31 11:59:07 -04001398static clib_error_t *
1399interface_api_hookup (vlib_main_t * vm)
1400{
1401 api_main_t *am = &api_main;
1402
1403#define _(N,n) \
1404 vl_msg_api_set_handlers(VL_API_##N, #n, \
1405 vl_api_##n##_t_handler, \
1406 vl_noop_handler, \
1407 vl_api_##n##_t_endian, \
1408 vl_api_##n##_t_print, \
1409 sizeof(vl_api_##n##_t), 1);
1410 foreach_vpe_api_msg;
1411#undef _
1412
Steven Luongc5fa2b82019-04-25 11:19:49 -07001413 /* Mark these APIs as mp safe */
1414 am->is_mp_safe[VL_API_SW_INTERFACE_DUMP] = 1;
1415 am->is_mp_safe[VL_API_SW_INTERFACE_DETAILS] = 1;
1416 am->is_mp_safe[VL_API_SW_INTERFACE_TAG_ADD_DEL] = 1;
1417
Dave Barach3940de32019-07-23 16:28:36 -04001418 /* Do not replay VL_API_SW_INTERFACE_DUMP messages */
1419 am->api_trace_cfg[VL_API_SW_INTERFACE_DUMP].replay_enable = 0;
1420
Dave Barachaff70772016-10-31 11:59:07 -04001421 /*
1422 * Set up the (msg_name, crc, message-id) table
1423 */
1424 setup_message_id_table (am);
1425
1426 return 0;
1427}
1428
1429VLIB_API_INIT_FUNCTION (interface_api_hookup);
1430
1431/*
1432 * fd.io coding-style-patch-verification: ON
1433 *
1434 * Local Variables:
1435 * eval: (c-set-style "gnu")
1436 * End:
1437 */