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/ip/ip.h>
53 #include <vnet/ip/ip6.h>
54 #include <vnet/ip/ip6_neighbor.h>
55 #include <vnet/mpls/mpls.h>
56 #include <vnet/mpls/mpls_tunnel.h>
57 #include <vnet/dhcp/proxy.h>
58 #include <vnet/dhcp/client.h>
60 #include <vnet/sr/sr.h>
62 #include <vnet/dhcpv6/proxy.h>
63 #include <vlib/vlib.h>
64 #include <vlib/unix/unix.h>
65 #include <vlibapi/api.h>
66 #include <vlibmemory/api.h>
67 #include <vnet/classify/vnet_classify.h>
68 #include <vnet/classify/input_acl.h>
69 #include <vnet/classify/policer_classify.h>
70 #include <vnet/classify/flow_classify.h>
71 #include <vnet/l2/l2_classify.h>
72 #include <vnet/vxlan/vxlan.h>
73 #include <vnet/l2/l2_vtr.h>
74 #include <vnet/vxlan-gpe/vxlan_gpe.h>
75 #include <vnet/lisp-gpe/lisp_gpe.h>
76 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
77 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
78 #include <vnet/lisp-cp/control.h>
79 #include <vnet/map/map.h>
80 #include <vnet/cop/cop.h>
81 #include <vnet/ip/ip6_hop_by_hop.h>
82 #include <vnet/ip/ip_source_and_port_range_check.h>
83 #include <vnet/policer/policer.h>
84 #include <vnet/flow/flow_report.h>
85 #include <vnet/flow/flow_report_classify.h>
86 #include <vnet/ip/punt.h>
87 #include <vnet/feature/feature.h>
90 #undef __included_bihash_template_h__
91 #include <vnet/l2/l2_fib.h>
94 #include <vnet/devices/dpdk/dpdk.h>
97 #include <stats/stats.h>
99 #include <vnet/ethernet/ethernet.h>
100 #include <vnet/ethernet/arp_packet.h>
101 #include <vnet/interface.h>
102 #include <vnet/l2/l2_fib.h>
103 #include <vnet/l2/l2_bd.h>
104 #include <vpp-api/vpe_msg_enum.h>
105 #include <vnet/span/span.h>
106 #include <vnet/fib/ip6_fib.h>
107 #include <vnet/fib/ip4_fib.h>
108 #include <vnet/fib/fib_api.h>
109 #include <vnet/dpo/drop_dpo.h>
110 #include <vnet/dpo/receive_dpo.h>
111 #include <vnet/dpo/lookup_dpo.h>
112 #include <vnet/dpo/classify_dpo.h>
113 #include <vnet/dpo/ip_null_dpo.h>
114 #define vl_typedefs /* define message structures */
115 #include <vpp-api/vpe_all_api_h.h>
117 #define vl_endianfun /* define message structures */
118 #include <vpp-api/vpe_all_api_h.h>
120 /* instantiate all the print functions we know about */
121 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
123 #include <vpp-api/vpe_all_api_h.h>
125 #include <vlibapi/api_helper_macros.h>
126 #define foreach_vpe_api_msg \
127 _(WANT_OAM_EVENTS, want_oam_events) \
128 _(OAM_ADD_DEL, oam_add_del) \
129 _(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \
130 _(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \
131 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
132 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
133 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
134 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
135 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
136 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
137 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
138 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
139 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
140 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
141 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
142 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
143 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
144 _(L2FIB_ADD_DEL, l2fib_add_del) \
145 _(L2_FLAGS, l2_flags) \
146 _(BRIDGE_FLAGS, bridge_flags) \
147 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
148 _(CREATE_SUBIF, create_subif) \
149 _(MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del) \
150 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
151 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
152 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
153 _(RESET_FIB, reset_fib) \
154 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
155 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
156 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
157 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
158 _(CREATE_LOOPBACK, create_loopback) \
159 _(CONTROL_PING, control_ping) \
160 _(CLI_REQUEST, cli_request) \
161 _(CLI_INBAND, cli_inband) \
162 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
163 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
164 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
165 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
166 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
167 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
168 _(GET_NODE_INDEX, get_node_index) \
169 _(ADD_NODE_NEXT, add_node_next) \
170 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
171 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
172 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
173 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
174 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
175 _(SHOW_VERSION, show_version) \
176 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
177 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
178 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
179 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
180 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
181 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
182 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
183 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
184 _(DELETE_LOOPBACK, delete_loopback) \
185 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
186 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
187 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
188 _(GET_NODE_GRAPH, get_node_graph) \
189 _(IOAM_ENABLE, ioam_enable) \
190 _(IOAM_DISABLE, ioam_disable) \
191 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
192 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
193 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
194 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
195 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
196 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
197 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
198 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
199 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
200 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
201 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
202 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
203 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
204 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
205 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
206 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
207 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
208 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
209 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
210 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
211 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
212 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
213 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
214 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
215 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
216 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
217 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
218 _(SHOW_LISP_STATUS, show_lisp_status) \
219 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
220 lisp_add_del_map_request_itr_rlocs) \
221 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
222 _(SHOW_LISP_PITR, show_lisp_pitr) \
223 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
224 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
225 _(POLICER_ADD_DEL, policer_add_del) \
226 _(POLICER_DUMP, policer_dump) \
227 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
228 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
229 _(MPLS_TUNNEL_DUMP, mpls_tunnel_dump) \
230 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
231 _(MPLS_FIB_DUMP, mpls_fib_dump) \
232 _(MPLS_FIB_DETAILS, mpls_fib_details) \
233 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
234 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
235 _(CLASSIFY_TABLE_INFO,classify_table_info) \
236 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
237 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
238 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
239 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
240 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
241 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
242 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
243 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
244 _(GET_NEXT_INDEX, get_next_index) \
245 _(PG_CREATE_INTERFACE, pg_create_interface) \
246 _(PG_CAPTURE, pg_capture) \
247 _(PG_ENABLE_DISABLE, pg_enable_disable) \
248 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
249 ip_source_and_port_range_check_add_del) \
250 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
251 ip_source_and_port_range_check_interface_add_del) \
252 _(DELETE_SUBIF, delete_subif) \
253 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
255 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
256 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
257 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
260 #define QUOTE(x) QUOTE_(x)
263 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
264 RESOLVE_IP6_ADD_DEL_ROUTE,
267 static vlib_node_registration_t vpe_resolver_process_node;
268 vpe_api_main_t vpe_api_main;
270 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
271 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
273 /* Clean up all registrations belonging to the indicated client */
275 vl_api_memclnt_delete_callback (u32 client_index)
277 vpe_api_main_t *vam = &vpe_api_main;
278 vpe_client_registration_t *rp;
280 int stats_memclnt_delete_callback (u32 client_index);
282 stats_memclnt_delete_callback (client_index);
285 p = hash_get (vam->a##_registration_hash, client_index); \
287 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
288 pool_put (vam->a##_registrations, rp); \
289 hash_unset (vam->a##_registration_hash, client_index); \
291 foreach_registration_hash;
296 pub_sub_handler (oam_events, OAM_EVENTS);
298 #define RESOLUTION_EVENT 1
299 #define RESOLUTION_PENDING_EVENT 2
300 #define IP4_ARP_EVENT 3
301 #define IP6_ND_EVENT 4
303 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
305 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
308 handle_ip4_arp_event (u32 pool_index)
310 vpe_api_main_t *vam = &vpe_api_main;
311 vnet_main_t *vnm = vam->vnet_main;
312 vlib_main_t *vm = vam->vlib_main;
313 vl_api_ip4_arp_event_t *event;
314 vl_api_ip4_arp_event_t *mp;
315 unix_shared_memory_queue_t *q;
317 /* Client can cancel, die, etc. */
318 if (pool_is_free_index (vam->arp_events, pool_index))
321 event = pool_elt_at_index (vam->arp_events, pool_index);
323 q = vl_api_client_index_to_input_queue (event->client_index);
326 (void) vnet_add_del_ip4_arp_change_event
327 (vnm, arp_change_delete_callback,
328 event->pid, &event->address,
329 vpe_resolver_process_node.index, IP4_ARP_EVENT,
330 ~0 /* pool index, notused */ , 0 /* is_add */ );
334 if (q->cursize < q->maxsize)
336 mp = vl_msg_api_alloc (sizeof (*mp));
337 clib_memcpy (mp, event, sizeof (*mp));
338 vl_msg_api_send_shmem (q, (u8 *) & mp);
342 static f64 last_time;
344 * Throttle syslog msgs.
345 * It's pretty tempting to just revoke the registration...
347 if (vlib_time_now (vm) > last_time + 10.0)
349 clib_warning ("arp event for %U to pid %d: queue stuffed!",
350 format_ip4_address, &event->address, event->pid);
351 last_time = vlib_time_now (vm);
357 handle_ip6_nd_event (u32 pool_index)
359 vpe_api_main_t *vam = &vpe_api_main;
360 vnet_main_t *vnm = vam->vnet_main;
361 vlib_main_t *vm = vam->vlib_main;
362 vl_api_ip6_nd_event_t *event;
363 vl_api_ip6_nd_event_t *mp;
364 unix_shared_memory_queue_t *q;
366 /* Client can cancel, die, etc. */
367 if (pool_is_free_index (vam->nd_events, pool_index))
370 event = pool_elt_at_index (vam->nd_events, pool_index);
372 q = vl_api_client_index_to_input_queue (event->client_index);
375 (void) vnet_add_del_ip6_nd_change_event
376 (vnm, nd_change_delete_callback,
377 event->pid, &event->address,
378 vpe_resolver_process_node.index, IP6_ND_EVENT,
379 ~0 /* pool index, notused */ , 0 /* is_add */ );
383 if (q->cursize < q->maxsize)
385 mp = vl_msg_api_alloc (sizeof (*mp));
386 clib_memcpy (mp, event, sizeof (*mp));
387 vl_msg_api_send_shmem (q, (u8 *) & mp);
391 static f64 last_time;
393 * Throttle syslog msgs.
394 * It's pretty tempting to just revoke the registration...
396 if (vlib_time_now (vm) > last_time + 10.0)
398 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
399 format_ip6_address, &event->address, event->pid);
400 last_time = vlib_time_now (vm);
406 resolver_process (vlib_main_t * vm,
407 vlib_node_runtime_t * rt, vlib_frame_t * f)
410 uword *event_data = 0;
416 vlib_process_wait_for_event_or_clock (vm, timeout);
418 event_type = vlib_process_get_events (vm, &event_data);
422 case RESOLUTION_PENDING_EVENT:
426 case RESOLUTION_EVENT:
427 clib_warning ("resolver: BOGUS TYPE");
431 for (i = 0; i < vec_len (event_data); i++)
432 handle_ip4_arp_event (event_data[i]);
436 for (i = 0; i < vec_len (event_data); i++)
437 handle_ip6_nd_event (event_data[i]);
440 case ~0: /* timeout */
444 vec_reset_length (event_data);
446 return 0; /* or not */
450 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
451 .function = resolver_process,
452 .type = VLIB_NODE_TYPE_PROCESS,
453 .name = "vpe-route-resolver-process",
458 mpls_route_add_del_t_handler (vnet_main_t * vnm,
459 vl_api_mpls_route_add_del_t * mp)
461 u32 fib_index, next_hop_fib_index;
462 mpls_label_t *label_stack = NULL;
463 int rv, ii, n_labels;;
467 .fp_proto = FIB_PROTOCOL_MPLS,
468 .fp_eos = mp->mr_eos,
469 .fp_label = ntohl (mp->mr_label),
473 if (mp->mr_next_hop_proto_is_ip4)
475 pfx.fp_payload_proto = DPO_PROTO_IP4;
479 pfx.fp_payload_proto = DPO_PROTO_IP6;
484 pfx.fp_payload_proto = DPO_PROTO_MPLS;
487 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
489 mp->mr_next_hop_sw_if_index,
490 dpo_proto_to_fib (pfx.fp_payload_proto),
491 mp->mr_next_hop_table_id,
492 mp->mr_create_table_if_needed,
493 &fib_index, &next_hop_fib_index);
499 memset (&nh, 0, sizeof (nh));
501 if (mp->mr_next_hop_proto_is_ip4)
502 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
504 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
506 n_labels = mp->mr_next_hop_n_out_labels;
509 else if (1 == n_labels)
510 vec_add1 (label_stack, ntohl (mp->mr_next_hop_out_label_stack[0]));
513 vec_validate (label_stack, n_labels - 1);
514 for (ii = 0; ii < n_labels; ii++)
515 label_stack[ii] = ntohl (mp->mr_next_hop_out_label_stack[ii]);
518 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
519 0, // mp->is_unreach,
520 0, // mp->is_prohibit,
523 mp->mr_classify_table_index,
524 mp->mr_is_resolve_host,
525 mp->mr_is_resolve_attached,
527 mp->mr_next_hop_proto_is_ip4,
528 &nh, ntohl (mp->mr_next_hop_sw_if_index),
530 mp->mr_next_hop_weight,
531 ntohl (mp->mr_next_hop_via_label),
536 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
538 vl_api_mpls_route_add_del_reply_t *rmp;
542 vnm = vnet_get_main ();
545 rv = mpls_route_add_del_t_handler (vnm, mp);
547 rv = (rv == 0) ? vnm->api_errno : rv;
549 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
553 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
554 vl_api_mpls_ip_bind_unbind_t * mp)
556 u32 mpls_fib_index, ip_fib_index;
559 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
561 if (~0 == mpls_fib_index)
563 if (mp->mb_create_table_if_needed)
566 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
567 ntohl (mp->mb_mpls_table_id));
570 return VNET_API_ERROR_NO_SUCH_FIB;
573 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
576 ntohl (mp->mb_ip_table_id));
577 if (~0 == ip_fib_index)
578 return VNET_API_ERROR_NO_SUCH_FIB;
581 .fp_len = mp->mb_address_length,
586 pfx.fp_proto = FIB_PROTOCOL_IP4;
587 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
588 sizeof (pfx.fp_addr.ip4));
592 pfx.fp_proto = FIB_PROTOCOL_IP6;
593 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
594 sizeof (pfx.fp_addr.ip6));
598 fib_table_entry_local_label_add (ip_fib_index, &pfx,
599 ntohl (mp->mb_label));
601 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
602 ntohl (mp->mb_label));
608 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
610 vl_api_mpls_route_add_del_reply_t *rmp;
614 vnm = vnet_get_main ();
617 rv = mpls_ip_bind_unbind_handler (vnm, mp);
619 rv = (rv == 0) ? vnm->api_errno : rv;
621 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
625 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
627 vl_api_sw_interface_set_vpath_reply_t *rmp;
629 u32 sw_if_index = ntohl (mp->sw_if_index);
631 VALIDATE_SW_IF_INDEX (mp);
633 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
634 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
635 sw_if_index, mp->enable, 0, 0);
636 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
637 sw_if_index, mp->enable, 0, 0);
638 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
639 sw_if_index, mp->enable, 0, 0);
640 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
641 sw_if_index, mp->enable, 0, 0);
643 BAD_SW_IF_INDEX_LABEL;
645 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
649 vl_api_sw_interface_set_vxlan_bypass_t_handler
650 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
652 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
654 u32 sw_if_index = ntohl (mp->sw_if_index);
656 VALIDATE_SW_IF_INDEX (mp);
660 /* not yet implemented */
663 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
664 sw_if_index, mp->enable, 0, 0);
666 BAD_SW_IF_INDEX_LABEL;
668 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
672 vl_api_sw_interface_set_l2_xconnect_t_handler
673 (vl_api_sw_interface_set_l2_xconnect_t * mp)
675 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
677 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
678 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
679 vlib_main_t *vm = vlib_get_main ();
680 vnet_main_t *vnm = vnet_get_main ();
682 VALIDATE_RX_SW_IF_INDEX (mp);
686 VALIDATE_TX_SW_IF_INDEX (mp);
687 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
688 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
692 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
695 BAD_RX_SW_IF_INDEX_LABEL;
696 BAD_TX_SW_IF_INDEX_LABEL;
698 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
702 vl_api_sw_interface_set_l2_bridge_t_handler
703 (vl_api_sw_interface_set_l2_bridge_t * mp)
705 bd_main_t *bdm = &bd_main;
706 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
708 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
709 u32 bd_id = ntohl (mp->bd_id);
713 vlib_main_t *vm = vlib_get_main ();
714 vnet_main_t *vnm = vnet_get_main ();
716 VALIDATE_RX_SW_IF_INDEX (mp);
718 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
722 //VALIDATE_TX_SW_IF_INDEX(mp);
723 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
724 rx_sw_if_index, bd_index, bvi, shg, 0);
728 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
731 BAD_RX_SW_IF_INDEX_LABEL;
733 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
737 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
738 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
740 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
744 dpdk_main_t *dm = &dpdk_main;
747 u32 sw_if_index = ntohl (mp->sw_if_index);
748 u32 subport = ntohl (mp->subport);
749 u32 pipe = ntohl (mp->pipe);
750 u32 profile = ntohl (mp->profile);
751 vnet_hw_interface_t *hw;
753 VALIDATE_SW_IF_INDEX (mp);
755 /* hw_if & dpdk device */
756 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
758 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
760 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
762 BAD_SW_IF_INDEX_LABEL;
764 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
765 rv = VNET_API_ERROR_UNIMPLEMENTED;
768 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
772 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
773 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
775 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
779 dpdk_main_t *dm = &dpdk_main;
781 struct rte_sched_subport_params p;
783 u32 sw_if_index = ntohl (mp->sw_if_index);
784 u32 subport = ntohl (mp->subport);
785 p.tb_rate = ntohl (mp->tb_rate);
786 p.tb_size = ntohl (mp->tb_size);
787 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
788 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
789 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
790 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
791 p.tc_period = ntohl (mp->tc_period);
793 vnet_hw_interface_t *hw;
795 VALIDATE_SW_IF_INDEX (mp);
797 /* hw_if & dpdk device */
798 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
800 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
802 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
804 BAD_SW_IF_INDEX_LABEL;
807 ("setting HQoS subport parameters without DPDK not implemented");
808 rv = VNET_API_ERROR_UNIMPLEMENTED;
811 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
815 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
816 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
818 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
822 dpdk_main_t *dm = &dpdk_main;
823 vlib_thread_main_t *tm = vlib_get_thread_main ();
826 u32 sw_if_index = ntohl (mp->sw_if_index);
827 u32 entry = ntohl (mp->entry);
828 u32 tc = ntohl (mp->tc);
829 u32 queue = ntohl (mp->queue);
832 vnet_hw_interface_t *hw;
834 VALIDATE_SW_IF_INDEX (mp);
836 /* hw_if & dpdk device */
837 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
839 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
841 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
843 clib_warning ("invalid traffic class !!");
844 rv = VNET_API_ERROR_INVALID_VALUE;
847 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
849 clib_warning ("invalid queue !!");
850 rv = VNET_API_ERROR_INVALID_VALUE;
854 /* Detect the set of worker threads */
855 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
859 clib_warning ("worker thread registration AWOL !!");
860 rv = VNET_API_ERROR_INVALID_VALUE_2;
864 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
865 int worker_thread_first = tr->first_index;
866 int worker_thread_count = tr->count;
868 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
869 for (i = 0; i < worker_thread_count; i++)
870 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
872 BAD_SW_IF_INDEX_LABEL;
875 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
876 rv = VNET_API_ERROR_UNIMPLEMENTED;
879 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
883 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
885 vlib_main_t *vm = vlib_get_main ();
886 bd_main_t *bdm = &bd_main;
887 vl_api_bridge_domain_add_del_reply_t *rmp;
889 u32 enable_flags = 0, disable_flags = 0;
890 u32 bd_id = ntohl (mp->bd_id);
895 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
898 enable_flags |= L2_FLOOD;
900 disable_flags |= L2_FLOOD;
903 enable_flags |= L2_UU_FLOOD;
905 disable_flags |= L2_UU_FLOOD;
908 enable_flags |= L2_FWD;
910 disable_flags |= L2_FWD;
913 enable_flags |= L2_ARP_TERM;
915 disable_flags |= L2_ARP_TERM;
918 enable_flags |= L2_LEARN;
920 disable_flags |= L2_LEARN;
923 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
926 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
928 bd_set_mac_age (vm, bd_index, mp->mac_age);
931 rv = bd_delete_bd_index (bdm, bd_id);
933 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
937 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
939 clib_warning ("BUG");
943 vl_api_bridge_domain_sw_if_details_t_handler
944 (vl_api_bridge_domain_sw_if_details_t * mp)
946 clib_warning ("BUG");
950 send_bridge_domain_details (unix_shared_memory_queue_t * q,
951 l2_bridge_domain_t * bd_config,
952 u32 n_sw_ifs, u32 context)
954 vl_api_bridge_domain_details_t *mp;
956 mp = vl_msg_api_alloc (sizeof (*mp));
957 memset (mp, 0, sizeof (*mp));
958 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
959 mp->bd_id = ntohl (bd_config->bd_id);
960 mp->flood = bd_feature_flood (bd_config);
961 mp->uu_flood = bd_feature_uu_flood (bd_config);
962 mp->forward = bd_feature_forward (bd_config);
963 mp->learn = bd_feature_learn (bd_config);
964 mp->arp_term = bd_feature_arp_term (bd_config);
965 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
966 mp->mac_age = bd_config->mac_age;
967 mp->n_sw_ifs = ntohl (n_sw_ifs);
968 mp->context = context;
970 vl_msg_api_send_shmem (q, (u8 *) & mp);
974 send_bd_sw_if_details (l2input_main_t * l2im,
975 unix_shared_memory_queue_t * q,
976 l2_flood_member_t * member, u32 bd_id, u32 context)
978 vl_api_bridge_domain_sw_if_details_t *mp;
979 l2_input_config_t *input_cfg;
981 mp = vl_msg_api_alloc (sizeof (*mp));
982 memset (mp, 0, sizeof (*mp));
983 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
984 mp->bd_id = ntohl (bd_id);
985 mp->sw_if_index = ntohl (member->sw_if_index);
986 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
987 mp->shg = input_cfg->shg;
988 mp->context = context;
990 vl_msg_api_send_shmem (q, (u8 *) & mp);
994 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
996 bd_main_t *bdm = &bd_main;
997 l2input_main_t *l2im = &l2input_main;
998 unix_shared_memory_queue_t *q;
999 l2_bridge_domain_t *bd_config;
1000 u32 bd_id, bd_index;
1003 q = vl_api_client_index_to_input_queue (mp->client_index);
1008 bd_id = ntohl (mp->bd_id);
1010 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1011 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1012 for (; bd_index < end; bd_index++)
1014 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1015 /* skip dummy bd_id 0 */
1016 if (bd_config && (bd_config->bd_id > 0))
1019 l2_flood_member_t *m;
1021 n_sw_ifs = vec_len (bd_config->members);
1022 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1024 vec_foreach (m, bd_config->members)
1026 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1033 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1035 bd_main_t *bdm = &bd_main;
1036 l2input_main_t *l2im = &l2input_main;
1037 vl_api_l2fib_add_del_reply_t *rmp;
1040 u32 sw_if_index = ntohl (mp->sw_if_index);
1041 u32 bd_id = ntohl (mp->bd_id);
1050 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1053 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1054 goto bad_sw_if_index;
1060 filter_mac = mp->filter_mac ? 1 : 0;
1061 if (filter_mac == 0)
1063 VALIDATE_SW_IF_INDEX (mp);
1064 if (vec_len (l2im->configs) <= sw_if_index)
1066 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1067 goto bad_sw_if_index;
1071 l2_input_config_t *config;
1072 config = vec_elt_at_index (l2im->configs, sw_if_index);
1073 if (config->bridge == 0)
1075 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1076 goto bad_sw_if_index;
1080 static_mac = mp->static_mac ? 1 : 0;
1081 bvi_mac = mp->bvi_mac ? 1 : 0;
1082 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1087 l2fib_del_entry (mac, bd_index);
1090 BAD_SW_IF_INDEX_LABEL;
1092 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1096 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1098 vl_api_l2_flags_reply_t *rmp;
1100 u32 sw_if_index = ntohl (mp->sw_if_index);
1101 u32 flags = ntohl (mp->feature_bitmap);
1104 VALIDATE_SW_IF_INDEX (mp);
1107 if (flags & L2INPUT_FEAT_ ## a) \
1108 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1109 foreach_l2input_feat;
1112 BAD_SW_IF_INDEX_LABEL;
1115 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1117 rmp->resulting_feature_bitmap = ntohl(rbm);
1123 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1125 vlib_main_t *vm = vlib_get_main ();
1126 bd_main_t *bdm = &bd_main;
1127 vl_api_bridge_flags_reply_t *rmp;
1129 u32 bd_id = ntohl (mp->bd_id);
1131 u32 flags = ntohl (mp->feature_bitmap);
1134 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1137 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1143 bd_set_flags (vm, bd_index, flags, mp->is_set);
1147 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1149 rmp->resulting_feature_bitmap = ntohl(flags);
1155 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1157 bd_main_t *bdm = &bd_main;
1158 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1160 u32 bd_id = ntohl (mp->bd_id);
1164 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1167 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1172 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1173 mp->mac_address, mp->is_ipv6, mp->is_add))
1174 rv = VNET_API_ERROR_UNSPECIFIED;
1177 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1181 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1183 vl_api_create_vlan_subif_reply_t *rmp;
1184 vnet_main_t *vnm = vnet_get_main ();
1185 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1186 vnet_hw_interface_t *hi;
1189 vnet_sw_interface_t template;
1191 vnet_interface_main_t *im = &vnm->interface_main;
1192 u64 sup_and_sub_key;
1194 unix_shared_memory_queue_t *q;
1195 clib_error_t *error;
1197 VALIDATE_SW_IF_INDEX (mp);
1199 hw_if_index = ntohl (mp->sw_if_index);
1200 hi = vnet_get_hw_interface (vnm, hw_if_index);
1202 id = ntohl (mp->vlan_id);
1203 if (id == 0 || id > 4095)
1205 rv = VNET_API_ERROR_INVALID_VLAN;
1209 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1211 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1214 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1218 kp = clib_mem_alloc (sizeof (*kp));
1219 *kp = sup_and_sub_key;
1221 memset (&template, 0, sizeof (template));
1222 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1223 template.sup_sw_if_index = hi->sw_if_index;
1224 template.sub.id = id;
1225 template.sub.eth.raw_flags = 0;
1226 template.sub.eth.flags.one_tag = 1;
1227 template.sub.eth.outer_vlan_id = id;
1228 template.sub.eth.flags.exact_match = 1;
1230 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1233 clib_error_report (error);
1234 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1237 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1238 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1240 BAD_SW_IF_INDEX_LABEL;
1243 q = vl_api_client_index_to_input_queue (mp->client_index);
1247 rmp = vl_msg_api_alloc (sizeof (*rmp));
1248 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1249 rmp->context = mp->context;
1250 rmp->retval = ntohl (rv);
1251 rmp->sw_if_index = ntohl (sw_if_index);
1252 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1256 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1258 vl_api_create_subif_reply_t *rmp;
1259 vnet_main_t *vnm = vnet_get_main ();
1260 u32 sw_if_index = ~0;
1263 vnet_sw_interface_t *si;
1264 vnet_hw_interface_t *hi;
1265 vnet_sw_interface_t template;
1267 vnet_interface_main_t *im = &vnm->interface_main;
1268 u64 sup_and_sub_key;
1270 clib_error_t *error;
1272 VALIDATE_SW_IF_INDEX (mp);
1274 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1275 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1277 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1279 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1283 sw_if_index = si->sw_if_index;
1284 sub_id = ntohl (mp->sub_id);
1286 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1288 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1292 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1293 sw_if_index, sub_id);
1294 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1298 kp = clib_mem_alloc (sizeof (*kp));
1299 *kp = sup_and_sub_key;
1301 memset (&template, 0, sizeof (template));
1302 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1303 template.sup_sw_if_index = sw_if_index;
1304 template.sub.id = sub_id;
1305 template.sub.eth.flags.no_tags = mp->no_tags;
1306 template.sub.eth.flags.one_tag = mp->one_tag;
1307 template.sub.eth.flags.two_tags = mp->two_tags;
1308 template.sub.eth.flags.dot1ad = mp->dot1ad;
1309 template.sub.eth.flags.exact_match = mp->exact_match;
1310 template.sub.eth.flags.default_sub = mp->default_sub;
1311 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1312 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1313 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1314 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1316 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1319 clib_error_report (error);
1320 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1324 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1325 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1327 BAD_SW_IF_INDEX_LABEL;
1332 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1334 rmp->sw_if_index = ntohl(sw_if_index);
1340 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
1342 vl_api_mpls_tunnel_add_del_reply_t *rmp;
1344 stats_main_t *sm = &stats_main;
1345 u32 tunnel_sw_if_index;
1348 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1352 fib_route_path_t rpath, *rpaths = NULL;
1353 mpls_label_t *label_stack = NULL;
1355 memset (&rpath, 0, sizeof (rpath));
1357 if (mp->mt_next_hop_proto_is_ip4)
1359 rpath.frp_proto = FIB_PROTOCOL_IP4;
1360 clib_memcpy (&rpath.frp_addr.ip4,
1361 mp->mt_next_hop, sizeof (rpath.frp_addr.ip4));
1365 rpath.frp_proto = FIB_PROTOCOL_IP6;
1366 clib_memcpy (&rpath.frp_addr.ip6,
1367 mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
1369 rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
1371 for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
1372 vec_add1 (label_stack, ntohl (mp->mt_next_hop_out_label_stack[ii]));
1374 vec_add1 (rpaths, rpath);
1376 vnet_mpls_tunnel_add (rpaths, label_stack,
1377 mp->mt_l2_only, &tunnel_sw_if_index);
1379 vec_free (label_stack);
1383 tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
1384 vnet_mpls_tunnel_del (tunnel_sw_if_index);
1390 REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
1392 rmp->sw_if_index = ntohl(tunnel_sw_if_index);
1398 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
1400 vl_api_proxy_arp_add_del_reply_t *rmp;
1403 ip4_main_t *im = &ip4_main;
1404 stats_main_t *sm = &stats_main;
1405 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
1406 ip4_address_t * hi_addr,
1407 u32 fib_index, int is_del);
1410 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
1412 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1416 rv = VNET_API_ERROR_NO_SUCH_FIB;
1422 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
1423 (ip4_address_t *) mp->hi_address,
1424 fib_index, mp->is_add == 0);
1428 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
1432 vl_api_proxy_arp_intfc_enable_disable_t_handler
1433 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
1436 vnet_main_t *vnm = vnet_get_main ();
1437 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
1438 vnet_sw_interface_t *si;
1441 VALIDATE_SW_IF_INDEX (mp);
1443 sw_if_index = ntohl (mp->sw_if_index);
1445 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1447 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1451 si = vnet_get_sw_interface (vnm, sw_if_index);
1455 if (mp->enable_disable)
1456 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1458 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1460 BAD_SW_IF_INDEX_LABEL;
1463 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
1467 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
1470 vpe_main_t *rm = &vpe_main;
1471 ip4_main_t *im4 = &ip4_main;
1472 ip6_main_t *im6 = &ip6_main;
1473 ip_lookup_main_t *lm;
1479 u32 adj_index, sw_if_index;
1480 vl_api_is_address_reachable_t *rmp;
1481 ip_adjacency_t *adj;
1482 unix_shared_memory_queue_t *q;
1484 q = vl_api_client_index_to_input_queue (mp->client_index);
1487 increment_missing_api_client_counter (rm->vlib_main);
1491 rmp = vl_msg_api_alloc (sizeof (*rmp));
1492 clib_memcpy (rmp, mp, sizeof (*rmp));
1494 sw_if_index = mp->next_hop_sw_if_index;
1495 clib_memcpy (&addr, mp->address, sizeof (addr));
1498 lm = &im6->lookup_main;
1499 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
1503 lm = &im4->lookup_main;
1505 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
1507 if (adj_index == ~0)
1512 adj = ip_get_adjacency (lm, adj_index);
1514 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
1515 && adj->rewrite_header.sw_if_index == sw_if_index)
1521 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
1522 && adj->rewrite_header.sw_if_index == sw_if_index)
1525 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
1527 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
1529 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
1538 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1543 vl_api_sw_interface_set_mpls_enable_t_handler
1544 (vl_api_sw_interface_set_mpls_enable_t * mp)
1546 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
1549 VALIDATE_SW_IF_INDEX (mp);
1551 mpls_sw_interface_enable_disable (&mpls_main,
1552 ntohl (mp->sw_if_index), mp->enable);
1554 BAD_SW_IF_INDEX_LABEL;
1555 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
1559 send_oam_event (oam_target_t * t)
1561 vpe_api_main_t *vam = &vpe_api_main;
1562 unix_shared_memory_queue_t *q;
1563 vpe_client_registration_t *reg;
1564 vl_api_oam_event_t *mp;
1567 pool_foreach(reg, vam->oam_events_registrations,
1569 q = vl_api_client_index_to_input_queue (reg->client_index);
1572 mp = vl_msg_api_alloc (sizeof (*mp));
1573 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
1574 clib_memcpy (mp->dst_address, &t->dst_address,
1575 sizeof (mp->dst_address));
1576 mp->state = t->state;
1577 vl_msg_api_send_shmem (q, (u8 *)&mp);
1584 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
1586 vl_api_oam_add_del_reply_t *rmp;
1589 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
1590 (ip4_address_t *) mp->dst_address,
1591 ntohl (mp->vrf_id), (int) (mp->is_add));
1593 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
1597 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
1599 stats_main_t *sm = &stats_main;
1600 vnet_interface_main_t *im = sm->interface_main;
1601 vl_api_vnet_summary_stats_reply_t *rmp;
1602 vlib_combined_counter_main_t *cm;
1605 u64 total_pkts[VLIB_N_RX_TX];
1606 u64 total_bytes[VLIB_N_RX_TX];
1608 unix_shared_memory_queue_t *q =
1609 vl_api_client_index_to_input_queue (mp->client_index);
1614 rmp = vl_msg_api_alloc (sizeof (*rmp));
1615 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
1616 rmp->context = mp->context;
1619 memset (total_pkts, 0, sizeof (total_pkts));
1620 memset (total_bytes, 0, sizeof (total_bytes));
1622 vnet_interface_counter_lock (im);
1624 vec_foreach (cm, im->combined_sw_if_counters)
1626 which = cm - im->combined_sw_if_counters;
1628 for (i = 0; i < vec_len (cm->maxi); i++)
1630 vlib_get_combined_counter (cm, i, &v);
1631 total_pkts[which] += v.packets;
1632 total_bytes[which] += v.bytes;
1635 vnet_interface_counter_unlock (im);
1637 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
1638 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
1639 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
1640 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
1642 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
1644 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1648 typedef CLIB_PACKED (struct {
1649 ip4_address_t address;
1650 u32 address_length: 6;
1656 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1658 vnet_main_t *vnm = vnet_get_main ();
1659 vnet_interface_main_t *im = &vnm->interface_main;
1660 ip4_main_t *im4 = &ip4_main;
1661 static u32 *sw_if_indices_to_shut;
1662 stats_main_t *sm = &stats_main;
1663 fib_table_t *fib_table;
1667 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1668 u32 target_fib_id = ntohl (mp->vrf_id);
1670 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
1673 pool_foreach (fib_table, im4->fibs,
1675 fib = &fib_table->v4;
1676 vnet_sw_interface_t * si;
1678 if (fib->table_id != target_fib_id)
1681 /* remove any mpls encap/decap labels */
1682 mpls_fib_reset_labels (fib->table_id);
1684 /* remove any proxy arps in this fib */
1685 vnet_proxy_arp_fib_reset (fib->table_id);
1687 /* Set the flow hash for this fib to the default */
1688 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
1690 vec_reset_length (sw_if_indices_to_shut);
1692 /* Shut down interfaces in this FIB / clean out intfc routes */
1693 pool_foreach (si, im->sw_interfaces,
1695 u32 sw_if_index = si->sw_if_index;
1697 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
1698 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
1700 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1703 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1704 sw_if_index = sw_if_indices_to_shut[i];
1705 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1707 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1708 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1709 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1712 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
1713 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
1717 })); /* pool_foreach (fib) */
1725 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1727 vnet_main_t *vnm = vnet_get_main ();
1728 vnet_interface_main_t *im = &vnm->interface_main;
1729 ip6_main_t *im6 = &ip6_main;
1730 stats_main_t *sm = &stats_main;
1731 static u32 *sw_if_indices_to_shut;
1732 fib_table_t *fib_table;
1736 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1737 u32 target_fib_id = ntohl (mp->vrf_id);
1739 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
1742 pool_foreach (fib_table, im6->fibs,
1744 vnet_sw_interface_t * si;
1745 fib = &(fib_table->v6);
1747 if (fib->table_id != target_fib_id)
1750 vec_reset_length (sw_if_indices_to_shut);
1752 /* Shut down interfaces in this FIB / clean out intfc routes */
1753 pool_foreach (si, im->sw_interfaces,
1755 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1757 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1760 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1761 sw_if_index = sw_if_indices_to_shut[i];
1762 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1764 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1765 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1766 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1769 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1770 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
1774 })); /* pool_foreach (fib) */
1782 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1785 vl_api_reset_fib_reply_t *rmp;
1788 rv = ip6_reset_fib_t_handler (mp);
1790 rv = ip4_reset_fib_t_handler (mp);
1792 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1797 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1799 vl_api_dhcp_proxy_config_reply_t *rmp;
1802 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
1803 (ip4_address_t *) (&mp->dhcp_src_address),
1804 (u32) ntohl (mp->vrf_id),
1805 (int) mp->insert_circuit_id,
1806 (int) (mp->is_add == 0));
1808 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1813 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1815 vl_api_dhcp_proxy_config_reply_t *rmp;
1818 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
1819 (ip6_address_t *) (&mp->dhcp_src_address),
1820 (u32) ntohl (mp->vrf_id),
1821 (int) mp->insert_circuit_id,
1822 (int) (mp->is_add == 0));
1824 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1828 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1830 vl_api_dhcp_proxy_config_reply_t *rmp;
1833 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
1834 (ip4_address_t *) (&mp->dhcp_src_address),
1835 (u32) ntohl (mp->rx_vrf_id),
1836 (u32) ntohl (mp->server_vrf_id),
1837 (int) mp->insert_circuit_id,
1838 (int) (mp->is_add == 0));
1840 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1845 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1847 vl_api_dhcp_proxy_config_reply_t *rmp;
1850 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
1851 (ip6_address_t *) (&mp->dhcp_src_address),
1852 (u32) ntohl (mp->rx_vrf_id),
1853 (u32) ntohl (mp->server_vrf_id),
1854 (int) mp->insert_circuit_id,
1855 (int) (mp->is_add == 0));
1857 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1862 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
1864 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
1867 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
1870 (int) mp->is_add == 0);
1872 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
1874 ntohl (mp->fib_id), (int) mp->is_add == 0);
1876 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
1880 static void vl_api_dhcp_proxy_config_t_handler
1881 (vl_api_dhcp_proxy_config_t * mp)
1883 if (mp->is_ipv6 == 0)
1884 dhcpv4_proxy_config (mp);
1886 dhcpv6_proxy_config (mp);
1889 static void vl_api_dhcp_proxy_config_2_t_handler
1890 (vl_api_dhcp_proxy_config_2_t * mp)
1892 if (mp->is_ipv6 == 0)
1893 dhcpv4_proxy_config_2 (mp);
1895 dhcpv6_proxy_config_2 (mp);
1899 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
1900 u8 is_ipv6, u8 * host_address, u8 * router_address,
1903 unix_shared_memory_queue_t *q;
1904 vl_api_dhcp_compl_event_t *mp;
1906 q = vl_api_client_index_to_input_queue (client_index);
1910 mp = vl_msg_api_alloc (sizeof (*mp));
1911 mp->client_index = client_index;
1913 mp->is_ipv6 = is_ipv6;
1914 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
1915 mp->hostname[vec_len (hostname) + 1] = '\n';
1916 clib_memcpy (&mp->host_address[0], host_address, 16);
1917 clib_memcpy (&mp->router_address[0], router_address, 16);
1919 if (NULL != host_mac)
1920 clib_memcpy (&mp->host_mac[0], host_mac, 6);
1922 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
1924 vl_msg_api_send_shmem (q, (u8 *) & mp);
1927 static void vl_api_dhcp_client_config_t_handler
1928 (vl_api_dhcp_client_config_t * mp)
1930 vlib_main_t *vm = vlib_get_main ();
1931 vl_api_dhcp_client_config_reply_t *rmp;
1934 VALIDATE_SW_IF_INDEX (mp);
1936 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
1937 mp->hostname, mp->is_add, mp->client_index,
1938 mp->want_dhcp_event ? dhcp_compl_event_callback :
1941 BAD_SW_IF_INDEX_LABEL;
1943 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
1947 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1949 vl_api_create_loopback_reply_t *rmp;
1953 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1956 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1958 rmp->sw_if_index = ntohl (sw_if_index);
1964 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1966 vl_api_delete_loopback_reply_t *rmp;
1970 sw_if_index = ntohl (mp->sw_if_index);
1971 rv = vnet_delete_loopback_interface (sw_if_index);
1973 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1977 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1979 vl_api_control_ping_reply_t *rmp;
1983 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1985 rmp->vpe_pid = ntohl (getpid());
1991 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1993 u8 **shmem_vecp = (u8 **) arg;
1996 api_main_t *am = &api_main;
1999 shmem_vec = *shmem_vecp;
2001 offset = vec_len (shmem_vec);
2003 pthread_mutex_lock (&am->vlib_rp->mutex);
2004 oldheap = svm_push_data_heap (am->vlib_rp);
2006 vec_validate (shmem_vec, offset + buffer_bytes - 1);
2008 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
2010 svm_pop_heap (oldheap);
2011 pthread_mutex_unlock (&am->vlib_rp->mutex);
2013 *shmem_vecp = shmem_vec;
2018 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
2020 vl_api_cli_reply_t *rp;
2021 unix_shared_memory_queue_t *q;
2022 vlib_main_t *vm = vlib_get_main ();
2023 api_main_t *am = &api_main;
2024 unformat_input_t input;
2028 q = vl_api_client_index_to_input_queue (mp->client_index);
2032 rp = vl_msg_api_alloc (sizeof (*rp));
2033 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
2034 rp->context = mp->context;
2036 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
2038 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
2040 pthread_mutex_lock (&am->vlib_rp->mutex);
2041 oldheap = svm_push_data_heap (am->vlib_rp);
2043 vec_add1 (shmem_vec, 0);
2045 svm_pop_heap (oldheap);
2046 pthread_mutex_unlock (&am->vlib_rp->mutex);
2048 rp->reply_in_shmem = (uword) shmem_vec;
2050 vl_msg_api_send_shmem (q, (u8 *) & rp);
2054 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2056 u8 **mem_vecp = (u8 **) arg;
2057 u8 *mem_vec = *mem_vecp;
2058 u32 offset = vec_len (mem_vec);
2060 vec_validate (mem_vec, offset + buffer_bytes - 1);
2061 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
2062 *mem_vecp = mem_vec;
2066 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
2068 vl_api_cli_inband_reply_t *rmp;
2070 unix_shared_memory_queue_t *q;
2071 vlib_main_t *vm = vlib_get_main ();
2072 unformat_input_t input;
2075 q = vl_api_client_index_to_input_queue (mp->client_index);
2079 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
2080 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
2082 u32 len = vec_len (out_vec);
2084 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
2086 rmp->length = htonl (len);
2087 clib_memcpy (rmp->reply, out_vec, len);
2094 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2097 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2098 vnet_main_t *vnm = vnet_get_main ();
2099 clib_error_t *error;
2104 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2106 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2110 clib_error_report (error);
2111 rv = VNET_API_ERROR_UNSPECIFIED;
2115 rv = vnm->api_errno;
2118 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2121 static void vl_api_sr_tunnel_add_del_t_handler
2122 (vl_api_sr_tunnel_add_del_t * mp)
2125 clib_warning ("unimplemented");
2127 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
2129 vl_api_sr_tunnel_add_del_reply_t *rmp;
2130 ip6_address_t *segments = 0, *seg;
2131 ip6_address_t *tags = 0, *tag;
2132 ip6_address_t *this_address;
2135 if (mp->n_segments == 0)
2141 memset (a, 0, sizeof (*a));
2142 a->src_address = (ip6_address_t *) & mp->src_address;
2143 a->dst_address = (ip6_address_t *) & mp->dst_address;
2144 a->dst_mask_width = mp->dst_mask_width;
2145 a->flags_net_byte_order = mp->flags_net_byte_order;
2146 a->is_del = (mp->is_add == 0);
2147 a->rx_table_id = ntohl (mp->outer_vrf_id);
2148 a->tx_table_id = ntohl (mp->inner_vrf_id);
2150 a->name = format (0, "%s", mp->name);
2151 if (!(vec_len (a->name)))
2154 a->policy_name = format (0, "%s", mp->policy_name);
2155 if (!(vec_len (a->policy_name)))
2158 /* Yank segments and tags out of the API message */
2159 this_address = (ip6_address_t *) mp->segs_and_tags;
2160 for (i = 0; i < mp->n_segments; i++)
2162 vec_add2 (segments, seg, 1);
2163 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
2166 for (i = 0; i < mp->n_tags; i++)
2168 vec_add2 (tags, tag, 1);
2169 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
2173 a->segments = segments;
2176 rv = ip6_sr_add_del_tunnel (a);
2180 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
2184 static void vl_api_sr_policy_add_del_t_handler
2185 (vl_api_sr_policy_add_del_t * mp)
2188 clib_warning ("unimplemented");
2190 ip6_sr_add_del_policy_args_t _a, *a = &_a;
2192 vl_api_sr_policy_add_del_reply_t *rmp;
2195 memset (a, 0, sizeof (*a));
2196 a->is_del = (mp->is_add == 0);
2198 a->name = format (0, "%s", mp->name);
2199 if (!(vec_len (a->name)))
2201 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2205 if (!(mp->tunnel_names[0]))
2207 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2211 // start deserializing tunnel_names
2212 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
2213 u8 *deser_tun_names = mp->tunnel_names;
2214 deser_tun_names += 1; //moving along
2217 int tun_name_len = 0;
2219 for (i = 0; i < num_tunnels; i++)
2221 tun_name_len = *deser_tun_names;
2222 deser_tun_names += 1;
2223 vec_resize (tun_name, tun_name_len);
2224 memcpy (tun_name, deser_tun_names, tun_name_len);
2225 vec_add1 (a->tunnel_names, tun_name);
2226 deser_tun_names += tun_name_len;
2230 rv = ip6_sr_add_del_policy (a);
2234 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
2238 static void vl_api_sr_multicast_map_add_del_t_handler
2239 (vl_api_sr_multicast_map_add_del_t * mp)
2242 clib_warning ("unimplemented");
2244 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
2246 vl_api_sr_multicast_map_add_del_reply_t *rmp;
2248 memset (a, 0, sizeof (*a));
2249 a->is_del = (mp->is_add == 0);
2251 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
2252 a->policy_name = format (0, "%s", mp->policy_name);
2254 if (a->multicast_address == 0)
2260 if (!(a->policy_name))
2266 #if DPDK > 0 /* Cannot call replicate without DPDK */
2267 rv = ip6_sr_add_del_multicastmap (a);
2269 clib_warning ("multicast replication without DPDK not implemented");
2270 rv = VNET_API_ERROR_UNIMPLEMENTED;
2275 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
2279 #define foreach_classify_add_del_table_field \
2284 _(match_n_vectors) \
2285 _(next_table_index) \
2286 _(miss_next_index) \
2287 _(current_data_flag) \
2288 _(current_data_offset)
2290 static void vl_api_classify_add_del_table_t_handler
2291 (vl_api_classify_add_del_table_t * mp)
2293 vl_api_classify_add_del_table_reply_t *rmp;
2294 vnet_classify_main_t *cm = &vnet_classify_main;
2295 vnet_classify_table_t *t;
2299 foreach_classify_add_del_table_field;
2302 #define _(a) a = ntohl(mp->a);
2303 foreach_classify_add_del_table_field;
2306 /* The underlying API fails silently, on purpose, so check here */
2307 if (mp->is_add == 0) /* delete */
2309 if (pool_is_free_index (cm->tables, table_index))
2311 rv = VNET_API_ERROR_NO_SUCH_TABLE;
2315 else /* add or update */
2317 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
2321 rv = vnet_classify_add_del_table
2322 (cm, mp->mask, nbuckets, memory_size,
2323 skip_n_vectors, match_n_vectors,
2324 next_table_index, miss_next_index, &table_index,
2325 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
2329 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
2331 if (rv == 0 && mp->is_add)
2333 t = pool_elt_at_index (cm->tables, table_index);
2334 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
2335 rmp->match_n_vectors = ntohl(t->match_n_vectors);
2336 rmp->new_table_index = ntohl(table_index);
2340 rmp->skip_n_vectors = ~0;
2341 rmp->match_n_vectors = ~0;
2342 rmp->new_table_index = ~0;
2348 static void vl_api_classify_add_del_session_t_handler
2349 (vl_api_classify_add_del_session_t * mp)
2351 vnet_classify_main_t *cm = &vnet_classify_main;
2352 vl_api_classify_add_del_session_reply_t *rmp;
2354 u32 table_index, hit_next_index, opaque_index, metadata;
2358 table_index = ntohl (mp->table_index);
2359 hit_next_index = ntohl (mp->hit_next_index);
2360 opaque_index = ntohl (mp->opaque_index);
2361 advance = ntohl (mp->advance);
2362 action = mp->action;
2363 metadata = ntohl (mp->metadata);
2365 rv = vnet_classify_add_del_session
2366 (cm, table_index, mp->match, hit_next_index, opaque_index,
2367 advance, action, metadata, mp->is_add);
2369 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
2372 static void vl_api_classify_set_interface_ip_table_t_handler
2373 (vl_api_classify_set_interface_ip_table_t * mp)
2375 vlib_main_t *vm = vlib_get_main ();
2376 vl_api_classify_set_interface_ip_table_reply_t *rmp;
2378 u32 table_index, sw_if_index;
2380 table_index = ntohl (mp->table_index);
2381 sw_if_index = ntohl (mp->sw_if_index);
2383 VALIDATE_SW_IF_INDEX (mp);
2386 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
2388 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
2390 BAD_SW_IF_INDEX_LABEL;
2392 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
2395 static void vl_api_classify_set_interface_l2_tables_t_handler
2396 (vl_api_classify_set_interface_l2_tables_t * mp)
2398 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
2400 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
2403 ip4_table_index = ntohl (mp->ip4_table_index);
2404 ip6_table_index = ntohl (mp->ip6_table_index);
2405 other_table_index = ntohl (mp->other_table_index);
2406 sw_if_index = ntohl (mp->sw_if_index);
2408 VALIDATE_SW_IF_INDEX (mp);
2411 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
2415 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
2421 if (ip4_table_index != ~0 || ip6_table_index != ~0
2422 || other_table_index != ~0)
2428 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
2430 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
2433 BAD_SW_IF_INDEX_LABEL;
2435 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
2439 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
2442 vl_api_l2_fib_clear_table_reply_t *rmp;
2444 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
2445 * that is not currently implemented. When that TODO is fixed
2446 * this call should be changed to pass 1 instead of 0.
2448 l2fib_clear_table (0);
2450 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
2453 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
2454 u32 sw_if_index, u32 enable);
2457 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
2461 vl_api_l2_interface_efp_filter_reply_t *rmp;
2462 vnet_main_t *vnm = vnet_get_main ();
2464 // enable/disable the feature
2465 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
2466 rv = vnm->api_errno;
2468 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
2472 vl_api_l2_interface_vlan_tag_rewrite_t_handler
2473 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
2476 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
2477 vnet_main_t *vnm = vnet_get_main ();
2478 vlib_main_t *vm = vlib_get_main ();
2481 VALIDATE_SW_IF_INDEX (mp);
2483 vtr_op = ntohl (mp->vtr_op);
2485 /* The L2 code is unsuspicious */
2488 case L2_VTR_DISABLED:
2493 case L2_VTR_TRANSLATE_1_1:
2494 case L2_VTR_TRANSLATE_1_2:
2495 case L2_VTR_TRANSLATE_2_1:
2496 case L2_VTR_TRANSLATE_2_2:
2500 rv = VNET_API_ERROR_INVALID_VALUE;
2501 goto bad_sw_if_index;
2504 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
2505 ntohl (mp->push_dot1q), ntohl (mp->tag1),
2508 BAD_SW_IF_INDEX_LABEL;
2510 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
2514 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
2516 clib_warning ("BUG");
2520 send_l2fib_table_entry (vpe_api_main_t * am,
2521 unix_shared_memory_queue_t * q,
2522 l2fib_entry_key_t * l2fe_key,
2523 l2fib_entry_result_t * l2fe_res, u32 context)
2525 vl_api_l2_fib_table_entry_t *mp;
2527 mp = vl_msg_api_alloc (sizeof (*mp));
2528 memset (mp, 0, sizeof (*mp));
2529 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
2532 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
2534 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
2535 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
2536 mp->static_mac = l2fe_res->fields.static_mac;
2537 mp->filter_mac = l2fe_res->fields.filter;
2538 mp->bvi_mac = l2fe_res->fields.bvi;
2539 mp->context = context;
2541 vl_msg_api_send_shmem (q, (u8 *) & mp);
2545 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
2547 vpe_api_main_t *am = &vpe_api_main;
2548 bd_main_t *bdm = &bd_main;
2549 l2fib_entry_key_t *l2fe_key = NULL;
2550 l2fib_entry_result_t *l2fe_res = NULL;
2551 u32 ni, bd_id = ntohl (mp->bd_id);
2553 unix_shared_memory_queue_t *q;
2556 q = vl_api_client_index_to_input_queue (mp->client_index);
2560 /* see l2fib_table_dump: ~0 means "any" */
2565 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2572 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
2574 vec_foreach_index (ni, l2fe_key)
2576 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
2577 vec_elt_at_index (l2fe_res, ni), mp->context);
2579 vec_free (l2fe_key);
2580 vec_free (l2fe_res);
2584 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
2586 vl_api_show_version_reply_t *rmp;
2588 char *vpe_api_get_build_directory (void);
2589 char *vpe_api_get_version (void);
2590 char *vpe_api_get_build_date (void);
2592 unix_shared_memory_queue_t *q =
2593 vl_api_client_index_to_input_queue (mp->client_index);
2599 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
2601 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
2602 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
2603 ARRAY_LEN(rmp->build_directory)-1);
2604 strncpy ((char *) rmp->version, vpe_api_get_version(),
2605 ARRAY_LEN(rmp->version)-1);
2606 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
2607 ARRAY_LEN(rmp->build_date)-1);
2613 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
2615 vlib_main_t *vm = vlib_get_main ();
2616 vl_api_get_node_index_reply_t *rmp;
2619 u32 node_index = ~0;
2621 n = vlib_get_node_by_name (vm, mp->node_name);
2624 rv = VNET_API_ERROR_NO_SUCH_NODE;
2626 node_index = n->index;
2629 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
2631 rmp->node_index = ntohl(node_index);
2637 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
2639 vlib_main_t *vm = vlib_get_main ();
2640 vl_api_get_next_index_reply_t *rmp;
2641 vlib_node_t *node, *next_node;
2643 u32 next_node_index = ~0, next_index = ~0;
2646 node = vlib_get_node_by_name (vm, mp->node_name);
2650 rv = VNET_API_ERROR_NO_SUCH_NODE;
2654 next_node = vlib_get_node_by_name (vm, mp->next_name);
2658 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2662 next_node_index = next_node->index;
2664 p = hash_get (node->next_slot_by_node, next_node_index);
2668 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2676 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
2678 rmp->next_index = ntohl(next_index);
2684 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
2686 vlib_main_t *vm = vlib_get_main ();
2687 vl_api_add_node_next_reply_t *rmp;
2688 vlib_node_t *n, *next;
2690 u32 next_index = ~0;
2692 n = vlib_get_node_by_name (vm, mp->node_name);
2696 rv = VNET_API_ERROR_NO_SUCH_NODE;
2700 next = vlib_get_node_by_name (vm, mp->next_name);
2703 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2705 next_index = vlib_node_add_next (vm, n->index, next->index);
2709 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
2711 rmp->next_index = ntohl(next_index);
2716 static void vl_api_vxlan_add_del_tunnel_t_handler
2717 (vl_api_vxlan_add_del_tunnel_t * mp)
2719 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
2721 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
2722 u32 encap_fib_index;
2724 ip4_main_t *im = &ip4_main;
2725 vnet_main_t *vnm = vnet_get_main ();
2726 u32 sw_if_index = ~0;
2728 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
2731 rv = VNET_API_ERROR_NO_SUCH_FIB;
2734 encap_fib_index = p[0];
2735 memset (a, 0, sizeof (*a));
2737 a->is_add = mp->is_add;
2738 a->is_ip6 = mp->is_ipv6;
2740 /* ip addresses sent in network byte order */
2741 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
2742 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
2744 /* Check src & dst are different */
2745 if (ip46_address_cmp (&a->dst, &a->src) == 0)
2747 rv = VNET_API_ERROR_SAME_SRC_DST;
2750 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
2751 if (ip46_address_is_multicast (&a->dst) &&
2752 pool_is_free_index (vnm->interface_main.sw_interfaces,
2753 a->mcast_sw_if_index))
2755 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2758 a->encap_fib_index = encap_fib_index;
2759 a->decap_next_index = ntohl (mp->decap_next_index);
2760 a->vni = ntohl (mp->vni);
2761 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
2765 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
2767 rmp->sw_if_index = ntohl (sw_if_index);
2772 static void send_vxlan_tunnel_details
2773 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
2775 vl_api_vxlan_tunnel_details_t *rmp;
2776 ip4_main_t *im4 = &ip4_main;
2777 ip6_main_t *im6 = &ip6_main;
2778 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
2780 rmp = vl_msg_api_alloc (sizeof (*rmp));
2781 memset (rmp, 0, sizeof (*rmp));
2782 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
2785 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
2786 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
2787 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
2791 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
2792 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
2793 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
2795 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
2796 rmp->vni = htonl (t->vni);
2797 rmp->decap_next_index = htonl (t->decap_next_index);
2798 rmp->sw_if_index = htonl (t->sw_if_index);
2799 rmp->is_ipv6 = is_ipv6;
2800 rmp->context = context;
2802 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2805 static void vl_api_vxlan_tunnel_dump_t_handler
2806 (vl_api_vxlan_tunnel_dump_t * mp)
2808 unix_shared_memory_queue_t *q;
2809 vxlan_main_t *vxm = &vxlan_main;
2813 q = vl_api_client_index_to_input_queue (mp->client_index);
2819 sw_if_index = ntohl (mp->sw_if_index);
2821 if (~0 == sw_if_index)
2824 pool_foreach (t, vxm->tunnels,
2826 send_vxlan_tunnel_details(t, q, mp->context);
2832 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
2833 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
2837 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
2838 send_vxlan_tunnel_details (t, q, mp->context);
2843 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
2845 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
2847 vl_api_l2_patch_add_del_reply_t *rmp;
2848 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
2852 VALIDATE_RX_SW_IF_INDEX (mp);
2853 VALIDATE_TX_SW_IF_INDEX (mp);
2855 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
2856 ntohl (mp->tx_sw_if_index),
2857 (int) (mp->is_add != 0));
2859 BAD_RX_SW_IF_INDEX_LABEL;
2860 BAD_TX_SW_IF_INDEX_LABEL;
2862 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
2866 vl_api_vxlan_gpe_add_del_tunnel_t_handler
2867 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
2869 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
2871 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
2872 u32 encap_fib_index, decap_fib_index;
2875 ip4_main_t *im = &ip4_main;
2876 u32 sw_if_index = ~0;
2879 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
2882 rv = VNET_API_ERROR_NO_SUCH_FIB;
2885 encap_fib_index = p[0];
2887 protocol = mp->protocol;
2889 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
2890 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
2892 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
2895 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
2898 decap_fib_index = p[0];
2902 decap_fib_index = ntohl (mp->decap_vrf_id);
2905 /* Check src & dst are different */
2906 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
2907 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
2909 rv = VNET_API_ERROR_SAME_SRC_DST;
2912 memset (a, 0, sizeof (*a));
2914 a->is_add = mp->is_add;
2915 a->is_ip6 = mp->is_ipv6;
2916 /* ip addresses sent in network byte order */
2919 clib_memcpy (&(a->local.ip6), mp->local, 16);
2920 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
2924 clib_memcpy (&(a->local.ip4), mp->local, 4);
2925 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
2927 a->encap_fib_index = encap_fib_index;
2928 a->decap_fib_index = decap_fib_index;
2929 a->protocol = protocol;
2930 a->vni = ntohl (mp->vni);
2931 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
2935 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
2937 rmp->sw_if_index = ntohl (sw_if_index);
2942 static void send_vxlan_gpe_tunnel_details
2943 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
2945 vl_api_vxlan_gpe_tunnel_details_t *rmp;
2946 ip4_main_t *im4 = &ip4_main;
2947 ip6_main_t *im6 = &ip6_main;
2948 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
2950 rmp = vl_msg_api_alloc (sizeof (*rmp));
2951 memset (rmp, 0, sizeof (*rmp));
2952 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
2955 memcpy (rmp->local, &(t->local.ip6), 16);
2956 memcpy (rmp->remote, &(t->remote.ip6), 16);
2957 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
2958 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
2962 memcpy (rmp->local, &(t->local.ip4), 4);
2963 memcpy (rmp->remote, &(t->remote.ip4), 4);
2964 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
2965 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
2967 rmp->vni = htonl (t->vni);
2968 rmp->protocol = t->protocol;
2969 rmp->sw_if_index = htonl (t->sw_if_index);
2970 rmp->is_ipv6 = is_ipv6;
2971 rmp->context = context;
2973 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2976 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
2977 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
2979 unix_shared_memory_queue_t *q;
2980 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
2981 vxlan_gpe_tunnel_t *t;
2984 q = vl_api_client_index_to_input_queue (mp->client_index);
2990 sw_if_index = ntohl (mp->sw_if_index);
2992 if (~0 == sw_if_index)
2995 pool_foreach (t, vgm->tunnels,
2997 send_vxlan_gpe_tunnel_details(t, q, mp->context);
3003 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
3004 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
3008 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
3009 send_vxlan_gpe_tunnel_details (t, q, mp->context);
3013 /** Used for transferring locators via VPP API */
3015 typedef CLIB_PACKED (struct {
3016 u32 sw_if_index; /**< locator sw_if_index */
3017 u8 priority; /**< locator priority */
3018 u8 weight; /**< locator weight */
3023 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
3026 vl_api_lisp_add_del_locator_set_reply_t *rmp;
3028 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
3030 ls_locator_t *ls_loc;
3031 u32 ls_index = ~0, locator_num;
3032 u8 *locator_name = NULL;
3035 memset (a, 0, sizeof (a[0]));
3037 locator_name = format (0, "%s", mp->locator_set_name);
3039 a->name = locator_name;
3040 a->is_add = mp->is_add;
3042 locator_num = clib_net_to_host_u32 (mp->locator_num);
3044 memset (&locator, 0, sizeof (locator));
3045 for (i = 0; i < locator_num; i++)
3047 ls_loc = &((ls_locator_t *) mp->locators)[i];
3048 VALIDATE_SW_IF_INDEX (ls_loc);
3050 locator.sw_if_index = htonl (ls_loc->sw_if_index);
3051 locator.priority = ls_loc->priority;
3052 locator.weight = ls_loc->weight;
3054 vec_add1 (a->locators, locator);
3057 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
3059 BAD_SW_IF_INDEX_LABEL;
3061 vec_free (locator_name);
3062 vec_free (a->locators);
3065 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
3067 rmp->ls_index = clib_host_to_net_u32 (ls_index);
3073 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
3075 vl_api_lisp_add_del_locator_reply_t *rmp;
3077 locator_t locator, *locators = NULL;
3078 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
3080 u8 *locator_name = NULL;
3082 memset (&locator, 0, sizeof (locator));
3083 memset (a, 0, sizeof (a[0]));
3085 locator.sw_if_index = ntohl (mp->sw_if_index);
3086 locator.priority = mp->priority;
3087 locator.weight = mp->weight;
3089 vec_add1 (locators, locator);
3091 locator_name = format (0, "%s", mp->locator_set_name);
3093 a->name = locator_name;
3094 a->locators = locators;
3095 a->is_add = mp->is_add;
3098 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
3100 vec_free (locators);
3101 vec_free (locator_name);
3103 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
3107 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
3113 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3114 gid_address_ip_set (dst, src, IP4);
3115 gid_address_ippref_len (dst) = len;
3116 ip_prefix_normalize (&gid_address_ippref (dst));
3119 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3120 gid_address_ip_set (dst, src, IP6);
3121 gid_address_ippref_len (dst) = len;
3122 ip_prefix_normalize (&gid_address_ippref (dst));
3124 case 2: /* l2 mac */
3125 gid_address_type (dst) = GID_ADDR_MAC;
3126 clib_memcpy (&gid_address_mac (dst), src, 6);
3130 return VNET_API_ERROR_INVALID_VALUE;
3133 gid_address_vni (dst) = vni;
3139 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
3141 vl_api_lisp_add_del_local_eid_reply_t *rmp;
3142 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3144 gid_address_t _eid, *eid = &_eid;
3146 u32 locator_set_index = ~0, map_index = ~0;
3147 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
3148 u8 *name = NULL, *key = NULL;
3149 memset (a, 0, sizeof (a[0]));
3150 memset (eid, 0, sizeof (eid[0]));
3152 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3153 mp->eid_type, mp->eid, mp->prefix_len);
3157 name = format (0, "%s", mp->locator_set_name);
3158 p = hash_get_mem (lcm->locator_set_index_by_name, name);
3161 rv = VNET_API_ERROR_INVALID_VALUE;
3164 locator_set_index = p[0];
3167 key = format (0, "%s", mp->key);
3169 /* XXX treat batch configuration */
3170 a->is_add = mp->is_add;
3171 gid_address_copy (&a->eid, eid);
3172 a->locator_set_index = locator_set_index;
3175 a->key_id = clib_net_to_host_u16 (mp->key_id);
3177 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
3182 gid_address_free (&a->eid);
3184 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
3188 vl_api_lisp_eid_table_add_del_map_t_handler
3189 (vl_api_lisp_eid_table_add_del_map_t * mp)
3191 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
3193 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
3194 clib_net_to_host_u32 (mp->dp_table),
3195 mp->is_l2, mp->is_add);
3196 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
3198 /** Used for transferring locators via VPP API */
3200 typedef CLIB_PACKED (struct {
3201 u8 is_ip4; /**< is locator an IPv4 address */
3202 u8 priority; /**< locator priority */
3203 u8 weight; /**< locator weight */
3204 u8 addr[16]; /**< IPv4/IPv6 address */
3208 static locator_pair_t *
3209 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
3212 locator_pair_t *pairs = 0, pair;
3215 for (i = 0; i < rloc_num; i++)
3218 r = &((rloc_t *) lcl_locs)[i];
3219 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
3220 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
3222 /* remote locators */
3223 r = &((rloc_t *) rmt_locs)[i];
3224 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
3225 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
3227 pair.priority = r->priority;
3228 pair.weight = r->weight;
3230 vec_add1 (pairs, pair);
3236 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
3239 locator_t *locs = 0, loc;
3242 for (i = 0; i < rloc_num; i++)
3244 /* remote locators */
3245 r = &((rloc_t *) rmt_locs)[i];
3246 memset (&loc, 0, sizeof (loc));
3247 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
3249 loc.priority = r->priority;
3250 loc.weight = r->weight;
3252 vec_add1 (locs, loc);
3258 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
3259 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
3261 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
3262 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
3263 locator_pair_t *pairs = 0;
3266 memset (a, 0, sizeof (a[0]));
3268 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
3269 mp->rmt_eid, mp->rmt_len);
3270 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
3271 mp->lcl_eid, mp->lcl_len);
3273 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
3275 if (rv || 0 == pairs)
3278 a->is_add = mp->is_add;
3279 a->locator_pairs = pairs;
3280 a->dp_table = mp->dp_table;
3282 a->action = mp->action;
3284 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
3287 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
3291 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
3294 vl_api_lisp_add_del_map_server_reply_t *rmp;
3298 memset (&addr, 0, sizeof (addr));
3300 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
3301 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
3303 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
3307 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
3310 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
3312 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
3314 memset (a, 0, sizeof (a[0]));
3316 a->is_add = mp->is_add;
3317 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
3319 rv = vnet_lisp_add_del_map_resolver (a);
3321 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
3325 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
3328 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
3330 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
3332 a->is_en = mp->is_en;
3333 vnet_lisp_gpe_enable_disable (a);
3335 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
3339 vl_api_lisp_map_register_enable_disable_t_handler
3340 (vl_api_lisp_map_register_enable_disable_t * mp)
3342 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
3345 vnet_lisp_map_register_enable_disable (mp->is_enabled);
3346 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3350 vl_api_lisp_rloc_probe_enable_disable_t_handler
3351 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
3353 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
3356 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
3357 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3361 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
3363 vl_api_lisp_enable_disable_reply_t *rmp;
3366 vnet_lisp_enable_disable (mp->is_en);
3367 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3371 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
3373 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
3381 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
3385 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
3392 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
3396 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
3399 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
3403 vl_api_show_lisp_map_request_mode_t_handler
3404 (vl_api_show_lisp_map_request_mode_t * mp)
3407 vl_api_show_lisp_map_request_mode_reply_t *rmp;
3410 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
3412 rmp->mode = vnet_lisp_get_map_request_mode ();
3418 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
3420 vl_api_lisp_map_request_mode_reply_t *rmp;
3423 rv = vnet_lisp_set_map_request_mode (mp->mode);
3425 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
3429 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
3432 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
3436 ls_name = format (0, "%s", mp->ls_name);
3437 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
3440 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
3444 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
3445 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
3447 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
3449 u8 *locator_set_name = NULL;
3450 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
3452 locator_set_name = format (0, "%s", mp->locator_set_name);
3454 a->is_add = mp->is_add;
3455 a->locator_set_name = locator_set_name;
3457 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
3459 vec_free (locator_set_name);
3461 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
3465 vl_api_lisp_add_del_remote_mapping_t_handler
3466 (vl_api_lisp_add_del_remote_mapping_t * mp)
3468 locator_t *rlocs = 0;
3469 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
3471 gid_address_t _eid, *eid = &_eid;
3472 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
3474 memset (eid, 0, sizeof (eid[0]));
3476 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3477 mp->eid_type, mp->eid, mp->eid_len);
3481 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
3485 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
3486 gid_address_copy (&a->reid, eid);
3488 rv = vnet_lisp_add_del_adjacency (a);
3495 /* NOTE: for now this works as a static remote mapping, i.e.,
3496 * not authoritative and ttl infinite. */
3497 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
3498 mp->is_add, 1 /* is_static */ , 0);
3501 vnet_lisp_clear_all_remote_adjacencies ();
3506 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
3510 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
3512 vl_api_lisp_add_del_adjacency_reply_t *rmp;
3513 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
3516 memset (a, 0, sizeof (a[0]));
3518 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
3519 mp->eid_type, mp->leid, mp->leid_len);
3520 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
3521 mp->eid_type, mp->reid, mp->reid_len);
3526 a->is_add = mp->is_add;
3527 rv = vnet_lisp_add_del_adjacency (a);
3530 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
3534 send_lisp_locator_details (lisp_cp_main_t * lcm,
3536 unix_shared_memory_queue_t * q, u32 context)
3538 vl_api_lisp_locator_details_t *rmp;
3540 rmp = vl_msg_api_alloc (sizeof (*rmp));
3541 memset (rmp, 0, sizeof (*rmp));
3542 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
3543 rmp->context = context;
3545 rmp->local = loc->local;
3548 rmp->sw_if_index = ntohl (loc->sw_if_index);
3552 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
3553 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
3555 rmp->priority = loc->priority;
3556 rmp->weight = loc->weight;
3558 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3562 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
3565 unix_shared_memory_queue_t *q = 0;
3566 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3567 locator_set_t *lsit = 0;
3569 u32 ls_index = ~0, *locit = 0;
3572 q = vl_api_client_index_to_input_queue (mp->client_index);
3578 if (mp->is_index_set)
3579 ls_index = htonl (mp->ls_index);
3582 /* make sure we get a proper C-string */
3583 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
3584 ls_name = format (0, "%s", mp->ls_name);
3585 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
3591 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
3594 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
3596 vec_foreach (locit, lsit->locator_indices)
3598 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
3599 send_lisp_locator_details (lcm, loc, q, mp->context);
3606 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
3607 locator_set_t * lsit,
3608 unix_shared_memory_queue_t * q,
3609 u32 context, u32 ls_index)
3611 vl_api_lisp_locator_set_details_t *rmp;
3614 rmp = vl_msg_api_alloc (sizeof (*rmp));
3615 memset (rmp, 0, sizeof (*rmp));
3616 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
3617 rmp->context = context;
3619 rmp->ls_index = htonl (ls_index);
3622 ASSERT (lsit->name != NULL);
3623 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
3624 vec_len (lsit->name));
3628 str = format (0, "<remote-%d>", ls_index);
3629 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
3633 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3637 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
3639 unix_shared_memory_queue_t *q = NULL;
3640 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3641 locator_set_t *lsit = NULL;
3644 q = vl_api_client_index_to_input_queue (mp->client_index);
3650 filter = mp->filter;
3652 pool_foreach (lsit, lcm->locator_set_pool,
3654 if (filter && !((1 == filter && lsit->local) ||
3655 (2 == filter && !lsit->local)))
3659 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
3660 lsit - lcm->locator_set_pool);
3666 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
3668 ASSERT (prefix_length);
3669 ip_prefix_t *ippref = &fid_addr_ippref (src);
3671 switch (fid_addr_type (src))
3673 case FID_ADDR_IP_PREF:
3674 if (ip_prefix_version (ippref) == IP4)
3675 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
3677 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
3678 prefix_length[0] = ip_prefix_len (ippref);
3682 prefix_length[0] = 0;
3683 clib_memcpy (dst, fid_addr_mac (src), 6);
3687 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
3693 fid_type_to_api_type (fid_address_t * fid)
3695 ip_prefix_t *ippref;
3697 switch (fid_addr_type (fid))
3699 case FID_ADDR_IP_PREF:
3700 ippref = &fid_addr_ippref (fid);
3701 if (ip_prefix_version (ippref) == IP4)
3703 else if (ip_prefix_version (ippref) == IP6)
3716 send_lisp_eid_table_details (mapping_t * mapit,
3717 unix_shared_memory_queue_t * q,
3718 u32 context, u8 filter)
3721 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3722 locator_set_t *ls = 0;
3723 vl_api_lisp_eid_table_details_t *rmp = NULL;
3724 gid_address_t *gid = NULL;
3726 ip_prefix_t *ip_prefix = NULL;
3730 case 0: /* all mappings */
3733 case 1: /* local only */
3737 case 2: /* remote only */
3742 clib_warning ("Filter error, unknown filter: %d", filter);
3747 ip_prefix = &gid_address_ippref (gid);
3748 mac = gid_address_mac (gid);
3750 rmp = vl_msg_api_alloc (sizeof (*rmp));
3751 memset (rmp, 0, sizeof (*rmp));
3752 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
3754 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
3755 if (vec_len (ls->locator_indices) == 0)
3756 rmp->locator_set_index = ~0;
3758 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
3760 rmp->is_local = mapit->local;
3761 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
3762 rmp->action = mapit->action;
3763 rmp->authoritative = mapit->authoritative;
3765 switch (gid_address_type (gid))
3767 case GID_ADDR_SRC_DST:
3768 rmp->is_src_dst = 1;
3769 fid = &gid_address_sd_src (gid);
3770 rmp->eid_type = fid_type_to_api_type (fid);
3771 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
3772 &rmp->seid_prefix_len);
3773 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
3774 &rmp->eid_prefix_len);
3776 case GID_ADDR_IP_PREFIX:
3777 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
3778 if (ip_prefix_version (ip_prefix) == IP4)
3780 rmp->eid_type = 0; /* ipv4 type */
3781 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
3782 sizeof (ip_prefix_v4 (ip_prefix)));
3786 rmp->eid_type = 1; /* ipv6 type */
3787 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
3788 sizeof (ip_prefix_v6 (ip_prefix)));
3792 rmp->eid_type = 2; /* l2 mac type */
3793 clib_memcpy (rmp->eid, mac, 6);
3798 rmp->context = context;
3799 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
3800 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
3801 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
3802 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3806 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
3809 unix_shared_memory_queue_t *q = NULL;
3810 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3811 mapping_t *mapit = NULL;
3812 gid_address_t _eid, *eid = &_eid;
3814 q = vl_api_client_index_to_input_queue (mp->client_index);
3822 memset (eid, 0, sizeof (*eid));
3824 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3825 mp->eid_type, mp->eid, mp->prefix_length);
3827 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
3828 if ((u32) ~ 0 == mi)
3831 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
3832 send_lisp_eid_table_details (mapit, q, mp->context,
3833 0 /* ignore filter */ );
3838 pool_foreach (mapit, lcm->mapping_pool,
3840 send_lisp_eid_table_details(mapit, q, mp->context,
3848 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
3849 unix_shared_memory_queue_t * q, u32 context)
3851 vl_api_lisp_gpe_tunnel_details_t *rmp;
3852 lisp_gpe_main_t *lgm = &lisp_gpe_main;
3854 rmp = vl_msg_api_alloc (sizeof (*rmp));
3855 memset (rmp, 0, sizeof (*rmp));
3856 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
3858 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
3860 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
3861 ip_address_copy_addr (rmp->source_ip,
3862 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
3863 ip_address_copy_addr (rmp->destination_ip,
3864 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
3866 rmp->encap_fib_id = htonl (0);
3867 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
3868 rmp->iid = htonl (lfe->key->vni);
3869 rmp->context = context;
3871 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3875 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
3877 unix_shared_memory_queue_t *q = NULL;
3878 lisp_gpe_main_t *lgm = &lisp_gpe_main;
3879 lisp_gpe_fwd_entry_t *lfe = NULL;
3881 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
3886 q = vl_api_client_index_to_input_queue (mp->client_index);
3893 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
3895 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
3901 send_lisp_map_server_details (ip_address_t * ip,
3902 unix_shared_memory_queue_t * q, u32 context)
3904 vl_api_lisp_map_server_details_t *rmp = NULL;
3906 rmp = vl_msg_api_alloc (sizeof (*rmp));
3907 memset (rmp, 0, sizeof (*rmp));
3908 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
3910 switch (ip_addr_version (ip))
3914 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
3915 sizeof (ip_addr_v4 (ip)));
3920 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
3921 sizeof (ip_addr_v6 (ip)));
3927 rmp->context = context;
3929 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3933 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
3935 unix_shared_memory_queue_t *q = NULL;
3936 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3939 q = vl_api_client_index_to_input_queue (mp->client_index);
3945 vec_foreach (mr, lcm->map_servers)
3947 send_lisp_map_server_details (&mr->address, q, mp->context);
3952 send_lisp_map_resolver_details (ip_address_t * ip,
3953 unix_shared_memory_queue_t * q, u32 context)
3955 vl_api_lisp_map_resolver_details_t *rmp = NULL;
3957 rmp = vl_msg_api_alloc (sizeof (*rmp));
3958 memset (rmp, 0, sizeof (*rmp));
3959 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
3961 switch (ip_addr_version (ip))
3965 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
3966 sizeof (ip_addr_v4 (ip)));
3971 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
3972 sizeof (ip_addr_v6 (ip)));
3978 rmp->context = context;
3980 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3984 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
3986 unix_shared_memory_queue_t *q = NULL;
3987 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3990 q = vl_api_client_index_to_input_queue (mp->client_index);
3996 vec_foreach (mr, lcm->map_resolvers)
3998 send_lisp_map_resolver_details (&mr->address, q, mp->context);
4003 send_eid_table_map_pair (hash_pair_t * p,
4004 unix_shared_memory_queue_t * q, u32 context)
4006 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
4008 rmp = vl_msg_api_alloc (sizeof (*rmp));
4009 memset (rmp, 0, sizeof (*rmp));
4010 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
4012 rmp->vni = clib_host_to_net_u32 (p->key);
4013 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
4014 rmp->context = context;
4015 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4019 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
4022 unix_shared_memory_queue_t *q = NULL;
4023 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4025 uword *vni_table = 0;
4027 q = vl_api_client_index_to_input_queue (mp->client_index);
4035 vni_table = lcm->bd_id_by_vni;
4039 vni_table = lcm->table_id_by_vni;
4043 hash_foreach_pair (p, vni_table,
4045 send_eid_table_map_pair (p, q, mp->context);
4051 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
4053 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
4055 rmp = vl_msg_api_alloc (sizeof (*rmp));
4056 memset (rmp, 0, sizeof (*rmp));
4057 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
4058 rmp->context = context;
4059 rmp->vni = clib_host_to_net_u32 (vni);
4060 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4064 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
4066 lisp_adjacency_t *adj;
4067 vl_api_lisp_adjacency_t a;
4068 u32 i, n = vec_len (adjs);
4070 for (i = 0; i < n; i++)
4072 adj = vec_elt_at_index (adjs, i);
4073 memset (&a, 0, sizeof (a));
4075 switch (gid_address_type (&adj->reid))
4077 case GID_ADDR_IP_PREFIX:
4078 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
4079 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
4080 if (gid_address_ip_version (&adj->reid) == IP4)
4082 a.eid_type = 0; /* ipv4 type */
4083 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
4084 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
4088 a.eid_type = 1; /* ipv6 type */
4089 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
4090 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
4094 a.eid_type = 2; /* l2 mac type */
4095 mac_copy (a.reid, gid_address_mac (&adj->reid));
4096 mac_copy (a.leid, gid_address_mac (&adj->leid));
4106 vl_api_show_lisp_rloc_probe_state_t_handler
4107 (vl_api_show_lisp_rloc_probe_state_t * mp)
4109 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
4113 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
4115 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
4121 vl_api_show_lisp_map_register_state_t_handler
4122 (vl_api_show_lisp_map_register_state_t * mp)
4124 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
4128 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
4130 rmp->is_enabled = vnet_lisp_map_register_state_get ();
4136 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
4138 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
4139 lisp_adjacency_t *adjs = 0;
4141 vl_api_lisp_adjacency_t a;
4143 u32 vni = clib_net_to_host_u32 (mp->vni);
4145 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
4146 size = vec_len (adjs) * sizeof (a);
4149 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
4151 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
4152 lisp_adjacency_copy (rmp->adjacencies, adjs);
4160 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
4165 unix_shared_memory_queue_t *q = 0;
4166 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4168 q = vl_api_client_index_to_input_queue (mp->client_index);
4175 hash_foreach_pair (p, lcm->table_id_by_vni,
4177 hash_set (vnis, p->key, 0);
4180 hash_foreach_pair (p, lcm->bd_id_by_vni,
4182 hash_set (vnis, p->key, 0);
4185 hash_foreach_pair (p, vnis,
4187 send_eid_table_vni (p->key, q, mp->context);
4195 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
4197 unix_shared_memory_queue_t *q = NULL;
4198 vl_api_show_lisp_status_reply_t *rmp = NULL;
4201 q = vl_api_client_index_to_input_queue (mp->client_index);
4208 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
4210 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
4211 rmp->feature_status = vnet_lisp_enable_disable_status ();
4217 vl_api_lisp_get_map_request_itr_rlocs_t_handler
4218 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
4220 unix_shared_memory_queue_t *q = NULL;
4221 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
4222 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4223 locator_set_t *loc_set = 0;
4227 q = vl_api_client_index_to_input_queue (mp->client_index);
4233 if (~0 == lcm->mreq_itr_rlocs)
4235 tmp_str = format (0, " ");
4240 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
4241 tmp_str = format (0, "%s", loc_set->name);
4245 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
4247 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
4248 ARRAY_LEN(rmp->locator_set_name) - 1);
4256 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
4258 unix_shared_memory_queue_t *q = NULL;
4259 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
4260 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4262 locator_set_t *ls = 0;
4266 q = vl_api_client_index_to_input_queue (mp->client_index);
4272 if (!lcm->lisp_pitr)
4274 tmp_str = format (0, "N/A");
4278 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
4279 if (~0 != m->locator_set_index)
4282 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
4283 tmp_str = format (0, "%s", ls->name);
4287 tmp_str = format (0, "N/A");
4290 vec_add1 (tmp_str, 0);
4293 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
4295 rmp->status = lcm->lisp_pitr;
4296 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
4297 ARRAY_LEN(rmp->locator_set_name) - 1);
4303 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
4306 vl_api_interface_name_renumber_reply_t *rmp;
4309 VALIDATE_SW_IF_INDEX (mp);
4311 rv = vnet_interface_name_renumber
4312 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
4314 BAD_SW_IF_INDEX_LABEL;
4316 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4320 arp_change_data_callback (u32 pool_index, u8 * new_mac,
4321 u32 sw_if_index, u32 address)
4323 vpe_api_main_t *am = &vpe_api_main;
4324 vlib_main_t *vm = am->vlib_main;
4325 vl_api_ip4_arp_event_t *event;
4326 static f64 arp_event_last_time;
4327 f64 now = vlib_time_now (vm);
4329 if (pool_is_free_index (am->arp_events, pool_index))
4332 event = pool_elt_at_index (am->arp_events, pool_index);
4334 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
4336 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
4340 if (sw_if_index == event->sw_if_index &&
4342 /* for BD case, also check IP address with 10 sec timeout */
4343 (address == event->address &&
4344 (now - arp_event_last_time) < 10.0)))
4349 arp_event_last_time = now;
4350 event->sw_if_index = sw_if_index;
4352 event->address = address;
4357 nd_change_data_callback (u32 pool_index, u8 * new_mac,
4358 u32 sw_if_index, ip6_address_t * address)
4360 vpe_api_main_t *am = &vpe_api_main;
4361 vlib_main_t *vm = am->vlib_main;
4362 vl_api_ip6_nd_event_t *event;
4363 static f64 nd_event_last_time;
4364 f64 now = vlib_time_now (vm);
4366 if (pool_is_free_index (am->nd_events, pool_index))
4369 event = pool_elt_at_index (am->nd_events, pool_index);
4372 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
4374 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
4378 if (sw_if_index == event->sw_if_index &&
4380 /* for BD case, also check IP address with 10 sec timeout */
4381 (ip6_address_is_equal (address,
4382 (ip6_address_t *) event->address) &&
4383 (now - nd_event_last_time) < 10.0)))
4388 nd_event_last_time = now;
4389 event->sw_if_index = sw_if_index;
4391 clib_memcpy (event->address, address, sizeof (event->address));
4396 arp_change_delete_callback (u32 pool_index, u8 * notused)
4398 vpe_api_main_t *am = &vpe_api_main;
4400 if (pool_is_free_index (am->arp_events, pool_index))
4403 pool_put_index (am->arp_events, pool_index);
4408 nd_change_delete_callback (u32 pool_index, u8 * notused)
4410 vpe_api_main_t *am = &vpe_api_main;
4412 if (pool_is_free_index (am->nd_events, pool_index))
4415 pool_put_index (am->nd_events, pool_index);
4420 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
4422 vpe_api_main_t *am = &vpe_api_main;
4423 vnet_main_t *vnm = vnet_get_main ();
4424 vl_api_want_ip4_arp_events_reply_t *rmp;
4425 vl_api_ip4_arp_event_t *event;
4428 if (mp->enable_disable)
4430 pool_get (am->arp_events, event);
4431 memset (event, 0, sizeof (*event));
4433 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
4434 event->client_index = mp->client_index;
4435 event->context = mp->context;
4436 event->address = mp->address;
4437 event->pid = mp->pid;
4438 if (mp->address == 0)
4441 rv = vnet_add_del_ip4_arp_change_event
4442 (vnm, arp_change_data_callback,
4443 mp->pid, &mp->address /* addr, in net byte order */ ,
4444 vpe_resolver_process_node.index,
4445 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
4449 rv = vnet_add_del_ip4_arp_change_event
4450 (vnm, arp_change_delete_callback,
4451 mp->pid, &mp->address /* addr, in net byte order */ ,
4452 vpe_resolver_process_node.index,
4453 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
4455 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4459 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
4461 vpe_api_main_t *am = &vpe_api_main;
4462 vnet_main_t *vnm = vnet_get_main ();
4463 vl_api_want_ip6_nd_events_reply_t *rmp;
4464 vl_api_ip6_nd_event_t *event;
4467 if (mp->enable_disable)
4469 pool_get (am->nd_events, event);
4470 memset (event, 0, sizeof (*event));
4472 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
4473 event->client_index = mp->client_index;
4474 event->context = mp->context;
4475 clib_memcpy (event->address, mp->address, 16);
4476 event->pid = mp->pid;
4477 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
4480 rv = vnet_add_del_ip6_nd_change_event
4481 (vnm, nd_change_data_callback,
4482 mp->pid, mp->address /* addr, in net byte order */ ,
4483 vpe_resolver_process_node.index,
4484 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
4488 rv = vnet_add_del_ip6_nd_change_event
4489 (vnm, nd_change_delete_callback,
4490 mp->pid, mp->address /* addr, in net byte order */ ,
4491 vpe_resolver_process_node.index,
4492 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
4494 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
4497 static void vl_api_input_acl_set_interface_t_handler
4498 (vl_api_input_acl_set_interface_t * mp)
4500 vlib_main_t *vm = vlib_get_main ();
4501 vl_api_input_acl_set_interface_reply_t *rmp;
4503 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4505 ip4_table_index = ntohl (mp->ip4_table_index);
4506 ip6_table_index = ntohl (mp->ip6_table_index);
4507 l2_table_index = ntohl (mp->l2_table_index);
4508 sw_if_index = ntohl (mp->sw_if_index);
4510 VALIDATE_SW_IF_INDEX (mp);
4512 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4513 ip6_table_index, l2_table_index, mp->is_add);
4515 BAD_SW_IF_INDEX_LABEL;
4517 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4520 static void vl_api_cop_interface_enable_disable_t_handler
4521 (vl_api_cop_interface_enable_disable_t * mp)
4523 vl_api_cop_interface_enable_disable_reply_t *rmp;
4525 u32 sw_if_index = ntohl (mp->sw_if_index);
4528 VALIDATE_SW_IF_INDEX (mp);
4530 enable_disable = (int) mp->enable_disable;
4532 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
4534 BAD_SW_IF_INDEX_LABEL;
4536 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
4539 static void vl_api_cop_whitelist_enable_disable_t_handler
4540 (vl_api_cop_whitelist_enable_disable_t * mp)
4542 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
4543 cop_whitelist_enable_disable_args_t _a, *a = &_a;
4544 u32 sw_if_index = ntohl (mp->sw_if_index);
4547 VALIDATE_SW_IF_INDEX (mp);
4549 a->sw_if_index = sw_if_index;
4552 a->default_cop = mp->default_cop;
4553 a->fib_id = ntohl (mp->fib_id);
4555 rv = cop_whitelist_enable_disable (a);
4557 BAD_SW_IF_INDEX_LABEL;
4559 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
4563 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
4567 api_main_t *am = &api_main;
4568 vlib_main_t *vm = vlib_get_main ();
4570 vl_api_get_node_graph_reply_t *rmp;
4572 pthread_mutex_lock (&am->vlib_rp->mutex);
4573 oldheap = svm_push_data_heap (am->vlib_rp);
4576 * Keep the number of memcpy ops to a minimum (e.g. 1).
4578 vec_validate (vector, 16384);
4579 vec_reset_length (vector);
4582 vector = vlib_node_serialize (&vm->node_main, vector,
4583 (u32) ~ 0 /* all threads */ ,
4584 1 /* include nexts */ ,
4585 1 /* include stats */ );
4587 svm_pop_heap (oldheap);
4588 pthread_mutex_unlock (&am->vlib_rp->mutex);
4591 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
4593 rmp->reply_in_shmem = (uword) vector;
4599 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
4602 vl_api_ioam_enable_reply_t *rmp;
4603 clib_error_t *error;
4605 /* Ignoring the profile id as currently a single profile
4607 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
4608 mp->seqno, mp->analyse);
4611 clib_error_report (error);
4612 rv = clib_error_get_code (error);
4615 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
4619 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
4622 vl_api_ioam_disable_reply_t *rmp;
4623 clib_error_t *error;
4625 error = clear_ioam_rewrite_fn ();
4628 clib_error_report (error);
4629 rv = clib_error_get_code (error);
4632 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
4636 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
4638 vlib_main_t *vm = vlib_get_main ();
4639 vl_api_policer_add_del_reply_t *rmp;
4642 sse2_qos_pol_cfg_params_st cfg;
4643 clib_error_t *error;
4646 name = format (0, "%s", mp->name);
4648 memset (&cfg, 0, sizeof (cfg));
4650 cfg.rnd_type = mp->round_type;
4651 cfg.rate_type = mp->rate_type;
4652 cfg.rb.kbps.cir_kbps = mp->cir;
4653 cfg.rb.kbps.eir_kbps = mp->eir;
4654 cfg.rb.kbps.cb_bytes = mp->cb;
4655 cfg.rb.kbps.eb_bytes = mp->eb;
4656 cfg.conform_action.action_type = mp->conform_action_type;
4657 cfg.conform_action.dscp = mp->conform_dscp;
4658 cfg.exceed_action.action_type = mp->exceed_action_type;
4659 cfg.exceed_action.dscp = mp->exceed_dscp;
4660 cfg.violate_action.action_type = mp->violate_action_type;
4661 cfg.violate_action.dscp = mp->violate_dscp;
4662 cfg.color_aware = mp->color_aware;
4664 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
4667 rv = VNET_API_ERROR_UNSPECIFIED;
4670 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
4672 if (rv == 0 && mp->is_add)
4673 rmp->policer_index = ntohl(policer_index);
4675 rmp->policer_index = ~0;
4681 send_policer_details (u8 * name,
4682 sse2_qos_pol_cfg_params_st * config,
4683 policer_read_response_type_st * templ,
4684 unix_shared_memory_queue_t * q, u32 context)
4686 vl_api_policer_details_t *mp;
4688 mp = vl_msg_api_alloc (sizeof (*mp));
4689 memset (mp, 0, sizeof (*mp));
4690 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
4691 mp->context = context;
4692 mp->cir = htonl (config->rb.kbps.cir_kbps);
4693 mp->eir = htonl (config->rb.kbps.eir_kbps);
4694 mp->cb = htonl (config->rb.kbps.cb_bytes);
4695 mp->eb = htonl (config->rb.kbps.eb_bytes);
4696 mp->rate_type = config->rate_type;
4697 mp->round_type = config->rnd_type;
4698 mp->type = config->rfc;
4699 mp->conform_action_type = config->conform_action.action_type;
4700 mp->conform_dscp = config->conform_action.dscp;
4701 mp->exceed_action_type = config->exceed_action.action_type;
4702 mp->exceed_dscp = config->exceed_action.dscp;
4703 mp->violate_action_type = config->violate_action.action_type;
4704 mp->violate_dscp = config->violate_action.dscp;
4705 mp->single_rate = templ->single_rate ? 1 : 0;
4706 mp->color_aware = templ->color_aware ? 1 : 0;
4707 mp->scale = htonl (templ->scale);
4708 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
4709 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
4710 mp->current_limit = htonl (templ->current_limit);
4711 mp->current_bucket = htonl (templ->current_bucket);
4712 mp->extended_limit = htonl (templ->extended_limit);
4713 mp->extended_bucket = htonl (templ->extended_bucket);
4714 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
4716 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
4718 vl_msg_api_send_shmem (q, (u8 *) & mp);
4722 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
4724 unix_shared_memory_queue_t *q;
4725 vnet_policer_main_t *pm = &vnet_policer_main;
4731 sse2_qos_pol_cfg_params_st *config;
4732 policer_read_response_type_st *templ;
4734 q = vl_api_client_index_to_input_queue (mp->client_index);
4738 if (mp->match_name_valid)
4740 match_name = format (0, "%s%c", mp->match_name, 0);
4743 if (mp->match_name_valid)
4745 p = hash_get_mem (pm->policer_config_by_name, match_name);
4749 config = pool_elt_at_index (pm->configs, pool_index);
4750 templ = pool_elt_at_index (pm->policer_templates, pool_index);
4751 send_policer_details (match_name, config, templ, q, mp->context);
4757 hash_foreach_pair (hp, pm->policer_config_by_name,
4759 name = (u8 *) hp->key;
4760 pool_index = hp->value[0];
4761 config = pool_elt_at_index (pm->configs, pool_index);
4762 templ = pool_elt_at_index (pm->policer_templates, pool_index);
4763 send_policer_details(name, config, templ, q, mp->context);
4770 vl_api_policer_classify_set_interface_t_handler
4771 (vl_api_policer_classify_set_interface_t * mp)
4773 vlib_main_t *vm = vlib_get_main ();
4774 vl_api_policer_classify_set_interface_reply_t *rmp;
4776 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4778 ip4_table_index = ntohl (mp->ip4_table_index);
4779 ip6_table_index = ntohl (mp->ip6_table_index);
4780 l2_table_index = ntohl (mp->l2_table_index);
4781 sw_if_index = ntohl (mp->sw_if_index);
4783 VALIDATE_SW_IF_INDEX (mp);
4785 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
4786 ip6_table_index, l2_table_index,
4789 BAD_SW_IF_INDEX_LABEL;
4791 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
4795 send_policer_classify_details (u32 sw_if_index,
4797 unix_shared_memory_queue_t * q, u32 context)
4799 vl_api_policer_classify_details_t *mp;
4801 mp = vl_msg_api_alloc (sizeof (*mp));
4802 memset (mp, 0, sizeof (*mp));
4803 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
4804 mp->context = context;
4805 mp->sw_if_index = htonl (sw_if_index);
4806 mp->table_index = htonl (table_index);
4808 vl_msg_api_send_shmem (q, (u8 *) & mp);
4812 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
4814 unix_shared_memory_queue_t *q;
4815 policer_classify_main_t *pcm = &policer_classify_main;
4819 q = vl_api_client_index_to_input_queue (mp->client_index);
4823 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
4825 if (vec_len (vec_tbl))
4827 for (i = 0; i < vec_len (vec_tbl); i++)
4829 if (vec_elt (vec_tbl, i) == ~0)
4832 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
4839 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_fib_details_t * mp)
4841 clib_warning ("BUG");
4844 typedef struct mpls_tunnel_send_walk_ctx_t_
4846 unix_shared_memory_queue_t *q;
4849 } mpls_tunnel_send_walk_ctx_t;
4852 send_mpls_tunnel_entry (u32 mti, void *arg)
4854 mpls_tunnel_send_walk_ctx_t *ctx;
4855 vl_api_mpls_tunnel_details_t *mp;
4856 const mpls_tunnel_t *mt;
4861 if (~0 != ctx->index && mti != ctx->index)
4864 mt = mpls_tunnel_get (mti);
4865 nlabels = vec_len (mt->mt_label_stack);
4867 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
4868 memset (mp, 0, sizeof (*mp));
4869 mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
4870 mp->context = ctx->context;
4872 mp->tunnel_index = ntohl (mti);
4873 memcpy (mp->mt_next_hop_out_labels,
4874 mt->mt_label_stack, nlabels * sizeof (u32));
4878 vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
4882 vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
4884 unix_shared_memory_queue_t *q;
4886 q = vl_api_client_index_to_input_queue (mp->client_index);
4890 mpls_tunnel_send_walk_ctx_t ctx = {
4892 .index = ntohl (mp->tunnel_index),
4893 .context = mp->context,
4895 mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
4899 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
4901 clib_warning ("BUG");
4905 vl_api_mpls_fib_details_t_endian (vl_api_mpls_fib_details_t * mp)
4907 clib_warning ("BUG");
4911 vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp)
4913 clib_warning ("BUG");
4917 send_mpls_fib_details (vpe_api_main_t * am,
4918 unix_shared_memory_queue_t * q,
4919 u32 table_id, u32 label, u32 eos,
4920 fib_route_path_encode_t * api_rpaths, u32 context)
4922 vl_api_mpls_fib_details_t *mp;
4923 fib_route_path_encode_t *api_rpath;
4924 vl_api_fib_path2_t *fp;
4927 path_count = vec_len (api_rpaths);
4928 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
4931 memset (mp, 0, sizeof (*mp));
4932 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
4933 mp->context = context;
4935 mp->table_id = htonl (table_id);
4937 mp->label = htonl (label);
4939 mp->count = htonl (path_count);
4941 vec_foreach (api_rpath, api_rpaths)
4943 memset (fp, 0, sizeof (*fp));
4944 fp->weight = htonl (api_rpath->rpath.frp_weight);
4945 fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
4946 copy_fib_next_hop (api_rpath, fp);
4950 vl_msg_api_send_shmem (q, (u8 *) & mp);
4954 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
4956 vpe_api_main_t *am = &vpe_api_main;
4957 unix_shared_memory_queue_t *q;
4958 mpls_main_t *mm = &mpls_main;
4959 fib_table_t *fib_table;
4960 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
4964 fib_route_path_encode_t *api_rpaths;
4966 q = vl_api_client_index_to_input_queue (mp->client_index);
4971 pool_foreach (fib_table, mm->fibs,
4973 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
4975 vec_add1(lfeis, lfei);
4978 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
4980 vec_foreach(lfeip, lfeis)
4982 fib_entry_get_prefix(*lfeip, &pfx);
4983 fib_index = fib_entry_get_fib_index(*lfeip);
4984 fib_table = fib_table_get(fib_index, pfx.fp_proto);
4986 fib_entry_encode(*lfeip, &api_rpaths);
4987 send_mpls_fib_details (am, q,
4988 fib_table->ft_table_id,
4993 vec_free(api_rpaths);
5000 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
5002 unix_shared_memory_queue_t *q;
5004 q = vl_api_client_index_to_input_queue (mp->client_index);
5008 vnet_classify_main_t *cm = &vnet_classify_main;
5009 vnet_classify_table_t *t;
5014 pool_foreach (t, cm->tables,
5016 vec_add1 (table_ids, ntohl(t - cm->tables));
5019 count = vec_len (table_ids);
5021 vl_api_classify_table_ids_reply_t *rmp;
5022 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
5023 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
5024 rmp->context = mp->context;
5025 rmp->count = ntohl (count);
5026 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
5029 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5031 vec_free (table_ids);
5035 vl_api_classify_table_by_interface_t_handler
5036 (vl_api_classify_table_by_interface_t * mp)
5038 vl_api_classify_table_by_interface_reply_t *rmp;
5041 u32 sw_if_index = ntohl (mp->sw_if_index);
5044 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
5047 VALIDATE_SW_IF_INDEX (mp);
5049 input_acl_main_t *am = &input_acl_main;
5054 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
5056 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
5057 if (vec_len (vec_tbl))
5059 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
5061 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
5065 acl[type] = vec_elt (vec_tbl, if_idx);
5070 BAD_SW_IF_INDEX_LABEL;
5073 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
5075 rmp->sw_if_index = ntohl(sw_if_index);
5076 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
5077 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
5078 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
5085 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
5087 unix_shared_memory_queue_t *q;
5089 q = vl_api_client_index_to_input_queue (mp->client_index);
5093 vl_api_classify_table_info_reply_t *rmp = 0;
5095 vnet_classify_main_t *cm = &vnet_classify_main;
5096 u32 table_id = ntohl (mp->table_id);
5097 vnet_classify_table_t *t;
5100 pool_foreach (t, cm->tables,
5102 if (table_id == t - cm->tables)
5104 rmp = vl_msg_api_alloc_as_if_client
5105 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
5106 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
5107 rmp->context = mp->context;
5108 rmp->table_id = ntohl(table_id);
5109 rmp->nbuckets = ntohl(t->nbuckets);
5110 rmp->match_n_vectors = ntohl(t->match_n_vectors);
5111 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
5112 rmp->active_sessions = ntohl(t->active_elements);
5113 rmp->next_table_index = ntohl(t->next_table_index);
5114 rmp->miss_next_index = ntohl(t->miss_next_index);
5115 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
5116 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
5125 rmp = vl_msg_api_alloc (sizeof (*rmp));
5126 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
5127 rmp->context = mp->context;
5128 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
5131 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5135 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
5138 clib_warning ("BUG");
5142 send_classify_session_details (unix_shared_memory_queue_t * q,
5145 vnet_classify_entry_t * e, u32 context)
5147 vl_api_classify_session_details_t *rmp;
5149 rmp = vl_msg_api_alloc (sizeof (*rmp));
5150 memset (rmp, 0, sizeof (*rmp));
5151 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
5152 rmp->context = context;
5153 rmp->table_id = ntohl (table_id);
5154 rmp->hit_next_index = ntohl (e->next_index);
5155 rmp->advance = ntohl (e->advance);
5156 rmp->opaque_index = ntohl (e->opaque_index);
5157 rmp->match_length = ntohl (match_length);
5158 clib_memcpy (rmp->match, e->key, match_length);
5160 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5164 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
5166 vnet_classify_main_t *cm = &vnet_classify_main;
5167 unix_shared_memory_queue_t *q;
5169 u32 table_id = ntohl (mp->table_id);
5170 vnet_classify_table_t *t;
5172 q = vl_api_client_index_to_input_queue (mp->client_index);
5177 pool_foreach (t, cm->tables,
5179 if (table_id == t - cm->tables)
5181 vnet_classify_bucket_t * b;
5182 vnet_classify_entry_t * v, * save_v;
5185 for (i = 0; i < t->nbuckets; i++)
5187 b = &t->buckets [i];
5191 save_v = vnet_classify_get_entry (t, b->offset);
5192 for (j = 0; j < (1<<b->log2_pages); j++)
5194 for (k = 0; k < t->entries_per_page; k++)
5196 v = vnet_classify_entry_at_index
5197 (t, save_v, j*t->entries_per_page + k);
5198 if (vnet_classify_entry_is_free (v))
5201 send_classify_session_details
5202 (q, table_id, t->match_n_vectors * sizeof (u32x4),
5214 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
5216 vlib_main_t *vm = vlib_get_main ();
5217 flow_report_main_t *frm = &flow_report_main;
5218 vl_api_set_ipfix_exporter_reply_t *rmp;
5219 ip4_address_t collector, src;
5220 u16 collector_port = UDP_DST_PORT_ipfix;
5222 u32 template_interval;
5228 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
5229 collector_port = ntohs (mp->collector_port);
5230 if (collector_port == (u16) ~ 0)
5231 collector_port = UDP_DST_PORT_ipfix;
5232 memcpy (src.data, mp->src_address, sizeof (src.data));
5233 fib_id = ntohl (mp->vrf_id);
5235 ip4_main_t *im = &ip4_main;
5242 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
5245 rv = VNET_API_ERROR_NO_SUCH_FIB;
5251 path_mtu = ntohl (mp->path_mtu);
5253 path_mtu = 512; // RFC 7011 section 10.3.3.
5254 template_interval = ntohl (mp->template_interval);
5255 if (template_interval == ~0)
5256 template_interval = 20;
5257 udp_checksum = mp->udp_checksum;
5259 if (collector.as_u32 == 0)
5261 rv = VNET_API_ERROR_INVALID_VALUE;
5265 if (src.as_u32 == 0)
5267 rv = VNET_API_ERROR_INVALID_VALUE;
5271 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
5273 rv = VNET_API_ERROR_INVALID_VALUE;
5279 rv = VNET_API_ERROR_INVALID_VALUE;
5283 /* Reset report streams if we are reconfiguring IP addresses */
5284 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
5285 frm->src_address.as_u32 != src.as_u32 ||
5286 frm->collector_port != collector_port)
5287 vnet_flow_reports_reset (frm);
5289 frm->ipfix_collector.as_u32 = collector.as_u32;
5290 frm->collector_port = collector_port;
5291 frm->src_address.as_u32 = src.as_u32;
5292 frm->fib_index = fib_index;
5293 frm->path_mtu = path_mtu;
5294 frm->template_interval = template_interval;
5295 frm->udp_checksum = udp_checksum;
5297 /* Turn on the flow reporting process */
5298 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
5301 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
5305 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
5307 flow_report_main_t *frm = &flow_report_main;
5308 unix_shared_memory_queue_t *q;
5309 vl_api_ipfix_exporter_details_t *rmp;
5310 ip4_main_t *im = &ip4_main;
5313 q = vl_api_client_index_to_input_queue (mp->client_index);
5317 rmp = vl_msg_api_alloc (sizeof (*rmp));
5318 memset (rmp, 0, sizeof (*rmp));
5319 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
5320 rmp->context = mp->context;
5321 memcpy (rmp->collector_address, frm->ipfix_collector.data,
5322 sizeof (frm->ipfix_collector.data));
5323 rmp->collector_port = htons (frm->collector_port);
5324 memcpy (rmp->src_address, frm->src_address.data,
5325 sizeof (frm->src_address.data));
5326 if (frm->fib_index == ~0)
5329 vrf_id = im->fibs[frm->fib_index].ft_table_id;
5330 rmp->vrf_id = htonl (vrf_id);
5331 rmp->path_mtu = htonl (frm->path_mtu);
5332 rmp->template_interval = htonl (frm->template_interval);
5333 rmp->udp_checksum = (frm->udp_checksum != 0);
5335 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5339 vl_api_set_ipfix_classify_stream_t_handler
5340 (vl_api_set_ipfix_classify_stream_t * mp)
5342 vl_api_set_ipfix_classify_stream_reply_t *rmp;
5343 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5344 flow_report_main_t *frm = &flow_report_main;
5346 u32 src_port = UDP_DST_PORT_ipfix;
5349 domain_id = ntohl (mp->domain_id);
5350 src_port = ntohs (mp->src_port);
5352 if (fcm->src_port != 0 &&
5353 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
5355 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
5356 domain_id, (u16) src_port);
5360 fcm->domain_id = domain_id;
5361 fcm->src_port = (u16) src_port;
5363 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
5367 vl_api_ipfix_classify_stream_dump_t_handler
5368 (vl_api_ipfix_classify_stream_dump_t * mp)
5370 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5371 unix_shared_memory_queue_t *q;
5372 vl_api_ipfix_classify_stream_details_t *rmp;
5374 q = vl_api_client_index_to_input_queue (mp->client_index);
5378 rmp = vl_msg_api_alloc (sizeof (*rmp));
5379 memset (rmp, 0, sizeof (*rmp));
5380 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
5381 rmp->context = mp->context;
5382 rmp->domain_id = htonl (fcm->domain_id);
5383 rmp->src_port = htons (fcm->src_port);
5385 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5389 vl_api_ipfix_classify_table_add_del_t_handler
5390 (vl_api_ipfix_classify_table_add_del_t * mp)
5392 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
5393 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5394 flow_report_main_t *frm = &flow_report_main;
5395 vnet_flow_report_add_del_args_t args;
5396 ipfix_classify_table_t *table;
5398 u32 classify_table_index;
5400 u8 transport_protocol;
5403 classify_table_index = ntohl (mp->table_id);
5404 ip_version = mp->ip_version;
5405 transport_protocol = mp->transport_protocol;
5406 is_add = mp->is_add;
5408 if (fcm->src_port == 0)
5410 /* call set_ipfix_classify_stream first */
5411 rv = VNET_API_ERROR_UNSPECIFIED;
5415 memset (&args, 0, sizeof (args));
5419 for (i = 0; i < vec_len (fcm->tables); i++)
5420 if (ipfix_classify_table_index_valid (i))
5421 if (fcm->tables[i].classify_table_index == classify_table_index)
5423 table = &fcm->tables[i];
5431 rv = VNET_API_ERROR_VALUE_EXIST;
5434 table = ipfix_classify_add_table ();
5435 table->classify_table_index = classify_table_index;
5441 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
5446 table->ip_version = ip_version;
5447 table->transport_protocol = transport_protocol;
5449 args.opaque.as_uword = table - fcm->tables;
5450 args.rewrite_callback = ipfix_classify_template_rewrite;
5451 args.flow_data_callback = ipfix_classify_send_flows;
5452 args.is_add = is_add;
5453 args.domain_id = fcm->domain_id;
5454 args.src_port = fcm->src_port;
5456 rv = vnet_flow_report_add_del (frm, &args);
5458 /* If deleting, or add failed */
5459 if (is_add == 0 || (rv && is_add))
5460 ipfix_classify_delete_table (table - fcm->tables);
5463 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
5467 send_ipfix_classify_table_details (u32 table_index,
5468 unix_shared_memory_queue_t * q,
5471 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5472 vl_api_ipfix_classify_table_details_t *mp;
5474 ipfix_classify_table_t *table = &fcm->tables[table_index];
5476 mp = vl_msg_api_alloc (sizeof (*mp));
5477 memset (mp, 0, sizeof (*mp));
5478 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
5479 mp->context = context;
5480 mp->table_id = htonl (table->classify_table_index);
5481 mp->ip_version = table->ip_version;
5482 mp->transport_protocol = table->transport_protocol;
5484 vl_msg_api_send_shmem (q, (u8 *) & mp);
5488 vl_api_ipfix_classify_table_dump_t_handler
5489 (vl_api_ipfix_classify_table_dump_t * mp)
5491 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5492 unix_shared_memory_queue_t *q;
5495 q = vl_api_client_index_to_input_queue (mp->client_index);
5499 for (i = 0; i < vec_len (fcm->tables); i++)
5500 if (ipfix_classify_table_index_valid (i))
5501 send_ipfix_classify_table_details (i, q, mp->context);
5505 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
5507 vl_api_pg_create_interface_reply_t *rmp;
5510 pg_main_t *pg = &pg_main;
5511 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
5512 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
5515 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
5517 rmp->sw_if_index = ntohl(pi->sw_if_index);
5523 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
5525 vl_api_pg_capture_reply_t *rmp;
5528 vnet_main_t *vnm = vnet_get_main ();
5529 vnet_interface_main_t *im = &vnm->interface_main;
5530 vnet_hw_interface_t *hi = 0;
5532 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
5533 u32 hw_if_index = ~0;
5534 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
5537 vec_free (intf_name);
5539 if (hw_if_index != ~0)
5541 pg_capture_args_t _a, *a = &_a;
5543 u32 len = ntohl (mp->pcap_name_length);
5544 u8 *pcap_file_name = vec_new (u8, len);
5545 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
5547 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
5548 a->hw_if_index = hw_if_index;
5549 a->dev_instance = hi->dev_instance;
5550 a->is_enabled = mp->is_enabled;
5551 a->pcap_file_name = pcap_file_name;
5552 a->count = ntohl (mp->count);
5554 clib_error_t *e = pg_capture (a);
5557 clib_error_report (e);
5558 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
5561 vec_free (pcap_file_name);
5563 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
5567 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
5569 vl_api_pg_enable_disable_reply_t *rmp;
5572 pg_main_t *pg = &pg_main;
5573 u32 stream_index = ~0;
5575 int is_enable = mp->is_enabled != 0;
5576 u32 len = ntohl (mp->stream_name_length) - 1;
5580 u8 *stream_name = vec_new (u8, len);
5581 clib_memcpy (stream_name, mp->stream_name, len);
5582 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
5585 vec_free (stream_name);
5588 pg_enable_disable (stream_index, is_enable);
5590 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
5594 vl_api_ip_source_and_port_range_check_add_del_t_handler
5595 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
5597 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
5600 u8 is_ipv6 = mp->is_ipv6;
5601 u8 is_add = mp->is_add;
5602 u8 mask_length = mp->mask_length;
5603 ip4_address_t ip4_addr;
5604 ip6_address_t ip6_addr;
5606 u16 *high_ports = 0;
5608 u16 tmp_low, tmp_high;
5612 // Validate port range
5613 num_ranges = mp->number_of_ranges;
5614 if (num_ranges > 32)
5615 { // This is size of array in VPE.API
5616 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
5620 vec_reset_length (low_ports);
5621 vec_reset_length (high_ports);
5623 for (i = 0; i < num_ranges; i++)
5625 tmp_low = mp->low_ports[i];
5626 tmp_high = mp->high_ports[i];
5627 // If tmp_low <= tmp_high then only need to check tmp_low = 0
5628 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
5629 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
5631 rv = VNET_API_ERROR_INVALID_VALUE;
5634 vec_add1 (low_ports, tmp_low);
5635 vec_add1 (high_ports, tmp_high + 1);
5638 // Validate mask_length
5639 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
5641 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
5645 vrf_id = ntohl (mp->vrf_id);
5649 rv = VNET_API_ERROR_INVALID_VALUE;
5656 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
5657 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
5661 high_ports, is_add);
5665 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
5666 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
5670 high_ports, is_add);
5674 vec_free (low_ports);
5675 vec_free (high_ports);
5676 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
5680 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
5681 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
5683 vlib_main_t *vm = vlib_get_main ();
5684 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
5685 ip4_main_t *im = &ip4_main;
5688 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
5689 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
5693 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
5694 ntohl (mp->tcp_out_vrf_id);
5695 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
5696 ntohl (mp->udp_out_vrf_id);
5697 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
5698 ntohl (mp->tcp_in_vrf_id);
5699 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
5700 ntohl (mp->udp_in_vrf_id);
5703 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
5705 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
5707 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
5711 rv = VNET_API_ERROR_INVALID_VALUE;
5715 fib_index[i] = p[0];
5720 sw_if_index = ntohl (mp->sw_if_index);
5722 VALIDATE_SW_IF_INDEX (mp);
5725 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
5728 BAD_SW_IF_INDEX_LABEL;
5731 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
5735 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
5737 vl_api_delete_subif_reply_t *rmp;
5740 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
5742 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
5746 vl_api_l2_interface_pbb_tag_rewrite_t_handler
5747 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
5749 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
5750 vnet_main_t *vnm = vnet_get_main ();
5751 vlib_main_t *vm = vlib_get_main ();
5755 VALIDATE_SW_IF_INDEX (mp);
5757 vtr_op = ntohl (mp->vtr_op);
5761 case L2_VTR_DISABLED:
5764 case L2_VTR_TRANSLATE_2_1:
5768 rv = VNET_API_ERROR_INVALID_VALUE;
5769 goto bad_sw_if_index;
5772 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
5773 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
5774 ntohl (mp->i_sid), ntohs (mp->outer_tag));
5776 BAD_SW_IF_INDEX_LABEL;
5778 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
5783 vl_api_punt_t_handler (vl_api_punt_t * mp)
5785 vl_api_punt_reply_t *rmp;
5786 vlib_main_t *vm = vlib_get_main ();
5788 clib_error_t *error;
5790 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
5791 ntohs (mp->l4_port), mp->is_add);
5795 clib_error_report (error);
5798 REPLY_MACRO (VL_API_PUNT_REPLY);
5802 vl_api_flow_classify_set_interface_t_handler
5803 (vl_api_flow_classify_set_interface_t * mp)
5805 vlib_main_t *vm = vlib_get_main ();
5806 vl_api_flow_classify_set_interface_reply_t *rmp;
5808 u32 sw_if_index, ip4_table_index, ip6_table_index;
5810 ip4_table_index = ntohl (mp->ip4_table_index);
5811 ip6_table_index = ntohl (mp->ip6_table_index);
5812 sw_if_index = ntohl (mp->sw_if_index);
5814 VALIDATE_SW_IF_INDEX (mp);
5816 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
5817 ip6_table_index, mp->is_add);
5819 BAD_SW_IF_INDEX_LABEL;
5821 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
5825 send_flow_classify_details (u32 sw_if_index,
5827 unix_shared_memory_queue_t * q, u32 context)
5829 vl_api_flow_classify_details_t *mp;
5831 mp = vl_msg_api_alloc (sizeof (*mp));
5832 memset (mp, 0, sizeof (*mp));
5833 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
5834 mp->context = context;
5835 mp->sw_if_index = htonl (sw_if_index);
5836 mp->table_index = htonl (table_index);
5838 vl_msg_api_send_shmem (q, (u8 *) & mp);
5842 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
5844 unix_shared_memory_queue_t *q;
5845 flow_classify_main_t *pcm = &flow_classify_main;
5849 q = vl_api_client_index_to_input_queue (mp->client_index);
5853 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
5855 if (vec_len (vec_tbl))
5857 for (i = 0; i < vec_len (vec_tbl); i++)
5859 if (vec_elt (vec_tbl, i) == ~0)
5862 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
5869 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
5871 vl_api_feature_enable_disable_reply_t *rmp;
5873 u8 *arc_name, *feature_name;
5875 VALIDATE_SW_IF_INDEX (mp);
5877 arc_name = format (0, "%s%c", mp->arc_name, 0);
5878 feature_name = format (0, "%s%c", mp->feature_name, 0);
5880 vnet_feature_registration_t *reg;
5882 vnet_get_feature_reg ((const char *) arc_name,
5883 (const char *) feature_name);
5885 rv = VNET_API_ERROR_INVALID_VALUE;
5889 clib_error_t *error = 0;
5891 sw_if_index = ntohl (mp->sw_if_index);
5892 if (reg->enable_disable_cb)
5893 error = reg->enable_disable_cb (sw_if_index, mp->enable);
5895 vnet_feature_enable_disable ((const char *) arc_name,
5896 (const char *) feature_name,
5897 sw_if_index, mp->enable, 0, 0);
5900 clib_error_report (error);
5901 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
5905 vec_free (feature_name);
5906 vec_free (arc_name);
5908 BAD_SW_IF_INDEX_LABEL;
5910 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
5913 #define BOUNCE_HANDLER(nn) \
5914 static void vl_api_##nn##_t_handler ( \
5915 vl_api_##nn##_t *mp) \
5917 vpe_client_registration_t *reg; \
5918 vpe_api_main_t * vam = &vpe_api_main; \
5919 unix_shared_memory_queue_t * q; \
5921 /* One registration only... */ \
5922 pool_foreach(reg, vam->nn##_registrations, \
5924 q = vl_api_client_index_to_input_queue (reg->client_index); \
5927 * If the queue is stuffed, turf the msg and complain \
5928 * It's unlikely that the intended recipient is \
5929 * alive; avoid deadlock at all costs. \
5931 if (q->cursize == q->maxsize) { \
5932 clib_warning ("ERROR: receiver queue full, drop msg"); \
5933 vl_msg_api_free (mp); \
5936 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5940 vl_msg_api_free (mp); \
5943 static void setup_message_id_table (api_main_t * am);
5947 * Add vpe's API message handlers to the table.
5948 * vlib has alread mapped shared memory and
5949 * added the client registration handlers.
5950 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5952 static clib_error_t *
5953 vpe_api_hookup (vlib_main_t * vm)
5955 api_main_t *am = &api_main;
5958 vl_msg_api_set_handlers(VL_API_##N, #n, \
5959 vl_api_##n##_t_handler, \
5961 vl_api_##n##_t_endian, \
5962 vl_api_##n##_t_print, \
5963 sizeof(vl_api_##n##_t), 1);
5964 foreach_vpe_api_msg;
5968 * Manually register the sr tunnel add del msg, so we trace
5969 * enough bytes to capture a typical segment list
5971 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5972 "sr_tunnel_add_del",
5973 vl_api_sr_tunnel_add_del_t_handler,
5975 vl_api_sr_tunnel_add_del_t_endian,
5976 vl_api_sr_tunnel_add_del_t_print, 256, 1);
5980 * Manually register the sr policy add del msg, so we trace
5981 * enough bytes to capture a typical tunnel name list
5983 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
5984 "sr_policy_add_del",
5985 vl_api_sr_policy_add_del_t_handler,
5987 vl_api_sr_policy_add_del_t_endian,
5988 vl_api_sr_policy_add_del_t_print, 256, 1);
5991 * Trace space for 8 MPLS encap labels, classifier mask+match
5993 am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32);
5994 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
5995 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
5996 += 5 * sizeof (u32x4);
5997 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
6000 * Thread-safe API messages
6002 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
6003 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
6006 * Set up the (msg_name, crc, message-id) table
6008 setup_message_id_table (am);
6013 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
6015 static clib_error_t *
6016 vpe_api_init (vlib_main_t * vm)
6018 vpe_api_main_t *am = &vpe_api_main;
6021 am->vnet_main = vnet_get_main ();
6022 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6023 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6024 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6025 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6026 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6027 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6028 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
6031 vl_set_memory_region_name ("/vpe-api");
6032 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
6037 VLIB_INIT_FUNCTION (vpe_api_init);
6040 static clib_error_t *
6041 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
6044 u64 baseva, size, pvt_heap_size;
6046 const int max_buf_size = 4096;
6048 struct passwd _pw, *pw;
6049 struct group _grp, *grp;
6051 buf = vec_new (char, 128);
6052 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6054 if (unformat (input, "prefix %s", &chroot_path))
6056 vec_add1 (chroot_path, 0);
6057 vl_set_memory_root_path ((char *) chroot_path);
6059 else if (unformat (input, "uid %d", &uid))
6060 vl_set_memory_uid (uid);
6061 else if (unformat (input, "gid %d", &gid))
6062 vl_set_memory_gid (gid);
6063 else if (unformat (input, "baseva %llx", &baseva))
6064 vl_set_global_memory_baseva (baseva);
6065 else if (unformat (input, "global-size %lldM", &size))
6066 vl_set_global_memory_size (size * (1ULL << 20));
6067 else if (unformat (input, "global-size %lldG", &size))
6068 vl_set_global_memory_size (size * (1ULL << 30));
6069 else if (unformat (input, "global-size %lld", &size))
6070 vl_set_global_memory_size (size);
6071 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
6072 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
6073 else if (unformat (input, "global-pvt-heap-size size %lld",
6075 vl_set_global_pvt_heap_size (pvt_heap_size);
6076 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
6077 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
6078 else if (unformat (input, "api-pvt-heap-size size %lld",
6080 vl_set_api_pvt_heap_size (pvt_heap_size);
6081 else if (unformat (input, "api-size %lldM", &size))
6082 vl_set_api_memory_size (size * (1ULL << 20));
6083 else if (unformat (input, "api-size %lldG", &size))
6084 vl_set_api_memory_size (size * (1ULL << 30));
6085 else if (unformat (input, "api-size %lld", &size))
6086 vl_set_api_memory_size (size);
6087 else if (unformat (input, "uid %s", &s))
6089 /* lookup the username */
6092 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
6093 && (vec_len (buf) <= max_buf_size))
6095 vec_resize (buf, vec_len (buf) * 2);
6099 e = clib_error_return_code (0, rv,
6100 CLIB_ERROR_ERRNO_VALID |
6102 "cannot fetch username %s", s);
6110 clib_error_return_fatal (0, "username %s does not exist", s);
6116 vl_set_memory_uid (pw->pw_uid);
6118 else if (unformat (input, "gid %s", &s))
6120 /* lookup the group name */
6123 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
6124 && (vec_len (buf) <= max_buf_size))
6126 vec_resize (buf, vec_len (buf) * 2);
6130 e = clib_error_return_code (0, rv,
6131 CLIB_ERROR_ERRNO_VALID |
6133 "cannot fetch group %s", s);
6140 e = clib_error_return_fatal (0, "group %s does not exist", s);
6147 vl_set_memory_gid (grp->gr_gid);
6150 return clib_error_return (0, "unknown input `%U'",
6151 format_unformat_error, input);
6156 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
6159 get_unformat_vnet_sw_interface (void)
6161 return (void *) &unformat_vnet_sw_interface;
6165 format_arp_event (u8 * s, va_list * args)
6167 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
6169 s = format (s, "pid %d: ", event->pid);
6171 s = format (s, "bd mac/ip4 binding events");
6173 s = format (s, "resolution for %U", format_ip4_address, &event->address);
6178 format_nd_event (u8 * s, va_list * args)
6180 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
6182 s = format (s, "pid %d: ", event->pid);
6184 s = format (s, "bd mac/ip6 binding events");
6186 s = format (s, "resolution for %U", format_ip6_address, event->address);
6190 static clib_error_t *
6191 show_ip_arp_nd_events_fn (vlib_main_t * vm,
6192 unformat_input_t * input, vlib_cli_command_t * cmd)
6194 vpe_api_main_t *am = &vpe_api_main;
6195 vl_api_ip4_arp_event_t *arp_event;
6196 vl_api_ip6_nd_event_t *nd_event;
6198 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
6200 vlib_cli_output (vm, "No active arp or nd event registrations");
6205 pool_foreach (arp_event, am->arp_events,
6207 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
6210 pool_foreach (nd_event, am->nd_events,
6212 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
6220 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
6221 .path = "show arp-nd-event registrations",
6222 .function = show_ip_arp_nd_events_fn,
6223 .short_help = "Show ip4 arp and ip6 nd event registrations",
6227 #define vl_msg_name_crc_list
6228 #include <vpp-api/vpe_all_api_h.h>
6229 #undef vl_msg_name_crc_list
6232 setup_message_id_table (api_main_t * am)
6234 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
6235 foreach_vl_msg_name_crc_memclnt;
6236 foreach_vl_msg_name_crc_vpe;
6242 * fd.io coding-style-patch-verification: ON
6245 * eval: (c-set-style "gnu")