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 _(SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable) \
305 _(SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump) \
306 _(GET_NEXT_INDEX, get_next_index) \
307 _(PG_CREATE_INTERFACE, pg_create_interface) \
308 _(PG_CAPTURE, pg_capture) \
309 _(PG_ENABLE_DISABLE, pg_enable_disable) \
310 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
311 ip_source_and_port_range_check_add_del) \
312 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
313 ip_source_and_port_range_check_interface_add_del) \
314 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
315 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
316 _(DELETE_SUBIF, delete_subif) \
317 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
319 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
320 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
321 _(IPSEC_SPD_DUMP, ipsec_spd_dump) \
322 _(IP_FIB_DUMP, ip_fib_dump) \
323 _(IP_FIB_DETAILS, ip_fib_details) \
324 _(IP6_FIB_DUMP, ip6_fib_dump) \
325 _(IP6_FIB_DETAILS, ip6_fib_details) \
326 _(FEATURE_ENABLE_DISABLE, feature_enable_disable) \
327 _(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \
328 _(IP_NEIGHBOR_DETAILS, ip_neighbor_details)
331 #define QUOTE(x) QUOTE_(x)
335 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
336 RESOLVE_IP6_ADD_DEL_ROUTE,
339 static vlib_node_registration_t vpe_resolver_process_node;
340 vpe_api_main_t vpe_api_main;
342 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
343 unix_shared_memory_queue_t * q,
346 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
347 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
350 /* Clean up all registrations belonging to the indicated client */
352 vl_api_memclnt_delete_callback (u32 client_index)
354 vpe_api_main_t *vam = &vpe_api_main;
355 vpe_client_registration_t *rp;
357 int stats_memclnt_delete_callback (u32 client_index);
359 stats_memclnt_delete_callback (client_index);
362 p = hash_get (vam->a##_registration_hash, client_index); \
364 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
365 pool_put (vam->a##_registrations, rp); \
366 hash_unset (vam->a##_registration_hash, client_index); \
368 foreach_registration_hash;
373 pub_sub_handler (oam_events, OAM_EVENTS);
375 #define RESOLUTION_EVENT 1
376 #define RESOLUTION_PENDING_EVENT 2
377 #define IP4_ARP_EVENT 3
378 #define IP6_ND_EVENT 4
380 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
382 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
385 handle_ip4_arp_event (u32 pool_index)
387 vpe_api_main_t *vam = &vpe_api_main;
388 vnet_main_t *vnm = vam->vnet_main;
389 vlib_main_t *vm = vam->vlib_main;
390 vl_api_ip4_arp_event_t *event;
391 vl_api_ip4_arp_event_t *mp;
392 unix_shared_memory_queue_t *q;
394 /* Client can cancel, die, etc. */
395 if (pool_is_free_index (vam->arp_events, pool_index))
398 event = pool_elt_at_index (vam->arp_events, pool_index);
400 q = vl_api_client_index_to_input_queue (event->client_index);
403 (void) vnet_add_del_ip4_arp_change_event
404 (vnm, arp_change_delete_callback,
405 event->pid, &event->address,
406 vpe_resolver_process_node.index, IP4_ARP_EVENT,
407 ~0 /* pool index, notused */ , 0 /* is_add */ );
411 if (q->cursize < q->maxsize)
413 mp = vl_msg_api_alloc (sizeof (*mp));
414 clib_memcpy (mp, event, sizeof (*mp));
415 vl_msg_api_send_shmem (q, (u8 *) & mp);
419 static f64 last_time;
421 * Throttle syslog msgs.
422 * It's pretty tempting to just revoke the registration...
424 if (vlib_time_now (vm) > last_time + 10.0)
426 clib_warning ("arp event for %U to pid %d: queue stuffed!",
427 format_ip4_address, &event->address, event->pid);
428 last_time = vlib_time_now (vm);
434 handle_ip6_nd_event (u32 pool_index)
436 vpe_api_main_t *vam = &vpe_api_main;
437 vnet_main_t *vnm = vam->vnet_main;
438 vlib_main_t *vm = vam->vlib_main;
439 vl_api_ip6_nd_event_t *event;
440 vl_api_ip6_nd_event_t *mp;
441 unix_shared_memory_queue_t *q;
443 /* Client can cancel, die, etc. */
444 if (pool_is_free_index (vam->nd_events, pool_index))
447 event = pool_elt_at_index (vam->nd_events, pool_index);
449 q = vl_api_client_index_to_input_queue (event->client_index);
452 (void) vnet_add_del_ip6_nd_change_event
453 (vnm, nd_change_delete_callback,
454 event->pid, &event->address,
455 vpe_resolver_process_node.index, IP6_ND_EVENT,
456 ~0 /* pool index, notused */ , 0 /* is_add */ );
460 if (q->cursize < q->maxsize)
462 mp = vl_msg_api_alloc (sizeof (*mp));
463 clib_memcpy (mp, event, sizeof (*mp));
464 vl_msg_api_send_shmem (q, (u8 *) & mp);
468 static f64 last_time;
470 * Throttle syslog msgs.
471 * It's pretty tempting to just revoke the registration...
473 if (vlib_time_now (vm) > last_time + 10.0)
475 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
476 format_ip6_address, &event->address, event->pid);
477 last_time = vlib_time_now (vm);
483 resolver_process (vlib_main_t * vm,
484 vlib_node_runtime_t * rt, vlib_frame_t * f)
487 uword *event_data = 0;
493 vlib_process_wait_for_event_or_clock (vm, timeout);
495 event_type = vlib_process_get_events (vm, &event_data);
499 case RESOLUTION_PENDING_EVENT:
503 case RESOLUTION_EVENT:
504 clib_warning ("resolver: BOGUS TYPE");
508 for (i = 0; i < vec_len (event_data); i++)
509 handle_ip4_arp_event (event_data[i]);
513 for (i = 0; i < vec_len (event_data); i++)
514 handle_ip6_nd_event (event_data[i]);
517 case ~0: /* timeout */
521 vec_reset_length (event_data);
523 return 0; /* or not */
527 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
528 .function = resolver_process,
529 .type = VLIB_NODE_TYPE_PROCESS,
530 .name = "vpe-route-resolver-process",
535 add_del_route_t_handler (u8 is_multipath,
542 u32 classify_table_index,
544 u8 is_resolve_attached,
546 const fib_prefix_t * prefix,
547 u8 next_hop_proto_is_ip4,
548 const ip46_address_t * next_hop,
549 u32 next_hop_sw_if_index,
550 u8 next_hop_fib_index,
552 mpls_label_t next_hop_via_label,
553 mpls_label_t * next_hop_out_label_stack)
555 vnet_classify_main_t *cm = &vnet_classify_main;
556 stats_main_t *sm = &stats_main;
557 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
558 fib_route_path_t path = {
559 .frp_proto = (next_hop_proto_is_ip4 ?
560 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6),
561 .frp_addr = (NULL == next_hop ? zero_addr : *next_hop),
562 .frp_sw_if_index = next_hop_sw_if_index,
563 .frp_fib_index = next_hop_fib_index,
564 .frp_weight = next_hop_weight,
565 .frp_label_stack = next_hop_out_label_stack,
567 fib_route_path_t *paths = NULL;
569 if (MPLS_LABEL_INVALID != next_hop_via_label)
571 path.frp_proto = FIB_PROTOCOL_MPLS;
572 path.frp_local_label = next_hop_via_label;
575 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
576 if (is_resolve_attached)
577 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
579 path.frp_flags = path_flags;
583 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
586 vec_add1 (paths, path);
589 fib_table_entry_path_add2 (fib_index,
592 FIB_ENTRY_FLAG_NONE, paths);
594 fib_table_entry_path_remove2 (fib_index,
595 prefix, FIB_SOURCE_API, paths);
602 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
604 if (is_drop || is_local || is_classify || is_unreach || is_prohibit)
607 * special route types that link directly to the adj
611 dpo_id_t dpo = DPO_INVALID;
614 dproto = fib_proto_to_dpo (prefix->fp_proto);
617 ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo);
619 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
621 ip_null_dpo_add_and_lock (dproto,
622 IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo);
623 else if (is_prohibit)
624 ip_null_dpo_add_and_lock (dproto,
625 IP_NULL_ACTION_SEND_ICMP_PROHIBIT,
627 else if (is_classify)
629 if (pool_is_free_index (cm->tables,
630 ntohl (classify_table_index)))
633 return VNET_API_ERROR_NO_SUCH_TABLE;
636 dpo_set (&dpo, DPO_CLASSIFY, dproto,
637 classify_dpo_create (dproto,
638 ntohl (classify_table_index)));
643 return VNET_API_ERROR_NO_SUCH_TABLE;
646 fib_table_entry_special_dpo_update (fib_index,
649 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
654 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
661 vec_add1 (paths, path);
662 fib_table_entry_update (fib_index,
664 FIB_SOURCE_API, FIB_ENTRY_FLAG_NONE, paths);
669 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
678 add_del_route_check (fib_protocol_t table_proto,
680 u32 next_hop_sw_if_index,
681 fib_protocol_t next_hop_table_proto,
682 u32 next_hop_table_id,
683 u8 create_missing_tables,
684 u32 * fib_index, u32 * next_hop_fib_index)
686 vnet_main_t *vnm = vnet_get_main ();
688 *fib_index = fib_table_find (table_proto, ntohl (table_id));
689 if (~0 == *fib_index)
691 if (create_missing_tables)
693 *fib_index = fib_table_find_or_create_and_lock (table_proto,
698 /* No such VRF, and we weren't asked to create one */
699 return VNET_API_ERROR_NO_SUCH_FIB;
703 if (~0 != ntohl (next_hop_sw_if_index))
705 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
706 ntohl (next_hop_sw_if_index)))
708 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
713 *next_hop_fib_index = fib_table_find (next_hop_table_proto,
714 ntohl (next_hop_table_id));
716 if (~0 == *next_hop_fib_index)
718 if (create_missing_tables)
720 *next_hop_fib_index =
721 fib_table_find_or_create_and_lock (next_hop_table_proto,
722 ntohl (next_hop_table_id));
726 /* No such VRF, and we weren't asked to create one */
727 return VNET_API_ERROR_NO_SUCH_FIB;
736 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
738 u32 fib_index, next_hop_fib_index;
739 mpls_label_t *label_stack = NULL;
740 int rv, ii, n_labels;;
742 rv = add_del_route_check (FIB_PROTOCOL_IP4,
744 mp->next_hop_sw_if_index,
746 mp->next_hop_table_id,
747 mp->create_vrf_if_needed,
748 &fib_index, &next_hop_fib_index);
754 .fp_len = mp->dst_address_length,
755 .fp_proto = FIB_PROTOCOL_IP4,
757 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
760 memset (&nh, 0, sizeof (nh));
761 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
763 n_labels = mp->next_hop_n_out_labels;
766 else if (1 == n_labels)
767 vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0]));
770 vec_validate (label_stack, n_labels - 1);
771 for (ii = 0; ii < n_labels; ii++)
772 label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]);
775 return (add_del_route_t_handler (mp->is_multipath,
782 mp->classify_table_index,
784 mp->is_resolve_attached,
787 ntohl (mp->next_hop_sw_if_index),
790 ntohl (mp->next_hop_via_label),
795 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
797 u32 fib_index, next_hop_fib_index;
798 mpls_label_t *label_stack = NULL;
799 int rv, ii, n_labels;;
801 rv = add_del_route_check (FIB_PROTOCOL_IP6,
803 mp->next_hop_sw_if_index,
805 mp->next_hop_table_id,
806 mp->create_vrf_if_needed,
807 &fib_index, &next_hop_fib_index);
813 .fp_len = mp->dst_address_length,
814 .fp_proto = FIB_PROTOCOL_IP6,
816 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
819 memset (&nh, 0, sizeof (nh));
820 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
822 n_labels = mp->next_hop_n_out_labels;
825 else if (1 == n_labels)
826 vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0]));
829 vec_validate (label_stack, n_labels - 1);
830 for (ii = 0; ii < n_labels; ii++)
831 label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]);
834 return (add_del_route_t_handler (mp->is_multipath,
841 mp->classify_table_index,
843 mp->is_resolve_attached,
845 &nh, ntohl (mp->next_hop_sw_if_index),
848 ntohl (mp->next_hop_via_label),
853 mpls_route_add_del_t_handler (vnet_main_t * vnm,
854 vl_api_mpls_route_add_del_t * mp)
856 u32 fib_index, next_hop_fib_index;
857 mpls_label_t *label_stack = NULL;
858 int rv, ii, n_labels;;
862 .fp_proto = FIB_PROTOCOL_MPLS,
863 .fp_eos = mp->mr_eos,
864 .fp_label = ntohl (mp->mr_label),
868 if (mp->mr_next_hop_proto_is_ip4)
870 pfx.fp_payload_proto = DPO_PROTO_IP4;
874 pfx.fp_payload_proto = DPO_PROTO_IP6;
879 pfx.fp_payload_proto = DPO_PROTO_MPLS;
882 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
884 mp->mr_next_hop_sw_if_index,
885 dpo_proto_to_fib (pfx.fp_payload_proto),
886 mp->mr_next_hop_table_id,
887 mp->mr_create_table_if_needed,
888 &fib_index, &next_hop_fib_index);
894 memset (&nh, 0, sizeof (nh));
896 if (mp->mr_next_hop_proto_is_ip4)
897 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
899 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
901 n_labels = mp->mr_next_hop_n_out_labels;
904 else if (1 == n_labels)
905 vec_add1 (label_stack, ntohl (mp->mr_next_hop_out_label_stack[0]));
908 vec_validate (label_stack, n_labels - 1);
909 for (ii = 0; ii < n_labels; ii++)
910 label_stack[ii] = ntohl (mp->mr_next_hop_out_label_stack[ii]);
913 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
914 0, // mp->is_unreach,
915 0, // mp->is_prohibit,
918 mp->mr_classify_table_index,
919 mp->mr_is_resolve_host,
920 mp->mr_is_resolve_attached,
922 mp->mr_next_hop_proto_is_ip4,
923 &nh, ntohl (mp->mr_next_hop_sw_if_index),
925 mp->mr_next_hop_weight,
926 ntohl (mp->mr_next_hop_via_label),
931 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
933 vl_api_ip_add_del_route_reply_t *rmp;
935 vnet_main_t *vnm = vnet_get_main ();
940 rv = ip6_add_del_route_t_handler (mp);
942 rv = ip4_add_del_route_t_handler (mp);
944 rv = (rv == 0) ? vnm->api_errno : rv;
946 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
950 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
952 vl_api_mpls_route_add_del_reply_t *rmp;
956 vnm = vnet_get_main ();
959 rv = mpls_route_add_del_t_handler (vnm, mp);
961 rv = (rv == 0) ? vnm->api_errno : rv;
963 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
967 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
968 vl_api_mpls_ip_bind_unbind_t * mp)
970 u32 mpls_fib_index, ip_fib_index;
973 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
975 if (~0 == mpls_fib_index)
977 if (mp->mb_create_table_if_needed)
980 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
981 ntohl (mp->mb_mpls_table_id));
984 return VNET_API_ERROR_NO_SUCH_FIB;
987 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
990 ntohl (mp->mb_ip_table_id));
991 if (~0 == ip_fib_index)
992 return VNET_API_ERROR_NO_SUCH_FIB;
995 .fp_len = mp->mb_address_length,
1000 pfx.fp_proto = FIB_PROTOCOL_IP4;
1001 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
1002 sizeof (pfx.fp_addr.ip4));
1006 pfx.fp_proto = FIB_PROTOCOL_IP6;
1007 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
1008 sizeof (pfx.fp_addr.ip6));
1012 fib_table_entry_local_label_add (ip_fib_index, &pfx,
1013 ntohl (mp->mb_label));
1015 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
1016 ntohl (mp->mb_label));
1022 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
1024 vl_api_mpls_route_add_del_reply_t *rmp;
1028 vnm = vnet_get_main ();
1031 rv = mpls_ip_bind_unbind_handler (vnm, mp);
1033 rv = (rv == 0) ? vnm->api_errno : rv;
1035 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1039 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1041 vl_api_sw_interface_set_vpath_reply_t *rmp;
1043 u32 sw_if_index = ntohl (mp->sw_if_index);
1045 VALIDATE_SW_IF_INDEX (mp);
1047 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1048 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
1049 sw_if_index, mp->enable, 0, 0);
1050 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
1051 sw_if_index, mp->enable, 0, 0);
1052 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
1053 sw_if_index, mp->enable, 0, 0);
1054 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
1055 sw_if_index, mp->enable, 0, 0);
1057 BAD_SW_IF_INDEX_LABEL;
1059 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1063 vl_api_sw_interface_set_vxlan_bypass_t_handler
1064 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
1066 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
1068 u32 sw_if_index = ntohl (mp->sw_if_index);
1070 VALIDATE_SW_IF_INDEX (mp);
1074 /* not yet implemented */
1077 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
1078 sw_if_index, mp->enable, 0, 0);
1080 BAD_SW_IF_INDEX_LABEL;
1082 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
1086 vl_api_sw_interface_set_l2_xconnect_t_handler
1087 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1089 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1091 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1092 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1093 vlib_main_t *vm = vlib_get_main ();
1094 vnet_main_t *vnm = vnet_get_main ();
1096 VALIDATE_RX_SW_IF_INDEX (mp);
1100 VALIDATE_TX_SW_IF_INDEX (mp);
1101 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1102 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1106 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1109 BAD_RX_SW_IF_INDEX_LABEL;
1110 BAD_TX_SW_IF_INDEX_LABEL;
1112 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1116 vl_api_sw_interface_set_l2_bridge_t_handler
1117 (vl_api_sw_interface_set_l2_bridge_t * mp)
1119 bd_main_t *bdm = &bd_main;
1120 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1122 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1123 u32 bd_id = ntohl (mp->bd_id);
1127 vlib_main_t *vm = vlib_get_main ();
1128 vnet_main_t *vnm = vnet_get_main ();
1130 VALIDATE_RX_SW_IF_INDEX (mp);
1132 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1136 //VALIDATE_TX_SW_IF_INDEX(mp);
1137 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1138 rx_sw_if_index, bd_index, bvi, shg, 0);
1142 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1145 BAD_RX_SW_IF_INDEX_LABEL;
1147 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1151 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1152 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1154 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1158 dpdk_main_t *dm = &dpdk_main;
1161 u32 sw_if_index = ntohl (mp->sw_if_index);
1162 u32 subport = ntohl (mp->subport);
1163 u32 pipe = ntohl (mp->pipe);
1164 u32 profile = ntohl (mp->profile);
1165 vnet_hw_interface_t *hw;
1167 VALIDATE_SW_IF_INDEX (mp);
1169 /* hw_if & dpdk device */
1170 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1172 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1174 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1176 BAD_SW_IF_INDEX_LABEL;
1178 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1179 rv = VNET_API_ERROR_UNIMPLEMENTED;
1182 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1186 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1187 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1189 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1193 dpdk_main_t *dm = &dpdk_main;
1195 struct rte_sched_subport_params p;
1197 u32 sw_if_index = ntohl (mp->sw_if_index);
1198 u32 subport = ntohl (mp->subport);
1199 p.tb_rate = ntohl (mp->tb_rate);
1200 p.tb_size = ntohl (mp->tb_size);
1201 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1202 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1203 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1204 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1205 p.tc_period = ntohl (mp->tc_period);
1207 vnet_hw_interface_t *hw;
1209 VALIDATE_SW_IF_INDEX (mp);
1211 /* hw_if & dpdk device */
1212 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1214 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1216 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1218 BAD_SW_IF_INDEX_LABEL;
1221 ("setting HQoS subport parameters without DPDK not implemented");
1222 rv = VNET_API_ERROR_UNIMPLEMENTED;
1225 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1229 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1230 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1232 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1236 dpdk_main_t *dm = &dpdk_main;
1237 vlib_thread_main_t *tm = vlib_get_thread_main ();
1240 u32 sw_if_index = ntohl (mp->sw_if_index);
1241 u32 entry = ntohl (mp->entry);
1242 u32 tc = ntohl (mp->tc);
1243 u32 queue = ntohl (mp->queue);
1246 vnet_hw_interface_t *hw;
1248 VALIDATE_SW_IF_INDEX (mp);
1250 /* hw_if & dpdk device */
1251 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1253 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1255 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1257 clib_warning ("invalid traffic class !!");
1258 rv = VNET_API_ERROR_INVALID_VALUE;
1261 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1263 clib_warning ("invalid queue !!");
1264 rv = VNET_API_ERROR_INVALID_VALUE;
1268 /* Detect the set of worker threads */
1269 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1273 clib_warning ("worker thread registration AWOL !!");
1274 rv = VNET_API_ERROR_INVALID_VALUE_2;
1278 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1279 int worker_thread_first = tr->first_index;
1280 int worker_thread_count = tr->count;
1282 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1283 for (i = 0; i < worker_thread_count; i++)
1284 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1286 BAD_SW_IF_INDEX_LABEL;
1289 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1290 rv = VNET_API_ERROR_UNIMPLEMENTED;
1293 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1297 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1299 vlib_main_t *vm = vlib_get_main ();
1300 bd_main_t *bdm = &bd_main;
1301 vl_api_bridge_domain_add_del_reply_t *rmp;
1303 u32 enable_flags = 0, disable_flags = 0;
1304 u32 bd_id = ntohl (mp->bd_id);
1309 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1312 enable_flags |= L2_FLOOD;
1314 disable_flags |= L2_FLOOD;
1317 enable_flags |= L2_UU_FLOOD;
1319 disable_flags |= L2_UU_FLOOD;
1322 enable_flags |= L2_FWD;
1324 disable_flags |= L2_FWD;
1327 enable_flags |= L2_ARP_TERM;
1329 disable_flags |= L2_ARP_TERM;
1332 enable_flags |= L2_LEARN;
1334 disable_flags |= L2_LEARN;
1337 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1340 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1344 rv = bd_delete_bd_index (bdm, bd_id);
1346 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1350 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1352 clib_warning ("BUG");
1356 vl_api_bridge_domain_sw_if_details_t_handler
1357 (vl_api_bridge_domain_sw_if_details_t * mp)
1359 clib_warning ("BUG");
1363 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1364 l2_bridge_domain_t * bd_config,
1365 u32 n_sw_ifs, u32 context)
1367 vl_api_bridge_domain_details_t *mp;
1369 mp = vl_msg_api_alloc (sizeof (*mp));
1370 memset (mp, 0, sizeof (*mp));
1371 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1372 mp->bd_id = ntohl (bd_config->bd_id);
1373 mp->flood = bd_feature_flood (bd_config);
1374 mp->uu_flood = bd_feature_uu_flood (bd_config);
1375 mp->forward = bd_feature_forward (bd_config);
1376 mp->learn = bd_feature_learn (bd_config);
1377 mp->arp_term = bd_feature_arp_term (bd_config);
1378 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1379 mp->n_sw_ifs = ntohl (n_sw_ifs);
1380 mp->context = context;
1382 vl_msg_api_send_shmem (q, (u8 *) & mp);
1386 send_bd_sw_if_details (l2input_main_t * l2im,
1387 unix_shared_memory_queue_t * q,
1388 l2_flood_member_t * member, u32 bd_id, u32 context)
1390 vl_api_bridge_domain_sw_if_details_t *mp;
1391 l2_input_config_t *input_cfg;
1393 mp = vl_msg_api_alloc (sizeof (*mp));
1394 memset (mp, 0, sizeof (*mp));
1395 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1396 mp->bd_id = ntohl (bd_id);
1397 mp->sw_if_index = ntohl (member->sw_if_index);
1398 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1399 mp->shg = input_cfg->shg;
1400 mp->context = context;
1402 vl_msg_api_send_shmem (q, (u8 *) & mp);
1406 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1408 bd_main_t *bdm = &bd_main;
1409 l2input_main_t *l2im = &l2input_main;
1410 unix_shared_memory_queue_t *q;
1411 l2_bridge_domain_t *bd_config;
1412 u32 bd_id, bd_index;
1415 q = vl_api_client_index_to_input_queue (mp->client_index);
1420 bd_id = ntohl (mp->bd_id);
1422 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1423 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1424 for (; bd_index < end; bd_index++)
1426 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1427 /* skip dummy bd_id 0 */
1428 if (bd_config && (bd_config->bd_id > 0))
1431 l2_flood_member_t *m;
1433 n_sw_ifs = vec_len (bd_config->members);
1434 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1436 vec_foreach (m, bd_config->members)
1438 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1445 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1447 bd_main_t *bdm = &bd_main;
1448 l2input_main_t *l2im = &l2input_main;
1449 vl_api_l2fib_add_del_reply_t *rmp;
1452 u32 sw_if_index = ntohl (mp->sw_if_index);
1453 u32 bd_id = ntohl (mp->bd_id);
1462 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1465 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1466 goto bad_sw_if_index;
1472 filter_mac = mp->filter_mac ? 1 : 0;
1473 if (filter_mac == 0)
1475 VALIDATE_SW_IF_INDEX (mp);
1476 if (vec_len (l2im->configs) <= sw_if_index)
1478 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1479 goto bad_sw_if_index;
1483 l2_input_config_t *config;
1484 config = vec_elt_at_index (l2im->configs, sw_if_index);
1485 if (config->bridge == 0)
1487 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1488 goto bad_sw_if_index;
1492 static_mac = mp->static_mac ? 1 : 0;
1493 bvi_mac = mp->bvi_mac ? 1 : 0;
1494 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1499 l2fib_del_entry (mac, bd_index);
1502 BAD_SW_IF_INDEX_LABEL;
1504 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1508 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1510 vl_api_l2_flags_reply_t *rmp;
1512 u32 sw_if_index = ntohl (mp->sw_if_index);
1513 u32 flags = ntohl (mp->feature_bitmap);
1516 VALIDATE_SW_IF_INDEX (mp);
1519 if (flags & L2INPUT_FEAT_ ## a) \
1520 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1521 foreach_l2input_feat;
1524 BAD_SW_IF_INDEX_LABEL;
1527 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1529 rmp->resulting_feature_bitmap = ntohl(rbm);
1535 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1537 vlib_main_t *vm = vlib_get_main ();
1538 bd_main_t *bdm = &bd_main;
1539 vl_api_bridge_flags_reply_t *rmp;
1541 u32 bd_id = ntohl (mp->bd_id);
1543 u32 flags = ntohl (mp->feature_bitmap);
1546 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1549 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1555 bd_set_flags (vm, bd_index, flags, mp->is_set);
1559 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1561 rmp->resulting_feature_bitmap = ntohl(flags);
1567 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1569 bd_main_t *bdm = &bd_main;
1570 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1572 u32 bd_id = ntohl (mp->bd_id);
1576 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1579 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1584 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1585 mp->mac_address, mp->is_ipv6, mp->is_add))
1586 rv = VNET_API_ERROR_UNSPECIFIED;
1589 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1593 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp)
1595 vlib_main_t *vm = vlib_get_main ();
1597 vl_api_tap_connect_reply_t *rmp;
1598 vnet_main_t *vnm = vnet_get_main ();
1599 unix_shared_memory_queue_t *q;
1600 u32 sw_if_index = (u32) ~ 0;
1603 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1604 mp->use_random_mac ? 0 : mp->mac_address,
1605 &sw_if_index, mp->renumber,
1606 ntohl (mp->custom_dev_instance));
1608 /* Add tag if supplied */
1609 if (rv == 0 && mp->tag[0])
1611 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
1612 tag = format (0, "%s%c", mp->tag, 0);
1613 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1616 q = vl_api_client_index_to_input_queue (mp->client_index);
1620 rmp = vl_msg_api_alloc (sizeof (*rmp));
1621 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1622 rmp->context = mp->context;
1623 rmp->retval = ntohl (rv);
1624 rmp->sw_if_index = ntohl (sw_if_index);
1626 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1630 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp)
1633 vl_api_tap_modify_reply_t *rmp;
1634 unix_shared_memory_queue_t *q;
1635 u32 sw_if_index = (u32) ~ 0;
1636 vlib_main_t *vm = vlib_get_main ();
1638 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1639 mp->use_random_mac ? 0 : mp->mac_address,
1640 &sw_if_index, mp->renumber,
1641 ntohl (mp->custom_dev_instance));
1643 q = vl_api_client_index_to_input_queue (mp->client_index);
1647 rmp = vl_msg_api_alloc (sizeof (*rmp));
1648 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1649 rmp->context = mp->context;
1650 rmp->retval = ntohl (rv);
1651 rmp->sw_if_index = ntohl (sw_if_index);
1653 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1657 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp)
1659 vlib_main_t *vm = vlib_get_main ();
1661 vpe_api_main_t *vam = &vpe_api_main;
1662 vl_api_tap_delete_reply_t *rmp;
1663 unix_shared_memory_queue_t *q;
1664 u32 sw_if_index = ntohl (mp->sw_if_index);
1666 rv = vnet_tap_delete (vm, sw_if_index);
1669 vnet_main_t *vnm = vnet_get_main ();
1670 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1673 q = vl_api_client_index_to_input_queue (mp->client_index);
1677 rmp = vl_msg_api_alloc (sizeof (*rmp));
1678 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1679 rmp->context = mp->context;
1680 rmp->retval = ntohl (rv);
1682 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1685 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1689 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1691 vl_api_create_vlan_subif_reply_t *rmp;
1692 vnet_main_t *vnm = vnet_get_main ();
1693 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1694 vnet_hw_interface_t *hi;
1697 vnet_sw_interface_t template;
1699 vnet_interface_main_t *im = &vnm->interface_main;
1700 u64 sup_and_sub_key;
1702 unix_shared_memory_queue_t *q;
1703 clib_error_t *error;
1705 VALIDATE_SW_IF_INDEX (mp);
1707 hw_if_index = ntohl (mp->sw_if_index);
1708 hi = vnet_get_hw_interface (vnm, hw_if_index);
1710 id = ntohl (mp->vlan_id);
1711 if (id == 0 || id > 4095)
1713 rv = VNET_API_ERROR_INVALID_VLAN;
1717 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1719 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1722 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1726 kp = clib_mem_alloc (sizeof (*kp));
1727 *kp = sup_and_sub_key;
1729 memset (&template, 0, sizeof (template));
1730 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1731 template.sup_sw_if_index = hi->sw_if_index;
1732 template.sub.id = id;
1733 template.sub.eth.raw_flags = 0;
1734 template.sub.eth.flags.one_tag = 1;
1735 template.sub.eth.outer_vlan_id = id;
1736 template.sub.eth.flags.exact_match = 1;
1738 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1741 clib_error_report (error);
1742 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1745 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1746 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1748 BAD_SW_IF_INDEX_LABEL;
1751 q = vl_api_client_index_to_input_queue (mp->client_index);
1755 rmp = vl_msg_api_alloc (sizeof (*rmp));
1756 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1757 rmp->context = mp->context;
1758 rmp->retval = ntohl (rv);
1759 rmp->sw_if_index = ntohl (sw_if_index);
1760 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1764 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1766 vl_api_create_subif_reply_t *rmp;
1767 vnet_main_t *vnm = vnet_get_main ();
1768 u32 sw_if_index = ~0;
1771 vnet_sw_interface_t *si;
1772 vnet_hw_interface_t *hi;
1773 vnet_sw_interface_t template;
1775 vnet_interface_main_t *im = &vnm->interface_main;
1776 u64 sup_and_sub_key;
1778 clib_error_t *error;
1780 VALIDATE_SW_IF_INDEX (mp);
1782 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1783 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1785 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1787 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1791 sw_if_index = si->sw_if_index;
1792 sub_id = ntohl (mp->sub_id);
1794 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1796 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1800 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1801 sw_if_index, sub_id);
1802 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1806 kp = clib_mem_alloc (sizeof (*kp));
1807 *kp = sup_and_sub_key;
1809 memset (&template, 0, sizeof (template));
1810 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1811 template.sup_sw_if_index = sw_if_index;
1812 template.sub.id = sub_id;
1813 template.sub.eth.flags.no_tags = mp->no_tags;
1814 template.sub.eth.flags.one_tag = mp->one_tag;
1815 template.sub.eth.flags.two_tags = mp->two_tags;
1816 template.sub.eth.flags.dot1ad = mp->dot1ad;
1817 template.sub.eth.flags.exact_match = mp->exact_match;
1818 template.sub.eth.flags.default_sub = mp->default_sub;
1819 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1820 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1821 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1822 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1824 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1827 clib_error_report (error);
1828 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1832 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1833 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1835 BAD_SW_IF_INDEX_LABEL;
1840 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1842 rmp->sw_if_index = ntohl(sw_if_index);
1848 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
1850 vl_api_mpls_tunnel_add_del_reply_t *rmp;
1852 stats_main_t *sm = &stats_main;
1853 u32 tunnel_sw_if_index;
1856 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1860 fib_route_path_t rpath, *rpaths = NULL;
1861 mpls_label_t *label_stack = NULL;
1863 memset (&rpath, 0, sizeof (rpath));
1865 if (mp->mt_next_hop_proto_is_ip4)
1867 rpath.frp_proto = FIB_PROTOCOL_IP4;
1868 clib_memcpy (&rpath.frp_addr.ip4,
1869 mp->mt_next_hop, sizeof (rpath.frp_addr.ip4));
1873 rpath.frp_proto = FIB_PROTOCOL_IP6;
1874 clib_memcpy (&rpath.frp_addr.ip6,
1875 mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
1877 rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
1879 for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
1880 vec_add1 (label_stack, ntohl (mp->mt_next_hop_out_label_stack[ii]));
1882 vec_add1 (rpaths, rpath);
1884 vnet_mpls_tunnel_add (rpaths, label_stack,
1885 mp->mt_l2_only, &tunnel_sw_if_index);
1887 vec_free (label_stack);
1891 tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
1892 vnet_mpls_tunnel_del (tunnel_sw_if_index);
1898 REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
1900 rmp->sw_if_index = ntohl(tunnel_sw_if_index);
1906 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
1908 vl_api_proxy_arp_add_del_reply_t *rmp;
1911 ip4_main_t *im = &ip4_main;
1912 stats_main_t *sm = &stats_main;
1913 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
1914 ip4_address_t * hi_addr,
1915 u32 fib_index, int is_del);
1918 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
1920 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1924 rv = VNET_API_ERROR_NO_SUCH_FIB;
1930 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
1931 (ip4_address_t *) mp->hi_address,
1932 fib_index, mp->is_add == 0);
1936 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
1940 vl_api_proxy_arp_intfc_enable_disable_t_handler
1941 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
1944 vnet_main_t *vnm = vnet_get_main ();
1945 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
1946 vnet_sw_interface_t *si;
1949 VALIDATE_SW_IF_INDEX (mp);
1951 sw_if_index = ntohl (mp->sw_if_index);
1953 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1955 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1959 si = vnet_get_sw_interface (vnm, sw_if_index);
1963 if (mp->enable_disable)
1964 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1966 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1968 BAD_SW_IF_INDEX_LABEL;
1971 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
1975 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
1978 vl_api_ip_neighbor_add_del_reply_t *rmp;
1979 vnet_main_t *vnm = vnet_get_main ();
1980 stats_main_t *sm = &stats_main;
1983 VALIDATE_SW_IF_INDEX (mp);
1985 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
1988 * there's no validation here of the ND/ARP entry being added.
1989 * The expectation is that the FIB will ensure that nothing bad
1990 * will come of adding bogus entries.
1995 rv = vnet_set_ip6_ethernet_neighbor
1996 (vm, ntohl (mp->sw_if_index),
1997 (ip6_address_t *) (mp->dst_address),
1998 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2000 rv = vnet_unset_ip6_ethernet_neighbor
2001 (vm, ntohl (mp->sw_if_index),
2002 (ip6_address_t *) (mp->dst_address),
2003 mp->mac_address, sizeof (mp->mac_address));
2007 ethernet_arp_ip4_over_ethernet_address_t a;
2009 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2010 clib_memcpy (&a.ip4, mp->dst_address, 4);
2013 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2017 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2020 BAD_SW_IF_INDEX_LABEL;
2023 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2027 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2030 vpe_main_t *rm = &vpe_main;
2031 ip4_main_t *im4 = &ip4_main;
2032 ip6_main_t *im6 = &ip6_main;
2033 ip_lookup_main_t *lm;
2039 u32 adj_index, sw_if_index;
2040 vl_api_is_address_reachable_t *rmp;
2041 ip_adjacency_t *adj;
2042 unix_shared_memory_queue_t *q;
2044 q = vl_api_client_index_to_input_queue (mp->client_index);
2047 increment_missing_api_client_counter (rm->vlib_main);
2051 rmp = vl_msg_api_alloc (sizeof (*rmp));
2052 clib_memcpy (rmp, mp, sizeof (*rmp));
2054 sw_if_index = mp->next_hop_sw_if_index;
2055 clib_memcpy (&addr, mp->address, sizeof (addr));
2058 lm = &im6->lookup_main;
2059 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2063 lm = &im4->lookup_main;
2065 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2067 if (adj_index == ~0)
2072 adj = ip_get_adjacency (lm, adj_index);
2074 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2075 && adj->rewrite_header.sw_if_index == sw_if_index)
2081 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2082 && adj->rewrite_header.sw_if_index == sw_if_index)
2085 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2087 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2089 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2098 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2103 vl_api_sw_interface_set_mpls_enable_t_handler
2104 (vl_api_sw_interface_set_mpls_enable_t * mp)
2106 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2109 VALIDATE_SW_IF_INDEX (mp);
2111 mpls_sw_interface_enable_disable (&mpls_main,
2112 ntohl (mp->sw_if_index), mp->enable);
2114 BAD_SW_IF_INDEX_LABEL;
2115 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2118 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2119 unix_shared_memory_queue_t * q,
2121 __attribute__ ((unused));
2124 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2125 unix_shared_memory_queue_t * q,
2128 vl_api_sw_interface_set_flags_t *mp;
2130 mp = vl_msg_api_alloc (sizeof (*mp));
2131 memset (mp, 0, sizeof (*mp));
2132 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2133 mp->sw_if_index = ntohl (sw_if_index);
2135 mp->admin_up_down = 0;
2136 mp->link_up_down = 0;
2138 vl_msg_api_send_shmem (q, (u8 *) & mp);
2142 send_oam_event (oam_target_t * t)
2144 vpe_api_main_t *vam = &vpe_api_main;
2145 unix_shared_memory_queue_t *q;
2146 vpe_client_registration_t *reg;
2147 vl_api_oam_event_t *mp;
2150 pool_foreach(reg, vam->oam_events_registrations,
2152 q = vl_api_client_index_to_input_queue (reg->client_index);
2155 mp = vl_msg_api_alloc (sizeof (*mp));
2156 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2157 clib_memcpy (mp->dst_address, &t->dst_address,
2158 sizeof (mp->dst_address));
2159 mp->state = t->state;
2160 vl_msg_api_send_shmem (q, (u8 *)&mp);
2167 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2169 vl_api_oam_add_del_reply_t *rmp;
2172 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2173 (ip4_address_t *) mp->dst_address,
2174 ntohl (mp->vrf_id), (int) (mp->is_add));
2176 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2180 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2182 stats_main_t *sm = &stats_main;
2183 vnet_interface_main_t *im = sm->interface_main;
2184 vl_api_vnet_summary_stats_reply_t *rmp;
2185 vlib_combined_counter_main_t *cm;
2188 u64 total_pkts[VLIB_N_RX_TX];
2189 u64 total_bytes[VLIB_N_RX_TX];
2191 unix_shared_memory_queue_t *q =
2192 vl_api_client_index_to_input_queue (mp->client_index);
2197 rmp = vl_msg_api_alloc (sizeof (*rmp));
2198 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2199 rmp->context = mp->context;
2202 memset (total_pkts, 0, sizeof (total_pkts));
2203 memset (total_bytes, 0, sizeof (total_bytes));
2205 vnet_interface_counter_lock (im);
2207 vec_foreach (cm, im->combined_sw_if_counters)
2209 which = cm - im->combined_sw_if_counters;
2211 for (i = 0; i < vec_len (cm->maxi); i++)
2213 vlib_get_combined_counter (cm, i, &v);
2214 total_pkts[which] += v.packets;
2215 total_bytes[which] += v.bytes;
2218 vnet_interface_counter_unlock (im);
2220 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2221 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2222 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2223 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2225 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2227 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2231 typedef CLIB_PACKED (struct {
2232 ip4_address_t address;
2233 u32 address_length: 6;
2239 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2241 vnet_main_t *vnm = vnet_get_main ();
2242 vnet_interface_main_t *im = &vnm->interface_main;
2243 ip4_main_t *im4 = &ip4_main;
2244 static u32 *sw_if_indices_to_shut;
2245 stats_main_t *sm = &stats_main;
2246 fib_table_t *fib_table;
2250 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2251 u32 target_fib_id = ntohl (mp->vrf_id);
2253 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2256 pool_foreach (fib_table, im4->fibs,
2258 fib = &fib_table->v4;
2259 vnet_sw_interface_t * si;
2261 if (fib->table_id != target_fib_id)
2264 /* remove any mpls encap/decap labels */
2265 mpls_fib_reset_labels (fib->table_id);
2267 /* remove any proxy arps in this fib */
2268 vnet_proxy_arp_fib_reset (fib->table_id);
2270 /* Set the flow hash for this fib to the default */
2271 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2273 vec_reset_length (sw_if_indices_to_shut);
2275 /* Shut down interfaces in this FIB / clean out intfc routes */
2276 pool_foreach (si, im->sw_interfaces,
2278 u32 sw_if_index = si->sw_if_index;
2280 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2281 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2283 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2286 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2287 sw_if_index = sw_if_indices_to_shut[i];
2288 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2290 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2291 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2292 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2295 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
2296 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
2300 })); /* pool_foreach (fib) */
2308 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2310 vnet_main_t *vnm = vnet_get_main ();
2311 vnet_interface_main_t *im = &vnm->interface_main;
2312 ip6_main_t *im6 = &ip6_main;
2313 stats_main_t *sm = &stats_main;
2314 static u32 *sw_if_indices_to_shut;
2315 fib_table_t *fib_table;
2319 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2320 u32 target_fib_id = ntohl (mp->vrf_id);
2322 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
2325 pool_foreach (fib_table, im6->fibs,
2327 vnet_sw_interface_t * si;
2328 fib = &(fib_table->v6);
2330 if (fib->table_id != target_fib_id)
2333 vec_reset_length (sw_if_indices_to_shut);
2335 /* Shut down interfaces in this FIB / clean out intfc routes */
2336 pool_foreach (si, im->sw_interfaces,
2338 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2340 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2343 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2344 sw_if_index = sw_if_indices_to_shut[i];
2345 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2347 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2348 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2349 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2352 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
2353 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
2357 })); /* pool_foreach (fib) */
2365 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2368 vl_api_reset_fib_reply_t *rmp;
2371 rv = ip6_reset_fib_t_handler (mp);
2373 rv = ip4_reset_fib_t_handler (mp);
2375 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
2380 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2382 vl_api_dhcp_proxy_config_reply_t *rmp;
2385 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
2386 (ip4_address_t *) (&mp->dhcp_src_address),
2387 (u32) ntohl (mp->vrf_id),
2388 (int) mp->insert_circuit_id,
2389 (int) (mp->is_add == 0));
2391 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2396 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2398 vl_api_dhcp_proxy_config_reply_t *rmp;
2401 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
2402 (ip6_address_t *) (&mp->dhcp_src_address),
2403 (u32) ntohl (mp->vrf_id),
2404 (int) mp->insert_circuit_id,
2405 (int) (mp->is_add == 0));
2407 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2411 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2413 vl_api_dhcp_proxy_config_reply_t *rmp;
2416 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
2417 (ip4_address_t *) (&mp->dhcp_src_address),
2418 (u32) ntohl (mp->rx_vrf_id),
2419 (u32) ntohl (mp->server_vrf_id),
2420 (int) mp->insert_circuit_id,
2421 (int) (mp->is_add == 0));
2423 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2428 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2430 vl_api_dhcp_proxy_config_reply_t *rmp;
2433 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
2434 (ip6_address_t *) (&mp->dhcp_src_address),
2435 (u32) ntohl (mp->rx_vrf_id),
2436 (u32) ntohl (mp->server_vrf_id),
2437 (int) mp->insert_circuit_id,
2438 (int) (mp->is_add == 0));
2440 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2445 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
2447 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2450 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
2453 (int) mp->is_add == 0);
2455 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
2457 ntohl (mp->fib_id), (int) mp->is_add == 0);
2459 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
2463 static void vl_api_dhcp_proxy_config_t_handler
2464 (vl_api_dhcp_proxy_config_t * mp)
2466 if (mp->is_ipv6 == 0)
2467 dhcpv4_proxy_config (mp);
2469 dhcpv6_proxy_config (mp);
2472 static void vl_api_dhcp_proxy_config_2_t_handler
2473 (vl_api_dhcp_proxy_config_2_t * mp)
2475 if (mp->is_ipv6 == 0)
2476 dhcpv4_proxy_config_2 (mp);
2478 dhcpv6_proxy_config_2 (mp);
2482 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2483 u8 is_ipv6, u8 * host_address, u8 * router_address,
2486 unix_shared_memory_queue_t *q;
2487 vl_api_dhcp_compl_event_t *mp;
2489 q = vl_api_client_index_to_input_queue (client_index);
2493 mp = vl_msg_api_alloc (sizeof (*mp));
2494 mp->client_index = client_index;
2496 mp->is_ipv6 = is_ipv6;
2497 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
2498 mp->hostname[vec_len (hostname) + 1] = '\n';
2499 clib_memcpy (&mp->host_address[0], host_address, 16);
2500 clib_memcpy (&mp->router_address[0], router_address, 16);
2502 if (NULL != host_mac)
2503 clib_memcpy (&mp->host_mac[0], host_mac, 6);
2505 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2507 vl_msg_api_send_shmem (q, (u8 *) & mp);
2510 static void vl_api_dhcp_client_config_t_handler
2511 (vl_api_dhcp_client_config_t * mp)
2513 vlib_main_t *vm = vlib_get_main ();
2514 vl_api_dhcp_client_config_reply_t *rmp;
2517 VALIDATE_SW_IF_INDEX (mp);
2519 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
2520 mp->hostname, mp->is_add, mp->client_index,
2521 mp->want_dhcp_event ? dhcp_compl_event_callback :
2524 BAD_SW_IF_INDEX_LABEL;
2526 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
2530 vl_api_sw_interface_ip6nd_ra_config_t_handler
2531 (vl_api_sw_interface_ip6nd_ra_config_t * mp)
2533 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
2534 vlib_main_t *vm = vlib_get_main ();
2536 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
2539 is_no = mp->is_no == 1;
2540 suppress = mp->suppress == 1;
2541 managed = mp->managed == 1;
2542 other = mp->other == 1;
2543 ll_option = mp->ll_option == 1;
2544 send_unicast = mp->send_unicast == 1;
2545 cease = mp->cease == 1;
2546 default_router = mp->default_router == 1;
2548 VALIDATE_SW_IF_INDEX (mp);
2550 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
2551 suppress, managed, other,
2552 ll_option, send_unicast, cease,
2553 default_router, ntohl (mp->lifetime),
2554 ntohl (mp->initial_count),
2555 ntohl (mp->initial_interval),
2556 ntohl (mp->max_interval),
2557 ntohl (mp->min_interval), is_no);
2559 BAD_SW_IF_INDEX_LABEL;
2561 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2565 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2566 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp)
2568 vlib_main_t *vm = vlib_get_main ();
2569 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
2571 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
2573 VALIDATE_SW_IF_INDEX (mp);
2575 is_no = mp->is_no == 1;
2576 use_default = mp->use_default == 1;
2577 no_advertise = mp->no_advertise == 1;
2578 off_link = mp->off_link == 1;
2579 no_autoconfig = mp->no_autoconfig == 1;
2580 no_onlink = mp->no_onlink == 1;
2582 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
2583 (ip6_address_t *) mp->address,
2584 mp->address_length, use_default,
2585 ntohl (mp->val_lifetime),
2586 ntohl (mp->pref_lifetime), no_advertise,
2587 off_link, no_autoconfig, no_onlink, is_no);
2589 BAD_SW_IF_INDEX_LABEL;
2590 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
2594 vl_api_sw_interface_ip6_enable_disable_t_handler
2595 (vl_api_sw_interface_ip6_enable_disable_t * mp)
2597 vlib_main_t *vm = vlib_get_main ();
2598 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
2599 vnet_main_t *vnm = vnet_get_main ();
2601 clib_error_t *error;
2605 VALIDATE_SW_IF_INDEX (mp);
2608 (mp->enable == 1) ? enable_ip6_interface (vm,
2609 ntohl (mp->sw_if_index)) :
2610 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
2614 clib_error_report (error);
2615 rv = VNET_API_ERROR_UNSPECIFIED;
2619 rv = vnm->api_errno;
2622 BAD_SW_IF_INDEX_LABEL;
2624 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
2628 vl_api_sw_interface_ip6_set_link_local_address_t_handler
2629 (vl_api_sw_interface_ip6_set_link_local_address_t * mp)
2631 vlib_main_t *vm = vlib_get_main ();
2632 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
2634 clib_error_t *error;
2635 vnet_main_t *vnm = vnet_get_main ();
2639 VALIDATE_SW_IF_INDEX (mp);
2641 error = set_ip6_link_local_address (vm,
2642 ntohl (mp->sw_if_index),
2643 (ip6_address_t *) mp->address,
2644 mp->address_length);
2647 clib_error_report (error);
2648 rv = VNET_API_ERROR_UNSPECIFIED;
2652 rv = vnm->api_errno;
2655 BAD_SW_IF_INDEX_LABEL;
2657 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
2661 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
2663 vl_api_set_ip_flow_hash_reply_t *rmp;
2664 int rv = VNET_API_ERROR_UNIMPLEMENTED;
2666 clib_warning ("unimplemented...");
2668 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
2672 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
2674 vl_api_set_ip_flow_hash_reply_t *rmp;
2677 flow_hash_config_t flow_hash_config = 0;
2679 table_id = ntohl (mp->vrf_id);
2681 #define _(a,b) if (mp->a) flow_hash_config |= b;
2682 foreach_flow_hash_bit;
2685 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
2687 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
2692 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
2694 if (mp->is_ipv6 == 0)
2695 set_ip4_flow_hash (mp);
2697 set_ip6_flow_hash (mp);
2701 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
2703 vl_api_create_loopback_reply_t *rmp;
2707 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
2710 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
2712 rmp->sw_if_index = ntohl (sw_if_index);
2718 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
2720 vl_api_delete_loopback_reply_t *rmp;
2724 sw_if_index = ntohl (mp->sw_if_index);
2725 rv = vnet_delete_loopback_interface (sw_if_index);
2727 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
2731 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
2733 vl_api_control_ping_reply_t *rmp;
2737 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
2739 rmp->vpe_pid = ntohl (getpid());
2745 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2747 u8 **shmem_vecp = (u8 **) arg;
2750 api_main_t *am = &api_main;
2753 shmem_vec = *shmem_vecp;
2755 offset = vec_len (shmem_vec);
2757 pthread_mutex_lock (&am->vlib_rp->mutex);
2758 oldheap = svm_push_data_heap (am->vlib_rp);
2760 vec_validate (shmem_vec, offset + buffer_bytes - 1);
2762 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
2764 svm_pop_heap (oldheap);
2765 pthread_mutex_unlock (&am->vlib_rp->mutex);
2767 *shmem_vecp = shmem_vec;
2772 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
2774 vl_api_cli_reply_t *rp;
2775 unix_shared_memory_queue_t *q;
2776 vlib_main_t *vm = vlib_get_main ();
2777 api_main_t *am = &api_main;
2778 unformat_input_t input;
2782 q = vl_api_client_index_to_input_queue (mp->client_index);
2786 rp = vl_msg_api_alloc (sizeof (*rp));
2787 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
2788 rp->context = mp->context;
2790 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
2792 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
2794 pthread_mutex_lock (&am->vlib_rp->mutex);
2795 oldheap = svm_push_data_heap (am->vlib_rp);
2797 vec_add1 (shmem_vec, 0);
2799 svm_pop_heap (oldheap);
2800 pthread_mutex_unlock (&am->vlib_rp->mutex);
2802 rp->reply_in_shmem = (uword) shmem_vec;
2804 vl_msg_api_send_shmem (q, (u8 *) & rp);
2808 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2810 u8 **mem_vecp = (u8 **) arg;
2811 u8 *mem_vec = *mem_vecp;
2812 u32 offset = vec_len (mem_vec);
2814 vec_validate (mem_vec, offset + buffer_bytes - 1);
2815 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
2816 *mem_vecp = mem_vec;
2820 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
2822 vl_api_cli_inband_reply_t *rmp;
2824 unix_shared_memory_queue_t *q;
2825 vlib_main_t *vm = vlib_get_main ();
2826 unformat_input_t input;
2829 q = vl_api_client_index_to_input_queue (mp->client_index);
2833 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
2834 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
2836 u32 len = vec_len (out_vec);
2838 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
2840 rmp->length = htonl (len);
2841 clib_memcpy (rmp->reply, out_vec, len);
2848 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2851 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2852 vnet_main_t *vnm = vnet_get_main ();
2853 clib_error_t *error;
2858 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2860 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2864 clib_error_report (error);
2865 rv = VNET_API_ERROR_UNSPECIFIED;
2869 rv = vnm->api_errno;
2872 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2875 static void vl_api_sr_tunnel_add_del_t_handler
2876 (vl_api_sr_tunnel_add_del_t * mp)
2879 clib_warning ("unimplemented");
2881 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
2883 vl_api_sr_tunnel_add_del_reply_t *rmp;
2884 ip6_address_t *segments = 0, *seg;
2885 ip6_address_t *tags = 0, *tag;
2886 ip6_address_t *this_address;
2889 if (mp->n_segments == 0)
2895 memset (a, 0, sizeof (*a));
2896 a->src_address = (ip6_address_t *) & mp->src_address;
2897 a->dst_address = (ip6_address_t *) & mp->dst_address;
2898 a->dst_mask_width = mp->dst_mask_width;
2899 a->flags_net_byte_order = mp->flags_net_byte_order;
2900 a->is_del = (mp->is_add == 0);
2901 a->rx_table_id = ntohl (mp->outer_vrf_id);
2902 a->tx_table_id = ntohl (mp->inner_vrf_id);
2904 a->name = format (0, "%s", mp->name);
2905 if (!(vec_len (a->name)))
2908 a->policy_name = format (0, "%s", mp->policy_name);
2909 if (!(vec_len (a->policy_name)))
2912 /* Yank segments and tags out of the API message */
2913 this_address = (ip6_address_t *) mp->segs_and_tags;
2914 for (i = 0; i < mp->n_segments; i++)
2916 vec_add2 (segments, seg, 1);
2917 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
2920 for (i = 0; i < mp->n_tags; i++)
2922 vec_add2 (tags, tag, 1);
2923 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
2927 a->segments = segments;
2930 rv = ip6_sr_add_del_tunnel (a);
2934 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
2938 static void vl_api_sr_policy_add_del_t_handler
2939 (vl_api_sr_policy_add_del_t * mp)
2942 clib_warning ("unimplemented");
2944 ip6_sr_add_del_policy_args_t _a, *a = &_a;
2946 vl_api_sr_policy_add_del_reply_t *rmp;
2949 memset (a, 0, sizeof (*a));
2950 a->is_del = (mp->is_add == 0);
2952 a->name = format (0, "%s", mp->name);
2953 if (!(vec_len (a->name)))
2955 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2959 if (!(mp->tunnel_names[0]))
2961 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2965 // start deserializing tunnel_names
2966 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
2967 u8 *deser_tun_names = mp->tunnel_names;
2968 deser_tun_names += 1; //moving along
2971 int tun_name_len = 0;
2973 for (i = 0; i < num_tunnels; i++)
2975 tun_name_len = *deser_tun_names;
2976 deser_tun_names += 1;
2977 vec_resize (tun_name, tun_name_len);
2978 memcpy (tun_name, deser_tun_names, tun_name_len);
2979 vec_add1 (a->tunnel_names, tun_name);
2980 deser_tun_names += tun_name_len;
2984 rv = ip6_sr_add_del_policy (a);
2988 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
2992 static void vl_api_sr_multicast_map_add_del_t_handler
2993 (vl_api_sr_multicast_map_add_del_t * mp)
2996 clib_warning ("unimplemented");
2998 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3000 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3002 memset (a, 0, sizeof (*a));
3003 a->is_del = (mp->is_add == 0);
3005 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3006 a->policy_name = format (0, "%s", mp->policy_name);
3008 if (a->multicast_address == 0)
3014 if (!(a->policy_name))
3020 #if DPDK > 0 /* Cannot call replicate without DPDK */
3021 rv = ip6_sr_add_del_multicastmap (a);
3023 clib_warning ("multicast replication without DPDK not implemented");
3024 rv = VNET_API_ERROR_UNIMPLEMENTED;
3029 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3033 #define foreach_classify_add_del_table_field \
3038 _(match_n_vectors) \
3039 _(next_table_index) \
3040 _(miss_next_index) \
3041 _(current_data_flag) \
3042 _(current_data_offset)
3044 static void vl_api_classify_add_del_table_t_handler
3045 (vl_api_classify_add_del_table_t * mp)
3047 vl_api_classify_add_del_table_reply_t *rmp;
3048 vnet_classify_main_t *cm = &vnet_classify_main;
3049 vnet_classify_table_t *t;
3053 foreach_classify_add_del_table_field;
3056 #define _(a) a = ntohl(mp->a);
3057 foreach_classify_add_del_table_field;
3060 /* The underlying API fails silently, on purpose, so check here */
3061 if (mp->is_add == 0) /* delete */
3063 if (pool_is_free_index (cm->tables, table_index))
3065 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3069 else /* add or update */
3071 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
3075 rv = vnet_classify_add_del_table
3076 (cm, mp->mask, nbuckets, memory_size,
3077 skip_n_vectors, match_n_vectors,
3078 next_table_index, miss_next_index, &table_index,
3079 current_data_flag, current_data_offset, mp->is_add);
3083 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3085 if (rv == 0 && mp->is_add)
3087 t = pool_elt_at_index (cm->tables, table_index);
3088 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3089 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3090 rmp->new_table_index = ntohl(table_index);
3094 rmp->skip_n_vectors = ~0;
3095 rmp->match_n_vectors = ~0;
3096 rmp->new_table_index = ~0;
3102 static void vl_api_classify_add_del_session_t_handler
3103 (vl_api_classify_add_del_session_t * mp)
3105 vnet_classify_main_t *cm = &vnet_classify_main;
3106 vl_api_classify_add_del_session_reply_t *rmp;
3108 u32 table_index, hit_next_index, opaque_index, metadata;
3112 table_index = ntohl (mp->table_index);
3113 hit_next_index = ntohl (mp->hit_next_index);
3114 opaque_index = ntohl (mp->opaque_index);
3115 advance = ntohl (mp->advance);
3116 action = mp->action;
3117 metadata = ntohl (mp->metadata);
3119 rv = vnet_classify_add_del_session
3120 (cm, table_index, mp->match, hit_next_index, opaque_index,
3121 advance, action, metadata, mp->is_add);
3123 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3126 static void vl_api_classify_set_interface_ip_table_t_handler
3127 (vl_api_classify_set_interface_ip_table_t * mp)
3129 vlib_main_t *vm = vlib_get_main ();
3130 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3132 u32 table_index, sw_if_index;
3134 table_index = ntohl (mp->table_index);
3135 sw_if_index = ntohl (mp->sw_if_index);
3137 VALIDATE_SW_IF_INDEX (mp);
3140 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3142 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3144 BAD_SW_IF_INDEX_LABEL;
3146 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3149 static void vl_api_classify_set_interface_l2_tables_t_handler
3150 (vl_api_classify_set_interface_l2_tables_t * mp)
3152 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3154 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3157 ip4_table_index = ntohl (mp->ip4_table_index);
3158 ip6_table_index = ntohl (mp->ip6_table_index);
3159 other_table_index = ntohl (mp->other_table_index);
3160 sw_if_index = ntohl (mp->sw_if_index);
3162 VALIDATE_SW_IF_INDEX (mp);
3165 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
3169 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
3175 if (ip4_table_index != ~0 || ip6_table_index != ~0
3176 || other_table_index != ~0)
3182 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
3184 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
3187 BAD_SW_IF_INDEX_LABEL;
3189 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3193 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3196 vl_api_l2_fib_clear_table_reply_t *rmp;
3198 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3199 * that is not currently implemented. When that TODO is fixed
3200 * this call should be changed to pass 1 instead of 0.
3202 l2fib_clear_table (0);
3204 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3207 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3208 u32 sw_if_index, u32 enable);
3211 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3215 vl_api_l2_interface_efp_filter_reply_t *rmp;
3216 vnet_main_t *vnm = vnet_get_main ();
3218 // enable/disable the feature
3219 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3220 rv = vnm->api_errno;
3222 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3226 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3227 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3230 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3231 vnet_main_t *vnm = vnet_get_main ();
3232 vlib_main_t *vm = vlib_get_main ();
3235 VALIDATE_SW_IF_INDEX (mp);
3237 vtr_op = ntohl (mp->vtr_op);
3239 /* The L2 code is unsuspicious */
3242 case L2_VTR_DISABLED:
3247 case L2_VTR_TRANSLATE_1_1:
3248 case L2_VTR_TRANSLATE_1_2:
3249 case L2_VTR_TRANSLATE_2_1:
3250 case L2_VTR_TRANSLATE_2_2:
3254 rv = VNET_API_ERROR_INVALID_VALUE;
3255 goto bad_sw_if_index;
3258 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
3259 ntohl (mp->push_dot1q), ntohl (mp->tag1),
3262 BAD_SW_IF_INDEX_LABEL;
3264 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3268 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
3271 vl_api_create_vhost_user_if_reply_t *rmp;
3272 u32 sw_if_index = (u32) ~ 0;
3273 vnet_main_t *vnm = vnet_get_main ();
3274 vlib_main_t *vm = vlib_get_main ();
3276 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
3277 mp->is_server, &sw_if_index, (u64) ~ 0,
3278 mp->renumber, ntohl (mp->custom_dev_instance),
3279 (mp->use_custom_mac) ? mp->mac_address : NULL);
3281 /* Remember an interface tag for the new interface */
3284 /* If a tag was supplied... */
3287 /* Make sure it's a proper C-string */
3288 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
3289 u8 *tag = format (0, "%s%c", mp->tag, 0);
3290 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
3295 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3297 rmp->sw_if_index = ntohl (sw_if_index);
3303 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
3306 vl_api_modify_vhost_user_if_reply_t *rmp;
3307 u32 sw_if_index = ntohl (mp->sw_if_index);
3309 vnet_main_t *vnm = vnet_get_main ();
3310 vlib_main_t *vm = vlib_get_main ();
3312 rv = vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
3313 mp->is_server, sw_if_index, (u64) ~ 0,
3314 mp->renumber, ntohl (mp->custom_dev_instance));
3316 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
3320 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
3323 vl_api_delete_vhost_user_if_reply_t *rmp;
3324 vpe_api_main_t *vam = &vpe_api_main;
3325 u32 sw_if_index = ntohl (mp->sw_if_index);
3327 vnet_main_t *vnm = vnet_get_main ();
3328 vlib_main_t *vm = vlib_get_main ();
3330 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
3332 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
3335 unix_shared_memory_queue_t *q =
3336 vl_api_client_index_to_input_queue (mp->client_index);
3340 vnet_clear_sw_interface_tag (vnm, sw_if_index);
3341 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3346 vl_api_sw_interface_vhost_user_details_t_handler
3347 (vl_api_sw_interface_vhost_user_details_t * mp)
3349 clib_warning ("BUG");
3353 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3354 unix_shared_memory_queue_t * q,
3355 vhost_user_intf_details_t * vui,
3358 vl_api_sw_interface_vhost_user_details_t *mp;
3360 mp = vl_msg_api_alloc (sizeof (*mp));
3361 memset (mp, 0, sizeof (*mp));
3362 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3363 mp->sw_if_index = ntohl (vui->sw_if_index);
3364 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3365 mp->features = clib_net_to_host_u64 (vui->features);
3366 mp->is_server = vui->is_server;
3367 mp->num_regions = ntohl (vui->num_regions);
3368 mp->sock_errno = ntohl (vui->sock_errno);
3369 mp->context = context;
3371 strncpy ((char *) mp->sock_filename,
3372 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
3373 strncpy ((char *) mp->interface_name,
3374 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
3376 vl_msg_api_send_shmem (q, (u8 *) & mp);
3380 vl_api_sw_interface_vhost_user_dump_t_handler
3381 (vl_api_sw_interface_vhost_user_dump_t * mp)
3384 vpe_api_main_t *am = &vpe_api_main;
3385 vnet_main_t *vnm = vnet_get_main ();
3386 vlib_main_t *vm = vlib_get_main ();
3387 vhost_user_intf_details_t *ifaces = NULL;
3388 vhost_user_intf_details_t *vuid = NULL;
3389 unix_shared_memory_queue_t *q;
3391 q = vl_api_client_index_to_input_queue (mp->client_index);
3395 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
3399 vec_foreach (vuid, ifaces)
3401 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3407 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3408 unix_shared_memory_queue_t * q,
3410 l2t_main_t * lm, u32 context)
3412 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
3414 vnet_sw_interface_t *si = NULL;
3416 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3418 if_name = format (if_name, "%U",
3419 format_vnet_sw_interface_name, lm->vnet_main, si);
3421 mp = vl_msg_api_alloc (sizeof (*mp));
3422 memset (mp, 0, sizeof (*mp));
3423 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3424 strncpy ((char *) mp->interface_name,
3425 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
3426 mp->sw_if_index = ntohl (si->sw_if_index);
3427 mp->local_session_id = s->local_session_id;
3428 mp->remote_session_id = s->remote_session_id;
3429 mp->local_cookie[0] = s->local_cookie[0];
3430 mp->local_cookie[1] = s->local_cookie[1];
3431 mp->remote_cookie = s->remote_cookie;
3432 clib_memcpy (mp->client_address, &s->client_address,
3433 sizeof (s->client_address));
3434 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
3435 mp->l2_sublayer_present = s->l2_sublayer_present;
3436 mp->context = context;
3438 vl_msg_api_send_shmem (q, (u8 *) & mp);
3442 send_ip_address_details (vpe_api_main_t * am,
3443 unix_shared_memory_queue_t * q,
3444 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
3446 vl_api_ip_address_details_t *mp;
3448 mp = vl_msg_api_alloc (sizeof (*mp));
3449 memset (mp, 0, sizeof (*mp));
3450 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
3454 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
3458 u32 *tp = (u32 *) mp->ip;
3461 mp->prefix_length = prefix_length;
3462 mp->context = context;
3464 vl_msg_api_send_shmem (q, (u8 *) & mp);
3468 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
3470 vpe_api_main_t *am = &vpe_api_main;
3471 unix_shared_memory_queue_t *q;
3474 ip6_main_t *im6 = &ip6_main;
3475 ip4_main_t *im4 = &ip4_main;
3476 ip_lookup_main_t *lm6 = &im6->lookup_main;
3477 ip_lookup_main_t *lm4 = &im4->lookup_main;
3478 ip_interface_address_t *ia = 0;
3479 u32 sw_if_index = ~0;
3480 int rv __attribute__ ((unused)) = 0;
3482 VALIDATE_SW_IF_INDEX (mp);
3484 sw_if_index = ntohl (mp->sw_if_index);
3486 q = vl_api_client_index_to_input_queue (mp->client_index);
3495 foreach_ip_interface_address (lm6, ia, sw_if_index,
3496 1 /* honor unnumbered */,
3498 r6 = ip_interface_address_get_address (lm6, ia);
3499 u16 prefix_length = ia->address_length;
3500 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3507 foreach_ip_interface_address (lm4, ia, sw_if_index,
3508 1 /* honor unnumbered */,
3510 r4 = ip_interface_address_get_address (lm4, ia);
3511 u16 prefix_length = ia->address_length;
3512 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3516 BAD_SW_IF_INDEX_LABEL;
3520 send_ip_details (vpe_api_main_t * am,
3521 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
3523 vl_api_ip_details_t *mp;
3525 mp = vl_msg_api_alloc (sizeof (*mp));
3526 memset (mp, 0, sizeof (*mp));
3527 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
3529 mp->sw_if_index = ntohl (sw_if_index);
3530 mp->context = context;
3532 vl_msg_api_send_shmem (q, (u8 *) & mp);
3536 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
3539 vpe_api_main_t *am = &vpe_api_main;
3540 l2t_main_t *lm = &l2t_main;
3541 unix_shared_memory_queue_t *q;
3542 l2t_session_t *session;
3544 q = vl_api_client_index_to_input_queue (mp->client_index);
3549 pool_foreach (session, lm->sessions,
3551 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
3558 send_sw_interface_tap_details (vpe_api_main_t * am,
3559 unix_shared_memory_queue_t * q,
3560 tapcli_interface_details_t * tap_if,
3563 vl_api_sw_interface_tap_details_t *mp;
3564 mp = vl_msg_api_alloc (sizeof (*mp));
3565 memset (mp, 0, sizeof (*mp));
3566 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
3567 mp->sw_if_index = ntohl (tap_if->sw_if_index);
3568 strncpy ((char *) mp->dev_name,
3569 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
3570 mp->context = context;
3572 vl_msg_api_send_shmem (q, (u8 *) & mp);
3576 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
3579 vpe_api_main_t *am = &vpe_api_main;
3580 unix_shared_memory_queue_t *q;
3581 tapcli_interface_details_t *tapifs = NULL;
3582 tapcli_interface_details_t *tap_if = NULL;
3584 q = vl_api_client_index_to_input_queue (mp->client_index);
3588 rv = vnet_tap_dump_ifs (&tapifs);
3592 vec_foreach (tap_if, tapifs)
3594 send_sw_interface_tap_details (am, q, tap_if, mp->context);
3601 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
3603 vpe_api_main_t *am = &vpe_api_main;
3604 vnet_main_t *vnm = vnet_get_main ();
3605 vlib_main_t *vm = vlib_get_main ();
3606 vnet_interface_main_t *im = &vnm->interface_main;
3607 unix_shared_memory_queue_t *q;
3608 vnet_sw_interface_t *si, *sorted_sis;
3609 u32 sw_if_index = ~0;
3611 q = vl_api_client_index_to_input_queue (mp->client_index);
3617 /* Gather interfaces. */
3618 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3619 _vec_len (sorted_sis) = 0;
3621 pool_foreach (si, im->sw_interfaces,
3623 vec_add1 (sorted_sis, si[0]);
3627 vec_foreach (si, sorted_sis)
3629 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
3631 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
3635 sw_if_index = si->sw_if_index;
3636 send_ip_details (am, q, sw_if_index, mp->context);
3642 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
3644 clib_warning ("BUG");
3648 send_l2fib_table_entry (vpe_api_main_t * am,
3649 unix_shared_memory_queue_t * q,
3650 l2fib_entry_key_t * l2fe_key,
3651 l2fib_entry_result_t * l2fe_res, u32 context)
3653 vl_api_l2_fib_table_entry_t *mp;
3655 mp = vl_msg_api_alloc (sizeof (*mp));
3656 memset (mp, 0, sizeof (*mp));
3657 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
3660 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3662 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3663 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
3664 mp->static_mac = l2fe_res->fields.static_mac;
3665 mp->filter_mac = l2fe_res->fields.filter;
3666 mp->bvi_mac = l2fe_res->fields.bvi;
3667 mp->context = context;
3669 vl_msg_api_send_shmem (q, (u8 *) & mp);
3673 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
3675 vpe_api_main_t *am = &vpe_api_main;
3676 bd_main_t *bdm = &bd_main;
3677 l2fib_entry_key_t *l2fe_key = NULL;
3678 l2fib_entry_result_t *l2fe_res = NULL;
3679 u32 ni, bd_id = ntohl (mp->bd_id);
3681 unix_shared_memory_queue_t *q;
3684 q = vl_api_client_index_to_input_queue (mp->client_index);
3688 /* see l2fib_table_dump: ~0 means "any" */
3693 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3700 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3702 vec_foreach_index (ni, l2fe_key)
3704 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
3705 vec_elt_at_index (l2fe_res, ni), mp->context);
3707 vec_free (l2fe_key);
3708 vec_free (l2fe_res);
3712 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
3714 vl_api_show_version_reply_t *rmp;
3716 char *vpe_api_get_build_directory (void);
3717 char *vpe_api_get_version (void);
3718 char *vpe_api_get_build_date (void);
3720 unix_shared_memory_queue_t *q =
3721 vl_api_client_index_to_input_queue (mp->client_index);
3727 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3729 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3730 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3731 ARRAY_LEN(rmp->build_directory)-1);
3732 strncpy ((char *) rmp->version, vpe_api_get_version(),
3733 ARRAY_LEN(rmp->version)-1);
3734 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3735 ARRAY_LEN(rmp->build_date)-1);
3741 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
3743 vlib_main_t *vm = vlib_get_main ();
3744 vl_api_get_node_index_reply_t *rmp;
3747 u32 node_index = ~0;
3749 n = vlib_get_node_by_name (vm, mp->node_name);
3752 rv = VNET_API_ERROR_NO_SUCH_NODE;
3754 node_index = n->index;
3757 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3759 rmp->node_index = ntohl(node_index);
3765 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
3767 vlib_main_t *vm = vlib_get_main ();
3768 vl_api_get_next_index_reply_t *rmp;
3769 vlib_node_t *node, *next_node;
3771 u32 next_node_index = ~0, next_index = ~0;
3774 node = vlib_get_node_by_name (vm, mp->node_name);
3778 rv = VNET_API_ERROR_NO_SUCH_NODE;
3782 next_node = vlib_get_node_by_name (vm, mp->next_name);
3786 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3790 next_node_index = next_node->index;
3792 p = hash_get (node->next_slot_by_node, next_node_index);
3796 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
3804 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
3806 rmp->next_index = ntohl(next_index);
3812 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
3814 vlib_main_t *vm = vlib_get_main ();
3815 vl_api_add_node_next_reply_t *rmp;
3816 vlib_node_t *n, *next;
3818 u32 next_index = ~0;
3820 n = vlib_get_node_by_name (vm, mp->node_name);
3824 rv = VNET_API_ERROR_NO_SUCH_NODE;
3828 next = vlib_get_node_by_name (vm, mp->next_name);
3831 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3833 next_index = vlib_node_add_next (vm, n->index, next->index);
3837 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3839 rmp->next_index = ntohl(next_index);
3844 static void vl_api_l2tpv3_create_tunnel_t_handler
3845 (vl_api_l2tpv3_create_tunnel_t * mp)
3847 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
3848 l2t_main_t *lm = &l2t_main;
3849 u32 sw_if_index = (u32) ~ 0;
3852 if (mp->is_ipv6 != 1)
3854 rv = VNET_API_ERROR_UNIMPLEMENTED;
3858 u32 encap_fib_index;
3860 if (mp->encap_vrf_id != ~0)
3863 ip6_main_t *im = &ip6_main;
3866 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
3868 rv = VNET_API_ERROR_NO_SUCH_FIB;
3871 encap_fib_index = p[0];
3875 encap_fib_index = ~0;
3878 rv = create_l2tpv3_ipv6_tunnel (lm,
3879 (ip6_address_t *) mp->client_address,
3880 (ip6_address_t *) mp->our_address,
3881 ntohl (mp->local_session_id),
3882 ntohl (mp->remote_session_id),
3883 clib_net_to_host_u64 (mp->local_cookie),
3884 clib_net_to_host_u64 (mp->remote_cookie),
3885 mp->l2_sublayer_present,
3886 encap_fib_index, &sw_if_index);
3890 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
3892 rmp->sw_if_index = ntohl (sw_if_index);
3897 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
3898 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
3900 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
3901 l2t_main_t *lm = &l2t_main;
3904 VALIDATE_SW_IF_INDEX (mp);
3906 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
3907 clib_net_to_host_u64 (mp->new_local_cookie),
3908 clib_net_to_host_u64
3909 (mp->new_remote_cookie));
3911 BAD_SW_IF_INDEX_LABEL;
3913 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
3916 static void vl_api_l2tpv3_interface_enable_disable_t_handler
3917 (vl_api_l2tpv3_interface_enable_disable_t * mp)
3920 vnet_main_t *vnm = vnet_get_main ();
3921 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
3923 VALIDATE_SW_IF_INDEX (mp);
3925 rv = l2tpv3_interface_enable_disable
3926 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
3928 BAD_SW_IF_INDEX_LABEL;
3930 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
3933 static void vl_api_l2tpv3_set_lookup_key_t_handler
3934 (vl_api_l2tpv3_set_lookup_key_t * mp)
3937 l2t_main_t *lm = &l2t_main;
3938 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
3940 if (mp->key > L2T_LOOKUP_SESSION_ID)
3942 rv = VNET_API_ERROR_INVALID_VALUE;
3946 lm->lookup_type = mp->key;
3949 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
3952 static void vl_api_vxlan_add_del_tunnel_t_handler
3953 (vl_api_vxlan_add_del_tunnel_t * mp)
3955 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
3957 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
3958 u32 encap_fib_index;
3960 ip4_main_t *im = &ip4_main;
3961 u32 sw_if_index = ~0;
3963 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
3966 rv = VNET_API_ERROR_NO_SUCH_FIB;
3969 encap_fib_index = p[0];
3970 memset (a, 0, sizeof (*a));
3972 a->is_add = mp->is_add;
3973 a->is_ip6 = mp->is_ipv6;
3975 /* ip addresses sent in network byte order */
3976 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
3977 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
3979 /* Check src & dst are different */
3980 if (ip46_address_cmp (&a->dst, &a->src) == 0)
3982 rv = VNET_API_ERROR_SAME_SRC_DST;
3985 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
3986 a->encap_fib_index = encap_fib_index;
3987 a->decap_next_index = ntohl (mp->decap_next_index);
3988 a->vni = ntohl (mp->vni);
3989 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
3993 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
3995 rmp->sw_if_index = ntohl (sw_if_index);
4000 static void send_vxlan_tunnel_details
4001 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4003 vl_api_vxlan_tunnel_details_t *rmp;
4004 ip4_main_t *im4 = &ip4_main;
4005 ip6_main_t *im6 = &ip6_main;
4006 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
4008 rmp = vl_msg_api_alloc (sizeof (*rmp));
4009 memset (rmp, 0, sizeof (*rmp));
4010 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4013 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
4014 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
4015 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4019 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
4020 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
4021 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4023 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
4024 rmp->vni = htonl (t->vni);
4025 rmp->decap_next_index = htonl (t->decap_next_index);
4026 rmp->sw_if_index = htonl (t->sw_if_index);
4027 rmp->is_ipv6 = is_ipv6;
4028 rmp->context = context;
4030 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4033 static void vl_api_vxlan_tunnel_dump_t_handler
4034 (vl_api_vxlan_tunnel_dump_t * mp)
4036 unix_shared_memory_queue_t *q;
4037 vxlan_main_t *vxm = &vxlan_main;
4041 q = vl_api_client_index_to_input_queue (mp->client_index);
4047 sw_if_index = ntohl (mp->sw_if_index);
4049 if (~0 == sw_if_index)
4052 pool_foreach (t, vxm->tunnels,
4054 send_vxlan_tunnel_details(t, q, mp->context);
4060 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4061 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4065 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4066 send_vxlan_tunnel_details (t, q, mp->context);
4070 static void vl_api_gre_add_del_tunnel_t_handler
4071 (vl_api_gre_add_del_tunnel_t * mp)
4073 vl_api_gre_add_del_tunnel_reply_t *rmp;
4075 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4078 ip4_main_t *im = &ip4_main;
4079 u32 sw_if_index = ~0;
4081 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4084 rv = VNET_API_ERROR_NO_SUCH_FIB;
4087 outer_fib_id = p[0];
4089 /* Check src & dst are different */
4090 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4091 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4093 rv = VNET_API_ERROR_SAME_SRC_DST;
4096 memset (a, 0, sizeof (*a));
4098 a->is_add = mp->is_add;
4101 /* ip addresses sent in network byte order */
4102 clib_memcpy (&(a->src), mp->src_address, 4);
4103 clib_memcpy (&(a->dst), mp->dst_address, 4);
4105 a->outer_fib_id = outer_fib_id;
4106 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4110 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4112 rmp->sw_if_index = ntohl (sw_if_index);
4117 static void send_gre_tunnel_details
4118 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4120 vl_api_gre_tunnel_details_t *rmp;
4121 ip4_main_t *im = &ip4_main;
4123 rmp = vl_msg_api_alloc (sizeof (*rmp));
4124 memset (rmp, 0, sizeof (*rmp));
4125 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4126 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4127 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4128 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4129 rmp->teb = (GRE_TUNNEL_TYPE_TEB == t->type);
4130 rmp->sw_if_index = htonl (t->sw_if_index);
4131 rmp->context = context;
4133 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4137 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4139 unix_shared_memory_queue_t *q;
4140 gre_main_t *gm = &gre_main;
4144 q = vl_api_client_index_to_input_queue (mp->client_index);
4150 sw_if_index = ntohl (mp->sw_if_index);
4152 if (~0 == sw_if_index)
4155 pool_foreach (t, gm->tunnels,
4157 send_gre_tunnel_details(t, q, mp->context);
4163 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4164 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4168 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4169 send_gre_tunnel_details (t, q, mp->context);
4174 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4176 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4178 vl_api_l2_patch_add_del_reply_t *rmp;
4179 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4183 VALIDATE_RX_SW_IF_INDEX (mp);
4184 VALIDATE_TX_SW_IF_INDEX (mp);
4186 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4187 ntohl (mp->tx_sw_if_index),
4188 (int) (mp->is_add != 0));
4190 BAD_RX_SW_IF_INDEX_LABEL;
4191 BAD_TX_SW_IF_INDEX_LABEL;
4193 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4197 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4198 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4200 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4202 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4203 u32 encap_fib_index, decap_fib_index;
4206 ip4_main_t *im = &ip4_main;
4207 u32 sw_if_index = ~0;
4210 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4213 rv = VNET_API_ERROR_NO_SUCH_FIB;
4216 encap_fib_index = p[0];
4218 protocol = mp->protocol;
4220 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4221 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4223 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4226 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4229 decap_fib_index = p[0];
4233 decap_fib_index = ntohl (mp->decap_vrf_id);
4236 /* Check src & dst are different */
4237 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4238 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
4240 rv = VNET_API_ERROR_SAME_SRC_DST;
4243 memset (a, 0, sizeof (*a));
4245 a->is_add = mp->is_add;
4246 a->is_ip6 = mp->is_ipv6;
4247 /* ip addresses sent in network byte order */
4250 clib_memcpy (&(a->local.ip6), mp->local, 16);
4251 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
4255 clib_memcpy (&(a->local.ip4), mp->local, 4);
4256 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
4258 a->encap_fib_index = encap_fib_index;
4259 a->decap_fib_index = decap_fib_index;
4260 a->protocol = protocol;
4261 a->vni = ntohl (mp->vni);
4262 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4266 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4268 rmp->sw_if_index = ntohl (sw_if_index);
4273 static void send_vxlan_gpe_tunnel_details
4274 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4276 vl_api_vxlan_gpe_tunnel_details_t *rmp;
4277 ip4_main_t *im4 = &ip4_main;
4278 ip6_main_t *im6 = &ip6_main;
4279 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4281 rmp = vl_msg_api_alloc (sizeof (*rmp));
4282 memset (rmp, 0, sizeof (*rmp));
4283 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4286 memcpy (rmp->local, &(t->local.ip6), 16);
4287 memcpy (rmp->remote, &(t->remote.ip6), 16);
4288 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4289 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
4293 memcpy (rmp->local, &(t->local.ip4), 4);
4294 memcpy (rmp->remote, &(t->remote.ip4), 4);
4295 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4296 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
4298 rmp->vni = htonl (t->vni);
4299 rmp->protocol = t->protocol;
4300 rmp->sw_if_index = htonl (t->sw_if_index);
4301 rmp->is_ipv6 = is_ipv6;
4302 rmp->context = context;
4304 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4307 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4308 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4310 unix_shared_memory_queue_t *q;
4311 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
4312 vxlan_gpe_tunnel_t *t;
4315 q = vl_api_client_index_to_input_queue (mp->client_index);
4321 sw_if_index = ntohl (mp->sw_if_index);
4323 if (~0 == sw_if_index)
4326 pool_foreach (t, vgm->tunnels,
4328 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4334 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
4335 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
4339 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4340 send_vxlan_gpe_tunnel_details (t, q, mp->context);
4344 /** Used for transferring locators via VPP API */
4346 typedef CLIB_PACKED (struct {
4347 u32 sw_if_index; /**< locator sw_if_index */
4348 u8 priority; /**< locator priority */
4349 u8 weight; /**< locator weight */
4354 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
4357 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4359 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4361 ls_locator_t *ls_loc;
4362 u32 ls_index = ~0, locator_num;
4363 u8 *locator_name = NULL;
4366 memset (a, 0, sizeof (a[0]));
4368 locator_name = format (0, "%s", mp->locator_set_name);
4370 a->name = locator_name;
4371 a->is_add = mp->is_add;
4373 locator_num = clib_net_to_host_u32 (mp->locator_num);
4375 memset (&locator, 0, sizeof (locator));
4376 for (i = 0; i < locator_num; i++)
4378 ls_loc = &((ls_locator_t *) mp->locators)[i];
4379 VALIDATE_SW_IF_INDEX (ls_loc);
4381 locator.sw_if_index = htonl (ls_loc->sw_if_index);
4382 locator.priority = ls_loc->priority;
4383 locator.weight = ls_loc->weight;
4385 vec_add1 (a->locators, locator);
4388 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
4390 BAD_SW_IF_INDEX_LABEL;
4392 vec_free (locator_name);
4393 vec_free (a->locators);
4396 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
4398 rmp->ls_index = clib_host_to_net_u32 (ls_index);
4404 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
4406 vl_api_lisp_add_del_locator_reply_t *rmp;
4408 locator_t locator, *locators = NULL;
4409 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4411 u8 *locator_name = NULL;
4413 memset (&locator, 0, sizeof (locator));
4414 memset (a, 0, sizeof (a[0]));
4416 locator.sw_if_index = ntohl (mp->sw_if_index);
4417 locator.priority = mp->priority;
4418 locator.weight = mp->weight;
4420 vec_add1 (locators, locator);
4422 locator_name = format (0, "%s", mp->locator_set_name);
4424 a->name = locator_name;
4425 a->locators = locators;
4426 a->is_add = mp->is_add;
4429 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
4431 vec_free (locators);
4432 vec_free (locator_name);
4434 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4438 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
4444 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
4445 gid_address_ip_set (dst, src, IP4);
4446 gid_address_ippref_len (dst) = len;
4447 ip_prefix_normalize (&gid_address_ippref (dst));
4450 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
4451 gid_address_ip_set (dst, src, IP6);
4452 gid_address_ippref_len (dst) = len;
4453 ip_prefix_normalize (&gid_address_ippref (dst));
4455 case 2: /* l2 mac */
4456 gid_address_type (dst) = GID_ADDR_MAC;
4457 clib_memcpy (&gid_address_mac (dst), src, 6);
4461 return VNET_API_ERROR_INVALID_VALUE;
4464 gid_address_vni (dst) = vni;
4470 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
4472 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4473 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4475 gid_address_t _eid, *eid = &_eid;
4477 u32 locator_set_index = ~0, map_index = ~0;
4478 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4479 u8 *name = NULL, *key = NULL;
4480 memset (a, 0, sizeof (a[0]));
4481 memset (eid, 0, sizeof (eid[0]));
4483 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4484 mp->eid_type, mp->eid, mp->prefix_len);
4488 name = format (0, "%s", mp->locator_set_name);
4489 p = hash_get_mem (lcm->locator_set_index_by_name, name);
4492 rv = VNET_API_ERROR_INVALID_VALUE;
4495 locator_set_index = p[0];
4498 key = format (0, "%s", mp->key);
4500 /* XXX treat batch configuration */
4501 a->is_add = mp->is_add;
4502 gid_address_copy (&a->eid, eid);
4503 a->locator_set_index = locator_set_index;
4506 a->key_id = clib_net_to_host_u16 (mp->key_id);
4508 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
4513 gid_address_free (&a->eid);
4515 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4519 vl_api_lisp_eid_table_add_del_map_t_handler
4520 (vl_api_lisp_eid_table_add_del_map_t * mp)
4522 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4524 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4525 clib_net_to_host_u32 (mp->dp_table),
4526 mp->is_l2, mp->is_add);
4527 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
4529 /** Used for transferring locators via VPP API */
4531 typedef CLIB_PACKED (struct {
4532 u8 is_ip4; /**< is locator an IPv4 address */
4533 u8 priority; /**< locator priority */
4534 u8 weight; /**< locator weight */
4535 u8 addr[16]; /**< IPv4/IPv6 address */
4539 static locator_pair_t *
4540 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
4543 locator_pair_t *pairs = 0, pair;
4546 for (i = 0; i < rloc_num; i++)
4549 r = &((rloc_t *) lcl_locs)[i];
4550 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
4551 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
4553 /* remote locators */
4554 r = &((rloc_t *) rmt_locs)[i];
4555 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
4556 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
4558 pair.priority = r->priority;
4559 pair.weight = r->weight;
4561 vec_add1 (pairs, pair);
4567 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
4570 locator_t *locs = 0, loc;
4573 for (i = 0; i < rloc_num; i++)
4575 /* remote locators */
4576 r = &((rloc_t *) rmt_locs)[i];
4577 memset (&loc, 0, sizeof (loc));
4578 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
4580 loc.priority = r->priority;
4581 loc.weight = r->weight;
4583 vec_add1 (locs, loc);
4589 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
4590 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
4592 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4593 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
4594 locator_pair_t *pairs = 0;
4597 memset (a, 0, sizeof (a[0]));
4599 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
4600 mp->rmt_eid, mp->rmt_len);
4601 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
4602 mp->lcl_eid, mp->lcl_len);
4604 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
4606 if (rv || 0 == pairs)
4609 a->is_add = mp->is_add;
4610 a->locator_pairs = pairs;
4611 a->dp_table = mp->dp_table;
4613 a->action = mp->action;
4615 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
4618 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4622 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
4625 vl_api_lisp_add_del_map_server_reply_t *rmp;
4629 memset (&addr, 0, sizeof (addr));
4631 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
4632 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
4634 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
4638 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
4641 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4643 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
4645 memset (a, 0, sizeof (a[0]));
4647 a->is_add = mp->is_add;
4648 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
4650 rv = vnet_lisp_add_del_map_resolver (a);
4652 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4656 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
4659 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4661 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
4663 a->is_en = mp->is_en;
4664 vnet_lisp_gpe_enable_disable (a);
4666 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4670 vl_api_lisp_map_register_enable_disable_t_handler
4671 (vl_api_lisp_map_register_enable_disable_t * mp)
4673 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
4676 vnet_lisp_map_register_enable_disable (mp->is_enabled);
4677 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4681 vl_api_lisp_rloc_probe_enable_disable_t_handler
4682 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
4684 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
4687 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
4688 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4692 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
4694 vl_api_lisp_enable_disable_reply_t *rmp;
4697 vnet_lisp_enable_disable (mp->is_en);
4698 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4702 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
4704 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4712 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
4716 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
4723 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
4727 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
4730 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4734 vl_api_show_lisp_map_request_mode_t_handler
4735 (vl_api_show_lisp_map_request_mode_t * mp)
4738 vl_api_show_lisp_map_request_mode_reply_t *rmp;
4741 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
4743 rmp->mode = vnet_lisp_get_map_request_mode ();
4749 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
4751 vl_api_lisp_map_request_mode_reply_t *rmp;
4754 rv = vnet_lisp_set_map_request_mode (mp->mode);
4756 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
4760 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
4763 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4767 ls_name = format (0, "%s", mp->ls_name);
4768 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4771 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4775 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
4776 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
4778 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
4780 u8 *locator_set_name = NULL;
4781 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
4783 locator_set_name = format (0, "%s", mp->locator_set_name);
4785 a->is_add = mp->is_add;
4786 a->locator_set_name = locator_set_name;
4788 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
4790 vec_free (locator_set_name);
4792 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
4796 vl_api_lisp_add_del_remote_mapping_t_handler
4797 (vl_api_lisp_add_del_remote_mapping_t * mp)
4799 locator_t *rlocs = 0;
4800 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
4802 gid_address_t _eid, *eid = &_eid;
4803 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
4805 memset (eid, 0, sizeof (eid[0]));
4807 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4808 mp->eid_type, mp->eid, mp->eid_len);
4812 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
4816 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
4817 gid_address_copy (&a->reid, eid);
4819 rv = vnet_lisp_add_del_adjacency (a);
4826 /* NOTE: for now this works as a static remote mapping, i.e.,
4827 * not authoritative and ttl infinite. */
4828 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
4829 mp->is_add, 1 /* is_static */ , 0);
4832 vnet_lisp_clear_all_remote_adjacencies ();
4837 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
4841 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
4843 vl_api_lisp_add_del_adjacency_reply_t *rmp;
4844 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
4847 memset (a, 0, sizeof (a[0]));
4849 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
4850 mp->eid_type, mp->leid, mp->leid_len);
4851 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
4852 mp->eid_type, mp->reid, mp->reid_len);
4857 a->is_add = mp->is_add;
4858 rv = vnet_lisp_add_del_adjacency (a);
4861 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
4865 send_lisp_locator_details (lisp_cp_main_t * lcm,
4867 unix_shared_memory_queue_t * q, u32 context)
4869 vl_api_lisp_locator_details_t *rmp;
4871 rmp = vl_msg_api_alloc (sizeof (*rmp));
4872 memset (rmp, 0, sizeof (*rmp));
4873 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
4874 rmp->context = context;
4876 rmp->local = loc->local;
4879 rmp->sw_if_index = ntohl (loc->sw_if_index);
4883 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
4884 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
4886 rmp->priority = loc->priority;
4887 rmp->weight = loc->weight;
4889 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4893 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
4896 unix_shared_memory_queue_t *q = 0;
4897 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4898 locator_set_t *lsit = 0;
4900 u32 ls_index = ~0, *locit = 0;
4903 q = vl_api_client_index_to_input_queue (mp->client_index);
4909 if (mp->is_index_set)
4910 ls_index = htonl (mp->ls_index);
4913 /* make sure we get a proper C-string */
4914 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
4915 ls_name = format (0, "%s", mp->ls_name);
4916 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
4922 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
4925 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
4927 vec_foreach (locit, lsit->locator_indices)
4929 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4930 send_lisp_locator_details (lcm, loc, q, mp->context);
4937 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
4938 locator_set_t * lsit,
4939 unix_shared_memory_queue_t * q,
4940 u32 context, u32 ls_index)
4942 vl_api_lisp_locator_set_details_t *rmp;
4945 rmp = vl_msg_api_alloc (sizeof (*rmp));
4946 memset (rmp, 0, sizeof (*rmp));
4947 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
4948 rmp->context = context;
4950 rmp->ls_index = htonl (ls_index);
4953 ASSERT (lsit->name != NULL);
4954 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
4955 vec_len (lsit->name));
4959 str = format (0, "<remote-%d>", ls_index);
4960 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
4964 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4968 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
4970 unix_shared_memory_queue_t *q = NULL;
4971 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4972 locator_set_t *lsit = NULL;
4975 q = vl_api_client_index_to_input_queue (mp->client_index);
4981 filter = mp->filter;
4983 pool_foreach (lsit, lcm->locator_set_pool,
4985 if (filter && !((1 == filter && lsit->local) ||
4986 (2 == filter && !lsit->local)))
4990 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
4991 lsit - lcm->locator_set_pool);
4997 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
4999 ASSERT (prefix_length);
5000 ip_prefix_t *ippref = &fid_addr_ippref (src);
5002 switch (fid_addr_type (src))
5004 case FID_ADDR_IP_PREF:
5005 if (ip_prefix_version (ippref) == IP4)
5006 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5008 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5009 prefix_length[0] = ip_prefix_len (ippref);
5013 prefix_length[0] = 0;
5014 clib_memcpy (dst, fid_addr_mac (src), 6);
5018 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5024 fid_type_to_api_type (fid_address_t * fid)
5026 ip_prefix_t *ippref;
5028 switch (fid_addr_type (fid))
5030 case FID_ADDR_IP_PREF:
5031 ippref = &fid_addr_ippref (fid);
5032 if (ip_prefix_version (ippref) == IP4)
5034 else if (ip_prefix_version (ippref) == IP6)
5047 send_lisp_eid_table_details (mapping_t * mapit,
5048 unix_shared_memory_queue_t * q,
5049 u32 context, u8 filter)
5052 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5053 locator_set_t *ls = 0;
5054 vl_api_lisp_eid_table_details_t *rmp = NULL;
5055 gid_address_t *gid = NULL;
5057 ip_prefix_t *ip_prefix = NULL;
5061 case 0: /* all mappings */
5064 case 1: /* local only */
5068 case 2: /* remote only */
5073 clib_warning ("Filter error, unknown filter: %d", filter);
5078 ip_prefix = &gid_address_ippref (gid);
5079 mac = gid_address_mac (gid);
5081 rmp = vl_msg_api_alloc (sizeof (*rmp));
5082 memset (rmp, 0, sizeof (*rmp));
5083 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5085 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5086 if (vec_len (ls->locator_indices) == 0)
5087 rmp->locator_set_index = ~0;
5089 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5091 rmp->is_local = mapit->local;
5092 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5093 rmp->action = mapit->action;
5094 rmp->authoritative = mapit->authoritative;
5096 switch (gid_address_type (gid))
5098 case GID_ADDR_SRC_DST:
5099 rmp->is_src_dst = 1;
5100 fid = &gid_address_sd_src (gid);
5101 rmp->eid_type = fid_type_to_api_type (fid);
5102 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5103 &rmp->seid_prefix_len);
5104 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5105 &rmp->eid_prefix_len);
5107 case GID_ADDR_IP_PREFIX:
5108 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5109 if (ip_prefix_version (ip_prefix) == IP4)
5111 rmp->eid_type = 0; /* ipv4 type */
5112 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5113 sizeof (ip_prefix_v4 (ip_prefix)));
5117 rmp->eid_type = 1; /* ipv6 type */
5118 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5119 sizeof (ip_prefix_v6 (ip_prefix)));
5123 rmp->eid_type = 2; /* l2 mac type */
5124 clib_memcpy (rmp->eid, mac, 6);
5129 rmp->context = context;
5130 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5131 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
5132 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
5133 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5137 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5140 unix_shared_memory_queue_t *q = NULL;
5141 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5142 mapping_t *mapit = NULL;
5143 gid_address_t _eid, *eid = &_eid;
5145 q = vl_api_client_index_to_input_queue (mp->client_index);
5153 memset (eid, 0, sizeof (*eid));
5155 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5156 mp->eid_type, mp->eid, mp->prefix_length);
5158 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5159 if ((u32) ~ 0 == mi)
5162 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5163 send_lisp_eid_table_details (mapit, q, mp->context,
5164 0 /* ignore filter */ );
5169 pool_foreach (mapit, lcm->mapping_pool,
5171 send_lisp_eid_table_details(mapit, q, mp->context,
5179 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
5180 unix_shared_memory_queue_t * q, u32 context)
5182 vl_api_lisp_gpe_tunnel_details_t *rmp;
5183 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5185 rmp = vl_msg_api_alloc (sizeof (*rmp));
5186 memset (rmp, 0, sizeof (*rmp));
5187 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5189 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
5191 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
5192 ip_address_copy_addr (rmp->source_ip,
5193 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5194 ip_address_copy_addr (rmp->destination_ip,
5195 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5197 rmp->encap_fib_id = htonl (0);
5198 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
5199 rmp->iid = htonl (lfe->key->vni);
5200 rmp->context = context;
5202 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5206 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5208 unix_shared_memory_queue_t *q = NULL;
5209 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5210 lisp_gpe_fwd_entry_t *lfe = NULL;
5212 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
5217 q = vl_api_client_index_to_input_queue (mp->client_index);
5224 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
5226 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
5232 send_lisp_map_server_details (ip_address_t * ip,
5233 unix_shared_memory_queue_t * q, u32 context)
5235 vl_api_lisp_map_server_details_t *rmp = NULL;
5237 rmp = vl_msg_api_alloc (sizeof (*rmp));
5238 memset (rmp, 0, sizeof (*rmp));
5239 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
5241 switch (ip_addr_version (ip))
5245 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5246 sizeof (ip_addr_v4 (ip)));
5251 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5252 sizeof (ip_addr_v6 (ip)));
5258 rmp->context = context;
5260 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5264 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
5266 unix_shared_memory_queue_t *q = NULL;
5267 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5270 q = vl_api_client_index_to_input_queue (mp->client_index);
5276 vec_foreach (mr, lcm->map_servers)
5278 send_lisp_map_server_details (&mr->address, q, mp->context);
5283 send_lisp_map_resolver_details (ip_address_t * ip,
5284 unix_shared_memory_queue_t * q, u32 context)
5286 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5288 rmp = vl_msg_api_alloc (sizeof (*rmp));
5289 memset (rmp, 0, sizeof (*rmp));
5290 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5292 switch (ip_addr_version (ip))
5296 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5297 sizeof (ip_addr_v4 (ip)));
5302 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5303 sizeof (ip_addr_v6 (ip)));
5309 rmp->context = context;
5311 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5315 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5317 unix_shared_memory_queue_t *q = NULL;
5318 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5321 q = vl_api_client_index_to_input_queue (mp->client_index);
5327 vec_foreach (mr, lcm->map_resolvers)
5329 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5334 send_eid_table_map_pair (hash_pair_t * p,
5335 unix_shared_memory_queue_t * q, u32 context)
5337 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5339 rmp = vl_msg_api_alloc (sizeof (*rmp));
5340 memset (rmp, 0, sizeof (*rmp));
5341 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5343 rmp->vni = clib_host_to_net_u32 (p->key);
5344 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5345 rmp->context = context;
5346 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5350 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5353 unix_shared_memory_queue_t *q = NULL;
5354 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5356 uword *vni_table = 0;
5358 q = vl_api_client_index_to_input_queue (mp->client_index);
5366 vni_table = lcm->bd_id_by_vni;
5370 vni_table = lcm->table_id_by_vni;
5374 hash_foreach_pair (p, vni_table,
5376 send_eid_table_map_pair (p, q, mp->context);
5382 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
5384 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
5386 rmp = vl_msg_api_alloc (sizeof (*rmp));
5387 memset (rmp, 0, sizeof (*rmp));
5388 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
5389 rmp->context = context;
5390 rmp->vni = clib_host_to_net_u32 (vni);
5391 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5395 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
5397 lisp_adjacency_t *adj;
5398 vl_api_lisp_adjacency_t a;
5399 u32 i, n = vec_len (adjs);
5401 for (i = 0; i < n; i++)
5403 adj = vec_elt_at_index (adjs, i);
5404 memset (&a, 0, sizeof (a));
5406 switch (gid_address_type (&adj->reid))
5408 case GID_ADDR_IP_PREFIX:
5409 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
5410 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
5411 if (gid_address_ip_version (&adj->reid) == IP4)
5413 a.eid_type = 0; /* ipv4 type */
5414 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
5415 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
5419 a.eid_type = 1; /* ipv6 type */
5420 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
5421 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
5425 a.eid_type = 2; /* l2 mac type */
5426 mac_copy (a.reid, gid_address_mac (&adj->reid));
5427 mac_copy (a.leid, gid_address_mac (&adj->leid));
5437 vl_api_show_lisp_rloc_probe_state_t_handler
5438 (vl_api_show_lisp_rloc_probe_state_t * mp)
5440 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
5444 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
5446 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
5452 vl_api_show_lisp_map_register_state_t_handler
5453 (vl_api_show_lisp_map_register_state_t * mp)
5455 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
5459 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
5461 rmp->is_enabled = vnet_lisp_map_register_state_get ();
5467 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
5469 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
5470 lisp_adjacency_t *adjs = 0;
5472 vl_api_lisp_adjacency_t a;
5474 u32 vni = clib_net_to_host_u32 (mp->vni);
5476 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
5477 size = vec_len (adjs) * sizeof (a);
5480 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
5482 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
5483 lisp_adjacency_copy (rmp->adjacencies, adjs);
5491 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
5496 unix_shared_memory_queue_t *q = 0;
5497 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5499 q = vl_api_client_index_to_input_queue (mp->client_index);
5506 hash_foreach_pair (p, lcm->table_id_by_vni,
5508 hash_set (vnis, p->key, 0);
5511 hash_foreach_pair (p, lcm->bd_id_by_vni,
5513 hash_set (vnis, p->key, 0);
5516 hash_foreach_pair (p, vnis,
5518 send_eid_table_vni (p->key, q, mp->context);
5526 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
5528 unix_shared_memory_queue_t *q = NULL;
5529 vl_api_show_lisp_status_reply_t *rmp = NULL;
5532 q = vl_api_client_index_to_input_queue (mp->client_index);
5539 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5541 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5542 rmp->feature_status = vnet_lisp_enable_disable_status ();
5548 vl_api_lisp_get_map_request_itr_rlocs_t_handler
5549 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
5551 unix_shared_memory_queue_t *q = NULL;
5552 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5553 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5554 locator_set_t *loc_set = 0;
5558 q = vl_api_client_index_to_input_queue (mp->client_index);
5564 if (~0 == lcm->mreq_itr_rlocs)
5566 tmp_str = format (0, " ");
5571 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5572 tmp_str = format (0, "%s", loc_set->name);
5576 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5578 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5579 ARRAY_LEN(rmp->locator_set_name) - 1);
5587 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5589 unix_shared_memory_queue_t *q = NULL;
5590 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
5591 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5593 locator_set_t *ls = 0;
5597 q = vl_api_client_index_to_input_queue (mp->client_index);
5603 if (!lcm->lisp_pitr)
5605 tmp_str = format (0, "N/A");
5609 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5610 if (~0 != m->locator_set_index)
5613 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5614 tmp_str = format (0, "%s", ls->name);
5618 tmp_str = format (0, "N/A");
5621 vec_add1 (tmp_str, 0);
5624 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5626 rmp->status = lcm->lisp_pitr;
5627 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5628 ARRAY_LEN(rmp->locator_set_name) - 1);
5634 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
5637 vl_api_interface_name_renumber_reply_t *rmp;
5640 VALIDATE_SW_IF_INDEX (mp);
5642 rv = vnet_interface_name_renumber
5643 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
5645 BAD_SW_IF_INDEX_LABEL;
5647 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5651 arp_change_data_callback (u32 pool_index, u8 * new_mac,
5652 u32 sw_if_index, u32 address)
5654 vpe_api_main_t *am = &vpe_api_main;
5655 vlib_main_t *vm = am->vlib_main;
5656 vl_api_ip4_arp_event_t *event;
5657 static f64 arp_event_last_time;
5658 f64 now = vlib_time_now (vm);
5660 if (pool_is_free_index (am->arp_events, pool_index))
5663 event = pool_elt_at_index (am->arp_events, pool_index);
5665 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
5667 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
5671 if (sw_if_index == event->sw_if_index &&
5673 /* for BD case, also check IP address with 10 sec timeout */
5674 (address == event->address &&
5675 (now - arp_event_last_time) < 10.0)))
5680 arp_event_last_time = now;
5681 event->sw_if_index = sw_if_index;
5683 event->address = address;
5688 nd_change_data_callback (u32 pool_index, u8 * new_mac,
5689 u32 sw_if_index, ip6_address_t * address)
5691 vpe_api_main_t *am = &vpe_api_main;
5692 vlib_main_t *vm = am->vlib_main;
5693 vl_api_ip6_nd_event_t *event;
5694 static f64 nd_event_last_time;
5695 f64 now = vlib_time_now (vm);
5697 if (pool_is_free_index (am->nd_events, pool_index))
5700 event = pool_elt_at_index (am->nd_events, pool_index);
5703 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
5705 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
5709 if (sw_if_index == event->sw_if_index &&
5711 /* for BD case, also check IP address with 10 sec timeout */
5712 (ip6_address_is_equal (address,
5713 (ip6_address_t *) event->address) &&
5714 (now - nd_event_last_time) < 10.0)))
5719 nd_event_last_time = now;
5720 event->sw_if_index = sw_if_index;
5722 clib_memcpy (event->address, address, sizeof (event->address));
5727 arp_change_delete_callback (u32 pool_index, u8 * notused)
5729 vpe_api_main_t *am = &vpe_api_main;
5731 if (pool_is_free_index (am->arp_events, pool_index))
5734 pool_put_index (am->arp_events, pool_index);
5739 nd_change_delete_callback (u32 pool_index, u8 * notused)
5741 vpe_api_main_t *am = &vpe_api_main;
5743 if (pool_is_free_index (am->nd_events, pool_index))
5746 pool_put_index (am->nd_events, pool_index);
5751 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
5753 vpe_api_main_t *am = &vpe_api_main;
5754 vnet_main_t *vnm = vnet_get_main ();
5755 vl_api_want_ip4_arp_events_reply_t *rmp;
5756 vl_api_ip4_arp_event_t *event;
5759 if (mp->enable_disable)
5761 pool_get (am->arp_events, event);
5762 memset (event, 0, sizeof (*event));
5764 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
5765 event->client_index = mp->client_index;
5766 event->context = mp->context;
5767 event->address = mp->address;
5768 event->pid = mp->pid;
5769 if (mp->address == 0)
5772 rv = vnet_add_del_ip4_arp_change_event
5773 (vnm, arp_change_data_callback,
5774 mp->pid, &mp->address /* addr, in net byte order */ ,
5775 vpe_resolver_process_node.index,
5776 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
5780 rv = vnet_add_del_ip4_arp_change_event
5781 (vnm, arp_change_delete_callback,
5782 mp->pid, &mp->address /* addr, in net byte order */ ,
5783 vpe_resolver_process_node.index,
5784 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
5786 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5790 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
5792 vpe_api_main_t *am = &vpe_api_main;
5793 vnet_main_t *vnm = vnet_get_main ();
5794 vl_api_want_ip6_nd_events_reply_t *rmp;
5795 vl_api_ip6_nd_event_t *event;
5798 if (mp->enable_disable)
5800 pool_get (am->nd_events, event);
5801 memset (event, 0, sizeof (*event));
5803 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
5804 event->client_index = mp->client_index;
5805 event->context = mp->context;
5806 clib_memcpy (event->address, mp->address, 16);
5807 event->pid = mp->pid;
5808 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
5811 rv = vnet_add_del_ip6_nd_change_event
5812 (vnm, nd_change_data_callback,
5813 mp->pid, mp->address /* addr, in net byte order */ ,
5814 vpe_resolver_process_node.index,
5815 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
5819 rv = vnet_add_del_ip6_nd_change_event
5820 (vnm, nd_change_delete_callback,
5821 mp->pid, mp->address /* addr, in net byte order */ ,
5822 vpe_resolver_process_node.index,
5823 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
5825 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
5828 static void vl_api_input_acl_set_interface_t_handler
5829 (vl_api_input_acl_set_interface_t * mp)
5831 vlib_main_t *vm = vlib_get_main ();
5832 vl_api_input_acl_set_interface_reply_t *rmp;
5834 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5836 ip4_table_index = ntohl (mp->ip4_table_index);
5837 ip6_table_index = ntohl (mp->ip6_table_index);
5838 l2_table_index = ntohl (mp->l2_table_index);
5839 sw_if_index = ntohl (mp->sw_if_index);
5841 VALIDATE_SW_IF_INDEX (mp);
5843 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5844 ip6_table_index, l2_table_index, mp->is_add);
5846 BAD_SW_IF_INDEX_LABEL;
5848 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5851 static void vl_api_ipsec_spd_add_del_t_handler
5852 (vl_api_ipsec_spd_add_del_t * mp)
5855 clib_warning ("unimplemented");
5858 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5859 vl_api_ipsec_spd_add_del_reply_t *rmp;
5863 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
5865 rv = VNET_API_ERROR_UNIMPLEMENTED;
5868 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5872 static void vl_api_ipsec_interface_add_del_spd_t_handler
5873 (vl_api_ipsec_interface_add_del_spd_t * mp)
5875 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5876 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
5878 u32 sw_if_index __attribute__ ((unused));
5879 u32 spd_id __attribute__ ((unused));
5881 sw_if_index = ntohl (mp->sw_if_index);
5882 spd_id = ntohl (mp->spd_id);
5884 VALIDATE_SW_IF_INDEX (mp);
5887 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
5889 rv = VNET_API_ERROR_UNIMPLEMENTED;
5892 BAD_SW_IF_INDEX_LABEL;
5894 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5897 static void vl_api_ipsec_spd_add_del_entry_t_handler
5898 (vl_api_ipsec_spd_add_del_entry_t * mp)
5900 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5901 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
5907 memset (&p, 0, sizeof (p));
5909 p.id = ntohl (mp->spd_id);
5910 p.priority = ntohl (mp->priority);
5911 p.is_outbound = mp->is_outbound;
5912 p.is_ipv6 = mp->is_ipv6;
5914 if (mp->is_ipv6 || mp->is_ip_any)
5916 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
5917 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
5918 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
5919 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
5923 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5924 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5925 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
5926 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5928 p.protocol = mp->protocol;
5929 p.rport.start = ntohs (mp->remote_port_start);
5930 p.rport.stop = ntohs (mp->remote_port_stop);
5931 p.lport.start = ntohs (mp->local_port_start);
5932 p.lport.stop = ntohs (mp->local_port_stop);
5933 /* policy action resolve unsupported */
5934 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
5936 clib_warning ("unsupported action: 'resolve'");
5937 rv = VNET_API_ERROR_UNIMPLEMENTED;
5940 p.policy = mp->policy;
5941 p.sa_id = ntohl (mp->sa_id);
5943 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5950 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5953 rv = VNET_API_ERROR_UNIMPLEMENTED;
5958 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5961 static void vl_api_ipsec_sad_add_del_entry_t_handler
5962 (vl_api_ipsec_sad_add_del_entry_t * mp)
5964 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5965 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
5970 memset (&sa, 0, sizeof (sa));
5972 sa.id = ntohl (mp->sad_id);
5973 sa.spi = ntohl (mp->spi);
5974 /* security protocol AH unsupported */
5975 if (mp->protocol == IPSEC_PROTOCOL_AH)
5977 clib_warning ("unsupported security protocol 'AH'");
5978 rv = VNET_API_ERROR_UNIMPLEMENTED;
5981 sa.protocol = mp->protocol;
5982 /* check for unsupported crypto-alg */
5983 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5984 mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
5986 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5987 mp->crypto_algorithm);
5988 rv = VNET_API_ERROR_UNIMPLEMENTED;
5991 sa.crypto_alg = mp->crypto_algorithm;
5992 sa.crypto_key_len = mp->crypto_key_length;
5993 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
5994 /* check for unsupported integ-alg */
5996 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_NONE ||
5998 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6000 mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
6002 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6003 mp->integrity_algorithm);
6004 rv = VNET_API_ERROR_UNIMPLEMENTED;
6009 /*Special cases, aes-gcm-128 encryption */
6010 if (mp->crypto_algorithm == IPSEC_CRYPTO_ALG_AES_GCM_128)
6012 if (mp->integrity_algorithm != IPSEC_INTEG_ALG_NONE
6013 && mp->integrity_algorithm != IPSEC_INTEG_ALG_AES_GCM_128)
6016 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
6017 rv = VNET_API_ERROR_UNIMPLEMENTED;
6020 else /*set integ-alg internally to aes-gcm-128 */
6021 mp->integrity_algorithm = IPSEC_INTEG_ALG_AES_GCM_128;
6023 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_AES_GCM_128)
6025 clib_warning ("unsupported integ-alg: aes-gcm-128");
6026 rv = VNET_API_ERROR_UNIMPLEMENTED;
6029 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_NONE)
6031 clib_warning ("unsupported integ-alg: none");
6032 rv = VNET_API_ERROR_UNIMPLEMENTED;
6037 sa.integ_alg = mp->integrity_algorithm;
6038 sa.integ_key_len = mp->integrity_key_length;
6039 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6040 sa.use_esn = mp->use_extended_sequence_number;
6041 sa.is_tunnel = mp->is_tunnel;
6042 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6043 if (sa.is_tunnel_ip6)
6045 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6046 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6050 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6051 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6054 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6056 rv = VNET_API_ERROR_UNIMPLEMENTED;
6061 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6065 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6067 vl_api_ikev2_profile_add_del_reply_t *rmp;
6071 vlib_main_t *vm = vlib_get_main ();
6072 clib_error_t *error;
6073 u8 *tmp = format (0, "%s", mp->name);
6074 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6077 rv = VNET_API_ERROR_UNSPECIFIED;
6079 rv = VNET_API_ERROR_UNIMPLEMENTED;
6082 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6086 vl_api_ikev2_profile_set_auth_t_handler
6087 (vl_api_ikev2_profile_set_auth_t * mp)
6089 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6093 vlib_main_t *vm = vlib_get_main ();
6094 clib_error_t *error;
6095 u8 *tmp = format (0, "%s", mp->name);
6096 u8 *data = vec_new (u8, mp->data_len);
6097 clib_memcpy (data, mp->data, mp->data_len);
6098 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6102 rv = VNET_API_ERROR_UNSPECIFIED;
6104 rv = VNET_API_ERROR_UNIMPLEMENTED;
6107 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6111 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6113 vl_api_ikev2_profile_add_del_reply_t *rmp;
6117 vlib_main_t *vm = vlib_get_main ();
6118 clib_error_t *error;
6119 u8 *tmp = format (0, "%s", mp->name);
6120 u8 *data = vec_new (u8, mp->data_len);
6121 clib_memcpy (data, mp->data, mp->data_len);
6122 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6126 rv = VNET_API_ERROR_UNSPECIFIED;
6128 rv = VNET_API_ERROR_UNIMPLEMENTED;
6131 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6135 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6137 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6141 vlib_main_t *vm = vlib_get_main ();
6142 clib_error_t *error;
6143 u8 *tmp = format (0, "%s", mp->name);
6144 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6145 mp->end_port, (ip4_address_t) mp->start_addr,
6146 (ip4_address_t) mp->end_addr, mp->is_local);
6149 rv = VNET_API_ERROR_UNSPECIFIED;
6151 rv = VNET_API_ERROR_UNIMPLEMENTED;
6154 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6158 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6160 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6164 vlib_main_t *vm = vlib_get_main ();
6165 clib_error_t *error;
6167 error = ikev2_set_local_key (vm, mp->key_file);
6169 rv = VNET_API_ERROR_UNSPECIFIED;
6171 rv = VNET_API_ERROR_UNIMPLEMENTED;
6174 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6178 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6180 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6181 vl_api_ipsec_sa_set_key_reply_t *rmp;
6185 sa.id = ntohl (mp->sa_id);
6186 sa.crypto_key_len = mp->crypto_key_length;
6187 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6188 sa.integ_key_len = mp->integrity_key_length;
6189 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6191 rv = ipsec_set_sa_key (vm, &sa);
6193 rv = VNET_API_ERROR_UNIMPLEMENTED;
6196 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6199 static void vl_api_cop_interface_enable_disable_t_handler
6200 (vl_api_cop_interface_enable_disable_t * mp)
6202 vl_api_cop_interface_enable_disable_reply_t *rmp;
6204 u32 sw_if_index = ntohl (mp->sw_if_index);
6207 VALIDATE_SW_IF_INDEX (mp);
6209 enable_disable = (int) mp->enable_disable;
6211 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6213 BAD_SW_IF_INDEX_LABEL;
6215 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6218 static void vl_api_cop_whitelist_enable_disable_t_handler
6219 (vl_api_cop_whitelist_enable_disable_t * mp)
6221 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6222 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6223 u32 sw_if_index = ntohl (mp->sw_if_index);
6226 VALIDATE_SW_IF_INDEX (mp);
6228 a->sw_if_index = sw_if_index;
6231 a->default_cop = mp->default_cop;
6232 a->fib_id = ntohl (mp->fib_id);
6234 rv = cop_whitelist_enable_disable (a);
6236 BAD_SW_IF_INDEX_LABEL;
6238 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6242 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6246 api_main_t *am = &api_main;
6247 vlib_main_t *vm = vlib_get_main ();
6249 vl_api_get_node_graph_reply_t *rmp;
6251 pthread_mutex_lock (&am->vlib_rp->mutex);
6252 oldheap = svm_push_data_heap (am->vlib_rp);
6255 * Keep the number of memcpy ops to a minimum (e.g. 1).
6257 vec_validate (vector, 16384);
6258 vec_reset_length (vector);
6261 vector = vlib_node_serialize (&vm->node_main, vector,
6262 (u32) ~ 0 /* all threads */ ,
6263 1 /* include nexts */ ,
6264 1 /* include stats */ );
6266 svm_pop_heap (oldheap);
6267 pthread_mutex_unlock (&am->vlib_rp->mutex);
6270 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6272 rmp->reply_in_shmem = (uword) vector;
6278 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
6281 vl_api_ioam_enable_reply_t *rmp;
6282 clib_error_t *error;
6284 /* Ignoring the profile id as currently a single profile
6286 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
6287 mp->seqno, mp->analyse);
6290 clib_error_report (error);
6291 rv = clib_error_get_code (error);
6294 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
6298 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
6301 vl_api_ioam_disable_reply_t *rmp;
6302 clib_error_t *error;
6304 error = clear_ioam_rewrite_fn ();
6307 clib_error_report (error);
6308 rv = clib_error_get_code (error);
6311 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
6315 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6317 vlib_main_t *vm = vlib_get_main ();
6318 vl_api_af_packet_create_reply_t *rmp;
6320 u8 *host_if_name = NULL;
6323 host_if_name = format (0, "%s", mp->host_if_name);
6324 vec_add1 (host_if_name, 0);
6326 rv = af_packet_create_if (vm, host_if_name,
6327 mp->use_random_hw_addr ? 0 : mp->hw_addr,
6330 vec_free (host_if_name);
6333 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6335 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
6341 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
6343 vlib_main_t *vm = vlib_get_main ();
6344 vl_api_af_packet_delete_reply_t *rmp;
6346 u8 *host_if_name = NULL;
6348 host_if_name = format (0, "%s", mp->host_if_name);
6349 vec_add1 (host_if_name, 0);
6351 rv = af_packet_delete_if (vm, host_if_name);
6353 vec_free (host_if_name);
6355 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
6359 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
6361 vlib_main_t *vm = vlib_get_main ();
6362 vl_api_policer_add_del_reply_t *rmp;
6365 sse2_qos_pol_cfg_params_st cfg;
6366 clib_error_t *error;
6369 name = format (0, "%s", mp->name);
6371 memset (&cfg, 0, sizeof (cfg));
6373 cfg.rnd_type = mp->round_type;
6374 cfg.rate_type = mp->rate_type;
6375 cfg.rb.kbps.cir_kbps = mp->cir;
6376 cfg.rb.kbps.eir_kbps = mp->eir;
6377 cfg.rb.kbps.cb_bytes = mp->cb;
6378 cfg.rb.kbps.eb_bytes = mp->eb;
6379 cfg.conform_action.action_type = mp->conform_action_type;
6380 cfg.conform_action.dscp = mp->conform_dscp;
6381 cfg.exceed_action.action_type = mp->exceed_action_type;
6382 cfg.exceed_action.dscp = mp->exceed_dscp;
6383 cfg.violate_action.action_type = mp->violate_action_type;
6384 cfg.violate_action.dscp = mp->violate_dscp;
6385 cfg.color_aware = mp->color_aware;
6387 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
6390 rv = VNET_API_ERROR_UNSPECIFIED;
6393 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6395 if (rv == 0 && mp->is_add)
6396 rmp->policer_index = ntohl(policer_index);
6398 rmp->policer_index = ~0;
6404 send_policer_details (u8 * name,
6405 sse2_qos_pol_cfg_params_st * config,
6406 policer_read_response_type_st * templ,
6407 unix_shared_memory_queue_t * q, u32 context)
6409 vl_api_policer_details_t *mp;
6411 mp = vl_msg_api_alloc (sizeof (*mp));
6412 memset (mp, 0, sizeof (*mp));
6413 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6414 mp->context = context;
6415 mp->cir = htonl (config->rb.kbps.cir_kbps);
6416 mp->eir = htonl (config->rb.kbps.eir_kbps);
6417 mp->cb = htonl (config->rb.kbps.cb_bytes);
6418 mp->eb = htonl (config->rb.kbps.eb_bytes);
6419 mp->rate_type = config->rate_type;
6420 mp->round_type = config->rnd_type;
6421 mp->type = config->rfc;
6422 mp->conform_action_type = config->conform_action.action_type;
6423 mp->conform_dscp = config->conform_action.dscp;
6424 mp->exceed_action_type = config->exceed_action.action_type;
6425 mp->exceed_dscp = config->exceed_action.dscp;
6426 mp->violate_action_type = config->violate_action.action_type;
6427 mp->violate_dscp = config->violate_action.dscp;
6428 mp->single_rate = templ->single_rate ? 1 : 0;
6429 mp->color_aware = templ->color_aware ? 1 : 0;
6430 mp->scale = htonl (templ->scale);
6431 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
6432 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
6433 mp->current_limit = htonl (templ->current_limit);
6434 mp->current_bucket = htonl (templ->current_bucket);
6435 mp->extended_limit = htonl (templ->extended_limit);
6436 mp->extended_bucket = htonl (templ->extended_bucket);
6437 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
6439 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
6441 vl_msg_api_send_shmem (q, (u8 *) & mp);
6445 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
6447 unix_shared_memory_queue_t *q;
6448 vnet_policer_main_t *pm = &vnet_policer_main;
6454 sse2_qos_pol_cfg_params_st *config;
6455 policer_read_response_type_st *templ;
6457 q = vl_api_client_index_to_input_queue (mp->client_index);
6461 if (mp->match_name_valid)
6463 match_name = format (0, "%s%c", mp->match_name, 0);
6466 if (mp->match_name_valid)
6468 p = hash_get_mem (pm->policer_config_by_name, match_name);
6472 config = pool_elt_at_index (pm->configs, pool_index);
6473 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6474 send_policer_details (match_name, config, templ, q, mp->context);
6480 hash_foreach_pair (hp, pm->policer_config_by_name,
6482 name = (u8 *) hp->key;
6483 pool_index = hp->value[0];
6484 config = pool_elt_at_index (pm->configs, pool_index);
6485 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6486 send_policer_details(name, config, templ, q, mp->context);
6493 vl_api_policer_classify_set_interface_t_handler
6494 (vl_api_policer_classify_set_interface_t * mp)
6496 vlib_main_t *vm = vlib_get_main ();
6497 vl_api_policer_classify_set_interface_reply_t *rmp;
6499 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6501 ip4_table_index = ntohl (mp->ip4_table_index);
6502 ip6_table_index = ntohl (mp->ip6_table_index);
6503 l2_table_index = ntohl (mp->l2_table_index);
6504 sw_if_index = ntohl (mp->sw_if_index);
6506 VALIDATE_SW_IF_INDEX (mp);
6508 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
6509 ip6_table_index, l2_table_index,
6512 BAD_SW_IF_INDEX_LABEL;
6514 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
6518 send_policer_classify_details (u32 sw_if_index,
6520 unix_shared_memory_queue_t * q, u32 context)
6522 vl_api_policer_classify_details_t *mp;
6524 mp = vl_msg_api_alloc (sizeof (*mp));
6525 memset (mp, 0, sizeof (*mp));
6526 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
6527 mp->context = context;
6528 mp->sw_if_index = htonl (sw_if_index);
6529 mp->table_index = htonl (table_index);
6531 vl_msg_api_send_shmem (q, (u8 *) & mp);
6535 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
6537 unix_shared_memory_queue_t *q;
6538 policer_classify_main_t *pcm = &policer_classify_main;
6542 q = vl_api_client_index_to_input_queue (mp->client_index);
6546 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6548 if (vec_len (vec_tbl))
6550 for (i = 0; i < vec_len (vec_tbl); i++)
6552 if (vec_elt (vec_tbl, i) == ~0)
6555 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
6562 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
6564 vlib_main_t *vm = vlib_get_main ();
6565 vl_api_netmap_create_reply_t *rmp;
6569 if_name = format (0, "%s", mp->netmap_if_name);
6570 vec_add1 (if_name, 0);
6573 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6574 mp->is_pipe, mp->is_master, 0);
6578 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
6582 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
6584 vlib_main_t *vm = vlib_get_main ();
6585 vl_api_netmap_delete_reply_t *rmp;
6589 if_name = format (0, "%s", mp->netmap_if_name);
6590 vec_add1 (if_name, 0);
6592 rv = netmap_delete_if (vm, if_name);
6596 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
6600 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_fib_details_t * mp)
6602 clib_warning ("BUG");
6605 typedef struct mpls_tunnel_send_walk_ctx_t_
6607 unix_shared_memory_queue_t *q;
6610 } mpls_tunnel_send_walk_ctx_t;
6613 send_mpls_tunnel_entry (u32 mti, void *arg)
6615 mpls_tunnel_send_walk_ctx_t *ctx;
6616 vl_api_mpls_tunnel_details_t *mp;
6617 const mpls_tunnel_t *mt;
6622 if (~0 != ctx->index && mti != ctx->index)
6625 mt = mpls_tunnel_get (mti);
6626 nlabels = vec_len (mt->mt_label_stack);
6628 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
6629 memset (mp, 0, sizeof (*mp));
6630 mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
6631 mp->context = ctx->context;
6633 mp->tunnel_index = ntohl (mti);
6634 memcpy (mp->mt_next_hop_out_labels,
6635 mt->mt_label_stack, nlabels * sizeof (u32));
6639 vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
6643 vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
6645 unix_shared_memory_queue_t *q;
6647 q = vl_api_client_index_to_input_queue (mp->client_index);
6651 mpls_tunnel_send_walk_ctx_t ctx = {
6653 .index = ntohl (mp->tunnel_index),
6654 .context = mp->context,
6656 mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
6660 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
6662 clib_warning ("BUG");
6666 vl_api_mpls_fib_details_t_endian (vl_api_mpls_fib_details_t * mp)
6668 clib_warning ("BUG");
6672 vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp)
6674 clib_warning ("BUG");
6679 copy_fib_next_hop (fib_route_path_encode_t * api_rpath,
6680 vl_api_fib_path_t * fp)
6684 if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4)
6685 fp->afi = IP46_TYPE_IP4;
6686 else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6)
6687 fp->afi = IP46_TYPE_IP6;
6690 is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr);
6692 fp->afi = IP46_TYPE_IP4;
6694 fp->afi = IP46_TYPE_IP6;
6696 if (fp->afi == IP46_TYPE_IP4)
6697 memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip4,
6698 sizeof (api_rpath->rpath.frp_addr.ip4));
6700 memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip6,
6701 sizeof (api_rpath->rpath.frp_addr.ip6));
6705 send_mpls_fib_details (vpe_api_main_t * am,
6706 unix_shared_memory_queue_t * q,
6707 u32 table_id, u32 label, u32 eos,
6708 fib_route_path_encode_t * api_rpaths, u32 context)
6710 vl_api_mpls_fib_details_t *mp;
6711 fib_route_path_encode_t *api_rpath;
6712 vl_api_fib_path_t *fp;
6715 path_count = vec_len (api_rpaths);
6716 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
6719 memset (mp, 0, sizeof (*mp));
6720 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
6721 mp->context = context;
6723 mp->table_id = htonl (table_id);
6725 mp->label = htonl (label);
6727 mp->count = htonl (path_count);
6729 vec_foreach (api_rpath, api_rpaths)
6731 memset (fp, 0, sizeof (*fp));
6732 fp->weight = htonl (api_rpath->rpath.frp_weight);
6733 fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
6734 copy_fib_next_hop (api_rpath, fp);
6738 vl_msg_api_send_shmem (q, (u8 *) & mp);
6742 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
6744 vpe_api_main_t *am = &vpe_api_main;
6745 unix_shared_memory_queue_t *q;
6746 mpls_main_t *mm = &mpls_main;
6747 fib_table_t *fib_table;
6748 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
6752 fib_route_path_encode_t *api_rpaths;
6754 q = vl_api_client_index_to_input_queue (mp->client_index);
6759 pool_foreach (fib_table, mm->fibs,
6761 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
6763 vec_add1(lfeis, lfei);
6766 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
6768 vec_foreach(lfeip, lfeis)
6770 fib_entry_get_prefix(*lfeip, &pfx);
6771 fib_index = fib_entry_get_fib_index(*lfeip);
6772 fib_table = fib_table_get(fib_index, pfx.fp_proto);
6774 fib_entry_encode(*lfeip, &api_rpaths);
6775 send_mpls_fib_details (am, q,
6776 fib_table->ft_table_id,
6781 vec_free(api_rpaths);
6788 vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
6790 clib_warning ("BUG");
6794 vl_api_ip_fib_details_t_endian (vl_api_ip_fib_details_t * mp)
6796 clib_warning ("BUG");
6800 vl_api_ip_fib_details_t_print (vl_api_ip_fib_details_t * mp)
6802 clib_warning ("BUG");
6806 send_ip_fib_details (vpe_api_main_t * am,
6807 unix_shared_memory_queue_t * q,
6808 u32 table_id, fib_prefix_t *pfx,
6809 fib_route_path_encode_t *api_rpaths, u32 context)
6811 vl_api_ip_fib_details_t *mp;
6812 fib_route_path_encode_t *api_rpath;
6813 vl_api_fib_path_t *fp;
6816 path_count = vec_len(api_rpaths);
6817 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
6820 memset (mp, 0, sizeof (*mp));
6821 mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS);
6822 mp->context = context;
6824 mp->table_id = htonl (table_id);
6825 mp->address_length = pfx->fp_len;
6826 memcpy(mp->address, &pfx->fp_addr.ip4, sizeof(pfx->fp_addr.ip4));
6828 mp->count = htonl (path_count);
6830 vec_foreach(api_rpath, api_rpaths)
6832 memset (fp, 0, sizeof (*fp));
6833 switch (api_rpath->dpo.dpoi_type)
6836 fp->is_local = true;
6842 switch (api_rpath->dpo.dpoi_index)
6844 case IP_NULL_ACTION_NONE:
6847 case IP_NULL_ACTION_SEND_ICMP_UNREACH:
6848 fp->is_unreach = true;
6850 case IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
6851 fp->is_prohibit = true;
6860 fp->weight = htonl(api_rpath->rpath.frp_weight);
6861 fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
6862 copy_fib_next_hop (api_rpath, fp);
6866 vl_msg_api_send_shmem (q, (u8 *) & mp);
6870 vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp)
6872 vpe_api_main_t *am = &vpe_api_main;
6873 unix_shared_memory_queue_t *q;
6874 ip4_main_t *im = &ip4_main;
6875 fib_table_t *fib_table;
6876 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
6880 fib_route_path_encode_t *api_rpaths;
6883 q = vl_api_client_index_to_input_queue (mp->client_index);
6888 pool_foreach (fib_table, im->fibs,
6890 for (i = 0; i < ARRAY_LEN (fib_table->v4.fib_entry_by_dst_address); i++)
6892 hash_foreach(key, lfei, fib_table->v4.fib_entry_by_dst_address[i],
6894 vec_add1(lfeis, lfei);
6899 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
6901 vec_foreach(lfeip, lfeis)
6903 fib_entry_get_prefix(*lfeip, &pfx);
6904 fib_index = fib_entry_get_fib_index(*lfeip);
6905 fib_table = fib_table_get(fib_index, pfx.fp_proto);
6907 fib_entry_encode(*lfeip, &api_rpaths);
6908 send_ip_fib_details (am, q,
6909 fib_table->ft_table_id,
6913 vec_free(api_rpaths);
6920 vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
6922 clib_warning ("BUG");
6926 vl_api_ip6_fib_details_t_endian (vl_api_ip6_fib_details_t * mp)
6928 clib_warning ("BUG");
6932 vl_api_ip6_fib_details_t_print (vl_api_ip6_fib_details_t * mp)
6934 clib_warning ("BUG");
6938 send_ip6_fib_details (vpe_api_main_t * am,
6939 unix_shared_memory_queue_t * q,
6940 u32 table_id, fib_prefix_t *pfx,
6941 fib_route_path_encode_t *api_rpaths, u32 context)
6943 vl_api_ip6_fib_details_t *mp;
6944 fib_route_path_encode_t *api_rpath;
6945 vl_api_fib_path_t *fp;
6948 path_count = vec_len(api_rpaths);
6949 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
6952 memset (mp, 0, sizeof (*mp));
6953 mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS);
6954 mp->context = context;
6956 mp->table_id = htonl (table_id);
6957 mp->address_length = pfx->fp_len;
6958 memcpy(mp->address, &pfx->fp_addr.ip6, sizeof(pfx->fp_addr.ip6));
6960 mp->count = htonl (path_count);
6962 vec_foreach(api_rpath, api_rpaths)
6964 memset (fp, 0, sizeof (*fp));
6965 switch (api_rpath->dpo.dpoi_type)
6968 fp->is_local = true;
6974 switch (api_rpath->dpo.dpoi_index)
6976 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_NONE:
6979 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_UNREACH:
6980 fp->is_unreach = true;
6982 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
6983 fp->is_prohibit = true;
6992 fp->weight = htonl(api_rpath->rpath.frp_weight);
6993 fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
6994 copy_fib_next_hop (api_rpath, fp);
6998 vl_msg_api_send_shmem (q, (u8 *) & mp);
7001 typedef struct apt_ip6_fib_show_ctx_t_ {
7003 fib_node_index_t *entries;
7004 } api_ip6_fib_show_ctx_t;
7007 api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp,
7010 api_ip6_fib_show_ctx_t *ctx = arg;
7012 if ((kvp->key[2] >> 32) == ctx->fib_index)
7014 vec_add1(ctx->entries, kvp->value);
7019 api_ip6_fib_table_get_all (unix_shared_memory_queue_t *q,
7020 vl_api_ip6_fib_dump_t *mp,
7021 fib_table_t *fib_table)
7023 vpe_api_main_t *am = &vpe_api_main;
7024 ip6_main_t *im6 = &ip6_main;
7025 ip6_fib_t *fib = &fib_table->v6;
7026 fib_node_index_t *fib_entry_index;
7027 api_ip6_fib_show_ctx_t ctx = {
7028 .fib_index = fib->index,
7031 fib_route_path_encode_t *api_rpaths;
7034 BV(clib_bihash_foreach_key_value_pair)
7035 ((BVT(clib_bihash) *) &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
7036 api_ip6_fib_table_put_entries,
7039 vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort);
7041 vec_foreach(fib_entry_index, ctx.entries)
7043 fib_entry_get_prefix(*fib_entry_index, &pfx);
7045 fib_entry_encode(*fib_entry_index, &api_rpaths);
7046 send_ip6_fib_details (am, q,
7047 fib_table->ft_table_id,
7051 vec_free(api_rpaths);
7054 vec_free(ctx.entries);
7058 vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp)
7060 unix_shared_memory_queue_t *q;
7061 ip6_main_t *im6 = &ip6_main;
7062 fib_table_t *fib_table;
7064 q = vl_api_client_index_to_input_queue (mp->client_index);
7069 pool_foreach (fib_table, im6->fibs,
7071 api_ip6_fib_table_get_all(q, mp, fib_table);
7076 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7078 unix_shared_memory_queue_t *q;
7080 q = vl_api_client_index_to_input_queue (mp->client_index);
7084 vnet_classify_main_t *cm = &vnet_classify_main;
7085 vnet_classify_table_t *t;
7090 pool_foreach (t, cm->tables,
7092 vec_add1 (table_ids, ntohl(t - cm->tables));
7095 count = vec_len (table_ids);
7097 vl_api_classify_table_ids_reply_t *rmp;
7098 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7099 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7100 rmp->context = mp->context;
7101 rmp->count = ntohl (count);
7102 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7105 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7107 vec_free (table_ids);
7111 vl_api_classify_table_by_interface_t_handler
7112 (vl_api_classify_table_by_interface_t * mp)
7114 vl_api_classify_table_by_interface_reply_t *rmp;
7117 u32 sw_if_index = ntohl (mp->sw_if_index);
7120 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7123 VALIDATE_SW_IF_INDEX (mp);
7125 input_acl_main_t *am = &input_acl_main;
7130 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7132 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7133 if (vec_len (vec_tbl))
7135 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7137 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7141 acl[type] = vec_elt (vec_tbl, if_idx);
7146 BAD_SW_IF_INDEX_LABEL;
7149 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7151 rmp->sw_if_index = ntohl(sw_if_index);
7152 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7153 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7154 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7161 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7163 unix_shared_memory_queue_t *q;
7165 q = vl_api_client_index_to_input_queue (mp->client_index);
7169 vl_api_classify_table_info_reply_t *rmp = 0;
7171 vnet_classify_main_t *cm = &vnet_classify_main;
7172 u32 table_id = ntohl (mp->table_id);
7173 vnet_classify_table_t *t;
7176 pool_foreach (t, cm->tables,
7178 if (table_id == t - cm->tables)
7180 rmp = vl_msg_api_alloc_as_if_client
7181 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7182 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7183 rmp->context = mp->context;
7184 rmp->table_id = ntohl(table_id);
7185 rmp->nbuckets = ntohl(t->nbuckets);
7186 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7187 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7188 rmp->active_sessions = ntohl(t->active_elements);
7189 rmp->next_table_index = ntohl(t->next_table_index);
7190 rmp->miss_next_index = ntohl(t->miss_next_index);
7191 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7192 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7201 rmp = vl_msg_api_alloc (sizeof (*rmp));
7202 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7203 rmp->context = mp->context;
7204 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7207 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7211 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7214 clib_warning ("BUG");
7218 send_classify_session_details (unix_shared_memory_queue_t * q,
7221 vnet_classify_entry_t * e, u32 context)
7223 vl_api_classify_session_details_t *rmp;
7225 rmp = vl_msg_api_alloc (sizeof (*rmp));
7226 memset (rmp, 0, sizeof (*rmp));
7227 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7228 rmp->context = context;
7229 rmp->table_id = ntohl (table_id);
7230 rmp->hit_next_index = ntohl (e->next_index);
7231 rmp->advance = ntohl (e->advance);
7232 rmp->opaque_index = ntohl (e->opaque_index);
7233 rmp->match_length = ntohl (match_length);
7234 clib_memcpy (rmp->match, e->key, match_length);
7236 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7240 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7242 vnet_classify_main_t *cm = &vnet_classify_main;
7243 unix_shared_memory_queue_t *q;
7245 u32 table_id = ntohl (mp->table_id);
7246 vnet_classify_table_t *t;
7248 q = vl_api_client_index_to_input_queue (mp->client_index);
7253 pool_foreach (t, cm->tables,
7255 if (table_id == t - cm->tables)
7257 vnet_classify_bucket_t * b;
7258 vnet_classify_entry_t * v, * save_v;
7261 for (i = 0; i < t->nbuckets; i++)
7263 b = &t->buckets [i];
7267 save_v = vnet_classify_get_entry (t, b->offset);
7268 for (j = 0; j < (1<<b->log2_pages); j++)
7270 for (k = 0; k < t->entries_per_page; k++)
7272 v = vnet_classify_entry_at_index
7273 (t, save_v, j*t->entries_per_page + k);
7274 if (vnet_classify_entry_is_free (v))
7277 send_classify_session_details
7278 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7290 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7292 vlib_main_t *vm = vlib_get_main ();
7293 flow_report_main_t *frm = &flow_report_main;
7294 vl_api_set_ipfix_exporter_reply_t *rmp;
7295 ip4_address_t collector, src;
7296 u16 collector_port = UDP_DST_PORT_ipfix;
7298 u32 template_interval;
7304 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7305 collector_port = ntohs (mp->collector_port);
7306 if (collector_port == (u16) ~ 0)
7307 collector_port = UDP_DST_PORT_ipfix;
7308 memcpy (src.data, mp->src_address, sizeof (src.data));
7309 fib_id = ntohl (mp->vrf_id);
7311 ip4_main_t *im = &ip4_main;
7318 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7321 rv = VNET_API_ERROR_NO_SUCH_FIB;
7327 path_mtu = ntohl (mp->path_mtu);
7329 path_mtu = 512; // RFC 7011 section 10.3.3.
7330 template_interval = ntohl (mp->template_interval);
7331 if (template_interval == ~0)
7332 template_interval = 20;
7333 udp_checksum = mp->udp_checksum;
7335 if (collector.as_u32 == 0)
7337 rv = VNET_API_ERROR_INVALID_VALUE;
7341 if (src.as_u32 == 0)
7343 rv = VNET_API_ERROR_INVALID_VALUE;
7347 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7349 rv = VNET_API_ERROR_INVALID_VALUE;
7355 rv = VNET_API_ERROR_INVALID_VALUE;
7359 /* Reset report streams if we are reconfiguring IP addresses */
7360 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7361 frm->src_address.as_u32 != src.as_u32 ||
7362 frm->collector_port != collector_port)
7363 vnet_flow_reports_reset (frm);
7365 frm->ipfix_collector.as_u32 = collector.as_u32;
7366 frm->collector_port = collector_port;
7367 frm->src_address.as_u32 = src.as_u32;
7368 frm->fib_index = fib_index;
7369 frm->path_mtu = path_mtu;
7370 frm->template_interval = template_interval;
7371 frm->udp_checksum = udp_checksum;
7373 /* Turn on the flow reporting process */
7374 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7377 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
7381 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
7383 flow_report_main_t *frm = &flow_report_main;
7384 unix_shared_memory_queue_t *q;
7385 vl_api_ipfix_exporter_details_t *rmp;
7386 ip4_main_t *im = &ip4_main;
7389 q = vl_api_client_index_to_input_queue (mp->client_index);
7393 rmp = vl_msg_api_alloc (sizeof (*rmp));
7394 memset (rmp, 0, sizeof (*rmp));
7395 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
7396 rmp->context = mp->context;
7397 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7398 sizeof (frm->ipfix_collector.data));
7399 rmp->collector_port = htons (frm->collector_port);
7400 memcpy (rmp->src_address, frm->src_address.data,
7401 sizeof (frm->src_address.data));
7402 if (frm->fib_index == ~0)
7405 vrf_id = im->fibs[frm->fib_index].ft_table_id;
7406 rmp->vrf_id = htonl (vrf_id);
7407 rmp->path_mtu = htonl (frm->path_mtu);
7408 rmp->template_interval = htonl (frm->template_interval);
7409 rmp->udp_checksum = (frm->udp_checksum != 0);
7411 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7415 vl_api_set_ipfix_classify_stream_t_handler
7416 (vl_api_set_ipfix_classify_stream_t * mp)
7418 vl_api_set_ipfix_classify_stream_reply_t *rmp;
7419 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7420 flow_report_main_t *frm = &flow_report_main;
7422 u32 src_port = UDP_DST_PORT_ipfix;
7425 domain_id = ntohl (mp->domain_id);
7426 src_port = ntohs (mp->src_port);
7428 if (fcm->src_port != 0 &&
7429 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
7431 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
7432 domain_id, (u16) src_port);
7436 fcm->domain_id = domain_id;
7437 fcm->src_port = (u16) src_port;
7439 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7443 vl_api_ipfix_classify_stream_dump_t_handler
7444 (vl_api_ipfix_classify_stream_dump_t * mp)
7446 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7447 unix_shared_memory_queue_t *q;
7448 vl_api_ipfix_classify_stream_details_t *rmp;
7450 q = vl_api_client_index_to_input_queue (mp->client_index);
7454 rmp = vl_msg_api_alloc (sizeof (*rmp));
7455 memset (rmp, 0, sizeof (*rmp));
7456 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
7457 rmp->context = mp->context;
7458 rmp->domain_id = htonl (fcm->domain_id);
7459 rmp->src_port = htons (fcm->src_port);
7461 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7465 vl_api_ipfix_classify_table_add_del_t_handler
7466 (vl_api_ipfix_classify_table_add_del_t * mp)
7468 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
7469 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7470 flow_report_main_t *frm = &flow_report_main;
7471 vnet_flow_report_add_del_args_t args;
7472 ipfix_classify_table_t *table;
7474 u32 classify_table_index;
7476 u8 transport_protocol;
7479 classify_table_index = ntohl (mp->table_id);
7480 ip_version = mp->ip_version;
7481 transport_protocol = mp->transport_protocol;
7482 is_add = mp->is_add;
7484 if (fcm->src_port == 0)
7486 /* call set_ipfix_classify_stream first */
7487 rv = VNET_API_ERROR_UNSPECIFIED;
7491 memset (&args, 0, sizeof (args));
7495 for (i = 0; i < vec_len (fcm->tables); i++)
7496 if (ipfix_classify_table_index_valid (i))
7497 if (fcm->tables[i].classify_table_index == classify_table_index)
7499 table = &fcm->tables[i];
7507 rv = VNET_API_ERROR_VALUE_EXIST;
7510 table = ipfix_classify_add_table ();
7511 table->classify_table_index = classify_table_index;
7517 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
7522 table->ip_version = ip_version;
7523 table->transport_protocol = transport_protocol;
7525 args.opaque.as_uword = table - fcm->tables;
7526 args.rewrite_callback = ipfix_classify_template_rewrite;
7527 args.flow_data_callback = ipfix_classify_send_flows;
7528 args.is_add = is_add;
7529 args.domain_id = fcm->domain_id;
7530 args.src_port = fcm->src_port;
7532 rv = vnet_flow_report_add_del (frm, &args);
7534 /* If deleting, or add failed */
7535 if (is_add == 0 || (rv && is_add))
7536 ipfix_classify_delete_table (table - fcm->tables);
7539 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7543 send_ipfix_classify_table_details (u32 table_index,
7544 unix_shared_memory_queue_t * q,
7547 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7548 vl_api_ipfix_classify_table_details_t *mp;
7550 ipfix_classify_table_t *table = &fcm->tables[table_index];
7552 mp = vl_msg_api_alloc (sizeof (*mp));
7553 memset (mp, 0, sizeof (*mp));
7554 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
7555 mp->context = context;
7556 mp->table_id = htonl (table->classify_table_index);
7557 mp->ip_version = table->ip_version;
7558 mp->transport_protocol = table->transport_protocol;
7560 vl_msg_api_send_shmem (q, (u8 *) & mp);
7564 vl_api_ipfix_classify_table_dump_t_handler
7565 (vl_api_ipfix_classify_table_dump_t * mp)
7567 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7568 unix_shared_memory_queue_t *q;
7571 q = vl_api_client_index_to_input_queue (mp->client_index);
7575 for (i = 0; i < vec_len (fcm->tables); i++)
7576 if (ipfix_classify_table_index_valid (i))
7577 send_ipfix_classify_table_details (i, q, mp->context);
7581 vl_api_sw_interface_span_enable_disable_t_handler
7582 (vl_api_sw_interface_span_enable_disable_t * mp)
7584 vl_api_sw_interface_span_enable_disable_reply_t *rmp;
7587 vlib_main_t *vm = vlib_get_main ();
7589 rv = span_add_delete_entry (vm, ntohl (mp->sw_if_index_from),
7590 ntohl (mp->sw_if_index_to), mp->enable);
7592 REPLY_MACRO (VL_API_SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY);
7596 vl_api_sw_interface_span_dump_t_handler (vl_api_sw_interface_span_dump_t * mp)
7599 unix_shared_memory_queue_t *q;
7600 vl_api_sw_interface_span_details_t *rmp;
7601 span_main_t *sm = &span_main;
7602 u32 src_sw_if_index = 0, *dst_sw_if_index;
7604 q = vl_api_client_index_to_input_queue (mp->client_index);
7608 vec_foreach (dst_sw_if_index, sm->dst_by_src_sw_if_index)
7610 if (*dst_sw_if_index > 0)
7612 rmp = vl_msg_api_alloc (sizeof (*rmp));
7613 memset (rmp, 0, sizeof (*rmp));
7614 rmp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SPAN_DETAILS);
7615 rmp->context = mp->context;
7617 rmp->sw_if_index_from = htonl (src_sw_if_index);
7618 rmp->sw_if_index_to = htonl (*dst_sw_if_index);
7620 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7627 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
7629 vl_api_pg_create_interface_reply_t *rmp;
7632 pg_main_t *pg = &pg_main;
7633 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
7634 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
7637 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7639 rmp->sw_if_index = ntohl(pi->sw_if_index);
7645 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
7647 vl_api_pg_capture_reply_t *rmp;
7650 vnet_main_t *vnm = vnet_get_main ();
7651 vnet_interface_main_t *im = &vnm->interface_main;
7652 vnet_hw_interface_t *hi = 0;
7654 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
7655 u32 hw_if_index = ~0;
7656 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
7659 vec_free (intf_name);
7661 if (hw_if_index != ~0)
7663 pg_capture_args_t _a, *a = &_a;
7665 u32 len = ntohl (mp->pcap_name_length);
7666 u8 *pcap_file_name = vec_new (u8, len);
7667 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
7669 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7670 a->hw_if_index = hw_if_index;
7671 a->dev_instance = hi->dev_instance;
7672 a->is_enabled = mp->is_enabled;
7673 a->pcap_file_name = pcap_file_name;
7674 a->count = ntohl (mp->count);
7676 clib_error_t *e = pg_capture (a);
7679 clib_error_report (e);
7680 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7683 vec_free (pcap_file_name);
7685 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
7689 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
7691 vl_api_pg_enable_disable_reply_t *rmp;
7694 pg_main_t *pg = &pg_main;
7695 u32 stream_index = ~0;
7697 int is_enable = mp->is_enabled != 0;
7698 u32 len = ntohl (mp->stream_name_length) - 1;
7702 u8 *stream_name = vec_new (u8, len);
7703 clib_memcpy (stream_name, mp->stream_name, len);
7704 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
7707 vec_free (stream_name);
7710 pg_enable_disable (stream_index, is_enable);
7712 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
7716 vl_api_ip_source_and_port_range_check_add_del_t_handler
7717 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
7719 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
7722 u8 is_ipv6 = mp->is_ipv6;
7723 u8 is_add = mp->is_add;
7724 u8 mask_length = mp->mask_length;
7725 ip4_address_t ip4_addr;
7726 ip6_address_t ip6_addr;
7728 u16 *high_ports = 0;
7730 u16 tmp_low, tmp_high;
7734 // Validate port range
7735 num_ranges = mp->number_of_ranges;
7736 if (num_ranges > 32)
7737 { // This is size of array in VPE.API
7738 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
7742 vec_reset_length (low_ports);
7743 vec_reset_length (high_ports);
7745 for (i = 0; i < num_ranges; i++)
7747 tmp_low = mp->low_ports[i];
7748 tmp_high = mp->high_ports[i];
7749 // If tmp_low <= tmp_high then only need to check tmp_low = 0
7750 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
7751 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
7753 rv = VNET_API_ERROR_INVALID_VALUE;
7756 vec_add1 (low_ports, tmp_low);
7757 vec_add1 (high_ports, tmp_high + 1);
7760 // Validate mask_length
7761 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
7763 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
7767 vrf_id = ntohl (mp->vrf_id);
7771 rv = VNET_API_ERROR_INVALID_VALUE;
7778 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
7779 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
7783 high_ports, is_add);
7787 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
7788 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
7792 high_ports, is_add);
7796 vec_free (low_ports);
7797 vec_free (high_ports);
7798 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
7802 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
7803 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
7805 vlib_main_t *vm = vlib_get_main ();
7806 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
7807 ip4_main_t *im = &ip4_main;
7810 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7811 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7815 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
7816 ntohl (mp->tcp_out_vrf_id);
7817 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
7818 ntohl (mp->udp_out_vrf_id);
7819 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
7820 ntohl (mp->tcp_in_vrf_id);
7821 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
7822 ntohl (mp->udp_in_vrf_id);
7825 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
7827 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
7829 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
7833 rv = VNET_API_ERROR_INVALID_VALUE;
7837 fib_index[i] = p[0];
7842 sw_if_index = ntohl (mp->sw_if_index);
7844 VALIDATE_SW_IF_INDEX (mp);
7847 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
7850 BAD_SW_IF_INDEX_LABEL;
7853 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
7857 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
7860 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
7862 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
7863 u32 sw_if_index = ~0;
7865 /* Check src & dst are different */
7866 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
7868 rv = VNET_API_ERROR_SAME_SRC_DST;
7872 memset (a, 0, sizeof (*a));
7874 /* ip addresses sent in network byte order */
7875 clib_memcpy (&(a->src), mp->src_address, 4);
7876 clib_memcpy (&(a->dst), mp->dst_address, 4);
7877 a->is_add = mp->is_add;
7878 a->lsa = ntohl (mp->local_sa_id);
7879 a->rsa = ntohl (mp->remote_sa_id);
7881 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
7885 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
7887 rmp->sw_if_index = ntohl (sw_if_index);
7892 static void send_ipsec_gre_tunnel_details
7893 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
7895 vl_api_ipsec_gre_tunnel_details_t *rmp;
7897 rmp = vl_msg_api_alloc (sizeof (*rmp));
7898 memset (rmp, 0, sizeof (*rmp));
7899 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
7900 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
7901 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
7902 rmp->sw_if_index = htonl (t->sw_if_index);
7903 rmp->local_sa_id = htonl (t->local_sa_id);
7904 rmp->remote_sa_id = htonl (t->remote_sa_id);
7905 rmp->context = context;
7907 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7910 static void vl_api_ipsec_gre_tunnel_dump_t_handler
7911 (vl_api_ipsec_gre_tunnel_dump_t * mp)
7913 unix_shared_memory_queue_t *q;
7914 ipsec_gre_main_t *igm = &ipsec_gre_main;
7915 ipsec_gre_tunnel_t *t;
7918 q = vl_api_client_index_to_input_queue (mp->client_index);
7924 sw_if_index = ntohl (mp->sw_if_index);
7926 if (~0 == sw_if_index)
7929 pool_foreach (t, igm->tunnels,
7931 send_ipsec_gre_tunnel_details(t, q, mp->context);
7937 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
7938 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
7942 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
7943 send_ipsec_gre_tunnel_details (t, q, mp->context);
7948 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
7950 vl_api_delete_subif_reply_t *rmp;
7953 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
7955 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
7959 vl_api_l2_interface_pbb_tag_rewrite_t_handler
7960 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
7962 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
7963 vnet_main_t *vnm = vnet_get_main ();
7964 vlib_main_t *vm = vlib_get_main ();
7968 VALIDATE_SW_IF_INDEX (mp);
7970 vtr_op = ntohl (mp->vtr_op);
7974 case L2_VTR_DISABLED:
7977 case L2_VTR_TRANSLATE_2_1:
7981 rv = VNET_API_ERROR_INVALID_VALUE;
7982 goto bad_sw_if_index;
7985 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
7986 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
7987 ntohl (mp->i_sid), ntohs (mp->outer_tag));
7989 BAD_SW_IF_INDEX_LABEL;
7991 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
7995 vl_api_punt_t_handler (vl_api_punt_t * mp)
7997 vl_api_punt_reply_t *rmp;
7998 vlib_main_t *vm = vlib_get_main ();
8000 clib_error_t *error;
8002 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8003 ntohs (mp->l4_port), mp->is_add);
8007 clib_error_report (error);
8010 REPLY_MACRO (VL_API_PUNT_REPLY);
8014 vl_api_flow_classify_set_interface_t_handler
8015 (vl_api_flow_classify_set_interface_t * mp)
8017 vlib_main_t *vm = vlib_get_main ();
8018 vl_api_flow_classify_set_interface_reply_t *rmp;
8020 u32 sw_if_index, ip4_table_index, ip6_table_index;
8022 ip4_table_index = ntohl (mp->ip4_table_index);
8023 ip6_table_index = ntohl (mp->ip6_table_index);
8024 sw_if_index = ntohl (mp->sw_if_index);
8026 VALIDATE_SW_IF_INDEX (mp);
8028 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
8029 ip6_table_index, mp->is_add);
8031 BAD_SW_IF_INDEX_LABEL;
8033 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
8037 send_flow_classify_details (u32 sw_if_index,
8039 unix_shared_memory_queue_t * q, u32 context)
8041 vl_api_flow_classify_details_t *mp;
8043 mp = vl_msg_api_alloc (sizeof (*mp));
8044 memset (mp, 0, sizeof (*mp));
8045 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
8046 mp->context = context;
8047 mp->sw_if_index = htonl (sw_if_index);
8048 mp->table_index = htonl (table_index);
8050 vl_msg_api_send_shmem (q, (u8 *) & mp);
8054 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8056 unix_shared_memory_queue_t *q;
8057 flow_classify_main_t *pcm = &flow_classify_main;
8061 q = vl_api_client_index_to_input_queue (mp->client_index);
8065 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8067 if (vec_len (vec_tbl))
8069 for (i = 0; i < vec_len (vec_tbl); i++)
8071 if (vec_elt (vec_tbl, i) == ~0)
8074 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8081 send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
8084 vl_api_ipsec_spd_details_t *mp;
8086 mp = vl_msg_api_alloc (sizeof (*mp));
8087 memset (mp, 0, sizeof (*mp));
8088 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
8089 mp->context = context;
8091 mp->spd_id = htonl (p->id);
8092 mp->priority = htonl (p->priority);
8093 mp->is_outbound = p->is_outbound;
8094 mp->is_ipv6 = p->is_ipv6;
8097 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
8098 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
8099 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
8100 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
8104 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
8105 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
8106 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
8107 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
8109 mp->local_start_port = htons (p->lport.start);
8110 mp->local_stop_port = htons (p->lport.stop);
8111 mp->remote_start_port = htons (p->rport.start);
8112 mp->remote_stop_port = htons (p->rport.stop);
8113 mp->protocol = p->protocol;
8114 mp->policy = p->policy;
8115 mp->sa_id = htonl (p->sa_id);
8116 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
8117 mp->packets = clib_host_to_net_u64 (p->counter.packets);
8119 vl_msg_api_send_shmem (q, (u8 *) & mp);
8123 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
8125 unix_shared_memory_queue_t *q;
8126 ipsec_main_t *im = &ipsec_main;
8127 ipsec_policy_t *policy;
8132 q = vl_api_client_index_to_input_queue (mp->client_index);
8136 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
8141 spd = pool_elt_at_index (im->spds, spd_index);
8144 pool_foreach (policy, spd->policies,
8146 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
8147 send_ipsec_spd_details (policy, q,
8152 clib_warning ("unimplemented");
8157 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
8159 vl_api_feature_enable_disable_reply_t *rmp;
8161 u8 *arc_name, *feature_name;
8163 VALIDATE_SW_IF_INDEX (mp);
8165 arc_name = format (0, "%s%c", mp->arc_name, 0);
8166 feature_name = format (0, "%s%c", mp->feature_name, 0);
8168 vnet_feature_registration_t *reg;
8170 vnet_get_feature_reg ((const char *) arc_name,
8171 (const char *) feature_name);
8173 rv = VNET_API_ERROR_INVALID_VALUE;
8177 clib_error_t *error = 0;
8179 sw_if_index = ntohl (mp->sw_if_index);
8180 if (reg->enable_disable_cb)
8181 error = reg->enable_disable_cb (sw_if_index, mp->enable);
8183 vnet_feature_enable_disable ((const char *) arc_name,
8184 (const char *) feature_name,
8185 sw_if_index, mp->enable, 0, 0);
8188 clib_error_report (error);
8189 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
8193 vec_free (feature_name);
8194 vec_free (arc_name);
8196 BAD_SW_IF_INDEX_LABEL;
8198 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
8202 send_ip_neighbor_details (u8 is_ipv6,
8206 unix_shared_memory_queue_t * q, u32 context)
8208 vl_api_ip_neighbor_details_t *mp;
8210 mp = vl_msg_api_alloc (sizeof (*mp));
8211 memset (mp, 0, sizeof (*mp));
8212 mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS);
8213 mp->context = context;
8214 mp->is_ipv6 = is_ipv6;
8215 mp->is_static = is_static;
8216 memcpy (mp->mac_address, mac_address, 6);
8217 memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
8219 vl_msg_api_send_shmem (q, (u8 *) & mp);
8223 vl_api_ip_neighbor_details_t_handler (vl_api_ip_neighbor_details_t * mp)
8225 clib_warning ("BUG");
8229 vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp)
8231 unix_shared_memory_queue_t *q;
8233 q = vl_api_client_index_to_input_queue (mp->client_index);
8237 u32 sw_if_index = ntohl (mp->sw_if_index);
8241 ip6_neighbor_t *n, *ns;
8243 ns = ip6_neighbors_entries (sw_if_index);
8247 send_ip_neighbor_details (mp->is_ipv6,
8248 ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0),
8249 (u8 *) n->link_layer_address,
8250 (u8 *) & (n->key.ip6_address.as_u8),
8258 ethernet_arp_ip4_entry_t *n, *ns;
8260 ns = ip4_neighbor_entries (sw_if_index);
8264 send_ip_neighbor_details (mp->is_ipv6,
8265 ((n->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) ? 1 : 0),
8266 (u8*) n->ethernet_address,
8267 (u8*) & (n->ip4_address.as_u8),
8275 #define BOUNCE_HANDLER(nn) \
8276 static void vl_api_##nn##_t_handler ( \
8277 vl_api_##nn##_t *mp) \
8279 vpe_client_registration_t *reg; \
8280 vpe_api_main_t * vam = &vpe_api_main; \
8281 unix_shared_memory_queue_t * q; \
8283 /* One registration only... */ \
8284 pool_foreach(reg, vam->nn##_registrations, \
8286 q = vl_api_client_index_to_input_queue (reg->client_index); \
8289 * If the queue is stuffed, turf the msg and complain \
8290 * It's unlikely that the intended recipient is \
8291 * alive; avoid deadlock at all costs. \
8293 if (q->cursize == q->maxsize) { \
8294 clib_warning ("ERROR: receiver queue full, drop msg"); \
8295 vl_msg_api_free (mp); \
8298 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8302 vl_msg_api_free (mp); \
8305 static void setup_message_id_table (api_main_t * am);
8309 * Add vpe's API message handlers to the table.
8310 * vlib has alread mapped shared memory and
8311 * added the client registration handlers.
8312 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8314 static clib_error_t *
8315 vpe_api_hookup (vlib_main_t * vm)
8317 api_main_t *am = &api_main;
8320 vl_msg_api_set_handlers(VL_API_##N, #n, \
8321 vl_api_##n##_t_handler, \
8323 vl_api_##n##_t_endian, \
8324 vl_api_##n##_t_print, \
8325 sizeof(vl_api_##n##_t), 1);
8326 foreach_vpe_api_msg;
8330 * Manually register the sr tunnel add del msg, so we trace
8331 * enough bytes to capture a typical segment list
8333 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8334 "sr_tunnel_add_del",
8335 vl_api_sr_tunnel_add_del_t_handler,
8337 vl_api_sr_tunnel_add_del_t_endian,
8338 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8342 * Manually register the sr policy add del msg, so we trace
8343 * enough bytes to capture a typical tunnel name list
8345 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8346 "sr_policy_add_del",
8347 vl_api_sr_policy_add_del_t_handler,
8349 vl_api_sr_policy_add_del_t_endian,
8350 vl_api_sr_policy_add_del_t_print, 256, 1);
8353 * Trace space for 8 MPLS encap labels, classifier mask+match
8355 am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32);
8356 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8357 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8358 += 5 * sizeof (u32x4);
8359 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8362 * Thread-safe API messages
8364 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8365 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8368 * Set up the (msg_name, crc, message-id) table
8370 setup_message_id_table (am);
8375 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8377 static clib_error_t *
8378 vpe_api_init (vlib_main_t * vm)
8380 vpe_api_main_t *am = &vpe_api_main;
8383 am->vnet_main = vnet_get_main ();
8384 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8385 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8386 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8387 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8388 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8389 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8392 vl_set_memory_region_name ("/vpe-api");
8393 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8398 VLIB_INIT_FUNCTION (vpe_api_init);
8401 static clib_error_t *
8402 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8405 u64 baseva, size, pvt_heap_size;
8407 const int max_buf_size = 4096;
8409 struct passwd _pw, *pw;
8410 struct group _grp, *grp;
8412 buf = vec_new (char, 128);
8413 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8415 if (unformat (input, "prefix %s", &chroot_path))
8417 vec_add1 (chroot_path, 0);
8418 vl_set_memory_root_path ((char *) chroot_path);
8420 else if (unformat (input, "uid %d", &uid))
8421 vl_set_memory_uid (uid);
8422 else if (unformat (input, "gid %d", &gid))
8423 vl_set_memory_gid (gid);
8424 else if (unformat (input, "baseva %llx", &baseva))
8425 vl_set_global_memory_baseva (baseva);
8426 else if (unformat (input, "global-size %lldM", &size))
8427 vl_set_global_memory_size (size * (1ULL << 20));
8428 else if (unformat (input, "global-size %lldG", &size))
8429 vl_set_global_memory_size (size * (1ULL << 30));
8430 else if (unformat (input, "global-size %lld", &size))
8431 vl_set_global_memory_size (size);
8432 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8433 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8434 else if (unformat (input, "global-pvt-heap-size size %lld",
8436 vl_set_global_pvt_heap_size (pvt_heap_size);
8437 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8438 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8439 else if (unformat (input, "api-pvt-heap-size size %lld",
8441 vl_set_api_pvt_heap_size (pvt_heap_size);
8442 else if (unformat (input, "api-size %lldM", &size))
8443 vl_set_api_memory_size (size * (1ULL << 20));
8444 else if (unformat (input, "api-size %lldG", &size))
8445 vl_set_api_memory_size (size * (1ULL << 30));
8446 else if (unformat (input, "api-size %lld", &size))
8447 vl_set_api_memory_size (size);
8448 else if (unformat (input, "uid %s", &s))
8450 /* lookup the username */
8453 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8454 && (vec_len (buf) <= max_buf_size))
8456 vec_resize (buf, vec_len (buf) * 2);
8460 e = clib_error_return_code (0, rv,
8461 CLIB_ERROR_ERRNO_VALID |
8463 "cannot fetch username %s", s);
8471 clib_error_return_fatal (0, "username %s does not exist", s);
8477 vl_set_memory_uid (pw->pw_uid);
8479 else if (unformat (input, "gid %s", &s))
8481 /* lookup the group name */
8484 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8485 && (vec_len (buf) <= max_buf_size))
8487 vec_resize (buf, vec_len (buf) * 2);
8491 e = clib_error_return_code (0, rv,
8492 CLIB_ERROR_ERRNO_VALID |
8494 "cannot fetch group %s", s);
8501 e = clib_error_return_fatal (0, "group %s does not exist", s);
8508 vl_set_memory_gid (grp->gr_gid);
8511 return clib_error_return (0, "unknown input `%U'",
8512 format_unformat_error, input);
8517 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8520 get_unformat_vnet_sw_interface (void)
8522 return (void *) &unformat_vnet_sw_interface;
8526 format_arp_event (u8 * s, va_list * args)
8528 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8530 s = format (s, "pid %d: ", event->pid);
8532 s = format (s, "bd mac/ip4 binding events");
8534 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8539 format_nd_event (u8 * s, va_list * args)
8541 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8543 s = format (s, "pid %d: ", event->pid);
8545 s = format (s, "bd mac/ip6 binding events");
8547 s = format (s, "resolution for %U", format_ip6_address, event->address);
8551 static clib_error_t *
8552 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8553 unformat_input_t * input, vlib_cli_command_t * cmd)
8555 vpe_api_main_t *am = &vpe_api_main;
8556 vl_api_ip4_arp_event_t *arp_event;
8557 vl_api_ip6_nd_event_t *nd_event;
8559 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8561 vlib_cli_output (vm, "No active arp or nd event registrations");
8566 pool_foreach (arp_event, am->arp_events,
8568 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8571 pool_foreach (nd_event, am->nd_events,
8573 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8581 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8582 .path = "show arp-nd-event registrations",
8583 .function = show_ip_arp_nd_events_fn,
8584 .short_help = "Show ip4 arp and ip6 nd event registrations",
8588 #define vl_msg_name_crc_list
8589 #include <vpp-api/vpe_all_api_h.h>
8590 #undef vl_msg_name_crc_list
8593 setup_message_id_table (api_main_t * am)
8595 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
8596 foreach_vl_msg_name_crc_memclnt;
8597 foreach_vl_msg_name_crc_vpe;
8603 * fd.io coding-style-patch-verification: ON
8606 * eval: (c-set-style "gnu")