2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010-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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
48 #include <vnet/api_errno.h>
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/l2tp/l2tp.h>
53 #include <vnet/ip/ip.h>
54 #include <vnet/ip/ip6.h>
55 #include <vnet/ip/ip6_neighbor.h>
56 #include <vnet/unix/tuntap.h>
57 #include <vnet/unix/tapcli.h>
58 #include <vnet/mpls/mpls.h>
59 #include <vnet/mpls/mpls_tunnel.h>
60 #include <vnet/dhcp/proxy.h>
61 #include <vnet/dhcp/client.h>
63 #include <vnet/sr/sr.h>
65 #include <vnet/dhcpv6/proxy.h>
66 #include <vlib/vlib.h>
67 #include <vlib/unix/unix.h>
68 #include <vlibapi/api.h>
69 #include <vlibmemory/api.h>
70 #include <vnet/classify/vnet_classify.h>
71 #include <vnet/classify/input_acl.h>
72 #include <vnet/classify/policer_classify.h>
73 #include <vnet/classify/flow_classify.h>
74 #include <vnet/l2/l2_classify.h>
75 #include <vnet/vxlan/vxlan.h>
76 #include <vnet/gre/gre.h>
77 #include <vnet/l2/l2_vtr.h>
78 #include <vnet/vxlan-gpe/vxlan_gpe.h>
79 #include <vnet/lisp-gpe/lisp_gpe.h>
80 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
81 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
82 #include <vnet/lisp-cp/control.h>
83 #include <vnet/map/map.h>
84 #include <vnet/cop/cop.h>
85 #include <vnet/ip/ip6_hop_by_hop.h>
86 #include <vnet/ip/ip_source_and_port_range_check.h>
87 #include <vnet/devices/af_packet/af_packet.h>
88 #include <vnet/policer/policer.h>
89 #include <vnet/devices/netmap/netmap.h>
90 #include <vnet/flow/flow_report.h>
91 #include <vnet/ipsec-gre/ipsec_gre.h>
92 #include <vnet/flow/flow_report_classify.h>
93 #include <vnet/ip/punt.h>
94 #include <vnet/feature/feature.h>
97 #undef __included_bihash_template_h__
98 #include <vnet/l2/l2_fib.h>
101 #include <vnet/devices/dpdk/dpdk.h>
105 #include <vnet/ipsec/ipsec.h>
106 #include <vnet/ipsec/ikev2.h>
108 #include <vnet/devices/virtio/vhost-user.h>
110 #include <stats/stats.h>
113 #include <vnet/ethernet/ethernet.h>
114 #include <vnet/ethernet/arp_packet.h>
115 #include <vnet/interface.h>
117 #include <vnet/l2/l2_fib.h>
118 #include <vnet/l2/l2_bd.h>
119 #include <vpp-api/vpe_msg_enum.h>
120 #include <vnet/span/span.h>
122 #include <vnet/fib/ip6_fib.h>
123 #include <vnet/fib/ip4_fib.h>
124 #include <vnet/dpo/drop_dpo.h>
125 #include <vnet/dpo/receive_dpo.h>
126 #include <vnet/dpo/lookup_dpo.h>
127 #include <vnet/dpo/classify_dpo.h>
128 #include <vnet/dpo/ip_null_dpo.h>
130 #define vl_typedefs /* define message structures */
131 #include <vpp-api/vpe_all_api_h.h>
134 #define vl_endianfun /* define message structures */
135 #include <vpp-api/vpe_all_api_h.h>
138 /* instantiate all the print functions we know about */
139 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
141 #include <vpp-api/vpe_all_api_h.h>
144 #include <vlibapi/api_helper_macros.h>
146 #define foreach_vpe_api_msg \
147 _(WANT_OAM_EVENTS, want_oam_events) \
148 _(OAM_ADD_DEL, oam_add_del) \
149 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
150 _(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \
151 _(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \
152 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
153 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
154 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
155 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
156 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
157 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
158 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
159 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
160 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
161 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
162 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
163 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
164 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
165 _(L2FIB_ADD_DEL, l2fib_add_del) \
166 _(L2_FLAGS, l2_flags) \
167 _(BRIDGE_FLAGS, bridge_flags) \
168 _(TAP_CONNECT, tap_connect) \
169 _(TAP_MODIFY, tap_modify) \
170 _(TAP_DELETE, tap_delete) \
171 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
172 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
173 _(CREATE_SUBIF, create_subif) \
174 _(MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del) \
175 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
176 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
177 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
178 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
179 _(RESET_FIB, reset_fib) \
180 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
181 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
182 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
183 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
184 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
185 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
186 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
187 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
188 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
189 sw_interface_ip6_set_link_local_address) \
190 _(CREATE_LOOPBACK, create_loopback) \
191 _(CONTROL_PING, control_ping) \
192 _(CLI_REQUEST, cli_request) \
193 _(CLI_INBAND, cli_inband) \
194 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
195 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
196 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
197 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
198 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
199 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
200 _(GET_NODE_INDEX, get_node_index) \
201 _(ADD_NODE_NEXT, add_node_next) \
202 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
203 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
204 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
205 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
206 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
207 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
208 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
209 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
210 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
211 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
212 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
213 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
214 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
215 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
216 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
217 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
218 _(IP_ADDRESS_DUMP, ip_address_dump) \
219 _(IP_DUMP, ip_dump) \
220 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
221 _(SHOW_VERSION, show_version) \
222 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
223 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
224 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
225 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
226 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
227 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
228 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
229 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
230 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
231 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
232 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
233 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
234 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
235 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
236 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
237 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
238 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
239 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
240 _(DELETE_LOOPBACK, delete_loopback) \
241 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
242 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
243 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
244 _(GET_NODE_GRAPH, get_node_graph) \
245 _(IOAM_ENABLE, ioam_enable) \
246 _(IOAM_DISABLE, ioam_disable) \
247 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
248 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
249 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
250 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
251 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
252 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
253 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
254 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
255 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
256 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
257 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
258 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
259 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
260 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
261 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
262 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
263 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
264 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
265 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
266 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
267 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
268 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
269 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
270 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
271 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
272 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
273 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
274 _(SHOW_LISP_STATUS, show_lisp_status) \
275 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
276 lisp_add_del_map_request_itr_rlocs) \
277 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
278 _(SHOW_LISP_PITR, show_lisp_pitr) \
279 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
280 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
281 _(AF_PACKET_CREATE, af_packet_create) \
282 _(AF_PACKET_DELETE, af_packet_delete) \
283 _(POLICER_ADD_DEL, policer_add_del) \
284 _(POLICER_DUMP, policer_dump) \
285 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
286 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
287 _(NETMAP_CREATE, netmap_create) \
288 _(NETMAP_DELETE, netmap_delete) \
289 _(MPLS_TUNNEL_DUMP, mpls_tunnel_dump) \
290 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
291 _(MPLS_FIB_DUMP, mpls_fib_dump) \
292 _(MPLS_FIB_DETAILS, mpls_fib_details) \
293 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
294 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
295 _(CLASSIFY_TABLE_INFO,classify_table_info) \
296 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
297 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
298 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
299 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
300 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
301 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
302 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
303 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
304 _(GET_NEXT_INDEX, get_next_index) \
305 _(PG_CREATE_INTERFACE, pg_create_interface) \
306 _(PG_CAPTURE, pg_capture) \
307 _(PG_ENABLE_DISABLE, pg_enable_disable) \
308 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
309 ip_source_and_port_range_check_add_del) \
310 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
311 ip_source_and_port_range_check_interface_add_del) \
312 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
313 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
314 _(DELETE_SUBIF, delete_subif) \
315 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
317 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
318 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
319 _(IPSEC_SPD_DUMP, ipsec_spd_dump) \
320 _(IP_FIB_DUMP, ip_fib_dump) \
321 _(IP_FIB_DETAILS, ip_fib_details) \
322 _(IP6_FIB_DUMP, ip6_fib_dump) \
323 _(IP6_FIB_DETAILS, ip6_fib_details) \
324 _(FEATURE_ENABLE_DISABLE, feature_enable_disable) \
325 _(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \
326 _(IP_NEIGHBOR_DETAILS, ip_neighbor_details)
329 #define QUOTE(x) QUOTE_(x)
333 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
334 RESOLVE_IP6_ADD_DEL_ROUTE,
337 static vlib_node_registration_t vpe_resolver_process_node;
338 vpe_api_main_t vpe_api_main;
340 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
341 unix_shared_memory_queue_t * q,
344 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
345 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
348 /* Clean up all registrations belonging to the indicated client */
350 vl_api_memclnt_delete_callback (u32 client_index)
352 vpe_api_main_t *vam = &vpe_api_main;
353 vpe_client_registration_t *rp;
355 int stats_memclnt_delete_callback (u32 client_index);
357 stats_memclnt_delete_callback (client_index);
360 p = hash_get (vam->a##_registration_hash, client_index); \
362 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
363 pool_put (vam->a##_registrations, rp); \
364 hash_unset (vam->a##_registration_hash, client_index); \
366 foreach_registration_hash;
371 pub_sub_handler (oam_events, OAM_EVENTS);
373 #define RESOLUTION_EVENT 1
374 #define RESOLUTION_PENDING_EVENT 2
375 #define IP4_ARP_EVENT 3
376 #define IP6_ND_EVENT 4
378 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
380 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
383 handle_ip4_arp_event (u32 pool_index)
385 vpe_api_main_t *vam = &vpe_api_main;
386 vnet_main_t *vnm = vam->vnet_main;
387 vlib_main_t *vm = vam->vlib_main;
388 vl_api_ip4_arp_event_t *event;
389 vl_api_ip4_arp_event_t *mp;
390 unix_shared_memory_queue_t *q;
392 /* Client can cancel, die, etc. */
393 if (pool_is_free_index (vam->arp_events, pool_index))
396 event = pool_elt_at_index (vam->arp_events, pool_index);
398 q = vl_api_client_index_to_input_queue (event->client_index);
401 (void) vnet_add_del_ip4_arp_change_event
402 (vnm, arp_change_delete_callback,
403 event->pid, &event->address,
404 vpe_resolver_process_node.index, IP4_ARP_EVENT,
405 ~0 /* pool index, notused */ , 0 /* is_add */ );
409 if (q->cursize < q->maxsize)
411 mp = vl_msg_api_alloc (sizeof (*mp));
412 clib_memcpy (mp, event, sizeof (*mp));
413 vl_msg_api_send_shmem (q, (u8 *) & mp);
417 static f64 last_time;
419 * Throttle syslog msgs.
420 * It's pretty tempting to just revoke the registration...
422 if (vlib_time_now (vm) > last_time + 10.0)
424 clib_warning ("arp event for %U to pid %d: queue stuffed!",
425 format_ip4_address, &event->address, event->pid);
426 last_time = vlib_time_now (vm);
432 handle_ip6_nd_event (u32 pool_index)
434 vpe_api_main_t *vam = &vpe_api_main;
435 vnet_main_t *vnm = vam->vnet_main;
436 vlib_main_t *vm = vam->vlib_main;
437 vl_api_ip6_nd_event_t *event;
438 vl_api_ip6_nd_event_t *mp;
439 unix_shared_memory_queue_t *q;
441 /* Client can cancel, die, etc. */
442 if (pool_is_free_index (vam->nd_events, pool_index))
445 event = pool_elt_at_index (vam->nd_events, pool_index);
447 q = vl_api_client_index_to_input_queue (event->client_index);
450 (void) vnet_add_del_ip6_nd_change_event
451 (vnm, nd_change_delete_callback,
452 event->pid, &event->address,
453 vpe_resolver_process_node.index, IP6_ND_EVENT,
454 ~0 /* pool index, notused */ , 0 /* is_add */ );
458 if (q->cursize < q->maxsize)
460 mp = vl_msg_api_alloc (sizeof (*mp));
461 clib_memcpy (mp, event, sizeof (*mp));
462 vl_msg_api_send_shmem (q, (u8 *) & mp);
466 static f64 last_time;
468 * Throttle syslog msgs.
469 * It's pretty tempting to just revoke the registration...
471 if (vlib_time_now (vm) > last_time + 10.0)
473 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
474 format_ip6_address, &event->address, event->pid);
475 last_time = vlib_time_now (vm);
481 resolver_process (vlib_main_t * vm,
482 vlib_node_runtime_t * rt, vlib_frame_t * f)
485 uword *event_data = 0;
491 vlib_process_wait_for_event_or_clock (vm, timeout);
493 event_type = vlib_process_get_events (vm, &event_data);
497 case RESOLUTION_PENDING_EVENT:
501 case RESOLUTION_EVENT:
502 clib_warning ("resolver: BOGUS TYPE");
506 for (i = 0; i < vec_len (event_data); i++)
507 handle_ip4_arp_event (event_data[i]);
511 for (i = 0; i < vec_len (event_data); i++)
512 handle_ip6_nd_event (event_data[i]);
515 case ~0: /* timeout */
519 vec_reset_length (event_data);
521 return 0; /* or not */
525 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
526 .function = resolver_process,
527 .type = VLIB_NODE_TYPE_PROCESS,
528 .name = "vpe-route-resolver-process",
533 add_del_route_t_handler (u8 is_multipath,
540 u32 classify_table_index,
542 u8 is_resolve_attached,
544 const fib_prefix_t * prefix,
545 u8 next_hop_proto_is_ip4,
546 const ip46_address_t * next_hop,
547 u32 next_hop_sw_if_index,
548 u8 next_hop_fib_index,
550 mpls_label_t next_hop_via_label,
551 mpls_label_t * next_hop_out_label_stack)
553 vnet_classify_main_t *cm = &vnet_classify_main;
554 stats_main_t *sm = &stats_main;
555 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
556 fib_route_path_t path = {
557 .frp_proto = (next_hop_proto_is_ip4 ?
558 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6),
559 .frp_addr = (NULL == next_hop ? zero_addr : *next_hop),
560 .frp_sw_if_index = next_hop_sw_if_index,
561 .frp_fib_index = next_hop_fib_index,
562 .frp_weight = next_hop_weight,
563 .frp_label_stack = next_hop_out_label_stack,
565 fib_route_path_t *paths = NULL;
567 if (MPLS_LABEL_INVALID != next_hop_via_label)
569 path.frp_proto = FIB_PROTOCOL_MPLS;
570 path.frp_local_label = next_hop_via_label;
573 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
574 if (is_resolve_attached)
575 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
577 path.frp_flags = path_flags;
581 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
584 vec_add1 (paths, path);
587 fib_table_entry_path_add2 (fib_index,
590 FIB_ENTRY_FLAG_NONE, paths);
592 fib_table_entry_path_remove2 (fib_index,
593 prefix, FIB_SOURCE_API, paths);
600 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
602 if (is_drop || is_local || is_classify || is_unreach || is_prohibit)
605 * special route types that link directly to the adj
609 dpo_id_t dpo = DPO_INVALID;
612 dproto = fib_proto_to_dpo (prefix->fp_proto);
615 ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo);
617 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
619 ip_null_dpo_add_and_lock (dproto,
620 IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo);
621 else if (is_prohibit)
622 ip_null_dpo_add_and_lock (dproto,
623 IP_NULL_ACTION_SEND_ICMP_PROHIBIT,
625 else if (is_classify)
627 if (pool_is_free_index (cm->tables,
628 ntohl (classify_table_index)))
631 return VNET_API_ERROR_NO_SUCH_TABLE;
634 dpo_set (&dpo, DPO_CLASSIFY, dproto,
635 classify_dpo_create (dproto,
636 ntohl (classify_table_index)));
641 return VNET_API_ERROR_NO_SUCH_TABLE;
644 fib_table_entry_special_dpo_update (fib_index,
647 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
652 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
659 vec_add1 (paths, path);
660 fib_table_entry_update (fib_index,
662 FIB_SOURCE_API, FIB_ENTRY_FLAG_NONE, paths);
667 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
676 add_del_route_check (fib_protocol_t table_proto,
678 u32 next_hop_sw_if_index,
679 fib_protocol_t next_hop_table_proto,
680 u32 next_hop_table_id,
681 u8 create_missing_tables,
682 u32 * fib_index, u32 * next_hop_fib_index)
684 vnet_main_t *vnm = vnet_get_main ();
686 *fib_index = fib_table_find (table_proto, ntohl (table_id));
687 if (~0 == *fib_index)
689 if (create_missing_tables)
691 *fib_index = fib_table_find_or_create_and_lock (table_proto,
696 /* No such VRF, and we weren't asked to create one */
697 return VNET_API_ERROR_NO_SUCH_FIB;
701 if (~0 != ntohl (next_hop_sw_if_index))
703 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
704 ntohl (next_hop_sw_if_index)))
706 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
711 *next_hop_fib_index = fib_table_find (next_hop_table_proto,
712 ntohl (next_hop_table_id));
714 if (~0 == *next_hop_fib_index)
716 if (create_missing_tables)
718 *next_hop_fib_index =
719 fib_table_find_or_create_and_lock (next_hop_table_proto,
720 ntohl (next_hop_table_id));
724 /* No such VRF, and we weren't asked to create one */
725 return VNET_API_ERROR_NO_SUCH_FIB;
734 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
736 u32 fib_index, next_hop_fib_index;
737 mpls_label_t *label_stack = NULL;
738 int rv, ii, n_labels;;
740 rv = add_del_route_check (FIB_PROTOCOL_IP4,
742 mp->next_hop_sw_if_index,
744 mp->next_hop_table_id,
745 mp->create_vrf_if_needed,
746 &fib_index, &next_hop_fib_index);
752 .fp_len = mp->dst_address_length,
753 .fp_proto = FIB_PROTOCOL_IP4,
755 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
758 memset (&nh, 0, sizeof (nh));
759 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
761 n_labels = mp->next_hop_n_out_labels;
764 else if (1 == n_labels)
765 vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0]));
768 vec_validate (label_stack, n_labels - 1);
769 for (ii = 0; ii < n_labels; ii++)
770 label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]);
773 return (add_del_route_t_handler (mp->is_multipath,
780 mp->classify_table_index,
782 mp->is_resolve_attached,
785 ntohl (mp->next_hop_sw_if_index),
788 ntohl (mp->next_hop_via_label),
793 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
795 u32 fib_index, next_hop_fib_index;
796 mpls_label_t *label_stack = NULL;
797 int rv, ii, n_labels;;
799 rv = add_del_route_check (FIB_PROTOCOL_IP6,
801 mp->next_hop_sw_if_index,
803 mp->next_hop_table_id,
804 mp->create_vrf_if_needed,
805 &fib_index, &next_hop_fib_index);
811 .fp_len = mp->dst_address_length,
812 .fp_proto = FIB_PROTOCOL_IP6,
814 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
817 memset (&nh, 0, sizeof (nh));
818 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
820 n_labels = mp->next_hop_n_out_labels;
823 else if (1 == n_labels)
824 vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0]));
827 vec_validate (label_stack, n_labels - 1);
828 for (ii = 0; ii < n_labels; ii++)
829 label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]);
832 return (add_del_route_t_handler (mp->is_multipath,
839 mp->classify_table_index,
841 mp->is_resolve_attached,
843 &nh, ntohl (mp->next_hop_sw_if_index),
846 ntohl (mp->next_hop_via_label),
851 mpls_route_add_del_t_handler (vnet_main_t * vnm,
852 vl_api_mpls_route_add_del_t * mp)
854 u32 fib_index, next_hop_fib_index;
855 mpls_label_t *label_stack = NULL;
856 int rv, ii, n_labels;;
860 .fp_proto = FIB_PROTOCOL_MPLS,
861 .fp_eos = mp->mr_eos,
862 .fp_label = ntohl (mp->mr_label),
866 if (mp->mr_next_hop_proto_is_ip4)
868 pfx.fp_payload_proto = DPO_PROTO_IP4;
872 pfx.fp_payload_proto = DPO_PROTO_IP6;
877 pfx.fp_payload_proto = DPO_PROTO_MPLS;
880 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
882 mp->mr_next_hop_sw_if_index,
883 dpo_proto_to_fib (pfx.fp_payload_proto),
884 mp->mr_next_hop_table_id,
885 mp->mr_create_table_if_needed,
886 &fib_index, &next_hop_fib_index);
892 memset (&nh, 0, sizeof (nh));
894 if (mp->mr_next_hop_proto_is_ip4)
895 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
897 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
899 n_labels = mp->mr_next_hop_n_out_labels;
902 else if (1 == n_labels)
903 vec_add1 (label_stack, ntohl (mp->mr_next_hop_out_label_stack[0]));
906 vec_validate (label_stack, n_labels - 1);
907 for (ii = 0; ii < n_labels; ii++)
908 label_stack[ii] = ntohl (mp->mr_next_hop_out_label_stack[ii]);
911 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
912 0, // mp->is_unreach,
913 0, // mp->is_prohibit,
916 mp->mr_classify_table_index,
917 mp->mr_is_resolve_host,
918 mp->mr_is_resolve_attached,
920 mp->mr_next_hop_proto_is_ip4,
921 &nh, ntohl (mp->mr_next_hop_sw_if_index),
923 mp->mr_next_hop_weight,
924 ntohl (mp->mr_next_hop_via_label),
929 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
931 vl_api_ip_add_del_route_reply_t *rmp;
933 vnet_main_t *vnm = vnet_get_main ();
938 rv = ip6_add_del_route_t_handler (mp);
940 rv = ip4_add_del_route_t_handler (mp);
942 rv = (rv == 0) ? vnm->api_errno : rv;
944 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
948 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
950 vl_api_mpls_route_add_del_reply_t *rmp;
954 vnm = vnet_get_main ();
957 rv = mpls_route_add_del_t_handler (vnm, mp);
959 rv = (rv == 0) ? vnm->api_errno : rv;
961 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
965 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
966 vl_api_mpls_ip_bind_unbind_t * mp)
968 u32 mpls_fib_index, ip_fib_index;
971 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
973 if (~0 == mpls_fib_index)
975 if (mp->mb_create_table_if_needed)
978 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
979 ntohl (mp->mb_mpls_table_id));
982 return VNET_API_ERROR_NO_SUCH_FIB;
985 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
988 ntohl (mp->mb_ip_table_id));
989 if (~0 == ip_fib_index)
990 return VNET_API_ERROR_NO_SUCH_FIB;
993 .fp_len = mp->mb_address_length,
998 pfx.fp_proto = FIB_PROTOCOL_IP4;
999 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
1000 sizeof (pfx.fp_addr.ip4));
1004 pfx.fp_proto = FIB_PROTOCOL_IP6;
1005 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
1006 sizeof (pfx.fp_addr.ip6));
1010 fib_table_entry_local_label_add (ip_fib_index, &pfx,
1011 ntohl (mp->mb_label));
1013 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
1014 ntohl (mp->mb_label));
1020 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
1022 vl_api_mpls_route_add_del_reply_t *rmp;
1026 vnm = vnet_get_main ();
1029 rv = mpls_ip_bind_unbind_handler (vnm, mp);
1031 rv = (rv == 0) ? vnm->api_errno : rv;
1033 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1037 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1039 vl_api_sw_interface_set_vpath_reply_t *rmp;
1041 u32 sw_if_index = ntohl (mp->sw_if_index);
1043 VALIDATE_SW_IF_INDEX (mp);
1045 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1046 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
1047 sw_if_index, mp->enable, 0, 0);
1048 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
1049 sw_if_index, mp->enable, 0, 0);
1050 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
1051 sw_if_index, mp->enable, 0, 0);
1052 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
1053 sw_if_index, mp->enable, 0, 0);
1055 BAD_SW_IF_INDEX_LABEL;
1057 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1061 vl_api_sw_interface_set_vxlan_bypass_t_handler
1062 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
1064 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
1066 u32 sw_if_index = ntohl (mp->sw_if_index);
1068 VALIDATE_SW_IF_INDEX (mp);
1072 /* not yet implemented */
1075 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
1076 sw_if_index, mp->enable, 0, 0);
1078 BAD_SW_IF_INDEX_LABEL;
1080 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
1084 vl_api_sw_interface_set_l2_xconnect_t_handler
1085 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1087 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1089 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1090 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1091 vlib_main_t *vm = vlib_get_main ();
1092 vnet_main_t *vnm = vnet_get_main ();
1094 VALIDATE_RX_SW_IF_INDEX (mp);
1098 VALIDATE_TX_SW_IF_INDEX (mp);
1099 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1100 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1104 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1107 BAD_RX_SW_IF_INDEX_LABEL;
1108 BAD_TX_SW_IF_INDEX_LABEL;
1110 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1114 vl_api_sw_interface_set_l2_bridge_t_handler
1115 (vl_api_sw_interface_set_l2_bridge_t * mp)
1117 bd_main_t *bdm = &bd_main;
1118 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1120 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1121 u32 bd_id = ntohl (mp->bd_id);
1125 vlib_main_t *vm = vlib_get_main ();
1126 vnet_main_t *vnm = vnet_get_main ();
1128 VALIDATE_RX_SW_IF_INDEX (mp);
1130 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1134 //VALIDATE_TX_SW_IF_INDEX(mp);
1135 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1136 rx_sw_if_index, bd_index, bvi, shg, 0);
1140 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1143 BAD_RX_SW_IF_INDEX_LABEL;
1145 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1149 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1150 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1152 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1156 dpdk_main_t *dm = &dpdk_main;
1159 u32 sw_if_index = ntohl (mp->sw_if_index);
1160 u32 subport = ntohl (mp->subport);
1161 u32 pipe = ntohl (mp->pipe);
1162 u32 profile = ntohl (mp->profile);
1163 vnet_hw_interface_t *hw;
1165 VALIDATE_SW_IF_INDEX (mp);
1167 /* hw_if & dpdk device */
1168 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1170 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1172 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1174 BAD_SW_IF_INDEX_LABEL;
1176 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1177 rv = VNET_API_ERROR_UNIMPLEMENTED;
1180 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1184 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1185 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1187 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1191 dpdk_main_t *dm = &dpdk_main;
1193 struct rte_sched_subport_params p;
1195 u32 sw_if_index = ntohl (mp->sw_if_index);
1196 u32 subport = ntohl (mp->subport);
1197 p.tb_rate = ntohl (mp->tb_rate);
1198 p.tb_size = ntohl (mp->tb_size);
1199 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1200 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1201 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1202 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1203 p.tc_period = ntohl (mp->tc_period);
1205 vnet_hw_interface_t *hw;
1207 VALIDATE_SW_IF_INDEX (mp);
1209 /* hw_if & dpdk device */
1210 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1212 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1214 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1216 BAD_SW_IF_INDEX_LABEL;
1219 ("setting HQoS subport parameters without DPDK not implemented");
1220 rv = VNET_API_ERROR_UNIMPLEMENTED;
1223 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1227 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1228 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1230 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1234 dpdk_main_t *dm = &dpdk_main;
1235 vlib_thread_main_t *tm = vlib_get_thread_main ();
1238 u32 sw_if_index = ntohl (mp->sw_if_index);
1239 u32 entry = ntohl (mp->entry);
1240 u32 tc = ntohl (mp->tc);
1241 u32 queue = ntohl (mp->queue);
1244 vnet_hw_interface_t *hw;
1246 VALIDATE_SW_IF_INDEX (mp);
1248 /* hw_if & dpdk device */
1249 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1251 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1253 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1255 clib_warning ("invalid traffic class !!");
1256 rv = VNET_API_ERROR_INVALID_VALUE;
1259 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1261 clib_warning ("invalid queue !!");
1262 rv = VNET_API_ERROR_INVALID_VALUE;
1266 /* Detect the set of worker threads */
1267 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1271 clib_warning ("worker thread registration AWOL !!");
1272 rv = VNET_API_ERROR_INVALID_VALUE_2;
1276 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1277 int worker_thread_first = tr->first_index;
1278 int worker_thread_count = tr->count;
1280 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1281 for (i = 0; i < worker_thread_count; i++)
1282 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1284 BAD_SW_IF_INDEX_LABEL;
1287 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1288 rv = VNET_API_ERROR_UNIMPLEMENTED;
1291 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1295 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1297 vlib_main_t *vm = vlib_get_main ();
1298 bd_main_t *bdm = &bd_main;
1299 vl_api_bridge_domain_add_del_reply_t *rmp;
1301 u32 enable_flags = 0, disable_flags = 0;
1302 u32 bd_id = ntohl (mp->bd_id);
1307 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1310 enable_flags |= L2_FLOOD;
1312 disable_flags |= L2_FLOOD;
1315 enable_flags |= L2_UU_FLOOD;
1317 disable_flags |= L2_UU_FLOOD;
1320 enable_flags |= L2_FWD;
1322 disable_flags |= L2_FWD;
1325 enable_flags |= L2_ARP_TERM;
1327 disable_flags |= L2_ARP_TERM;
1330 enable_flags |= L2_LEARN;
1332 disable_flags |= L2_LEARN;
1335 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1338 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1342 rv = bd_delete_bd_index (bdm, bd_id);
1344 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1348 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1350 clib_warning ("BUG");
1354 vl_api_bridge_domain_sw_if_details_t_handler
1355 (vl_api_bridge_domain_sw_if_details_t * mp)
1357 clib_warning ("BUG");
1361 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1362 l2_bridge_domain_t * bd_config,
1363 u32 n_sw_ifs, u32 context)
1365 vl_api_bridge_domain_details_t *mp;
1367 mp = vl_msg_api_alloc (sizeof (*mp));
1368 memset (mp, 0, sizeof (*mp));
1369 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1370 mp->bd_id = ntohl (bd_config->bd_id);
1371 mp->flood = bd_feature_flood (bd_config);
1372 mp->uu_flood = bd_feature_uu_flood (bd_config);
1373 mp->forward = bd_feature_forward (bd_config);
1374 mp->learn = bd_feature_learn (bd_config);
1375 mp->arp_term = bd_feature_arp_term (bd_config);
1376 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1377 mp->n_sw_ifs = ntohl (n_sw_ifs);
1378 mp->context = context;
1380 vl_msg_api_send_shmem (q, (u8 *) & mp);
1384 send_bd_sw_if_details (l2input_main_t * l2im,
1385 unix_shared_memory_queue_t * q,
1386 l2_flood_member_t * member, u32 bd_id, u32 context)
1388 vl_api_bridge_domain_sw_if_details_t *mp;
1389 l2_input_config_t *input_cfg;
1391 mp = vl_msg_api_alloc (sizeof (*mp));
1392 memset (mp, 0, sizeof (*mp));
1393 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1394 mp->bd_id = ntohl (bd_id);
1395 mp->sw_if_index = ntohl (member->sw_if_index);
1396 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1397 mp->shg = input_cfg->shg;
1398 mp->context = context;
1400 vl_msg_api_send_shmem (q, (u8 *) & mp);
1404 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1406 bd_main_t *bdm = &bd_main;
1407 l2input_main_t *l2im = &l2input_main;
1408 unix_shared_memory_queue_t *q;
1409 l2_bridge_domain_t *bd_config;
1410 u32 bd_id, bd_index;
1413 q = vl_api_client_index_to_input_queue (mp->client_index);
1418 bd_id = ntohl (mp->bd_id);
1420 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1421 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1422 for (; bd_index < end; bd_index++)
1424 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1425 /* skip dummy bd_id 0 */
1426 if (bd_config && (bd_config->bd_id > 0))
1429 l2_flood_member_t *m;
1431 n_sw_ifs = vec_len (bd_config->members);
1432 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1434 vec_foreach (m, bd_config->members)
1436 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1443 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1445 bd_main_t *bdm = &bd_main;
1446 l2input_main_t *l2im = &l2input_main;
1447 vl_api_l2fib_add_del_reply_t *rmp;
1450 u32 sw_if_index = ntohl (mp->sw_if_index);
1451 u32 bd_id = ntohl (mp->bd_id);
1460 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1463 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1464 goto bad_sw_if_index;
1470 filter_mac = mp->filter_mac ? 1 : 0;
1471 if (filter_mac == 0)
1473 VALIDATE_SW_IF_INDEX (mp);
1474 if (vec_len (l2im->configs) <= sw_if_index)
1476 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1477 goto bad_sw_if_index;
1481 l2_input_config_t *config;
1482 config = vec_elt_at_index (l2im->configs, sw_if_index);
1483 if (config->bridge == 0)
1485 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1486 goto bad_sw_if_index;
1490 static_mac = mp->static_mac ? 1 : 0;
1491 bvi_mac = mp->bvi_mac ? 1 : 0;
1492 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1497 l2fib_del_entry (mac, bd_index);
1500 BAD_SW_IF_INDEX_LABEL;
1502 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1506 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1508 vl_api_l2_flags_reply_t *rmp;
1510 u32 sw_if_index = ntohl (mp->sw_if_index);
1511 u32 flags = ntohl (mp->feature_bitmap);
1514 VALIDATE_SW_IF_INDEX (mp);
1517 if (flags & L2INPUT_FEAT_ ## a) \
1518 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1519 foreach_l2input_feat;
1522 BAD_SW_IF_INDEX_LABEL;
1525 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1527 rmp->resulting_feature_bitmap = ntohl(rbm);
1533 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1535 vlib_main_t *vm = vlib_get_main ();
1536 bd_main_t *bdm = &bd_main;
1537 vl_api_bridge_flags_reply_t *rmp;
1539 u32 bd_id = ntohl (mp->bd_id);
1541 u32 flags = ntohl (mp->feature_bitmap);
1544 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1547 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1553 bd_set_flags (vm, bd_index, flags, mp->is_set);
1557 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1559 rmp->resulting_feature_bitmap = ntohl(flags);
1565 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1567 bd_main_t *bdm = &bd_main;
1568 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1570 u32 bd_id = ntohl (mp->bd_id);
1574 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1577 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1582 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1583 mp->mac_address, mp->is_ipv6, mp->is_add))
1584 rv = VNET_API_ERROR_UNSPECIFIED;
1587 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1591 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp)
1593 vlib_main_t *vm = vlib_get_main ();
1595 vl_api_tap_connect_reply_t *rmp;
1596 vnet_main_t *vnm = vnet_get_main ();
1597 unix_shared_memory_queue_t *q;
1598 u32 sw_if_index = (u32) ~ 0;
1601 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1602 mp->use_random_mac ? 0 : mp->mac_address,
1603 &sw_if_index, mp->renumber,
1604 ntohl (mp->custom_dev_instance));
1606 /* Add tag if supplied */
1607 if (rv == 0 && mp->tag[0])
1609 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
1610 tag = format (0, "%s%c", mp->tag, 0);
1611 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1614 q = vl_api_client_index_to_input_queue (mp->client_index);
1618 rmp = vl_msg_api_alloc (sizeof (*rmp));
1619 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1620 rmp->context = mp->context;
1621 rmp->retval = ntohl (rv);
1622 rmp->sw_if_index = ntohl (sw_if_index);
1624 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1628 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp)
1631 vl_api_tap_modify_reply_t *rmp;
1632 unix_shared_memory_queue_t *q;
1633 u32 sw_if_index = (u32) ~ 0;
1634 vlib_main_t *vm = vlib_get_main ();
1636 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1637 mp->use_random_mac ? 0 : mp->mac_address,
1638 &sw_if_index, mp->renumber,
1639 ntohl (mp->custom_dev_instance));
1641 q = vl_api_client_index_to_input_queue (mp->client_index);
1645 rmp = vl_msg_api_alloc (sizeof (*rmp));
1646 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1647 rmp->context = mp->context;
1648 rmp->retval = ntohl (rv);
1649 rmp->sw_if_index = ntohl (sw_if_index);
1651 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1655 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp)
1657 vlib_main_t *vm = vlib_get_main ();
1659 vpe_api_main_t *vam = &vpe_api_main;
1660 vl_api_tap_delete_reply_t *rmp;
1661 unix_shared_memory_queue_t *q;
1662 u32 sw_if_index = ntohl (mp->sw_if_index);
1664 rv = vnet_tap_delete (vm, sw_if_index);
1667 vnet_main_t *vnm = vnet_get_main ();
1668 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1671 q = vl_api_client_index_to_input_queue (mp->client_index);
1675 rmp = vl_msg_api_alloc (sizeof (*rmp));
1676 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1677 rmp->context = mp->context;
1678 rmp->retval = ntohl (rv);
1680 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1683 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1687 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1689 vl_api_create_vlan_subif_reply_t *rmp;
1690 vnet_main_t *vnm = vnet_get_main ();
1691 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1692 vnet_hw_interface_t *hi;
1695 vnet_sw_interface_t template;
1697 vnet_interface_main_t *im = &vnm->interface_main;
1698 u64 sup_and_sub_key;
1700 unix_shared_memory_queue_t *q;
1701 clib_error_t *error;
1703 VALIDATE_SW_IF_INDEX (mp);
1705 hw_if_index = ntohl (mp->sw_if_index);
1706 hi = vnet_get_hw_interface (vnm, hw_if_index);
1708 id = ntohl (mp->vlan_id);
1709 if (id == 0 || id > 4095)
1711 rv = VNET_API_ERROR_INVALID_VLAN;
1715 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1717 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1720 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1724 kp = clib_mem_alloc (sizeof (*kp));
1725 *kp = sup_and_sub_key;
1727 memset (&template, 0, sizeof (template));
1728 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1729 template.sup_sw_if_index = hi->sw_if_index;
1730 template.sub.id = id;
1731 template.sub.eth.raw_flags = 0;
1732 template.sub.eth.flags.one_tag = 1;
1733 template.sub.eth.outer_vlan_id = id;
1734 template.sub.eth.flags.exact_match = 1;
1736 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1739 clib_error_report (error);
1740 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1743 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1744 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1746 BAD_SW_IF_INDEX_LABEL;
1749 q = vl_api_client_index_to_input_queue (mp->client_index);
1753 rmp = vl_msg_api_alloc (sizeof (*rmp));
1754 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1755 rmp->context = mp->context;
1756 rmp->retval = ntohl (rv);
1757 rmp->sw_if_index = ntohl (sw_if_index);
1758 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1762 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1764 vl_api_create_subif_reply_t *rmp;
1765 vnet_main_t *vnm = vnet_get_main ();
1766 u32 sw_if_index = ~0;
1769 vnet_sw_interface_t *si;
1770 vnet_hw_interface_t *hi;
1771 vnet_sw_interface_t template;
1773 vnet_interface_main_t *im = &vnm->interface_main;
1774 u64 sup_and_sub_key;
1776 clib_error_t *error;
1778 VALIDATE_SW_IF_INDEX (mp);
1780 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1781 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1783 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1785 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1789 sw_if_index = si->sw_if_index;
1790 sub_id = ntohl (mp->sub_id);
1792 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1794 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1798 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1799 sw_if_index, sub_id);
1800 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1804 kp = clib_mem_alloc (sizeof (*kp));
1805 *kp = sup_and_sub_key;
1807 memset (&template, 0, sizeof (template));
1808 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1809 template.sup_sw_if_index = sw_if_index;
1810 template.sub.id = sub_id;
1811 template.sub.eth.flags.no_tags = mp->no_tags;
1812 template.sub.eth.flags.one_tag = mp->one_tag;
1813 template.sub.eth.flags.two_tags = mp->two_tags;
1814 template.sub.eth.flags.dot1ad = mp->dot1ad;
1815 template.sub.eth.flags.exact_match = mp->exact_match;
1816 template.sub.eth.flags.default_sub = mp->default_sub;
1817 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1818 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1819 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1820 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1822 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1825 clib_error_report (error);
1826 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1830 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1831 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1833 BAD_SW_IF_INDEX_LABEL;
1838 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1840 rmp->sw_if_index = ntohl(sw_if_index);
1846 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
1848 vl_api_mpls_tunnel_add_del_reply_t *rmp;
1850 stats_main_t *sm = &stats_main;
1851 u32 tunnel_sw_if_index;
1854 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1858 fib_route_path_t rpath, *rpaths = NULL;
1859 mpls_label_t *label_stack = NULL;
1861 memset (&rpath, 0, sizeof (rpath));
1863 if (mp->mt_next_hop_proto_is_ip4)
1865 rpath.frp_proto = FIB_PROTOCOL_IP4;
1866 clib_memcpy (&rpath.frp_addr.ip4,
1867 mp->mt_next_hop, sizeof (rpath.frp_addr.ip4));
1871 rpath.frp_proto = FIB_PROTOCOL_IP6;
1872 clib_memcpy (&rpath.frp_addr.ip6,
1873 mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
1875 rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
1877 for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
1878 vec_add1 (label_stack, ntohl (mp->mt_next_hop_out_label_stack[ii]));
1880 vec_add1 (rpaths, rpath);
1882 vnet_mpls_tunnel_add (rpaths, label_stack,
1883 mp->mt_l2_only, &tunnel_sw_if_index);
1885 vec_free (label_stack);
1889 tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
1890 vnet_mpls_tunnel_del (tunnel_sw_if_index);
1896 REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
1898 rmp->sw_if_index = ntohl(tunnel_sw_if_index);
1904 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
1906 vl_api_proxy_arp_add_del_reply_t *rmp;
1909 ip4_main_t *im = &ip4_main;
1910 stats_main_t *sm = &stats_main;
1911 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
1912 ip4_address_t * hi_addr,
1913 u32 fib_index, int is_del);
1916 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
1918 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1922 rv = VNET_API_ERROR_NO_SUCH_FIB;
1928 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
1929 (ip4_address_t *) mp->hi_address,
1930 fib_index, mp->is_add == 0);
1934 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
1938 vl_api_proxy_arp_intfc_enable_disable_t_handler
1939 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
1942 vnet_main_t *vnm = vnet_get_main ();
1943 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
1944 vnet_sw_interface_t *si;
1947 VALIDATE_SW_IF_INDEX (mp);
1949 sw_if_index = ntohl (mp->sw_if_index);
1951 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1953 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1957 si = vnet_get_sw_interface (vnm, sw_if_index);
1961 if (mp->enable_disable)
1962 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1964 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1966 BAD_SW_IF_INDEX_LABEL;
1969 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
1973 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
1976 vl_api_ip_neighbor_add_del_reply_t *rmp;
1977 vnet_main_t *vnm = vnet_get_main ();
1978 stats_main_t *sm = &stats_main;
1981 VALIDATE_SW_IF_INDEX (mp);
1983 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
1986 * there's no validation here of the ND/ARP entry being added.
1987 * The expectation is that the FIB will ensure that nothing bad
1988 * will come of adding bogus entries.
1993 rv = vnet_set_ip6_ethernet_neighbor
1994 (vm, ntohl (mp->sw_if_index),
1995 (ip6_address_t *) (mp->dst_address),
1996 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
1998 rv = vnet_unset_ip6_ethernet_neighbor
1999 (vm, ntohl (mp->sw_if_index),
2000 (ip6_address_t *) (mp->dst_address),
2001 mp->mac_address, sizeof (mp->mac_address));
2005 ethernet_arp_ip4_over_ethernet_address_t a;
2007 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2008 clib_memcpy (&a.ip4, mp->dst_address, 4);
2011 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2015 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2018 BAD_SW_IF_INDEX_LABEL;
2021 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2025 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2028 vpe_main_t *rm = &vpe_main;
2029 ip4_main_t *im4 = &ip4_main;
2030 ip6_main_t *im6 = &ip6_main;
2031 ip_lookup_main_t *lm;
2037 u32 adj_index, sw_if_index;
2038 vl_api_is_address_reachable_t *rmp;
2039 ip_adjacency_t *adj;
2040 unix_shared_memory_queue_t *q;
2042 q = vl_api_client_index_to_input_queue (mp->client_index);
2045 increment_missing_api_client_counter (rm->vlib_main);
2049 rmp = vl_msg_api_alloc (sizeof (*rmp));
2050 clib_memcpy (rmp, mp, sizeof (*rmp));
2052 sw_if_index = mp->next_hop_sw_if_index;
2053 clib_memcpy (&addr, mp->address, sizeof (addr));
2056 lm = &im6->lookup_main;
2057 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2061 lm = &im4->lookup_main;
2063 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2065 if (adj_index == ~0)
2070 adj = ip_get_adjacency (lm, adj_index);
2072 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2073 && adj->rewrite_header.sw_if_index == sw_if_index)
2079 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2080 && adj->rewrite_header.sw_if_index == sw_if_index)
2083 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2085 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2087 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2096 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2101 vl_api_sw_interface_set_mpls_enable_t_handler
2102 (vl_api_sw_interface_set_mpls_enable_t * mp)
2104 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2107 VALIDATE_SW_IF_INDEX (mp);
2109 mpls_sw_interface_enable_disable (&mpls_main,
2110 ntohl (mp->sw_if_index), mp->enable);
2112 BAD_SW_IF_INDEX_LABEL;
2113 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2116 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2117 unix_shared_memory_queue_t * q,
2119 __attribute__ ((unused));
2122 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2123 unix_shared_memory_queue_t * q,
2126 vl_api_sw_interface_set_flags_t *mp;
2128 mp = vl_msg_api_alloc (sizeof (*mp));
2129 memset (mp, 0, sizeof (*mp));
2130 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2131 mp->sw_if_index = ntohl (sw_if_index);
2133 mp->admin_up_down = 0;
2134 mp->link_up_down = 0;
2136 vl_msg_api_send_shmem (q, (u8 *) & mp);
2140 send_oam_event (oam_target_t * t)
2142 vpe_api_main_t *vam = &vpe_api_main;
2143 unix_shared_memory_queue_t *q;
2144 vpe_client_registration_t *reg;
2145 vl_api_oam_event_t *mp;
2148 pool_foreach(reg, vam->oam_events_registrations,
2150 q = vl_api_client_index_to_input_queue (reg->client_index);
2153 mp = vl_msg_api_alloc (sizeof (*mp));
2154 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2155 clib_memcpy (mp->dst_address, &t->dst_address,
2156 sizeof (mp->dst_address));
2157 mp->state = t->state;
2158 vl_msg_api_send_shmem (q, (u8 *)&mp);
2165 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2167 vl_api_oam_add_del_reply_t *rmp;
2170 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2171 (ip4_address_t *) mp->dst_address,
2172 ntohl (mp->vrf_id), (int) (mp->is_add));
2174 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2178 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2180 stats_main_t *sm = &stats_main;
2181 vnet_interface_main_t *im = sm->interface_main;
2182 vl_api_vnet_summary_stats_reply_t *rmp;
2183 vlib_combined_counter_main_t *cm;
2186 u64 total_pkts[VLIB_N_RX_TX];
2187 u64 total_bytes[VLIB_N_RX_TX];
2189 unix_shared_memory_queue_t *q =
2190 vl_api_client_index_to_input_queue (mp->client_index);
2195 rmp = vl_msg_api_alloc (sizeof (*rmp));
2196 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2197 rmp->context = mp->context;
2200 memset (total_pkts, 0, sizeof (total_pkts));
2201 memset (total_bytes, 0, sizeof (total_bytes));
2203 vnet_interface_counter_lock (im);
2205 vec_foreach (cm, im->combined_sw_if_counters)
2207 which = cm - im->combined_sw_if_counters;
2209 for (i = 0; i < vec_len (cm->maxi); i++)
2211 vlib_get_combined_counter (cm, i, &v);
2212 total_pkts[which] += v.packets;
2213 total_bytes[which] += v.bytes;
2216 vnet_interface_counter_unlock (im);
2218 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2219 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2220 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2221 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2223 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2225 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2229 typedef CLIB_PACKED (struct {
2230 ip4_address_t address;
2231 u32 address_length: 6;
2237 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2239 vnet_main_t *vnm = vnet_get_main ();
2240 vnet_interface_main_t *im = &vnm->interface_main;
2241 ip4_main_t *im4 = &ip4_main;
2242 static u32 *sw_if_indices_to_shut;
2243 stats_main_t *sm = &stats_main;
2244 fib_table_t *fib_table;
2248 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2249 u32 target_fib_id = ntohl (mp->vrf_id);
2251 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2254 pool_foreach (fib_table, im4->fibs,
2256 fib = &fib_table->v4;
2257 vnet_sw_interface_t * si;
2259 if (fib->table_id != target_fib_id)
2262 /* remove any mpls encap/decap labels */
2263 mpls_fib_reset_labels (fib->table_id);
2265 /* remove any proxy arps in this fib */
2266 vnet_proxy_arp_fib_reset (fib->table_id);
2268 /* Set the flow hash for this fib to the default */
2269 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2271 vec_reset_length (sw_if_indices_to_shut);
2273 /* Shut down interfaces in this FIB / clean out intfc routes */
2274 pool_foreach (si, im->sw_interfaces,
2276 u32 sw_if_index = si->sw_if_index;
2278 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2279 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2281 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2284 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2285 sw_if_index = sw_if_indices_to_shut[i];
2286 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2288 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2289 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2290 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2293 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
2294 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
2298 })); /* pool_foreach (fib) */
2306 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2308 vnet_main_t *vnm = vnet_get_main ();
2309 vnet_interface_main_t *im = &vnm->interface_main;
2310 ip6_main_t *im6 = &ip6_main;
2311 stats_main_t *sm = &stats_main;
2312 static u32 *sw_if_indices_to_shut;
2313 fib_table_t *fib_table;
2317 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2318 u32 target_fib_id = ntohl (mp->vrf_id);
2320 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
2323 pool_foreach (fib_table, im6->fibs,
2325 vnet_sw_interface_t * si;
2326 fib = &(fib_table->v6);
2328 if (fib->table_id != target_fib_id)
2331 vec_reset_length (sw_if_indices_to_shut);
2333 /* Shut down interfaces in this FIB / clean out intfc routes */
2334 pool_foreach (si, im->sw_interfaces,
2336 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2338 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2341 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2342 sw_if_index = sw_if_indices_to_shut[i];
2343 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2345 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2346 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2347 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2350 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
2351 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
2355 })); /* pool_foreach (fib) */
2363 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2366 vl_api_reset_fib_reply_t *rmp;
2369 rv = ip6_reset_fib_t_handler (mp);
2371 rv = ip4_reset_fib_t_handler (mp);
2373 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
2378 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2380 vl_api_dhcp_proxy_config_reply_t *rmp;
2383 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
2384 (ip4_address_t *) (&mp->dhcp_src_address),
2385 (u32) ntohl (mp->vrf_id),
2386 (int) mp->insert_circuit_id,
2387 (int) (mp->is_add == 0));
2389 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2394 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2396 vl_api_dhcp_proxy_config_reply_t *rmp;
2399 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
2400 (ip6_address_t *) (&mp->dhcp_src_address),
2401 (u32) ntohl (mp->vrf_id),
2402 (int) mp->insert_circuit_id,
2403 (int) (mp->is_add == 0));
2405 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2409 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2411 vl_api_dhcp_proxy_config_reply_t *rmp;
2414 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
2415 (ip4_address_t *) (&mp->dhcp_src_address),
2416 (u32) ntohl (mp->rx_vrf_id),
2417 (u32) ntohl (mp->server_vrf_id),
2418 (int) mp->insert_circuit_id,
2419 (int) (mp->is_add == 0));
2421 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2426 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2428 vl_api_dhcp_proxy_config_reply_t *rmp;
2431 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
2432 (ip6_address_t *) (&mp->dhcp_src_address),
2433 (u32) ntohl (mp->rx_vrf_id),
2434 (u32) ntohl (mp->server_vrf_id),
2435 (int) mp->insert_circuit_id,
2436 (int) (mp->is_add == 0));
2438 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2443 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
2445 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2448 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
2451 (int) mp->is_add == 0);
2453 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
2455 ntohl (mp->fib_id), (int) mp->is_add == 0);
2457 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
2461 static void vl_api_dhcp_proxy_config_t_handler
2462 (vl_api_dhcp_proxy_config_t * mp)
2464 if (mp->is_ipv6 == 0)
2465 dhcpv4_proxy_config (mp);
2467 dhcpv6_proxy_config (mp);
2470 static void vl_api_dhcp_proxy_config_2_t_handler
2471 (vl_api_dhcp_proxy_config_2_t * mp)
2473 if (mp->is_ipv6 == 0)
2474 dhcpv4_proxy_config_2 (mp);
2476 dhcpv6_proxy_config_2 (mp);
2480 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2481 u8 is_ipv6, u8 * host_address, u8 * router_address,
2484 unix_shared_memory_queue_t *q;
2485 vl_api_dhcp_compl_event_t *mp;
2487 q = vl_api_client_index_to_input_queue (client_index);
2491 mp = vl_msg_api_alloc (sizeof (*mp));
2492 mp->client_index = client_index;
2494 mp->is_ipv6 = is_ipv6;
2495 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
2496 mp->hostname[vec_len (hostname) + 1] = '\n';
2497 clib_memcpy (&mp->host_address[0], host_address, 16);
2498 clib_memcpy (&mp->router_address[0], router_address, 16);
2500 if (NULL != host_mac)
2501 clib_memcpy (&mp->host_mac[0], host_mac, 6);
2503 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2505 vl_msg_api_send_shmem (q, (u8 *) & mp);
2508 static void vl_api_dhcp_client_config_t_handler
2509 (vl_api_dhcp_client_config_t * mp)
2511 vlib_main_t *vm = vlib_get_main ();
2512 vl_api_dhcp_client_config_reply_t *rmp;
2515 VALIDATE_SW_IF_INDEX (mp);
2517 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
2518 mp->hostname, mp->is_add, mp->client_index,
2519 mp->want_dhcp_event ? dhcp_compl_event_callback :
2522 BAD_SW_IF_INDEX_LABEL;
2524 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
2528 vl_api_sw_interface_ip6nd_ra_config_t_handler
2529 (vl_api_sw_interface_ip6nd_ra_config_t * mp)
2531 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
2532 vlib_main_t *vm = vlib_get_main ();
2534 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
2537 is_no = mp->is_no == 1;
2538 suppress = mp->suppress == 1;
2539 managed = mp->managed == 1;
2540 other = mp->other == 1;
2541 ll_option = mp->ll_option == 1;
2542 send_unicast = mp->send_unicast == 1;
2543 cease = mp->cease == 1;
2544 default_router = mp->default_router == 1;
2546 VALIDATE_SW_IF_INDEX (mp);
2548 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
2549 suppress, managed, other,
2550 ll_option, send_unicast, cease,
2551 default_router, ntohl (mp->lifetime),
2552 ntohl (mp->initial_count),
2553 ntohl (mp->initial_interval),
2554 ntohl (mp->max_interval),
2555 ntohl (mp->min_interval), is_no);
2557 BAD_SW_IF_INDEX_LABEL;
2559 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2563 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2564 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp)
2566 vlib_main_t *vm = vlib_get_main ();
2567 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
2569 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
2571 VALIDATE_SW_IF_INDEX (mp);
2573 is_no = mp->is_no == 1;
2574 use_default = mp->use_default == 1;
2575 no_advertise = mp->no_advertise == 1;
2576 off_link = mp->off_link == 1;
2577 no_autoconfig = mp->no_autoconfig == 1;
2578 no_onlink = mp->no_onlink == 1;
2580 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
2581 (ip6_address_t *) mp->address,
2582 mp->address_length, use_default,
2583 ntohl (mp->val_lifetime),
2584 ntohl (mp->pref_lifetime), no_advertise,
2585 off_link, no_autoconfig, no_onlink, is_no);
2587 BAD_SW_IF_INDEX_LABEL;
2588 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
2592 vl_api_sw_interface_ip6_enable_disable_t_handler
2593 (vl_api_sw_interface_ip6_enable_disable_t * mp)
2595 vlib_main_t *vm = vlib_get_main ();
2596 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
2597 vnet_main_t *vnm = vnet_get_main ();
2599 clib_error_t *error;
2603 VALIDATE_SW_IF_INDEX (mp);
2606 (mp->enable == 1) ? enable_ip6_interface (vm,
2607 ntohl (mp->sw_if_index)) :
2608 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
2612 clib_error_report (error);
2613 rv = VNET_API_ERROR_UNSPECIFIED;
2617 rv = vnm->api_errno;
2620 BAD_SW_IF_INDEX_LABEL;
2622 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
2626 vl_api_sw_interface_ip6_set_link_local_address_t_handler
2627 (vl_api_sw_interface_ip6_set_link_local_address_t * mp)
2629 vlib_main_t *vm = vlib_get_main ();
2630 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
2632 clib_error_t *error;
2633 vnet_main_t *vnm = vnet_get_main ();
2637 VALIDATE_SW_IF_INDEX (mp);
2639 error = set_ip6_link_local_address (vm,
2640 ntohl (mp->sw_if_index),
2641 (ip6_address_t *) mp->address,
2642 mp->address_length);
2645 clib_error_report (error);
2646 rv = VNET_API_ERROR_UNSPECIFIED;
2650 rv = vnm->api_errno;
2653 BAD_SW_IF_INDEX_LABEL;
2655 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
2659 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
2661 vl_api_set_ip_flow_hash_reply_t *rmp;
2662 int rv = VNET_API_ERROR_UNIMPLEMENTED;
2664 clib_warning ("unimplemented...");
2666 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
2670 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
2672 vl_api_set_ip_flow_hash_reply_t *rmp;
2675 flow_hash_config_t flow_hash_config = 0;
2677 table_id = ntohl (mp->vrf_id);
2679 #define _(a,b) if (mp->a) flow_hash_config |= b;
2680 foreach_flow_hash_bit;
2683 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
2685 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
2690 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
2692 if (mp->is_ipv6 == 0)
2693 set_ip4_flow_hash (mp);
2695 set_ip6_flow_hash (mp);
2699 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
2701 vl_api_create_loopback_reply_t *rmp;
2705 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
2708 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
2710 rmp->sw_if_index = ntohl (sw_if_index);
2716 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
2718 vl_api_delete_loopback_reply_t *rmp;
2722 sw_if_index = ntohl (mp->sw_if_index);
2723 rv = vnet_delete_loopback_interface (sw_if_index);
2725 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
2729 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
2731 vl_api_control_ping_reply_t *rmp;
2735 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
2737 rmp->vpe_pid = ntohl (getpid());
2743 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2745 u8 **shmem_vecp = (u8 **) arg;
2748 api_main_t *am = &api_main;
2751 shmem_vec = *shmem_vecp;
2753 offset = vec_len (shmem_vec);
2755 pthread_mutex_lock (&am->vlib_rp->mutex);
2756 oldheap = svm_push_data_heap (am->vlib_rp);
2758 vec_validate (shmem_vec, offset + buffer_bytes - 1);
2760 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
2762 svm_pop_heap (oldheap);
2763 pthread_mutex_unlock (&am->vlib_rp->mutex);
2765 *shmem_vecp = shmem_vec;
2770 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
2772 vl_api_cli_reply_t *rp;
2773 unix_shared_memory_queue_t *q;
2774 vlib_main_t *vm = vlib_get_main ();
2775 api_main_t *am = &api_main;
2776 unformat_input_t input;
2780 q = vl_api_client_index_to_input_queue (mp->client_index);
2784 rp = vl_msg_api_alloc (sizeof (*rp));
2785 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
2786 rp->context = mp->context;
2788 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
2790 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
2792 pthread_mutex_lock (&am->vlib_rp->mutex);
2793 oldheap = svm_push_data_heap (am->vlib_rp);
2795 vec_add1 (shmem_vec, 0);
2797 svm_pop_heap (oldheap);
2798 pthread_mutex_unlock (&am->vlib_rp->mutex);
2800 rp->reply_in_shmem = (uword) shmem_vec;
2802 vl_msg_api_send_shmem (q, (u8 *) & rp);
2806 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2808 u8 **mem_vecp = (u8 **) arg;
2809 u8 *mem_vec = *mem_vecp;
2810 u32 offset = vec_len (mem_vec);
2812 vec_validate (mem_vec, offset + buffer_bytes - 1);
2813 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
2814 *mem_vecp = mem_vec;
2818 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
2820 vl_api_cli_inband_reply_t *rmp;
2822 unix_shared_memory_queue_t *q;
2823 vlib_main_t *vm = vlib_get_main ();
2824 unformat_input_t input;
2827 q = vl_api_client_index_to_input_queue (mp->client_index);
2831 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
2832 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
2834 u32 len = vec_len (out_vec);
2836 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
2838 rmp->length = htonl (len);
2839 clib_memcpy (rmp->reply, out_vec, len);
2846 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2849 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2850 vnet_main_t *vnm = vnet_get_main ();
2851 clib_error_t *error;
2856 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2858 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2862 clib_error_report (error);
2863 rv = VNET_API_ERROR_UNSPECIFIED;
2867 rv = vnm->api_errno;
2870 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2873 static void vl_api_sr_tunnel_add_del_t_handler
2874 (vl_api_sr_tunnel_add_del_t * mp)
2877 clib_warning ("unimplemented");
2879 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
2881 vl_api_sr_tunnel_add_del_reply_t *rmp;
2882 ip6_address_t *segments = 0, *seg;
2883 ip6_address_t *tags = 0, *tag;
2884 ip6_address_t *this_address;
2887 if (mp->n_segments == 0)
2893 memset (a, 0, sizeof (*a));
2894 a->src_address = (ip6_address_t *) & mp->src_address;
2895 a->dst_address = (ip6_address_t *) & mp->dst_address;
2896 a->dst_mask_width = mp->dst_mask_width;
2897 a->flags_net_byte_order = mp->flags_net_byte_order;
2898 a->is_del = (mp->is_add == 0);
2899 a->rx_table_id = ntohl (mp->outer_vrf_id);
2900 a->tx_table_id = ntohl (mp->inner_vrf_id);
2902 a->name = format (0, "%s", mp->name);
2903 if (!(vec_len (a->name)))
2906 a->policy_name = format (0, "%s", mp->policy_name);
2907 if (!(vec_len (a->policy_name)))
2910 /* Yank segments and tags out of the API message */
2911 this_address = (ip6_address_t *) mp->segs_and_tags;
2912 for (i = 0; i < mp->n_segments; i++)
2914 vec_add2 (segments, seg, 1);
2915 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
2918 for (i = 0; i < mp->n_tags; i++)
2920 vec_add2 (tags, tag, 1);
2921 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
2925 a->segments = segments;
2928 rv = ip6_sr_add_del_tunnel (a);
2932 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
2936 static void vl_api_sr_policy_add_del_t_handler
2937 (vl_api_sr_policy_add_del_t * mp)
2940 clib_warning ("unimplemented");
2942 ip6_sr_add_del_policy_args_t _a, *a = &_a;
2944 vl_api_sr_policy_add_del_reply_t *rmp;
2947 memset (a, 0, sizeof (*a));
2948 a->is_del = (mp->is_add == 0);
2950 a->name = format (0, "%s", mp->name);
2951 if (!(vec_len (a->name)))
2953 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2957 if (!(mp->tunnel_names[0]))
2959 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2963 // start deserializing tunnel_names
2964 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
2965 u8 *deser_tun_names = mp->tunnel_names;
2966 deser_tun_names += 1; //moving along
2969 int tun_name_len = 0;
2971 for (i = 0; i < num_tunnels; i++)
2973 tun_name_len = *deser_tun_names;
2974 deser_tun_names += 1;
2975 vec_resize (tun_name, tun_name_len);
2976 memcpy (tun_name, deser_tun_names, tun_name_len);
2977 vec_add1 (a->tunnel_names, tun_name);
2978 deser_tun_names += tun_name_len;
2982 rv = ip6_sr_add_del_policy (a);
2986 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
2990 static void vl_api_sr_multicast_map_add_del_t_handler
2991 (vl_api_sr_multicast_map_add_del_t * mp)
2994 clib_warning ("unimplemented");
2996 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
2998 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3000 memset (a, 0, sizeof (*a));
3001 a->is_del = (mp->is_add == 0);
3003 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3004 a->policy_name = format (0, "%s", mp->policy_name);
3006 if (a->multicast_address == 0)
3012 if (!(a->policy_name))
3018 #if DPDK > 0 /* Cannot call replicate without DPDK */
3019 rv = ip6_sr_add_del_multicastmap (a);
3021 clib_warning ("multicast replication without DPDK not implemented");
3022 rv = VNET_API_ERROR_UNIMPLEMENTED;
3027 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3031 #define foreach_classify_add_del_table_field \
3036 _(match_n_vectors) \
3037 _(next_table_index) \
3038 _(miss_next_index) \
3039 _(current_data_flag) \
3040 _(current_data_offset)
3042 static void vl_api_classify_add_del_table_t_handler
3043 (vl_api_classify_add_del_table_t * mp)
3045 vl_api_classify_add_del_table_reply_t *rmp;
3046 vnet_classify_main_t *cm = &vnet_classify_main;
3047 vnet_classify_table_t *t;
3051 foreach_classify_add_del_table_field;
3054 #define _(a) a = ntohl(mp->a);
3055 foreach_classify_add_del_table_field;
3058 /* The underlying API fails silently, on purpose, so check here */
3059 if (mp->is_add == 0) /* delete */
3061 if (pool_is_free_index (cm->tables, table_index))
3063 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3067 else /* add or update */
3069 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
3073 rv = vnet_classify_add_del_table
3074 (cm, mp->mask, nbuckets, memory_size,
3075 skip_n_vectors, match_n_vectors,
3076 next_table_index, miss_next_index, &table_index,
3077 current_data_flag, current_data_offset, mp->is_add);
3081 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3083 if (rv == 0 && mp->is_add)
3085 t = pool_elt_at_index (cm->tables, table_index);
3086 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3087 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3088 rmp->new_table_index = ntohl(table_index);
3092 rmp->skip_n_vectors = ~0;
3093 rmp->match_n_vectors = ~0;
3094 rmp->new_table_index = ~0;
3100 static void vl_api_classify_add_del_session_t_handler
3101 (vl_api_classify_add_del_session_t * mp)
3103 vnet_classify_main_t *cm = &vnet_classify_main;
3104 vl_api_classify_add_del_session_reply_t *rmp;
3106 u32 table_index, hit_next_index, opaque_index, metadata;
3110 table_index = ntohl (mp->table_index);
3111 hit_next_index = ntohl (mp->hit_next_index);
3112 opaque_index = ntohl (mp->opaque_index);
3113 advance = ntohl (mp->advance);
3114 action = mp->action;
3115 metadata = ntohl (mp->metadata);
3117 rv = vnet_classify_add_del_session
3118 (cm, table_index, mp->match, hit_next_index, opaque_index,
3119 advance, action, metadata, mp->is_add);
3121 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3124 static void vl_api_classify_set_interface_ip_table_t_handler
3125 (vl_api_classify_set_interface_ip_table_t * mp)
3127 vlib_main_t *vm = vlib_get_main ();
3128 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3130 u32 table_index, sw_if_index;
3132 table_index = ntohl (mp->table_index);
3133 sw_if_index = ntohl (mp->sw_if_index);
3135 VALIDATE_SW_IF_INDEX (mp);
3138 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3140 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3142 BAD_SW_IF_INDEX_LABEL;
3144 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3147 static void vl_api_classify_set_interface_l2_tables_t_handler
3148 (vl_api_classify_set_interface_l2_tables_t * mp)
3150 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3152 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3155 ip4_table_index = ntohl (mp->ip4_table_index);
3156 ip6_table_index = ntohl (mp->ip6_table_index);
3157 other_table_index = ntohl (mp->other_table_index);
3158 sw_if_index = ntohl (mp->sw_if_index);
3160 VALIDATE_SW_IF_INDEX (mp);
3163 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
3167 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
3173 if (ip4_table_index != ~0 || ip6_table_index != ~0
3174 || other_table_index != ~0)
3180 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
3182 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
3185 BAD_SW_IF_INDEX_LABEL;
3187 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3191 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3194 vl_api_l2_fib_clear_table_reply_t *rmp;
3196 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3197 * that is not currently implemented. When that TODO is fixed
3198 * this call should be changed to pass 1 instead of 0.
3200 l2fib_clear_table (0);
3202 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3205 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3206 u32 sw_if_index, u32 enable);
3209 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3213 vl_api_l2_interface_efp_filter_reply_t *rmp;
3214 vnet_main_t *vnm = vnet_get_main ();
3216 // enable/disable the feature
3217 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3218 rv = vnm->api_errno;
3220 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3224 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3225 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3228 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3229 vnet_main_t *vnm = vnet_get_main ();
3230 vlib_main_t *vm = vlib_get_main ();
3233 VALIDATE_SW_IF_INDEX (mp);
3235 vtr_op = ntohl (mp->vtr_op);
3237 /* The L2 code is unsuspicious */
3240 case L2_VTR_DISABLED:
3245 case L2_VTR_TRANSLATE_1_1:
3246 case L2_VTR_TRANSLATE_1_2:
3247 case L2_VTR_TRANSLATE_2_1:
3248 case L2_VTR_TRANSLATE_2_2:
3252 rv = VNET_API_ERROR_INVALID_VALUE;
3253 goto bad_sw_if_index;
3256 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
3257 ntohl (mp->push_dot1q), ntohl (mp->tag1),
3260 BAD_SW_IF_INDEX_LABEL;
3262 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3266 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
3269 vl_api_create_vhost_user_if_reply_t *rmp;
3270 u32 sw_if_index = (u32) ~ 0;
3271 vnet_main_t *vnm = vnet_get_main ();
3272 vlib_main_t *vm = vlib_get_main ();
3274 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
3275 mp->is_server, &sw_if_index, (u64) ~ 0,
3276 mp->renumber, ntohl (mp->custom_dev_instance),
3277 (mp->use_custom_mac) ? mp->mac_address : NULL);
3279 /* Remember an interface tag for the new interface */
3282 /* If a tag was supplied... */
3285 /* Make sure it's a proper C-string */
3286 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
3287 u8 *tag = format (0, "%s%c", mp->tag, 0);
3288 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
3293 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3295 rmp->sw_if_index = ntohl (sw_if_index);
3301 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
3304 vl_api_modify_vhost_user_if_reply_t *rmp;
3305 u32 sw_if_index = ntohl (mp->sw_if_index);
3307 vnet_main_t *vnm = vnet_get_main ();
3308 vlib_main_t *vm = vlib_get_main ();
3310 rv = vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
3311 mp->is_server, sw_if_index, (u64) ~ 0,
3312 mp->renumber, ntohl (mp->custom_dev_instance));
3314 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
3318 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
3321 vl_api_delete_vhost_user_if_reply_t *rmp;
3322 vpe_api_main_t *vam = &vpe_api_main;
3323 u32 sw_if_index = ntohl (mp->sw_if_index);
3325 vnet_main_t *vnm = vnet_get_main ();
3326 vlib_main_t *vm = vlib_get_main ();
3328 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
3330 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
3333 unix_shared_memory_queue_t *q =
3334 vl_api_client_index_to_input_queue (mp->client_index);
3338 vnet_clear_sw_interface_tag (vnm, sw_if_index);
3339 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3344 vl_api_sw_interface_vhost_user_details_t_handler
3345 (vl_api_sw_interface_vhost_user_details_t * mp)
3347 clib_warning ("BUG");
3351 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3352 unix_shared_memory_queue_t * q,
3353 vhost_user_intf_details_t * vui,
3356 vl_api_sw_interface_vhost_user_details_t *mp;
3358 mp = vl_msg_api_alloc (sizeof (*mp));
3359 memset (mp, 0, sizeof (*mp));
3360 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3361 mp->sw_if_index = ntohl (vui->sw_if_index);
3362 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3363 mp->features = clib_net_to_host_u64 (vui->features);
3364 mp->is_server = vui->is_server;
3365 mp->num_regions = ntohl (vui->num_regions);
3366 mp->sock_errno = ntohl (vui->sock_errno);
3367 mp->context = context;
3369 strncpy ((char *) mp->sock_filename,
3370 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
3371 strncpy ((char *) mp->interface_name,
3372 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
3374 vl_msg_api_send_shmem (q, (u8 *) & mp);
3378 vl_api_sw_interface_vhost_user_dump_t_handler
3379 (vl_api_sw_interface_vhost_user_dump_t * mp)
3382 vpe_api_main_t *am = &vpe_api_main;
3383 vnet_main_t *vnm = vnet_get_main ();
3384 vlib_main_t *vm = vlib_get_main ();
3385 vhost_user_intf_details_t *ifaces = NULL;
3386 vhost_user_intf_details_t *vuid = NULL;
3387 unix_shared_memory_queue_t *q;
3389 q = vl_api_client_index_to_input_queue (mp->client_index);
3393 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
3397 vec_foreach (vuid, ifaces)
3399 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3405 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3406 unix_shared_memory_queue_t * q,
3408 l2t_main_t * lm, u32 context)
3410 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
3412 vnet_sw_interface_t *si = NULL;
3414 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3416 if_name = format (if_name, "%U",
3417 format_vnet_sw_interface_name, lm->vnet_main, si);
3419 mp = vl_msg_api_alloc (sizeof (*mp));
3420 memset (mp, 0, sizeof (*mp));
3421 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3422 strncpy ((char *) mp->interface_name,
3423 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
3424 mp->sw_if_index = ntohl (si->sw_if_index);
3425 mp->local_session_id = s->local_session_id;
3426 mp->remote_session_id = s->remote_session_id;
3427 mp->local_cookie[0] = s->local_cookie[0];
3428 mp->local_cookie[1] = s->local_cookie[1];
3429 mp->remote_cookie = s->remote_cookie;
3430 clib_memcpy (mp->client_address, &s->client_address,
3431 sizeof (s->client_address));
3432 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
3433 mp->l2_sublayer_present = s->l2_sublayer_present;
3434 mp->context = context;
3436 vl_msg_api_send_shmem (q, (u8 *) & mp);
3440 send_ip_address_details (vpe_api_main_t * am,
3441 unix_shared_memory_queue_t * q,
3442 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
3444 vl_api_ip_address_details_t *mp;
3446 mp = vl_msg_api_alloc (sizeof (*mp));
3447 memset (mp, 0, sizeof (*mp));
3448 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
3452 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
3456 u32 *tp = (u32 *) mp->ip;
3459 mp->prefix_length = prefix_length;
3460 mp->context = context;
3462 vl_msg_api_send_shmem (q, (u8 *) & mp);
3466 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
3468 vpe_api_main_t *am = &vpe_api_main;
3469 unix_shared_memory_queue_t *q;
3472 ip6_main_t *im6 = &ip6_main;
3473 ip4_main_t *im4 = &ip4_main;
3474 ip_lookup_main_t *lm6 = &im6->lookup_main;
3475 ip_lookup_main_t *lm4 = &im4->lookup_main;
3476 ip_interface_address_t *ia = 0;
3477 u32 sw_if_index = ~0;
3478 int rv __attribute__ ((unused)) = 0;
3480 VALIDATE_SW_IF_INDEX (mp);
3482 sw_if_index = ntohl (mp->sw_if_index);
3484 q = vl_api_client_index_to_input_queue (mp->client_index);
3493 foreach_ip_interface_address (lm6, ia, sw_if_index,
3494 1 /* honor unnumbered */,
3496 r6 = ip_interface_address_get_address (lm6, ia);
3497 u16 prefix_length = ia->address_length;
3498 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3505 foreach_ip_interface_address (lm4, ia, sw_if_index,
3506 1 /* honor unnumbered */,
3508 r4 = ip_interface_address_get_address (lm4, ia);
3509 u16 prefix_length = ia->address_length;
3510 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3514 BAD_SW_IF_INDEX_LABEL;
3518 send_ip_details (vpe_api_main_t * am,
3519 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
3521 vl_api_ip_details_t *mp;
3523 mp = vl_msg_api_alloc (sizeof (*mp));
3524 memset (mp, 0, sizeof (*mp));
3525 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
3527 mp->sw_if_index = ntohl (sw_if_index);
3528 mp->context = context;
3530 vl_msg_api_send_shmem (q, (u8 *) & mp);
3534 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
3537 vpe_api_main_t *am = &vpe_api_main;
3538 l2t_main_t *lm = &l2t_main;
3539 unix_shared_memory_queue_t *q;
3540 l2t_session_t *session;
3542 q = vl_api_client_index_to_input_queue (mp->client_index);
3547 pool_foreach (session, lm->sessions,
3549 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
3556 send_sw_interface_tap_details (vpe_api_main_t * am,
3557 unix_shared_memory_queue_t * q,
3558 tapcli_interface_details_t * tap_if,
3561 vl_api_sw_interface_tap_details_t *mp;
3562 mp = vl_msg_api_alloc (sizeof (*mp));
3563 memset (mp, 0, sizeof (*mp));
3564 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
3565 mp->sw_if_index = ntohl (tap_if->sw_if_index);
3566 strncpy ((char *) mp->dev_name,
3567 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
3568 mp->context = context;
3570 vl_msg_api_send_shmem (q, (u8 *) & mp);
3574 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
3577 vpe_api_main_t *am = &vpe_api_main;
3578 unix_shared_memory_queue_t *q;
3579 tapcli_interface_details_t *tapifs = NULL;
3580 tapcli_interface_details_t *tap_if = NULL;
3582 q = vl_api_client_index_to_input_queue (mp->client_index);
3586 rv = vnet_tap_dump_ifs (&tapifs);
3590 vec_foreach (tap_if, tapifs)
3592 send_sw_interface_tap_details (am, q, tap_if, mp->context);
3599 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
3601 vpe_api_main_t *am = &vpe_api_main;
3602 vnet_main_t *vnm = vnet_get_main ();
3603 vlib_main_t *vm = vlib_get_main ();
3604 vnet_interface_main_t *im = &vnm->interface_main;
3605 unix_shared_memory_queue_t *q;
3606 vnet_sw_interface_t *si, *sorted_sis;
3607 u32 sw_if_index = ~0;
3609 q = vl_api_client_index_to_input_queue (mp->client_index);
3615 /* Gather interfaces. */
3616 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3617 _vec_len (sorted_sis) = 0;
3619 pool_foreach (si, im->sw_interfaces,
3621 vec_add1 (sorted_sis, si[0]);
3625 vec_foreach (si, sorted_sis)
3627 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
3629 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
3633 sw_if_index = si->sw_if_index;
3634 send_ip_details (am, q, sw_if_index, mp->context);
3640 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
3642 clib_warning ("BUG");
3646 send_l2fib_table_entry (vpe_api_main_t * am,
3647 unix_shared_memory_queue_t * q,
3648 l2fib_entry_key_t * l2fe_key,
3649 l2fib_entry_result_t * l2fe_res, u32 context)
3651 vl_api_l2_fib_table_entry_t *mp;
3653 mp = vl_msg_api_alloc (sizeof (*mp));
3654 memset (mp, 0, sizeof (*mp));
3655 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
3658 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3660 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3661 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
3662 mp->static_mac = l2fe_res->fields.static_mac;
3663 mp->filter_mac = l2fe_res->fields.filter;
3664 mp->bvi_mac = l2fe_res->fields.bvi;
3665 mp->context = context;
3667 vl_msg_api_send_shmem (q, (u8 *) & mp);
3671 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
3673 vpe_api_main_t *am = &vpe_api_main;
3674 bd_main_t *bdm = &bd_main;
3675 l2fib_entry_key_t *l2fe_key = NULL;
3676 l2fib_entry_result_t *l2fe_res = NULL;
3677 u32 ni, bd_id = ntohl (mp->bd_id);
3679 unix_shared_memory_queue_t *q;
3682 q = vl_api_client_index_to_input_queue (mp->client_index);
3686 /* see l2fib_table_dump: ~0 means "any" */
3691 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3698 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3700 vec_foreach_index (ni, l2fe_key)
3702 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
3703 vec_elt_at_index (l2fe_res, ni), mp->context);
3705 vec_free (l2fe_key);
3706 vec_free (l2fe_res);
3710 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
3712 vl_api_show_version_reply_t *rmp;
3714 char *vpe_api_get_build_directory (void);
3715 char *vpe_api_get_version (void);
3716 char *vpe_api_get_build_date (void);
3718 unix_shared_memory_queue_t *q =
3719 vl_api_client_index_to_input_queue (mp->client_index);
3725 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3727 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3728 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3729 ARRAY_LEN(rmp->build_directory)-1);
3730 strncpy ((char *) rmp->version, vpe_api_get_version(),
3731 ARRAY_LEN(rmp->version)-1);
3732 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3733 ARRAY_LEN(rmp->build_date)-1);
3739 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
3741 vlib_main_t *vm = vlib_get_main ();
3742 vl_api_get_node_index_reply_t *rmp;
3745 u32 node_index = ~0;
3747 n = vlib_get_node_by_name (vm, mp->node_name);
3750 rv = VNET_API_ERROR_NO_SUCH_NODE;
3752 node_index = n->index;
3755 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3757 rmp->node_index = ntohl(node_index);
3763 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
3765 vlib_main_t *vm = vlib_get_main ();
3766 vl_api_get_next_index_reply_t *rmp;
3767 vlib_node_t *node, *next_node;
3769 u32 next_node_index = ~0, next_index = ~0;
3772 node = vlib_get_node_by_name (vm, mp->node_name);
3776 rv = VNET_API_ERROR_NO_SUCH_NODE;
3780 next_node = vlib_get_node_by_name (vm, mp->next_name);
3784 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3788 next_node_index = next_node->index;
3790 p = hash_get (node->next_slot_by_node, next_node_index);
3794 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
3802 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
3804 rmp->next_index = ntohl(next_index);
3810 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
3812 vlib_main_t *vm = vlib_get_main ();
3813 vl_api_add_node_next_reply_t *rmp;
3814 vlib_node_t *n, *next;
3816 u32 next_index = ~0;
3818 n = vlib_get_node_by_name (vm, mp->node_name);
3822 rv = VNET_API_ERROR_NO_SUCH_NODE;
3826 next = vlib_get_node_by_name (vm, mp->next_name);
3829 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3831 next_index = vlib_node_add_next (vm, n->index, next->index);
3835 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3837 rmp->next_index = ntohl(next_index);
3842 static void vl_api_l2tpv3_create_tunnel_t_handler
3843 (vl_api_l2tpv3_create_tunnel_t * mp)
3845 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
3846 l2t_main_t *lm = &l2t_main;
3847 u32 sw_if_index = (u32) ~ 0;
3850 if (mp->is_ipv6 != 1)
3852 rv = VNET_API_ERROR_UNIMPLEMENTED;
3856 u32 encap_fib_index;
3858 if (mp->encap_vrf_id != ~0)
3861 ip6_main_t *im = &ip6_main;
3864 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
3866 rv = VNET_API_ERROR_NO_SUCH_FIB;
3869 encap_fib_index = p[0];
3873 encap_fib_index = ~0;
3876 rv = create_l2tpv3_ipv6_tunnel (lm,
3877 (ip6_address_t *) mp->client_address,
3878 (ip6_address_t *) mp->our_address,
3879 ntohl (mp->local_session_id),
3880 ntohl (mp->remote_session_id),
3881 clib_net_to_host_u64 (mp->local_cookie),
3882 clib_net_to_host_u64 (mp->remote_cookie),
3883 mp->l2_sublayer_present,
3884 encap_fib_index, &sw_if_index);
3888 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
3890 rmp->sw_if_index = ntohl (sw_if_index);
3895 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
3896 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
3898 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
3899 l2t_main_t *lm = &l2t_main;
3902 VALIDATE_SW_IF_INDEX (mp);
3904 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
3905 clib_net_to_host_u64 (mp->new_local_cookie),
3906 clib_net_to_host_u64
3907 (mp->new_remote_cookie));
3909 BAD_SW_IF_INDEX_LABEL;
3911 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
3914 static void vl_api_l2tpv3_interface_enable_disable_t_handler
3915 (vl_api_l2tpv3_interface_enable_disable_t * mp)
3918 vnet_main_t *vnm = vnet_get_main ();
3919 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
3921 VALIDATE_SW_IF_INDEX (mp);
3923 rv = l2tpv3_interface_enable_disable
3924 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
3926 BAD_SW_IF_INDEX_LABEL;
3928 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
3931 static void vl_api_l2tpv3_set_lookup_key_t_handler
3932 (vl_api_l2tpv3_set_lookup_key_t * mp)
3935 l2t_main_t *lm = &l2t_main;
3936 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
3938 if (mp->key > L2T_LOOKUP_SESSION_ID)
3940 rv = VNET_API_ERROR_INVALID_VALUE;
3944 lm->lookup_type = mp->key;
3947 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
3950 static void vl_api_vxlan_add_del_tunnel_t_handler
3951 (vl_api_vxlan_add_del_tunnel_t * mp)
3953 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
3955 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
3956 u32 encap_fib_index;
3958 ip4_main_t *im = &ip4_main;
3959 u32 sw_if_index = ~0;
3961 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
3964 rv = VNET_API_ERROR_NO_SUCH_FIB;
3967 encap_fib_index = p[0];
3968 memset (a, 0, sizeof (*a));
3970 a->is_add = mp->is_add;
3971 a->is_ip6 = mp->is_ipv6;
3973 /* ip addresses sent in network byte order */
3974 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
3975 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
3977 /* Check src & dst are different */
3978 if (ip46_address_cmp (&a->dst, &a->src) == 0)
3980 rv = VNET_API_ERROR_SAME_SRC_DST;
3983 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
3984 a->encap_fib_index = encap_fib_index;
3985 a->decap_next_index = ntohl (mp->decap_next_index);
3986 a->vni = ntohl (mp->vni);
3987 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
3991 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
3993 rmp->sw_if_index = ntohl (sw_if_index);
3998 static void send_vxlan_tunnel_details
3999 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4001 vl_api_vxlan_tunnel_details_t *rmp;
4002 ip4_main_t *im4 = &ip4_main;
4003 ip6_main_t *im6 = &ip6_main;
4004 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
4006 rmp = vl_msg_api_alloc (sizeof (*rmp));
4007 memset (rmp, 0, sizeof (*rmp));
4008 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4011 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
4012 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
4013 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4017 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
4018 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
4019 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4021 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
4022 rmp->vni = htonl (t->vni);
4023 rmp->decap_next_index = htonl (t->decap_next_index);
4024 rmp->sw_if_index = htonl (t->sw_if_index);
4025 rmp->is_ipv6 = is_ipv6;
4026 rmp->context = context;
4028 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4031 static void vl_api_vxlan_tunnel_dump_t_handler
4032 (vl_api_vxlan_tunnel_dump_t * mp)
4034 unix_shared_memory_queue_t *q;
4035 vxlan_main_t *vxm = &vxlan_main;
4039 q = vl_api_client_index_to_input_queue (mp->client_index);
4045 sw_if_index = ntohl (mp->sw_if_index);
4047 if (~0 == sw_if_index)
4050 pool_foreach (t, vxm->tunnels,
4052 send_vxlan_tunnel_details(t, q, mp->context);
4058 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4059 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4063 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4064 send_vxlan_tunnel_details (t, q, mp->context);
4068 static void vl_api_gre_add_del_tunnel_t_handler
4069 (vl_api_gre_add_del_tunnel_t * mp)
4071 vl_api_gre_add_del_tunnel_reply_t *rmp;
4073 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4076 ip4_main_t *im = &ip4_main;
4077 u32 sw_if_index = ~0;
4079 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4082 rv = VNET_API_ERROR_NO_SUCH_FIB;
4085 outer_fib_id = p[0];
4087 /* Check src & dst are different */
4088 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4089 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4091 rv = VNET_API_ERROR_SAME_SRC_DST;
4094 memset (a, 0, sizeof (*a));
4096 a->is_add = mp->is_add;
4099 /* ip addresses sent in network byte order */
4100 clib_memcpy (&(a->src), mp->src_address, 4);
4101 clib_memcpy (&(a->dst), mp->dst_address, 4);
4103 a->outer_fib_id = outer_fib_id;
4104 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4108 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4110 rmp->sw_if_index = ntohl (sw_if_index);
4115 static void send_gre_tunnel_details
4116 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4118 vl_api_gre_tunnel_details_t *rmp;
4119 ip4_main_t *im = &ip4_main;
4121 rmp = vl_msg_api_alloc (sizeof (*rmp));
4122 memset (rmp, 0, sizeof (*rmp));
4123 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4124 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4125 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4126 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4127 rmp->teb = (GRE_TUNNEL_TYPE_TEB == t->type);
4128 rmp->sw_if_index = htonl (t->sw_if_index);
4129 rmp->context = context;
4131 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4135 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4137 unix_shared_memory_queue_t *q;
4138 gre_main_t *gm = &gre_main;
4142 q = vl_api_client_index_to_input_queue (mp->client_index);
4148 sw_if_index = ntohl (mp->sw_if_index);
4150 if (~0 == sw_if_index)
4153 pool_foreach (t, gm->tunnels,
4155 send_gre_tunnel_details(t, q, mp->context);
4161 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4162 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4166 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4167 send_gre_tunnel_details (t, q, mp->context);
4172 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4174 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4176 vl_api_l2_patch_add_del_reply_t *rmp;
4177 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4181 VALIDATE_RX_SW_IF_INDEX (mp);
4182 VALIDATE_TX_SW_IF_INDEX (mp);
4184 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4185 ntohl (mp->tx_sw_if_index),
4186 (int) (mp->is_add != 0));
4188 BAD_RX_SW_IF_INDEX_LABEL;
4189 BAD_TX_SW_IF_INDEX_LABEL;
4191 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4195 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4196 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4198 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4200 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4201 u32 encap_fib_index, decap_fib_index;
4204 ip4_main_t *im = &ip4_main;
4205 u32 sw_if_index = ~0;
4208 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4211 rv = VNET_API_ERROR_NO_SUCH_FIB;
4214 encap_fib_index = p[0];
4216 protocol = mp->protocol;
4218 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4219 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4221 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4224 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4227 decap_fib_index = p[0];
4231 decap_fib_index = ntohl (mp->decap_vrf_id);
4234 /* Check src & dst are different */
4235 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4236 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
4238 rv = VNET_API_ERROR_SAME_SRC_DST;
4241 memset (a, 0, sizeof (*a));
4243 a->is_add = mp->is_add;
4244 a->is_ip6 = mp->is_ipv6;
4245 /* ip addresses sent in network byte order */
4248 clib_memcpy (&(a->local.ip6), mp->local, 16);
4249 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
4253 clib_memcpy (&(a->local.ip4), mp->local, 4);
4254 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
4256 a->encap_fib_index = encap_fib_index;
4257 a->decap_fib_index = decap_fib_index;
4258 a->protocol = protocol;
4259 a->vni = ntohl (mp->vni);
4260 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4264 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4266 rmp->sw_if_index = ntohl (sw_if_index);
4271 static void send_vxlan_gpe_tunnel_details
4272 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4274 vl_api_vxlan_gpe_tunnel_details_t *rmp;
4275 ip4_main_t *im4 = &ip4_main;
4276 ip6_main_t *im6 = &ip6_main;
4277 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4279 rmp = vl_msg_api_alloc (sizeof (*rmp));
4280 memset (rmp, 0, sizeof (*rmp));
4281 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4284 memcpy (rmp->local, &(t->local.ip6), 16);
4285 memcpy (rmp->remote, &(t->remote.ip6), 16);
4286 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4287 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
4291 memcpy (rmp->local, &(t->local.ip4), 4);
4292 memcpy (rmp->remote, &(t->remote.ip4), 4);
4293 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4294 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
4296 rmp->vni = htonl (t->vni);
4297 rmp->protocol = t->protocol;
4298 rmp->sw_if_index = htonl (t->sw_if_index);
4299 rmp->is_ipv6 = is_ipv6;
4300 rmp->context = context;
4302 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4305 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4306 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4308 unix_shared_memory_queue_t *q;
4309 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
4310 vxlan_gpe_tunnel_t *t;
4313 q = vl_api_client_index_to_input_queue (mp->client_index);
4319 sw_if_index = ntohl (mp->sw_if_index);
4321 if (~0 == sw_if_index)
4324 pool_foreach (t, vgm->tunnels,
4326 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4332 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
4333 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
4337 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4338 send_vxlan_gpe_tunnel_details (t, q, mp->context);
4342 /** Used for transferring locators via VPP API */
4344 typedef CLIB_PACKED (struct {
4345 u32 sw_if_index; /**< locator sw_if_index */
4346 u8 priority; /**< locator priority */
4347 u8 weight; /**< locator weight */
4352 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
4355 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4357 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4359 ls_locator_t *ls_loc;
4360 u32 ls_index = ~0, locator_num;
4361 u8 *locator_name = NULL;
4364 memset (a, 0, sizeof (a[0]));
4366 locator_name = format (0, "%s", mp->locator_set_name);
4368 a->name = locator_name;
4369 a->is_add = mp->is_add;
4371 locator_num = clib_net_to_host_u32 (mp->locator_num);
4373 memset (&locator, 0, sizeof (locator));
4374 for (i = 0; i < locator_num; i++)
4376 ls_loc = &((ls_locator_t *) mp->locators)[i];
4377 VALIDATE_SW_IF_INDEX (ls_loc);
4379 locator.sw_if_index = htonl (ls_loc->sw_if_index);
4380 locator.priority = ls_loc->priority;
4381 locator.weight = ls_loc->weight;
4383 vec_add1 (a->locators, locator);
4386 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
4388 BAD_SW_IF_INDEX_LABEL;
4390 vec_free (locator_name);
4391 vec_free (a->locators);
4394 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
4396 rmp->ls_index = clib_host_to_net_u32 (ls_index);
4402 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
4404 vl_api_lisp_add_del_locator_reply_t *rmp;
4406 locator_t locator, *locators = NULL;
4407 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4409 u8 *locator_name = NULL;
4411 memset (&locator, 0, sizeof (locator));
4412 memset (a, 0, sizeof (a[0]));
4414 locator.sw_if_index = ntohl (mp->sw_if_index);
4415 locator.priority = mp->priority;
4416 locator.weight = mp->weight;
4418 vec_add1 (locators, locator);
4420 locator_name = format (0, "%s", mp->locator_set_name);
4422 a->name = locator_name;
4423 a->locators = locators;
4424 a->is_add = mp->is_add;
4427 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
4429 vec_free (locators);
4430 vec_free (locator_name);
4432 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4436 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
4442 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
4443 gid_address_ip_set (dst, src, IP4);
4444 gid_address_ippref_len (dst) = len;
4445 ip_prefix_normalize (&gid_address_ippref (dst));
4448 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
4449 gid_address_ip_set (dst, src, IP6);
4450 gid_address_ippref_len (dst) = len;
4451 ip_prefix_normalize (&gid_address_ippref (dst));
4453 case 2: /* l2 mac */
4454 gid_address_type (dst) = GID_ADDR_MAC;
4455 clib_memcpy (&gid_address_mac (dst), src, 6);
4459 return VNET_API_ERROR_INVALID_VALUE;
4462 gid_address_vni (dst) = vni;
4468 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
4470 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4471 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4473 gid_address_t _eid, *eid = &_eid;
4475 u32 locator_set_index = ~0, map_index = ~0;
4476 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4477 u8 *name = NULL, *key = NULL;
4478 memset (a, 0, sizeof (a[0]));
4479 memset (eid, 0, sizeof (eid[0]));
4481 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4482 mp->eid_type, mp->eid, mp->prefix_len);
4486 name = format (0, "%s", mp->locator_set_name);
4487 p = hash_get_mem (lcm->locator_set_index_by_name, name);
4490 rv = VNET_API_ERROR_INVALID_VALUE;
4493 locator_set_index = p[0];
4496 key = format (0, "%s", mp->key);
4498 /* XXX treat batch configuration */
4499 a->is_add = mp->is_add;
4500 gid_address_copy (&a->eid, eid);
4501 a->locator_set_index = locator_set_index;
4504 a->key_id = clib_net_to_host_u16 (mp->key_id);
4506 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
4511 gid_address_free (&a->eid);
4513 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4517 vl_api_lisp_eid_table_add_del_map_t_handler
4518 (vl_api_lisp_eid_table_add_del_map_t * mp)
4520 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4522 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4523 clib_net_to_host_u32 (mp->dp_table),
4524 mp->is_l2, mp->is_add);
4525 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
4527 /** Used for transferring locators via VPP API */
4529 typedef CLIB_PACKED (struct {
4530 u8 is_ip4; /**< is locator an IPv4 address */
4531 u8 priority; /**< locator priority */
4532 u8 weight; /**< locator weight */
4533 u8 addr[16]; /**< IPv4/IPv6 address */
4537 static locator_pair_t *
4538 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
4541 locator_pair_t *pairs = 0, pair;
4544 for (i = 0; i < rloc_num; i++)
4547 r = &((rloc_t *) lcl_locs)[i];
4548 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
4549 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
4551 /* remote locators */
4552 r = &((rloc_t *) rmt_locs)[i];
4553 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
4554 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
4556 pair.priority = r->priority;
4557 pair.weight = r->weight;
4559 vec_add1 (pairs, pair);
4565 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
4568 locator_t *locs = 0, loc;
4571 for (i = 0; i < rloc_num; i++)
4573 /* remote locators */
4574 r = &((rloc_t *) rmt_locs)[i];
4575 memset (&loc, 0, sizeof (loc));
4576 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
4578 loc.priority = r->priority;
4579 loc.weight = r->weight;
4581 vec_add1 (locs, loc);
4587 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
4588 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
4590 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4591 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
4592 locator_pair_t *pairs = 0;
4595 memset (a, 0, sizeof (a[0]));
4597 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
4598 mp->rmt_eid, mp->rmt_len);
4599 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
4600 mp->lcl_eid, mp->lcl_len);
4602 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
4604 if (rv || 0 == pairs)
4607 a->is_add = mp->is_add;
4608 a->locator_pairs = pairs;
4609 a->dp_table = mp->dp_table;
4611 a->action = mp->action;
4613 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
4616 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4620 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
4623 vl_api_lisp_add_del_map_server_reply_t *rmp;
4627 memset (&addr, 0, sizeof (addr));
4629 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
4630 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
4632 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
4636 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
4639 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4641 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
4643 memset (a, 0, sizeof (a[0]));
4645 a->is_add = mp->is_add;
4646 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
4648 rv = vnet_lisp_add_del_map_resolver (a);
4650 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4654 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
4657 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4659 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
4661 a->is_en = mp->is_en;
4662 vnet_lisp_gpe_enable_disable (a);
4664 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4668 vl_api_lisp_map_register_enable_disable_t_handler
4669 (vl_api_lisp_map_register_enable_disable_t * mp)
4671 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
4674 vnet_lisp_map_register_enable_disable (mp->is_enabled);
4675 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4679 vl_api_lisp_rloc_probe_enable_disable_t_handler
4680 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
4682 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
4685 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
4686 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4690 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
4692 vl_api_lisp_enable_disable_reply_t *rmp;
4695 vnet_lisp_enable_disable (mp->is_en);
4696 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4700 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
4702 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4710 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
4714 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
4721 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
4725 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
4728 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4732 vl_api_show_lisp_map_request_mode_t_handler
4733 (vl_api_show_lisp_map_request_mode_t * mp)
4736 vl_api_show_lisp_map_request_mode_reply_t *rmp;
4739 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
4741 rmp->mode = vnet_lisp_get_map_request_mode ();
4747 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
4749 vl_api_lisp_map_request_mode_reply_t *rmp;
4752 rv = vnet_lisp_set_map_request_mode (mp->mode);
4754 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
4758 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
4761 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4765 ls_name = format (0, "%s", mp->ls_name);
4766 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4769 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4773 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
4774 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
4776 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
4778 u8 *locator_set_name = NULL;
4779 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
4781 locator_set_name = format (0, "%s", mp->locator_set_name);
4783 a->is_add = mp->is_add;
4784 a->locator_set_name = locator_set_name;
4786 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
4788 vec_free (locator_set_name);
4790 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
4794 vl_api_lisp_add_del_remote_mapping_t_handler
4795 (vl_api_lisp_add_del_remote_mapping_t * mp)
4797 locator_t *rlocs = 0;
4798 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
4800 gid_address_t _eid, *eid = &_eid;
4801 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
4803 memset (eid, 0, sizeof (eid[0]));
4805 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4806 mp->eid_type, mp->eid, mp->eid_len);
4810 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
4814 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
4815 gid_address_copy (&a->reid, eid);
4817 rv = vnet_lisp_add_del_adjacency (a);
4824 /* NOTE: for now this works as a static remote mapping, i.e.,
4825 * not authoritative and ttl infinite. */
4826 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
4827 mp->is_add, 1 /* is_static */ , 0);
4830 vnet_lisp_clear_all_remote_adjacencies ();
4835 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
4839 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
4841 vl_api_lisp_add_del_adjacency_reply_t *rmp;
4842 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
4845 memset (a, 0, sizeof (a[0]));
4847 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
4848 mp->eid_type, mp->leid, mp->leid_len);
4849 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
4850 mp->eid_type, mp->reid, mp->reid_len);
4855 a->is_add = mp->is_add;
4856 rv = vnet_lisp_add_del_adjacency (a);
4859 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
4863 send_lisp_locator_details (lisp_cp_main_t * lcm,
4865 unix_shared_memory_queue_t * q, u32 context)
4867 vl_api_lisp_locator_details_t *rmp;
4869 rmp = vl_msg_api_alloc (sizeof (*rmp));
4870 memset (rmp, 0, sizeof (*rmp));
4871 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
4872 rmp->context = context;
4874 rmp->local = loc->local;
4877 rmp->sw_if_index = ntohl (loc->sw_if_index);
4881 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
4882 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
4884 rmp->priority = loc->priority;
4885 rmp->weight = loc->weight;
4887 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4891 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
4894 unix_shared_memory_queue_t *q = 0;
4895 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4896 locator_set_t *lsit = 0;
4898 u32 ls_index = ~0, *locit = 0;
4901 q = vl_api_client_index_to_input_queue (mp->client_index);
4907 if (mp->is_index_set)
4908 ls_index = htonl (mp->ls_index);
4911 /* make sure we get a proper C-string */
4912 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
4913 ls_name = format (0, "%s", mp->ls_name);
4914 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
4920 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
4923 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
4925 vec_foreach (locit, lsit->locator_indices)
4927 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4928 send_lisp_locator_details (lcm, loc, q, mp->context);
4935 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
4936 locator_set_t * lsit,
4937 unix_shared_memory_queue_t * q,
4938 u32 context, u32 ls_index)
4940 vl_api_lisp_locator_set_details_t *rmp;
4943 rmp = vl_msg_api_alloc (sizeof (*rmp));
4944 memset (rmp, 0, sizeof (*rmp));
4945 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
4946 rmp->context = context;
4948 rmp->ls_index = htonl (ls_index);
4951 ASSERT (lsit->name != NULL);
4952 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
4953 vec_len (lsit->name));
4957 str = format (0, "<remote-%d>", ls_index);
4958 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
4962 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4966 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
4968 unix_shared_memory_queue_t *q = NULL;
4969 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4970 locator_set_t *lsit = NULL;
4973 q = vl_api_client_index_to_input_queue (mp->client_index);
4979 filter = mp->filter;
4981 pool_foreach (lsit, lcm->locator_set_pool,
4983 if (filter && !((1 == filter && lsit->local) ||
4984 (2 == filter && !lsit->local)))
4988 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
4989 lsit - lcm->locator_set_pool);
4995 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
4997 ASSERT (prefix_length);
4998 ip_prefix_t *ippref = &fid_addr_ippref (src);
5000 switch (fid_addr_type (src))
5002 case FID_ADDR_IP_PREF:
5003 if (ip_prefix_version (ippref) == IP4)
5004 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5006 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5007 prefix_length[0] = ip_prefix_len (ippref);
5011 prefix_length[0] = 0;
5012 clib_memcpy (dst, fid_addr_mac (src), 6);
5016 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5022 fid_type_to_api_type (fid_address_t * fid)
5024 ip_prefix_t *ippref;
5026 switch (fid_addr_type (fid))
5028 case FID_ADDR_IP_PREF:
5029 ippref = &fid_addr_ippref (fid);
5030 if (ip_prefix_version (ippref) == IP4)
5032 else if (ip_prefix_version (ippref) == IP6)
5045 send_lisp_eid_table_details (mapping_t * mapit,
5046 unix_shared_memory_queue_t * q,
5047 u32 context, u8 filter)
5050 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5051 locator_set_t *ls = 0;
5052 vl_api_lisp_eid_table_details_t *rmp = NULL;
5053 gid_address_t *gid = NULL;
5055 ip_prefix_t *ip_prefix = NULL;
5059 case 0: /* all mappings */
5062 case 1: /* local only */
5066 case 2: /* remote only */
5071 clib_warning ("Filter error, unknown filter: %d", filter);
5076 ip_prefix = &gid_address_ippref (gid);
5077 mac = gid_address_mac (gid);
5079 rmp = vl_msg_api_alloc (sizeof (*rmp));
5080 memset (rmp, 0, sizeof (*rmp));
5081 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5083 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5084 if (vec_len (ls->locator_indices) == 0)
5085 rmp->locator_set_index = ~0;
5087 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5089 rmp->is_local = mapit->local;
5090 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5091 rmp->action = mapit->action;
5092 rmp->authoritative = mapit->authoritative;
5094 switch (gid_address_type (gid))
5096 case GID_ADDR_SRC_DST:
5097 rmp->is_src_dst = 1;
5098 fid = &gid_address_sd_src (gid);
5099 rmp->eid_type = fid_type_to_api_type (fid);
5100 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5101 &rmp->seid_prefix_len);
5102 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5103 &rmp->eid_prefix_len);
5105 case GID_ADDR_IP_PREFIX:
5106 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5107 if (ip_prefix_version (ip_prefix) == IP4)
5109 rmp->eid_type = 0; /* ipv4 type */
5110 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5111 sizeof (ip_prefix_v4 (ip_prefix)));
5115 rmp->eid_type = 1; /* ipv6 type */
5116 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5117 sizeof (ip_prefix_v6 (ip_prefix)));
5121 rmp->eid_type = 2; /* l2 mac type */
5122 clib_memcpy (rmp->eid, mac, 6);
5127 rmp->context = context;
5128 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5129 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
5130 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
5131 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5135 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5138 unix_shared_memory_queue_t *q = NULL;
5139 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5140 mapping_t *mapit = NULL;
5141 gid_address_t _eid, *eid = &_eid;
5143 q = vl_api_client_index_to_input_queue (mp->client_index);
5151 memset (eid, 0, sizeof (*eid));
5153 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5154 mp->eid_type, mp->eid, mp->prefix_length);
5156 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5157 if ((u32) ~ 0 == mi)
5160 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5161 send_lisp_eid_table_details (mapit, q, mp->context,
5162 0 /* ignore filter */ );
5167 pool_foreach (mapit, lcm->mapping_pool,
5169 send_lisp_eid_table_details(mapit, q, mp->context,
5177 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
5178 unix_shared_memory_queue_t * q, u32 context)
5180 vl_api_lisp_gpe_tunnel_details_t *rmp;
5181 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5183 rmp = vl_msg_api_alloc (sizeof (*rmp));
5184 memset (rmp, 0, sizeof (*rmp));
5185 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5187 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
5189 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
5190 ip_address_copy_addr (rmp->source_ip,
5191 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5192 ip_address_copy_addr (rmp->destination_ip,
5193 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5195 rmp->encap_fib_id = htonl (0);
5196 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
5197 rmp->iid = htonl (lfe->key->vni);
5198 rmp->context = context;
5200 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5204 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5206 unix_shared_memory_queue_t *q = NULL;
5207 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5208 lisp_gpe_fwd_entry_t *lfe = NULL;
5210 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
5215 q = vl_api_client_index_to_input_queue (mp->client_index);
5222 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
5224 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
5230 send_lisp_map_server_details (ip_address_t * ip,
5231 unix_shared_memory_queue_t * q, u32 context)
5233 vl_api_lisp_map_server_details_t *rmp = NULL;
5235 rmp = vl_msg_api_alloc (sizeof (*rmp));
5236 memset (rmp, 0, sizeof (*rmp));
5237 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
5239 switch (ip_addr_version (ip))
5243 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5244 sizeof (ip_addr_v4 (ip)));
5249 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5250 sizeof (ip_addr_v6 (ip)));
5256 rmp->context = context;
5258 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5262 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
5264 unix_shared_memory_queue_t *q = NULL;
5265 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5268 q = vl_api_client_index_to_input_queue (mp->client_index);
5274 vec_foreach (mr, lcm->map_servers)
5276 send_lisp_map_server_details (&mr->address, q, mp->context);
5281 send_lisp_map_resolver_details (ip_address_t * ip,
5282 unix_shared_memory_queue_t * q, u32 context)
5284 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5286 rmp = vl_msg_api_alloc (sizeof (*rmp));
5287 memset (rmp, 0, sizeof (*rmp));
5288 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5290 switch (ip_addr_version (ip))
5294 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5295 sizeof (ip_addr_v4 (ip)));
5300 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5301 sizeof (ip_addr_v6 (ip)));
5307 rmp->context = context;
5309 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5313 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5315 unix_shared_memory_queue_t *q = NULL;
5316 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5319 q = vl_api_client_index_to_input_queue (mp->client_index);
5325 vec_foreach (mr, lcm->map_resolvers)
5327 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5332 send_eid_table_map_pair (hash_pair_t * p,
5333 unix_shared_memory_queue_t * q, u32 context)
5335 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5337 rmp = vl_msg_api_alloc (sizeof (*rmp));
5338 memset (rmp, 0, sizeof (*rmp));
5339 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5341 rmp->vni = clib_host_to_net_u32 (p->key);
5342 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5343 rmp->context = context;
5344 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5348 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5351 unix_shared_memory_queue_t *q = NULL;
5352 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5354 uword *vni_table = 0;
5356 q = vl_api_client_index_to_input_queue (mp->client_index);
5364 vni_table = lcm->bd_id_by_vni;
5368 vni_table = lcm->table_id_by_vni;
5372 hash_foreach_pair (p, vni_table,
5374 send_eid_table_map_pair (p, q, mp->context);
5380 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
5382 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
5384 rmp = vl_msg_api_alloc (sizeof (*rmp));
5385 memset (rmp, 0, sizeof (*rmp));
5386 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
5387 rmp->context = context;
5388 rmp->vni = clib_host_to_net_u32 (vni);
5389 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5393 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
5395 lisp_adjacency_t *adj;
5396 vl_api_lisp_adjacency_t a;
5397 u32 i, n = vec_len (adjs);
5399 for (i = 0; i < n; i++)
5401 adj = vec_elt_at_index (adjs, i);
5402 memset (&a, 0, sizeof (a));
5404 switch (gid_address_type (&adj->reid))
5406 case GID_ADDR_IP_PREFIX:
5407 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
5408 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
5409 if (gid_address_ip_version (&adj->reid) == IP4)
5411 a.eid_type = 0; /* ipv4 type */
5412 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
5413 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
5417 a.eid_type = 1; /* ipv6 type */
5418 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
5419 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
5423 a.eid_type = 2; /* l2 mac type */
5424 mac_copy (a.reid, gid_address_mac (&adj->reid));
5425 mac_copy (a.leid, gid_address_mac (&adj->leid));
5435 vl_api_show_lisp_rloc_probe_state_t_handler
5436 (vl_api_show_lisp_rloc_probe_state_t * mp)
5438 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
5442 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
5444 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
5450 vl_api_show_lisp_map_register_state_t_handler
5451 (vl_api_show_lisp_map_register_state_t * mp)
5453 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
5457 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
5459 rmp->is_enabled = vnet_lisp_map_register_state_get ();
5465 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
5467 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
5468 lisp_adjacency_t *adjs = 0;
5470 vl_api_lisp_adjacency_t a;
5472 u32 vni = clib_net_to_host_u32 (mp->vni);
5474 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
5475 size = vec_len (adjs) * sizeof (a);
5478 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
5480 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
5481 lisp_adjacency_copy (rmp->adjacencies, adjs);
5489 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
5494 unix_shared_memory_queue_t *q = 0;
5495 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5497 q = vl_api_client_index_to_input_queue (mp->client_index);
5504 hash_foreach_pair (p, lcm->table_id_by_vni,
5506 hash_set (vnis, p->key, 0);
5509 hash_foreach_pair (p, lcm->bd_id_by_vni,
5511 hash_set (vnis, p->key, 0);
5514 hash_foreach_pair (p, vnis,
5516 send_eid_table_vni (p->key, q, mp->context);
5524 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
5526 unix_shared_memory_queue_t *q = NULL;
5527 vl_api_show_lisp_status_reply_t *rmp = NULL;
5530 q = vl_api_client_index_to_input_queue (mp->client_index);
5537 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5539 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5540 rmp->feature_status = vnet_lisp_enable_disable_status ();
5546 vl_api_lisp_get_map_request_itr_rlocs_t_handler
5547 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
5549 unix_shared_memory_queue_t *q = NULL;
5550 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5551 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5552 locator_set_t *loc_set = 0;
5556 q = vl_api_client_index_to_input_queue (mp->client_index);
5562 if (~0 == lcm->mreq_itr_rlocs)
5564 tmp_str = format (0, " ");
5569 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5570 tmp_str = format (0, "%s", loc_set->name);
5574 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5576 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5577 ARRAY_LEN(rmp->locator_set_name) - 1);
5585 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5587 unix_shared_memory_queue_t *q = NULL;
5588 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
5589 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5591 locator_set_t *ls = 0;
5595 q = vl_api_client_index_to_input_queue (mp->client_index);
5601 if (!lcm->lisp_pitr)
5603 tmp_str = format (0, "N/A");
5607 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5608 if (~0 != m->locator_set_index)
5611 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5612 tmp_str = format (0, "%s", ls->name);
5616 tmp_str = format (0, "N/A");
5619 vec_add1 (tmp_str, 0);
5622 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5624 rmp->status = lcm->lisp_pitr;
5625 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5626 ARRAY_LEN(rmp->locator_set_name) - 1);
5632 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
5635 vl_api_interface_name_renumber_reply_t *rmp;
5638 VALIDATE_SW_IF_INDEX (mp);
5640 rv = vnet_interface_name_renumber
5641 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
5643 BAD_SW_IF_INDEX_LABEL;
5645 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5649 arp_change_data_callback (u32 pool_index, u8 * new_mac,
5650 u32 sw_if_index, u32 address)
5652 vpe_api_main_t *am = &vpe_api_main;
5653 vlib_main_t *vm = am->vlib_main;
5654 vl_api_ip4_arp_event_t *event;
5655 static f64 arp_event_last_time;
5656 f64 now = vlib_time_now (vm);
5658 if (pool_is_free_index (am->arp_events, pool_index))
5661 event = pool_elt_at_index (am->arp_events, pool_index);
5663 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
5665 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
5669 if (sw_if_index == event->sw_if_index &&
5671 /* for BD case, also check IP address with 10 sec timeout */
5672 (address == event->address &&
5673 (now - arp_event_last_time) < 10.0)))
5678 arp_event_last_time = now;
5679 event->sw_if_index = sw_if_index;
5681 event->address = address;
5686 nd_change_data_callback (u32 pool_index, u8 * new_mac,
5687 u32 sw_if_index, ip6_address_t * address)
5689 vpe_api_main_t *am = &vpe_api_main;
5690 vlib_main_t *vm = am->vlib_main;
5691 vl_api_ip6_nd_event_t *event;
5692 static f64 nd_event_last_time;
5693 f64 now = vlib_time_now (vm);
5695 if (pool_is_free_index (am->nd_events, pool_index))
5698 event = pool_elt_at_index (am->nd_events, pool_index);
5701 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
5703 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
5707 if (sw_if_index == event->sw_if_index &&
5709 /* for BD case, also check IP address with 10 sec timeout */
5710 (ip6_address_is_equal (address,
5711 (ip6_address_t *) event->address) &&
5712 (now - nd_event_last_time) < 10.0)))
5717 nd_event_last_time = now;
5718 event->sw_if_index = sw_if_index;
5720 clib_memcpy (event->address, address, sizeof (event->address));
5725 arp_change_delete_callback (u32 pool_index, u8 * notused)
5727 vpe_api_main_t *am = &vpe_api_main;
5729 if (pool_is_free_index (am->arp_events, pool_index))
5732 pool_put_index (am->arp_events, pool_index);
5737 nd_change_delete_callback (u32 pool_index, u8 * notused)
5739 vpe_api_main_t *am = &vpe_api_main;
5741 if (pool_is_free_index (am->nd_events, pool_index))
5744 pool_put_index (am->nd_events, pool_index);
5749 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
5751 vpe_api_main_t *am = &vpe_api_main;
5752 vnet_main_t *vnm = vnet_get_main ();
5753 vl_api_want_ip4_arp_events_reply_t *rmp;
5754 vl_api_ip4_arp_event_t *event;
5757 if (mp->enable_disable)
5759 pool_get (am->arp_events, event);
5760 memset (event, 0, sizeof (*event));
5762 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
5763 event->client_index = mp->client_index;
5764 event->context = mp->context;
5765 event->address = mp->address;
5766 event->pid = mp->pid;
5767 if (mp->address == 0)
5770 rv = vnet_add_del_ip4_arp_change_event
5771 (vnm, arp_change_data_callback,
5772 mp->pid, &mp->address /* addr, in net byte order */ ,
5773 vpe_resolver_process_node.index,
5774 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
5778 rv = vnet_add_del_ip4_arp_change_event
5779 (vnm, arp_change_delete_callback,
5780 mp->pid, &mp->address /* addr, in net byte order */ ,
5781 vpe_resolver_process_node.index,
5782 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
5784 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5788 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
5790 vpe_api_main_t *am = &vpe_api_main;
5791 vnet_main_t *vnm = vnet_get_main ();
5792 vl_api_want_ip6_nd_events_reply_t *rmp;
5793 vl_api_ip6_nd_event_t *event;
5796 if (mp->enable_disable)
5798 pool_get (am->nd_events, event);
5799 memset (event, 0, sizeof (*event));
5801 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
5802 event->client_index = mp->client_index;
5803 event->context = mp->context;
5804 clib_memcpy (event->address, mp->address, 16);
5805 event->pid = mp->pid;
5806 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
5809 rv = vnet_add_del_ip6_nd_change_event
5810 (vnm, nd_change_data_callback,
5811 mp->pid, mp->address /* addr, in net byte order */ ,
5812 vpe_resolver_process_node.index,
5813 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
5817 rv = vnet_add_del_ip6_nd_change_event
5818 (vnm, nd_change_delete_callback,
5819 mp->pid, mp->address /* addr, in net byte order */ ,
5820 vpe_resolver_process_node.index,
5821 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
5823 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
5826 static void vl_api_input_acl_set_interface_t_handler
5827 (vl_api_input_acl_set_interface_t * mp)
5829 vlib_main_t *vm = vlib_get_main ();
5830 vl_api_input_acl_set_interface_reply_t *rmp;
5832 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5834 ip4_table_index = ntohl (mp->ip4_table_index);
5835 ip6_table_index = ntohl (mp->ip6_table_index);
5836 l2_table_index = ntohl (mp->l2_table_index);
5837 sw_if_index = ntohl (mp->sw_if_index);
5839 VALIDATE_SW_IF_INDEX (mp);
5841 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5842 ip6_table_index, l2_table_index, mp->is_add);
5844 BAD_SW_IF_INDEX_LABEL;
5846 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5849 static void vl_api_ipsec_spd_add_del_t_handler
5850 (vl_api_ipsec_spd_add_del_t * mp)
5853 clib_warning ("unimplemented");
5856 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5857 vl_api_ipsec_spd_add_del_reply_t *rmp;
5861 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
5863 rv = VNET_API_ERROR_UNIMPLEMENTED;
5866 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5870 static void vl_api_ipsec_interface_add_del_spd_t_handler
5871 (vl_api_ipsec_interface_add_del_spd_t * mp)
5873 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5874 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
5876 u32 sw_if_index __attribute__ ((unused));
5877 u32 spd_id __attribute__ ((unused));
5879 sw_if_index = ntohl (mp->sw_if_index);
5880 spd_id = ntohl (mp->spd_id);
5882 VALIDATE_SW_IF_INDEX (mp);
5885 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
5887 rv = VNET_API_ERROR_UNIMPLEMENTED;
5890 BAD_SW_IF_INDEX_LABEL;
5892 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5895 static void vl_api_ipsec_spd_add_del_entry_t_handler
5896 (vl_api_ipsec_spd_add_del_entry_t * mp)
5898 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5899 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
5905 memset (&p, 0, sizeof (p));
5907 p.id = ntohl (mp->spd_id);
5908 p.priority = ntohl (mp->priority);
5909 p.is_outbound = mp->is_outbound;
5910 p.is_ipv6 = mp->is_ipv6;
5912 if (mp->is_ipv6 || mp->is_ip_any)
5914 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
5915 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
5916 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
5917 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
5921 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5922 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5923 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
5924 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5926 p.protocol = mp->protocol;
5927 p.rport.start = ntohs (mp->remote_port_start);
5928 p.rport.stop = ntohs (mp->remote_port_stop);
5929 p.lport.start = ntohs (mp->local_port_start);
5930 p.lport.stop = ntohs (mp->local_port_stop);
5931 /* policy action resolve unsupported */
5932 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
5934 clib_warning ("unsupported action: 'resolve'");
5935 rv = VNET_API_ERROR_UNIMPLEMENTED;
5938 p.policy = mp->policy;
5939 p.sa_id = ntohl (mp->sa_id);
5941 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5948 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5951 rv = VNET_API_ERROR_UNIMPLEMENTED;
5956 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5959 static void vl_api_ipsec_sad_add_del_entry_t_handler
5960 (vl_api_ipsec_sad_add_del_entry_t * mp)
5962 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5963 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
5968 memset (&sa, 0, sizeof (sa));
5970 sa.id = ntohl (mp->sad_id);
5971 sa.spi = ntohl (mp->spi);
5972 /* security protocol AH unsupported */
5973 if (mp->protocol == IPSEC_PROTOCOL_AH)
5975 clib_warning ("unsupported security protocol 'AH'");
5976 rv = VNET_API_ERROR_UNIMPLEMENTED;
5979 sa.protocol = mp->protocol;
5980 /* check for unsupported crypto-alg */
5981 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5982 mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
5984 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5985 mp->crypto_algorithm);
5986 rv = VNET_API_ERROR_UNIMPLEMENTED;
5989 sa.crypto_alg = mp->crypto_algorithm;
5990 sa.crypto_key_len = mp->crypto_key_length;
5991 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
5992 /* check for unsupported integ-alg */
5994 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_NONE ||
5996 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5998 mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
6000 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6001 mp->integrity_algorithm);
6002 rv = VNET_API_ERROR_UNIMPLEMENTED;
6007 /*Special cases, aes-gcm-128 encryption */
6008 if (mp->crypto_algorithm == IPSEC_CRYPTO_ALG_AES_GCM_128)
6010 if (mp->integrity_algorithm != IPSEC_INTEG_ALG_NONE
6011 && mp->integrity_algorithm != IPSEC_INTEG_ALG_AES_GCM_128)
6014 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
6015 rv = VNET_API_ERROR_UNIMPLEMENTED;
6018 else /*set integ-alg internally to aes-gcm-128 */
6019 mp->integrity_algorithm = IPSEC_INTEG_ALG_AES_GCM_128;
6021 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_AES_GCM_128)
6023 clib_warning ("unsupported integ-alg: aes-gcm-128");
6024 rv = VNET_API_ERROR_UNIMPLEMENTED;
6027 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_NONE)
6029 clib_warning ("unsupported integ-alg: none");
6030 rv = VNET_API_ERROR_UNIMPLEMENTED;
6035 sa.integ_alg = mp->integrity_algorithm;
6036 sa.integ_key_len = mp->integrity_key_length;
6037 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6038 sa.use_esn = mp->use_extended_sequence_number;
6039 sa.is_tunnel = mp->is_tunnel;
6040 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6041 if (sa.is_tunnel_ip6)
6043 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6044 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6048 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6049 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6052 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6054 rv = VNET_API_ERROR_UNIMPLEMENTED;
6059 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6063 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6065 vl_api_ikev2_profile_add_del_reply_t *rmp;
6069 vlib_main_t *vm = vlib_get_main ();
6070 clib_error_t *error;
6071 u8 *tmp = format (0, "%s", mp->name);
6072 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6075 rv = VNET_API_ERROR_UNSPECIFIED;
6077 rv = VNET_API_ERROR_UNIMPLEMENTED;
6080 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6084 vl_api_ikev2_profile_set_auth_t_handler
6085 (vl_api_ikev2_profile_set_auth_t * mp)
6087 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6091 vlib_main_t *vm = vlib_get_main ();
6092 clib_error_t *error;
6093 u8 *tmp = format (0, "%s", mp->name);
6094 u8 *data = vec_new (u8, mp->data_len);
6095 clib_memcpy (data, mp->data, mp->data_len);
6096 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6100 rv = VNET_API_ERROR_UNSPECIFIED;
6102 rv = VNET_API_ERROR_UNIMPLEMENTED;
6105 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6109 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6111 vl_api_ikev2_profile_add_del_reply_t *rmp;
6115 vlib_main_t *vm = vlib_get_main ();
6116 clib_error_t *error;
6117 u8 *tmp = format (0, "%s", mp->name);
6118 u8 *data = vec_new (u8, mp->data_len);
6119 clib_memcpy (data, mp->data, mp->data_len);
6120 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6124 rv = VNET_API_ERROR_UNSPECIFIED;
6126 rv = VNET_API_ERROR_UNIMPLEMENTED;
6129 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6133 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6135 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6139 vlib_main_t *vm = vlib_get_main ();
6140 clib_error_t *error;
6141 u8 *tmp = format (0, "%s", mp->name);
6142 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6143 mp->end_port, (ip4_address_t) mp->start_addr,
6144 (ip4_address_t) mp->end_addr, mp->is_local);
6147 rv = VNET_API_ERROR_UNSPECIFIED;
6149 rv = VNET_API_ERROR_UNIMPLEMENTED;
6152 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6156 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6158 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6162 vlib_main_t *vm = vlib_get_main ();
6163 clib_error_t *error;
6165 error = ikev2_set_local_key (vm, mp->key_file);
6167 rv = VNET_API_ERROR_UNSPECIFIED;
6169 rv = VNET_API_ERROR_UNIMPLEMENTED;
6172 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6176 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6178 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6179 vl_api_ipsec_sa_set_key_reply_t *rmp;
6183 sa.id = ntohl (mp->sa_id);
6184 sa.crypto_key_len = mp->crypto_key_length;
6185 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6186 sa.integ_key_len = mp->integrity_key_length;
6187 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6189 rv = ipsec_set_sa_key (vm, &sa);
6191 rv = VNET_API_ERROR_UNIMPLEMENTED;
6194 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6197 static void vl_api_cop_interface_enable_disable_t_handler
6198 (vl_api_cop_interface_enable_disable_t * mp)
6200 vl_api_cop_interface_enable_disable_reply_t *rmp;
6202 u32 sw_if_index = ntohl (mp->sw_if_index);
6205 VALIDATE_SW_IF_INDEX (mp);
6207 enable_disable = (int) mp->enable_disable;
6209 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6211 BAD_SW_IF_INDEX_LABEL;
6213 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6216 static void vl_api_cop_whitelist_enable_disable_t_handler
6217 (vl_api_cop_whitelist_enable_disable_t * mp)
6219 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6220 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6221 u32 sw_if_index = ntohl (mp->sw_if_index);
6224 VALIDATE_SW_IF_INDEX (mp);
6226 a->sw_if_index = sw_if_index;
6229 a->default_cop = mp->default_cop;
6230 a->fib_id = ntohl (mp->fib_id);
6232 rv = cop_whitelist_enable_disable (a);
6234 BAD_SW_IF_INDEX_LABEL;
6236 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6240 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6244 api_main_t *am = &api_main;
6245 vlib_main_t *vm = vlib_get_main ();
6247 vl_api_get_node_graph_reply_t *rmp;
6249 pthread_mutex_lock (&am->vlib_rp->mutex);
6250 oldheap = svm_push_data_heap (am->vlib_rp);
6253 * Keep the number of memcpy ops to a minimum (e.g. 1).
6255 vec_validate (vector, 16384);
6256 vec_reset_length (vector);
6259 vector = vlib_node_serialize (&vm->node_main, vector,
6260 (u32) ~ 0 /* all threads */ ,
6261 1 /* include nexts */ ,
6262 1 /* include stats */ );
6264 svm_pop_heap (oldheap);
6265 pthread_mutex_unlock (&am->vlib_rp->mutex);
6268 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6270 rmp->reply_in_shmem = (uword) vector;
6276 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
6279 vl_api_ioam_enable_reply_t *rmp;
6280 clib_error_t *error;
6282 /* Ignoring the profile id as currently a single profile
6284 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
6285 mp->seqno, mp->analyse);
6288 clib_error_report (error);
6289 rv = clib_error_get_code (error);
6292 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
6296 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
6299 vl_api_ioam_disable_reply_t *rmp;
6300 clib_error_t *error;
6302 error = clear_ioam_rewrite_fn ();
6305 clib_error_report (error);
6306 rv = clib_error_get_code (error);
6309 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
6313 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6315 vlib_main_t *vm = vlib_get_main ();
6316 vl_api_af_packet_create_reply_t *rmp;
6318 u8 *host_if_name = NULL;
6321 host_if_name = format (0, "%s", mp->host_if_name);
6322 vec_add1 (host_if_name, 0);
6324 rv = af_packet_create_if (vm, host_if_name,
6325 mp->use_random_hw_addr ? 0 : mp->hw_addr,
6328 vec_free (host_if_name);
6331 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6333 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
6339 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
6341 vlib_main_t *vm = vlib_get_main ();
6342 vl_api_af_packet_delete_reply_t *rmp;
6344 u8 *host_if_name = NULL;
6346 host_if_name = format (0, "%s", mp->host_if_name);
6347 vec_add1 (host_if_name, 0);
6349 rv = af_packet_delete_if (vm, host_if_name);
6351 vec_free (host_if_name);
6353 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
6357 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
6359 vlib_main_t *vm = vlib_get_main ();
6360 vl_api_policer_add_del_reply_t *rmp;
6363 sse2_qos_pol_cfg_params_st cfg;
6364 clib_error_t *error;
6367 name = format (0, "%s", mp->name);
6369 memset (&cfg, 0, sizeof (cfg));
6371 cfg.rnd_type = mp->round_type;
6372 cfg.rate_type = mp->rate_type;
6373 cfg.rb.kbps.cir_kbps = mp->cir;
6374 cfg.rb.kbps.eir_kbps = mp->eir;
6375 cfg.rb.kbps.cb_bytes = mp->cb;
6376 cfg.rb.kbps.eb_bytes = mp->eb;
6377 cfg.conform_action.action_type = mp->conform_action_type;
6378 cfg.conform_action.dscp = mp->conform_dscp;
6379 cfg.exceed_action.action_type = mp->exceed_action_type;
6380 cfg.exceed_action.dscp = mp->exceed_dscp;
6381 cfg.violate_action.action_type = mp->violate_action_type;
6382 cfg.violate_action.dscp = mp->violate_dscp;
6383 cfg.color_aware = mp->color_aware;
6385 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
6388 rv = VNET_API_ERROR_UNSPECIFIED;
6391 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6393 if (rv == 0 && mp->is_add)
6394 rmp->policer_index = ntohl(policer_index);
6396 rmp->policer_index = ~0;
6402 send_policer_details (u8 * name,
6403 sse2_qos_pol_cfg_params_st * config,
6404 policer_read_response_type_st * templ,
6405 unix_shared_memory_queue_t * q, u32 context)
6407 vl_api_policer_details_t *mp;
6409 mp = vl_msg_api_alloc (sizeof (*mp));
6410 memset (mp, 0, sizeof (*mp));
6411 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6412 mp->context = context;
6413 mp->cir = htonl (config->rb.kbps.cir_kbps);
6414 mp->eir = htonl (config->rb.kbps.eir_kbps);
6415 mp->cb = htonl (config->rb.kbps.cb_bytes);
6416 mp->eb = htonl (config->rb.kbps.eb_bytes);
6417 mp->rate_type = config->rate_type;
6418 mp->round_type = config->rnd_type;
6419 mp->type = config->rfc;
6420 mp->conform_action_type = config->conform_action.action_type;
6421 mp->conform_dscp = config->conform_action.dscp;
6422 mp->exceed_action_type = config->exceed_action.action_type;
6423 mp->exceed_dscp = config->exceed_action.dscp;
6424 mp->violate_action_type = config->violate_action.action_type;
6425 mp->violate_dscp = config->violate_action.dscp;
6426 mp->single_rate = templ->single_rate ? 1 : 0;
6427 mp->color_aware = templ->color_aware ? 1 : 0;
6428 mp->scale = htonl (templ->scale);
6429 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
6430 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
6431 mp->current_limit = htonl (templ->current_limit);
6432 mp->current_bucket = htonl (templ->current_bucket);
6433 mp->extended_limit = htonl (templ->extended_limit);
6434 mp->extended_bucket = htonl (templ->extended_bucket);
6435 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
6437 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
6439 vl_msg_api_send_shmem (q, (u8 *) & mp);
6443 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
6445 unix_shared_memory_queue_t *q;
6446 vnet_policer_main_t *pm = &vnet_policer_main;
6452 sse2_qos_pol_cfg_params_st *config;
6453 policer_read_response_type_st *templ;
6455 q = vl_api_client_index_to_input_queue (mp->client_index);
6459 if (mp->match_name_valid)
6461 match_name = format (0, "%s%c", mp->match_name, 0);
6464 if (mp->match_name_valid)
6466 p = hash_get_mem (pm->policer_config_by_name, match_name);
6470 config = pool_elt_at_index (pm->configs, pool_index);
6471 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6472 send_policer_details (match_name, config, templ, q, mp->context);
6478 hash_foreach_pair (hp, pm->policer_config_by_name,
6480 name = (u8 *) hp->key;
6481 pool_index = hp->value[0];
6482 config = pool_elt_at_index (pm->configs, pool_index);
6483 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6484 send_policer_details(name, config, templ, q, mp->context);
6491 vl_api_policer_classify_set_interface_t_handler
6492 (vl_api_policer_classify_set_interface_t * mp)
6494 vlib_main_t *vm = vlib_get_main ();
6495 vl_api_policer_classify_set_interface_reply_t *rmp;
6497 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6499 ip4_table_index = ntohl (mp->ip4_table_index);
6500 ip6_table_index = ntohl (mp->ip6_table_index);
6501 l2_table_index = ntohl (mp->l2_table_index);
6502 sw_if_index = ntohl (mp->sw_if_index);
6504 VALIDATE_SW_IF_INDEX (mp);
6506 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
6507 ip6_table_index, l2_table_index,
6510 BAD_SW_IF_INDEX_LABEL;
6512 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
6516 send_policer_classify_details (u32 sw_if_index,
6518 unix_shared_memory_queue_t * q, u32 context)
6520 vl_api_policer_classify_details_t *mp;
6522 mp = vl_msg_api_alloc (sizeof (*mp));
6523 memset (mp, 0, sizeof (*mp));
6524 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
6525 mp->context = context;
6526 mp->sw_if_index = htonl (sw_if_index);
6527 mp->table_index = htonl (table_index);
6529 vl_msg_api_send_shmem (q, (u8 *) & mp);
6533 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
6535 unix_shared_memory_queue_t *q;
6536 policer_classify_main_t *pcm = &policer_classify_main;
6540 q = vl_api_client_index_to_input_queue (mp->client_index);
6544 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6546 if (vec_len (vec_tbl))
6548 for (i = 0; i < vec_len (vec_tbl); i++)
6550 if (vec_elt (vec_tbl, i) == ~0)
6553 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
6560 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
6562 vlib_main_t *vm = vlib_get_main ();
6563 vl_api_netmap_create_reply_t *rmp;
6567 if_name = format (0, "%s", mp->netmap_if_name);
6568 vec_add1 (if_name, 0);
6571 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6572 mp->is_pipe, mp->is_master, 0);
6576 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
6580 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
6582 vlib_main_t *vm = vlib_get_main ();
6583 vl_api_netmap_delete_reply_t *rmp;
6587 if_name = format (0, "%s", mp->netmap_if_name);
6588 vec_add1 (if_name, 0);
6590 rv = netmap_delete_if (vm, if_name);
6594 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
6598 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_fib_details_t * mp)
6600 clib_warning ("BUG");
6603 typedef struct mpls_tunnel_send_walk_ctx_t_
6605 unix_shared_memory_queue_t *q;
6608 } mpls_tunnel_send_walk_ctx_t;
6611 send_mpls_tunnel_entry (u32 mti, void *arg)
6613 mpls_tunnel_send_walk_ctx_t *ctx;
6614 vl_api_mpls_tunnel_details_t *mp;
6615 const mpls_tunnel_t *mt;
6620 if (~0 != ctx->index && mti != ctx->index)
6623 mt = mpls_tunnel_get (mti);
6624 nlabels = vec_len (mt->mt_label_stack);
6626 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
6627 memset (mp, 0, sizeof (*mp));
6628 mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
6629 mp->context = ctx->context;
6631 mp->tunnel_index = ntohl (mti);
6632 memcpy (mp->mt_next_hop_out_labels,
6633 mt->mt_label_stack, nlabels * sizeof (u32));
6637 vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
6641 vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
6643 unix_shared_memory_queue_t *q;
6645 q = vl_api_client_index_to_input_queue (mp->client_index);
6649 mpls_tunnel_send_walk_ctx_t ctx = {
6651 .index = ntohl (mp->tunnel_index),
6652 .context = mp->context,
6654 mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
6658 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
6660 clib_warning ("BUG");
6664 vl_api_mpls_fib_details_t_endian (vl_api_mpls_fib_details_t * mp)
6666 clib_warning ("BUG");
6670 vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp)
6672 clib_warning ("BUG");
6677 copy_fib_next_hop (fib_route_path_encode_t * api_rpath,
6678 vl_api_fib_path_t * fp)
6682 if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4)
6683 fp->afi = IP46_TYPE_IP4;
6684 else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6)
6685 fp->afi = IP46_TYPE_IP6;
6688 is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr);
6690 fp->afi = IP46_TYPE_IP4;
6692 fp->afi = IP46_TYPE_IP6;
6694 if (fp->afi == IP46_TYPE_IP4)
6695 memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip4,
6696 sizeof (api_rpath->rpath.frp_addr.ip4));
6698 memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip6,
6699 sizeof (api_rpath->rpath.frp_addr.ip6));
6703 send_mpls_fib_details (vpe_api_main_t * am,
6704 unix_shared_memory_queue_t * q,
6705 u32 table_id, u32 label, u32 eos,
6706 fib_route_path_encode_t * api_rpaths, u32 context)
6708 vl_api_mpls_fib_details_t *mp;
6709 fib_route_path_encode_t *api_rpath;
6710 vl_api_fib_path_t *fp;
6713 path_count = vec_len (api_rpaths);
6714 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
6717 memset (mp, 0, sizeof (*mp));
6718 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
6719 mp->context = context;
6721 mp->table_id = htonl (table_id);
6723 mp->label = htonl (label);
6725 mp->count = htonl (path_count);
6727 vec_foreach (api_rpath, api_rpaths)
6729 memset (fp, 0, sizeof (*fp));
6730 fp->weight = htonl (api_rpath->rpath.frp_weight);
6731 fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
6732 copy_fib_next_hop (api_rpath, fp);
6736 vl_msg_api_send_shmem (q, (u8 *) & mp);
6740 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
6742 vpe_api_main_t *am = &vpe_api_main;
6743 unix_shared_memory_queue_t *q;
6744 mpls_main_t *mm = &mpls_main;
6745 fib_table_t *fib_table;
6746 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
6750 fib_route_path_encode_t *api_rpaths;
6752 q = vl_api_client_index_to_input_queue (mp->client_index);
6757 pool_foreach (fib_table, mm->fibs,
6759 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
6761 vec_add1(lfeis, lfei);
6764 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
6766 vec_foreach(lfeip, lfeis)
6768 fib_entry_get_prefix(*lfeip, &pfx);
6769 fib_index = fib_entry_get_fib_index(*lfeip);
6770 fib_table = fib_table_get(fib_index, pfx.fp_proto);
6772 fib_entry_encode(*lfeip, &api_rpaths);
6773 send_mpls_fib_details (am, q,
6774 fib_table->ft_table_id,
6779 vec_free(api_rpaths);
6786 vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
6788 clib_warning ("BUG");
6792 vl_api_ip_fib_details_t_endian (vl_api_ip_fib_details_t * mp)
6794 clib_warning ("BUG");
6798 vl_api_ip_fib_details_t_print (vl_api_ip_fib_details_t * mp)
6800 clib_warning ("BUG");
6804 send_ip_fib_details (vpe_api_main_t * am,
6805 unix_shared_memory_queue_t * q,
6806 u32 table_id, fib_prefix_t *pfx,
6807 fib_route_path_encode_t *api_rpaths, u32 context)
6809 vl_api_ip_fib_details_t *mp;
6810 fib_route_path_encode_t *api_rpath;
6811 vl_api_fib_path_t *fp;
6814 path_count = vec_len(api_rpaths);
6815 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
6818 memset (mp, 0, sizeof (*mp));
6819 mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS);
6820 mp->context = context;
6822 mp->table_id = htonl (table_id);
6823 mp->address_length = pfx->fp_len;
6824 memcpy(mp->address, &pfx->fp_addr.ip4, sizeof(pfx->fp_addr.ip4));
6826 mp->count = htonl (path_count);
6828 vec_foreach(api_rpath, api_rpaths)
6830 memset (fp, 0, sizeof (*fp));
6831 switch (api_rpath->dpo.dpoi_type)
6834 fp->is_local = true;
6840 switch (api_rpath->dpo.dpoi_index)
6842 case IP_NULL_ACTION_NONE:
6845 case IP_NULL_ACTION_SEND_ICMP_UNREACH:
6846 fp->is_unreach = true;
6848 case IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
6849 fp->is_prohibit = true;
6858 fp->weight = htonl(api_rpath->rpath.frp_weight);
6859 fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
6860 copy_fib_next_hop (api_rpath, fp);
6864 vl_msg_api_send_shmem (q, (u8 *) & mp);
6868 vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp)
6870 vpe_api_main_t *am = &vpe_api_main;
6871 unix_shared_memory_queue_t *q;
6872 ip4_main_t *im = &ip4_main;
6873 fib_table_t *fib_table;
6874 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
6878 fib_route_path_encode_t *api_rpaths;
6881 q = vl_api_client_index_to_input_queue (mp->client_index);
6886 pool_foreach (fib_table, im->fibs,
6888 for (i = 0; i < ARRAY_LEN (fib_table->v4.fib_entry_by_dst_address); i++)
6890 hash_foreach(key, lfei, fib_table->v4.fib_entry_by_dst_address[i],
6892 vec_add1(lfeis, lfei);
6897 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
6899 vec_foreach(lfeip, lfeis)
6901 fib_entry_get_prefix(*lfeip, &pfx);
6902 fib_index = fib_entry_get_fib_index(*lfeip);
6903 fib_table = fib_table_get(fib_index, pfx.fp_proto);
6905 fib_entry_encode(*lfeip, &api_rpaths);
6906 send_ip_fib_details (am, q,
6907 fib_table->ft_table_id,
6911 vec_free(api_rpaths);
6918 vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
6920 clib_warning ("BUG");
6924 vl_api_ip6_fib_details_t_endian (vl_api_ip6_fib_details_t * mp)
6926 clib_warning ("BUG");
6930 vl_api_ip6_fib_details_t_print (vl_api_ip6_fib_details_t * mp)
6932 clib_warning ("BUG");
6936 send_ip6_fib_details (vpe_api_main_t * am,
6937 unix_shared_memory_queue_t * q,
6938 u32 table_id, fib_prefix_t *pfx,
6939 fib_route_path_encode_t *api_rpaths, u32 context)
6941 vl_api_ip6_fib_details_t *mp;
6942 fib_route_path_encode_t *api_rpath;
6943 vl_api_fib_path_t *fp;
6946 path_count = vec_len(api_rpaths);
6947 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
6950 memset (mp, 0, sizeof (*mp));
6951 mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS);
6952 mp->context = context;
6954 mp->table_id = htonl (table_id);
6955 mp->address_length = pfx->fp_len;
6956 memcpy(mp->address, &pfx->fp_addr.ip6, sizeof(pfx->fp_addr.ip6));
6958 mp->count = htonl (path_count);
6960 vec_foreach(api_rpath, api_rpaths)
6962 memset (fp, 0, sizeof (*fp));
6963 switch (api_rpath->dpo.dpoi_type)
6966 fp->is_local = true;
6972 switch (api_rpath->dpo.dpoi_index)
6974 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_NONE:
6977 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_UNREACH:
6978 fp->is_unreach = true;
6980 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
6981 fp->is_prohibit = true;
6990 fp->weight = htonl(api_rpath->rpath.frp_weight);
6991 fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
6992 copy_fib_next_hop (api_rpath, fp);
6996 vl_msg_api_send_shmem (q, (u8 *) & mp);
6999 typedef struct apt_ip6_fib_show_ctx_t_ {
7001 fib_node_index_t *entries;
7002 } api_ip6_fib_show_ctx_t;
7005 api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp,
7008 api_ip6_fib_show_ctx_t *ctx = arg;
7010 if ((kvp->key[2] >> 32) == ctx->fib_index)
7012 vec_add1(ctx->entries, kvp->value);
7017 api_ip6_fib_table_get_all (unix_shared_memory_queue_t *q,
7018 vl_api_ip6_fib_dump_t *mp,
7019 fib_table_t *fib_table)
7021 vpe_api_main_t *am = &vpe_api_main;
7022 ip6_main_t *im6 = &ip6_main;
7023 ip6_fib_t *fib = &fib_table->v6;
7024 fib_node_index_t *fib_entry_index;
7025 api_ip6_fib_show_ctx_t ctx = {
7026 .fib_index = fib->index,
7029 fib_route_path_encode_t *api_rpaths;
7032 BV(clib_bihash_foreach_key_value_pair)
7033 ((BVT(clib_bihash) *) &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
7034 api_ip6_fib_table_put_entries,
7037 vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort);
7039 vec_foreach(fib_entry_index, ctx.entries)
7041 fib_entry_get_prefix(*fib_entry_index, &pfx);
7043 fib_entry_encode(*fib_entry_index, &api_rpaths);
7044 send_ip6_fib_details (am, q,
7045 fib_table->ft_table_id,
7049 vec_free(api_rpaths);
7052 vec_free(ctx.entries);
7056 vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp)
7058 unix_shared_memory_queue_t *q;
7059 ip6_main_t *im6 = &ip6_main;
7060 fib_table_t *fib_table;
7062 q = vl_api_client_index_to_input_queue (mp->client_index);
7067 pool_foreach (fib_table, im6->fibs,
7069 api_ip6_fib_table_get_all(q, mp, fib_table);
7074 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7076 unix_shared_memory_queue_t *q;
7078 q = vl_api_client_index_to_input_queue (mp->client_index);
7082 vnet_classify_main_t *cm = &vnet_classify_main;
7083 vnet_classify_table_t *t;
7088 pool_foreach (t, cm->tables,
7090 vec_add1 (table_ids, ntohl(t - cm->tables));
7093 count = vec_len (table_ids);
7095 vl_api_classify_table_ids_reply_t *rmp;
7096 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7097 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7098 rmp->context = mp->context;
7099 rmp->count = ntohl (count);
7100 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7103 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7105 vec_free (table_ids);
7109 vl_api_classify_table_by_interface_t_handler
7110 (vl_api_classify_table_by_interface_t * mp)
7112 vl_api_classify_table_by_interface_reply_t *rmp;
7115 u32 sw_if_index = ntohl (mp->sw_if_index);
7118 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7121 VALIDATE_SW_IF_INDEX (mp);
7123 input_acl_main_t *am = &input_acl_main;
7128 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7130 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7131 if (vec_len (vec_tbl))
7133 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7135 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7139 acl[type] = vec_elt (vec_tbl, if_idx);
7144 BAD_SW_IF_INDEX_LABEL;
7147 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7149 rmp->sw_if_index = ntohl(sw_if_index);
7150 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7151 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7152 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7159 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7161 unix_shared_memory_queue_t *q;
7163 q = vl_api_client_index_to_input_queue (mp->client_index);
7167 vl_api_classify_table_info_reply_t *rmp = 0;
7169 vnet_classify_main_t *cm = &vnet_classify_main;
7170 u32 table_id = ntohl (mp->table_id);
7171 vnet_classify_table_t *t;
7174 pool_foreach (t, cm->tables,
7176 if (table_id == t - cm->tables)
7178 rmp = vl_msg_api_alloc_as_if_client
7179 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7180 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7181 rmp->context = mp->context;
7182 rmp->table_id = ntohl(table_id);
7183 rmp->nbuckets = ntohl(t->nbuckets);
7184 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7185 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7186 rmp->active_sessions = ntohl(t->active_elements);
7187 rmp->next_table_index = ntohl(t->next_table_index);
7188 rmp->miss_next_index = ntohl(t->miss_next_index);
7189 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7190 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7199 rmp = vl_msg_api_alloc (sizeof (*rmp));
7200 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7201 rmp->context = mp->context;
7202 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7205 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7209 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7212 clib_warning ("BUG");
7216 send_classify_session_details (unix_shared_memory_queue_t * q,
7219 vnet_classify_entry_t * e, u32 context)
7221 vl_api_classify_session_details_t *rmp;
7223 rmp = vl_msg_api_alloc (sizeof (*rmp));
7224 memset (rmp, 0, sizeof (*rmp));
7225 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7226 rmp->context = context;
7227 rmp->table_id = ntohl (table_id);
7228 rmp->hit_next_index = ntohl (e->next_index);
7229 rmp->advance = ntohl (e->advance);
7230 rmp->opaque_index = ntohl (e->opaque_index);
7231 rmp->match_length = ntohl (match_length);
7232 clib_memcpy (rmp->match, e->key, match_length);
7234 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7238 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7240 vnet_classify_main_t *cm = &vnet_classify_main;
7241 unix_shared_memory_queue_t *q;
7243 u32 table_id = ntohl (mp->table_id);
7244 vnet_classify_table_t *t;
7246 q = vl_api_client_index_to_input_queue (mp->client_index);
7251 pool_foreach (t, cm->tables,
7253 if (table_id == t - cm->tables)
7255 vnet_classify_bucket_t * b;
7256 vnet_classify_entry_t * v, * save_v;
7259 for (i = 0; i < t->nbuckets; i++)
7261 b = &t->buckets [i];
7265 save_v = vnet_classify_get_entry (t, b->offset);
7266 for (j = 0; j < (1<<b->log2_pages); j++)
7268 for (k = 0; k < t->entries_per_page; k++)
7270 v = vnet_classify_entry_at_index
7271 (t, save_v, j*t->entries_per_page + k);
7272 if (vnet_classify_entry_is_free (v))
7275 send_classify_session_details
7276 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7288 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7290 vlib_main_t *vm = vlib_get_main ();
7291 flow_report_main_t *frm = &flow_report_main;
7292 vl_api_set_ipfix_exporter_reply_t *rmp;
7293 ip4_address_t collector, src;
7294 u16 collector_port = UDP_DST_PORT_ipfix;
7296 u32 template_interval;
7302 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7303 collector_port = ntohs (mp->collector_port);
7304 if (collector_port == (u16) ~ 0)
7305 collector_port = UDP_DST_PORT_ipfix;
7306 memcpy (src.data, mp->src_address, sizeof (src.data));
7307 fib_id = ntohl (mp->vrf_id);
7309 ip4_main_t *im = &ip4_main;
7316 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7319 rv = VNET_API_ERROR_NO_SUCH_FIB;
7325 path_mtu = ntohl (mp->path_mtu);
7327 path_mtu = 512; // RFC 7011 section 10.3.3.
7328 template_interval = ntohl (mp->template_interval);
7329 if (template_interval == ~0)
7330 template_interval = 20;
7331 udp_checksum = mp->udp_checksum;
7333 if (collector.as_u32 == 0)
7335 rv = VNET_API_ERROR_INVALID_VALUE;
7339 if (src.as_u32 == 0)
7341 rv = VNET_API_ERROR_INVALID_VALUE;
7345 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7347 rv = VNET_API_ERROR_INVALID_VALUE;
7353 rv = VNET_API_ERROR_INVALID_VALUE;
7357 /* Reset report streams if we are reconfiguring IP addresses */
7358 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7359 frm->src_address.as_u32 != src.as_u32 ||
7360 frm->collector_port != collector_port)
7361 vnet_flow_reports_reset (frm);
7363 frm->ipfix_collector.as_u32 = collector.as_u32;
7364 frm->collector_port = collector_port;
7365 frm->src_address.as_u32 = src.as_u32;
7366 frm->fib_index = fib_index;
7367 frm->path_mtu = path_mtu;
7368 frm->template_interval = template_interval;
7369 frm->udp_checksum = udp_checksum;
7371 /* Turn on the flow reporting process */
7372 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7375 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
7379 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
7381 flow_report_main_t *frm = &flow_report_main;
7382 unix_shared_memory_queue_t *q;
7383 vl_api_ipfix_exporter_details_t *rmp;
7384 ip4_main_t *im = &ip4_main;
7387 q = vl_api_client_index_to_input_queue (mp->client_index);
7391 rmp = vl_msg_api_alloc (sizeof (*rmp));
7392 memset (rmp, 0, sizeof (*rmp));
7393 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
7394 rmp->context = mp->context;
7395 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7396 sizeof (frm->ipfix_collector.data));
7397 rmp->collector_port = htons (frm->collector_port);
7398 memcpy (rmp->src_address, frm->src_address.data,
7399 sizeof (frm->src_address.data));
7400 if (frm->fib_index == ~0)
7403 vrf_id = im->fibs[frm->fib_index].ft_table_id;
7404 rmp->vrf_id = htonl (vrf_id);
7405 rmp->path_mtu = htonl (frm->path_mtu);
7406 rmp->template_interval = htonl (frm->template_interval);
7407 rmp->udp_checksum = (frm->udp_checksum != 0);
7409 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7413 vl_api_set_ipfix_classify_stream_t_handler
7414 (vl_api_set_ipfix_classify_stream_t * mp)
7416 vl_api_set_ipfix_classify_stream_reply_t *rmp;
7417 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7418 flow_report_main_t *frm = &flow_report_main;
7420 u32 src_port = UDP_DST_PORT_ipfix;
7423 domain_id = ntohl (mp->domain_id);
7424 src_port = ntohs (mp->src_port);
7426 if (fcm->src_port != 0 &&
7427 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
7429 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
7430 domain_id, (u16) src_port);
7434 fcm->domain_id = domain_id;
7435 fcm->src_port = (u16) src_port;
7437 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7441 vl_api_ipfix_classify_stream_dump_t_handler
7442 (vl_api_ipfix_classify_stream_dump_t * mp)
7444 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7445 unix_shared_memory_queue_t *q;
7446 vl_api_ipfix_classify_stream_details_t *rmp;
7448 q = vl_api_client_index_to_input_queue (mp->client_index);
7452 rmp = vl_msg_api_alloc (sizeof (*rmp));
7453 memset (rmp, 0, sizeof (*rmp));
7454 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
7455 rmp->context = mp->context;
7456 rmp->domain_id = htonl (fcm->domain_id);
7457 rmp->src_port = htons (fcm->src_port);
7459 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7463 vl_api_ipfix_classify_table_add_del_t_handler
7464 (vl_api_ipfix_classify_table_add_del_t * mp)
7466 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
7467 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7468 flow_report_main_t *frm = &flow_report_main;
7469 vnet_flow_report_add_del_args_t args;
7470 ipfix_classify_table_t *table;
7472 u32 classify_table_index;
7474 u8 transport_protocol;
7477 classify_table_index = ntohl (mp->table_id);
7478 ip_version = mp->ip_version;
7479 transport_protocol = mp->transport_protocol;
7480 is_add = mp->is_add;
7482 if (fcm->src_port == 0)
7484 /* call set_ipfix_classify_stream first */
7485 rv = VNET_API_ERROR_UNSPECIFIED;
7489 memset (&args, 0, sizeof (args));
7493 for (i = 0; i < vec_len (fcm->tables); i++)
7494 if (ipfix_classify_table_index_valid (i))
7495 if (fcm->tables[i].classify_table_index == classify_table_index)
7497 table = &fcm->tables[i];
7505 rv = VNET_API_ERROR_VALUE_EXIST;
7508 table = ipfix_classify_add_table ();
7509 table->classify_table_index = classify_table_index;
7515 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
7520 table->ip_version = ip_version;
7521 table->transport_protocol = transport_protocol;
7523 args.opaque.as_uword = table - fcm->tables;
7524 args.rewrite_callback = ipfix_classify_template_rewrite;
7525 args.flow_data_callback = ipfix_classify_send_flows;
7526 args.is_add = is_add;
7527 args.domain_id = fcm->domain_id;
7528 args.src_port = fcm->src_port;
7530 rv = vnet_flow_report_add_del (frm, &args);
7532 /* If deleting, or add failed */
7533 if (is_add == 0 || (rv && is_add))
7534 ipfix_classify_delete_table (table - fcm->tables);
7537 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7541 send_ipfix_classify_table_details (u32 table_index,
7542 unix_shared_memory_queue_t * q,
7545 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7546 vl_api_ipfix_classify_table_details_t *mp;
7548 ipfix_classify_table_t *table = &fcm->tables[table_index];
7550 mp = vl_msg_api_alloc (sizeof (*mp));
7551 memset (mp, 0, sizeof (*mp));
7552 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
7553 mp->context = context;
7554 mp->table_id = htonl (table->classify_table_index);
7555 mp->ip_version = table->ip_version;
7556 mp->transport_protocol = table->transport_protocol;
7558 vl_msg_api_send_shmem (q, (u8 *) & mp);
7562 vl_api_ipfix_classify_table_dump_t_handler
7563 (vl_api_ipfix_classify_table_dump_t * mp)
7565 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7566 unix_shared_memory_queue_t *q;
7569 q = vl_api_client_index_to_input_queue (mp->client_index);
7573 for (i = 0; i < vec_len (fcm->tables); i++)
7574 if (ipfix_classify_table_index_valid (i))
7575 send_ipfix_classify_table_details (i, q, mp->context);
7579 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
7581 vl_api_pg_create_interface_reply_t *rmp;
7584 pg_main_t *pg = &pg_main;
7585 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
7586 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
7589 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7591 rmp->sw_if_index = ntohl(pi->sw_if_index);
7597 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
7599 vl_api_pg_capture_reply_t *rmp;
7602 vnet_main_t *vnm = vnet_get_main ();
7603 vnet_interface_main_t *im = &vnm->interface_main;
7604 vnet_hw_interface_t *hi = 0;
7606 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
7607 u32 hw_if_index = ~0;
7608 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
7611 vec_free (intf_name);
7613 if (hw_if_index != ~0)
7615 pg_capture_args_t _a, *a = &_a;
7617 u32 len = ntohl (mp->pcap_name_length);
7618 u8 *pcap_file_name = vec_new (u8, len);
7619 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
7621 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7622 a->hw_if_index = hw_if_index;
7623 a->dev_instance = hi->dev_instance;
7624 a->is_enabled = mp->is_enabled;
7625 a->pcap_file_name = pcap_file_name;
7626 a->count = ntohl (mp->count);
7628 clib_error_t *e = pg_capture (a);
7631 clib_error_report (e);
7632 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7635 vec_free (pcap_file_name);
7637 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
7641 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
7643 vl_api_pg_enable_disable_reply_t *rmp;
7646 pg_main_t *pg = &pg_main;
7647 u32 stream_index = ~0;
7649 int is_enable = mp->is_enabled != 0;
7650 u32 len = ntohl (mp->stream_name_length) - 1;
7654 u8 *stream_name = vec_new (u8, len);
7655 clib_memcpy (stream_name, mp->stream_name, len);
7656 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
7659 vec_free (stream_name);
7662 pg_enable_disable (stream_index, is_enable);
7664 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
7668 vl_api_ip_source_and_port_range_check_add_del_t_handler
7669 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
7671 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
7674 u8 is_ipv6 = mp->is_ipv6;
7675 u8 is_add = mp->is_add;
7676 u8 mask_length = mp->mask_length;
7677 ip4_address_t ip4_addr;
7678 ip6_address_t ip6_addr;
7680 u16 *high_ports = 0;
7682 u16 tmp_low, tmp_high;
7686 // Validate port range
7687 num_ranges = mp->number_of_ranges;
7688 if (num_ranges > 32)
7689 { // This is size of array in VPE.API
7690 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
7694 vec_reset_length (low_ports);
7695 vec_reset_length (high_ports);
7697 for (i = 0; i < num_ranges; i++)
7699 tmp_low = mp->low_ports[i];
7700 tmp_high = mp->high_ports[i];
7701 // If tmp_low <= tmp_high then only need to check tmp_low = 0
7702 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
7703 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
7705 rv = VNET_API_ERROR_INVALID_VALUE;
7708 vec_add1 (low_ports, tmp_low);
7709 vec_add1 (high_ports, tmp_high + 1);
7712 // Validate mask_length
7713 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
7715 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
7719 vrf_id = ntohl (mp->vrf_id);
7723 rv = VNET_API_ERROR_INVALID_VALUE;
7730 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
7731 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
7735 high_ports, is_add);
7739 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
7740 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
7744 high_ports, is_add);
7748 vec_free (low_ports);
7749 vec_free (high_ports);
7750 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
7754 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
7755 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
7757 vlib_main_t *vm = vlib_get_main ();
7758 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
7759 ip4_main_t *im = &ip4_main;
7762 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7763 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7767 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
7768 ntohl (mp->tcp_out_vrf_id);
7769 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
7770 ntohl (mp->udp_out_vrf_id);
7771 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
7772 ntohl (mp->tcp_in_vrf_id);
7773 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
7774 ntohl (mp->udp_in_vrf_id);
7777 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
7779 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
7781 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
7785 rv = VNET_API_ERROR_INVALID_VALUE;
7789 fib_index[i] = p[0];
7794 sw_if_index = ntohl (mp->sw_if_index);
7796 VALIDATE_SW_IF_INDEX (mp);
7799 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
7802 BAD_SW_IF_INDEX_LABEL;
7805 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
7809 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
7812 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
7814 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
7815 u32 sw_if_index = ~0;
7817 /* Check src & dst are different */
7818 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
7820 rv = VNET_API_ERROR_SAME_SRC_DST;
7824 memset (a, 0, sizeof (*a));
7826 /* ip addresses sent in network byte order */
7827 clib_memcpy (&(a->src), mp->src_address, 4);
7828 clib_memcpy (&(a->dst), mp->dst_address, 4);
7829 a->is_add = mp->is_add;
7830 a->lsa = ntohl (mp->local_sa_id);
7831 a->rsa = ntohl (mp->remote_sa_id);
7833 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
7837 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
7839 rmp->sw_if_index = ntohl (sw_if_index);
7844 static void send_ipsec_gre_tunnel_details
7845 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
7847 vl_api_ipsec_gre_tunnel_details_t *rmp;
7849 rmp = vl_msg_api_alloc (sizeof (*rmp));
7850 memset (rmp, 0, sizeof (*rmp));
7851 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
7852 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
7853 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
7854 rmp->sw_if_index = htonl (t->sw_if_index);
7855 rmp->local_sa_id = htonl (t->local_sa_id);
7856 rmp->remote_sa_id = htonl (t->remote_sa_id);
7857 rmp->context = context;
7859 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7862 static void vl_api_ipsec_gre_tunnel_dump_t_handler
7863 (vl_api_ipsec_gre_tunnel_dump_t * mp)
7865 unix_shared_memory_queue_t *q;
7866 ipsec_gre_main_t *igm = &ipsec_gre_main;
7867 ipsec_gre_tunnel_t *t;
7870 q = vl_api_client_index_to_input_queue (mp->client_index);
7876 sw_if_index = ntohl (mp->sw_if_index);
7878 if (~0 == sw_if_index)
7881 pool_foreach (t, igm->tunnels,
7883 send_ipsec_gre_tunnel_details(t, q, mp->context);
7889 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
7890 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
7894 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
7895 send_ipsec_gre_tunnel_details (t, q, mp->context);
7900 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
7902 vl_api_delete_subif_reply_t *rmp;
7905 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
7907 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
7911 vl_api_l2_interface_pbb_tag_rewrite_t_handler
7912 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
7914 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
7915 vnet_main_t *vnm = vnet_get_main ();
7916 vlib_main_t *vm = vlib_get_main ();
7920 VALIDATE_SW_IF_INDEX (mp);
7922 vtr_op = ntohl (mp->vtr_op);
7926 case L2_VTR_DISABLED:
7929 case L2_VTR_TRANSLATE_2_1:
7933 rv = VNET_API_ERROR_INVALID_VALUE;
7934 goto bad_sw_if_index;
7937 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
7938 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
7939 ntohl (mp->i_sid), ntohs (mp->outer_tag));
7941 BAD_SW_IF_INDEX_LABEL;
7943 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
7947 vl_api_punt_t_handler (vl_api_punt_t * mp)
7949 vl_api_punt_reply_t *rmp;
7950 vlib_main_t *vm = vlib_get_main ();
7952 clib_error_t *error;
7954 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
7955 ntohs (mp->l4_port), mp->is_add);
7959 clib_error_report (error);
7962 REPLY_MACRO (VL_API_PUNT_REPLY);
7966 vl_api_flow_classify_set_interface_t_handler
7967 (vl_api_flow_classify_set_interface_t * mp)
7969 vlib_main_t *vm = vlib_get_main ();
7970 vl_api_flow_classify_set_interface_reply_t *rmp;
7972 u32 sw_if_index, ip4_table_index, ip6_table_index;
7974 ip4_table_index = ntohl (mp->ip4_table_index);
7975 ip6_table_index = ntohl (mp->ip6_table_index);
7976 sw_if_index = ntohl (mp->sw_if_index);
7978 VALIDATE_SW_IF_INDEX (mp);
7980 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
7981 ip6_table_index, mp->is_add);
7983 BAD_SW_IF_INDEX_LABEL;
7985 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
7989 send_flow_classify_details (u32 sw_if_index,
7991 unix_shared_memory_queue_t * q, u32 context)
7993 vl_api_flow_classify_details_t *mp;
7995 mp = vl_msg_api_alloc (sizeof (*mp));
7996 memset (mp, 0, sizeof (*mp));
7997 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
7998 mp->context = context;
7999 mp->sw_if_index = htonl (sw_if_index);
8000 mp->table_index = htonl (table_index);
8002 vl_msg_api_send_shmem (q, (u8 *) & mp);
8006 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8008 unix_shared_memory_queue_t *q;
8009 flow_classify_main_t *pcm = &flow_classify_main;
8013 q = vl_api_client_index_to_input_queue (mp->client_index);
8017 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8019 if (vec_len (vec_tbl))
8021 for (i = 0; i < vec_len (vec_tbl); i++)
8023 if (vec_elt (vec_tbl, i) == ~0)
8026 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8033 send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
8036 vl_api_ipsec_spd_details_t *mp;
8038 mp = vl_msg_api_alloc (sizeof (*mp));
8039 memset (mp, 0, sizeof (*mp));
8040 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
8041 mp->context = context;
8043 mp->spd_id = htonl (p->id);
8044 mp->priority = htonl (p->priority);
8045 mp->is_outbound = p->is_outbound;
8046 mp->is_ipv6 = p->is_ipv6;
8049 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
8050 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
8051 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
8052 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
8056 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
8057 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
8058 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
8059 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
8061 mp->local_start_port = htons (p->lport.start);
8062 mp->local_stop_port = htons (p->lport.stop);
8063 mp->remote_start_port = htons (p->rport.start);
8064 mp->remote_stop_port = htons (p->rport.stop);
8065 mp->protocol = p->protocol;
8066 mp->policy = p->policy;
8067 mp->sa_id = htonl (p->sa_id);
8068 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
8069 mp->packets = clib_host_to_net_u64 (p->counter.packets);
8071 vl_msg_api_send_shmem (q, (u8 *) & mp);
8075 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
8077 unix_shared_memory_queue_t *q;
8078 ipsec_main_t *im = &ipsec_main;
8079 ipsec_policy_t *policy;
8084 q = vl_api_client_index_to_input_queue (mp->client_index);
8088 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
8093 spd = pool_elt_at_index (im->spds, spd_index);
8096 pool_foreach (policy, spd->policies,
8098 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
8099 send_ipsec_spd_details (policy, q,
8104 clib_warning ("unimplemented");
8109 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
8111 vl_api_feature_enable_disable_reply_t *rmp;
8113 u8 *arc_name, *feature_name;
8115 VALIDATE_SW_IF_INDEX (mp);
8117 arc_name = format (0, "%s%c", mp->arc_name, 0);
8118 feature_name = format (0, "%s%c", mp->feature_name, 0);
8120 vnet_feature_registration_t *reg;
8122 vnet_get_feature_reg ((const char *) arc_name,
8123 (const char *) feature_name);
8125 rv = VNET_API_ERROR_INVALID_VALUE;
8129 clib_error_t *error = 0;
8131 sw_if_index = ntohl (mp->sw_if_index);
8132 if (reg->enable_disable_cb)
8133 error = reg->enable_disable_cb (sw_if_index, mp->enable);
8135 vnet_feature_enable_disable ((const char *) arc_name,
8136 (const char *) feature_name,
8137 sw_if_index, mp->enable, 0, 0);
8140 clib_error_report (error);
8141 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
8145 vec_free (feature_name);
8146 vec_free (arc_name);
8148 BAD_SW_IF_INDEX_LABEL;
8150 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
8154 send_ip_neighbor_details (u8 is_ipv6,
8158 unix_shared_memory_queue_t * q, u32 context)
8160 vl_api_ip_neighbor_details_t *mp;
8162 mp = vl_msg_api_alloc (sizeof (*mp));
8163 memset (mp, 0, sizeof (*mp));
8164 mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS);
8165 mp->context = context;
8166 mp->is_ipv6 = is_ipv6;
8167 mp->is_static = is_static;
8168 memcpy (mp->mac_address, mac_address, 6);
8169 memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
8171 vl_msg_api_send_shmem (q, (u8 *) & mp);
8175 vl_api_ip_neighbor_details_t_handler (vl_api_ip_neighbor_details_t * mp)
8177 clib_warning ("BUG");
8181 vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp)
8183 unix_shared_memory_queue_t *q;
8185 q = vl_api_client_index_to_input_queue (mp->client_index);
8189 u32 sw_if_index = ntohl (mp->sw_if_index);
8193 ip6_neighbor_t *n, *ns;
8195 ns = ip6_neighbors_entries (sw_if_index);
8199 send_ip_neighbor_details (mp->is_ipv6,
8200 ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0),
8201 (u8 *) n->link_layer_address,
8202 (u8 *) & (n->key.ip6_address.as_u8),
8210 ethernet_arp_ip4_entry_t *n, *ns;
8212 ns = ip4_neighbor_entries (sw_if_index);
8216 send_ip_neighbor_details (mp->is_ipv6,
8217 ((n->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) ? 1 : 0),
8218 (u8*) n->ethernet_address,
8219 (u8*) & (n->ip4_address.as_u8),
8227 #define BOUNCE_HANDLER(nn) \
8228 static void vl_api_##nn##_t_handler ( \
8229 vl_api_##nn##_t *mp) \
8231 vpe_client_registration_t *reg; \
8232 vpe_api_main_t * vam = &vpe_api_main; \
8233 unix_shared_memory_queue_t * q; \
8235 /* One registration only... */ \
8236 pool_foreach(reg, vam->nn##_registrations, \
8238 q = vl_api_client_index_to_input_queue (reg->client_index); \
8241 * If the queue is stuffed, turf the msg and complain \
8242 * It's unlikely that the intended recipient is \
8243 * alive; avoid deadlock at all costs. \
8245 if (q->cursize == q->maxsize) { \
8246 clib_warning ("ERROR: receiver queue full, drop msg"); \
8247 vl_msg_api_free (mp); \
8250 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8254 vl_msg_api_free (mp); \
8257 static void setup_message_id_table (api_main_t * am);
8261 * Add vpe's API message handlers to the table.
8262 * vlib has alread mapped shared memory and
8263 * added the client registration handlers.
8264 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8266 static clib_error_t *
8267 vpe_api_hookup (vlib_main_t * vm)
8269 api_main_t *am = &api_main;
8272 vl_msg_api_set_handlers(VL_API_##N, #n, \
8273 vl_api_##n##_t_handler, \
8275 vl_api_##n##_t_endian, \
8276 vl_api_##n##_t_print, \
8277 sizeof(vl_api_##n##_t), 1);
8278 foreach_vpe_api_msg;
8282 * Manually register the sr tunnel add del msg, so we trace
8283 * enough bytes to capture a typical segment list
8285 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8286 "sr_tunnel_add_del",
8287 vl_api_sr_tunnel_add_del_t_handler,
8289 vl_api_sr_tunnel_add_del_t_endian,
8290 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8294 * Manually register the sr policy add del msg, so we trace
8295 * enough bytes to capture a typical tunnel name list
8297 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8298 "sr_policy_add_del",
8299 vl_api_sr_policy_add_del_t_handler,
8301 vl_api_sr_policy_add_del_t_endian,
8302 vl_api_sr_policy_add_del_t_print, 256, 1);
8305 * Trace space for 8 MPLS encap labels, classifier mask+match
8307 am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32);
8308 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8309 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8310 += 5 * sizeof (u32x4);
8311 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8314 * Thread-safe API messages
8316 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8317 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8320 * Set up the (msg_name, crc, message-id) table
8322 setup_message_id_table (am);
8327 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8329 static clib_error_t *
8330 vpe_api_init (vlib_main_t * vm)
8332 vpe_api_main_t *am = &vpe_api_main;
8335 am->vnet_main = vnet_get_main ();
8336 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8337 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8338 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8339 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8340 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8341 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8344 vl_set_memory_region_name ("/vpe-api");
8345 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8350 VLIB_INIT_FUNCTION (vpe_api_init);
8353 static clib_error_t *
8354 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8357 u64 baseva, size, pvt_heap_size;
8359 const int max_buf_size = 4096;
8361 struct passwd _pw, *pw;
8362 struct group _grp, *grp;
8364 buf = vec_new (char, 128);
8365 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8367 if (unformat (input, "prefix %s", &chroot_path))
8369 vec_add1 (chroot_path, 0);
8370 vl_set_memory_root_path ((char *) chroot_path);
8372 else if (unformat (input, "uid %d", &uid))
8373 vl_set_memory_uid (uid);
8374 else if (unformat (input, "gid %d", &gid))
8375 vl_set_memory_gid (gid);
8376 else if (unformat (input, "baseva %llx", &baseva))
8377 vl_set_global_memory_baseva (baseva);
8378 else if (unformat (input, "global-size %lldM", &size))
8379 vl_set_global_memory_size (size * (1ULL << 20));
8380 else if (unformat (input, "global-size %lldG", &size))
8381 vl_set_global_memory_size (size * (1ULL << 30));
8382 else if (unformat (input, "global-size %lld", &size))
8383 vl_set_global_memory_size (size);
8384 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8385 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8386 else if (unformat (input, "global-pvt-heap-size size %lld",
8388 vl_set_global_pvt_heap_size (pvt_heap_size);
8389 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8390 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8391 else if (unformat (input, "api-pvt-heap-size size %lld",
8393 vl_set_api_pvt_heap_size (pvt_heap_size);
8394 else if (unformat (input, "api-size %lldM", &size))
8395 vl_set_api_memory_size (size * (1ULL << 20));
8396 else if (unformat (input, "api-size %lldG", &size))
8397 vl_set_api_memory_size (size * (1ULL << 30));
8398 else if (unformat (input, "api-size %lld", &size))
8399 vl_set_api_memory_size (size);
8400 else if (unformat (input, "uid %s", &s))
8402 /* lookup the username */
8405 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8406 && (vec_len (buf) <= max_buf_size))
8408 vec_resize (buf, vec_len (buf) * 2);
8412 e = clib_error_return_code (0, rv,
8413 CLIB_ERROR_ERRNO_VALID |
8415 "cannot fetch username %s", s);
8423 clib_error_return_fatal (0, "username %s does not exist", s);
8429 vl_set_memory_uid (pw->pw_uid);
8431 else if (unformat (input, "gid %s", &s))
8433 /* lookup the group name */
8436 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8437 && (vec_len (buf) <= max_buf_size))
8439 vec_resize (buf, vec_len (buf) * 2);
8443 e = clib_error_return_code (0, rv,
8444 CLIB_ERROR_ERRNO_VALID |
8446 "cannot fetch group %s", s);
8453 e = clib_error_return_fatal (0, "group %s does not exist", s);
8460 vl_set_memory_gid (grp->gr_gid);
8463 return clib_error_return (0, "unknown input `%U'",
8464 format_unformat_error, input);
8469 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8472 get_unformat_vnet_sw_interface (void)
8474 return (void *) &unformat_vnet_sw_interface;
8478 format_arp_event (u8 * s, va_list * args)
8480 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8482 s = format (s, "pid %d: ", event->pid);
8484 s = format (s, "bd mac/ip4 binding events");
8486 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8491 format_nd_event (u8 * s, va_list * args)
8493 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8495 s = format (s, "pid %d: ", event->pid);
8497 s = format (s, "bd mac/ip6 binding events");
8499 s = format (s, "resolution for %U", format_ip6_address, event->address);
8503 static clib_error_t *
8504 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8505 unformat_input_t * input, vlib_cli_command_t * cmd)
8507 vpe_api_main_t *am = &vpe_api_main;
8508 vl_api_ip4_arp_event_t *arp_event;
8509 vl_api_ip6_nd_event_t *nd_event;
8511 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8513 vlib_cli_output (vm, "No active arp or nd event registrations");
8518 pool_foreach (arp_event, am->arp_events,
8520 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8523 pool_foreach (nd_event, am->nd_events,
8525 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8533 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8534 .path = "show arp-nd-event registrations",
8535 .function = show_ip_arp_nd_events_fn,
8536 .short_help = "Show ip4 arp and ip6 nd event registrations",
8540 #define vl_msg_name_crc_list
8541 #include <vpp-api/vpe_all_api_h.h>
8542 #undef vl_msg_name_crc_list
8545 setup_message_id_table (api_main_t * am)
8547 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
8548 foreach_vl_msg_name_crc_memclnt;
8549 foreach_vl_msg_name_crc_vpe;
8555 * fd.io coding-style-patch-verification: ON
8558 * eval: (c-set-style "gnu")