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/ipsec-gre/ipsec_gre.h>
86 #include <vnet/flow/flow_report_classify.h>
87 #include <vnet/ip/punt.h>
88 #include <vnet/feature/feature.h>
91 #undef __included_bihash_template_h__
92 #include <vnet/l2/l2_fib.h>
95 #include <vnet/devices/dpdk/dpdk.h>
98 #include <stats/stats.h>
100 #include <vnet/ethernet/ethernet.h>
101 #include <vnet/ethernet/arp_packet.h>
102 #include <vnet/interface.h>
103 #include <vnet/l2/l2_fib.h>
104 #include <vnet/l2/l2_bd.h>
105 #include <vpp-api/vpe_msg_enum.h>
106 #include <vnet/span/span.h>
107 #include <vnet/fib/ip6_fib.h>
108 #include <vnet/fib/ip4_fib.h>
109 #include <vnet/fib/fib_api.h>
110 #include <vnet/dpo/drop_dpo.h>
111 #include <vnet/dpo/receive_dpo.h>
112 #include <vnet/dpo/lookup_dpo.h>
113 #include <vnet/dpo/classify_dpo.h>
114 #include <vnet/dpo/ip_null_dpo.h>
115 #define vl_typedefs /* define message structures */
116 #include <vpp-api/vpe_all_api_h.h>
118 #define vl_endianfun /* define message structures */
119 #include <vpp-api/vpe_all_api_h.h>
121 /* instantiate all the print functions we know about */
122 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
124 #include <vpp-api/vpe_all_api_h.h>
126 #include <vlibapi/api_helper_macros.h>
127 #define foreach_vpe_api_msg \
128 _(WANT_OAM_EVENTS, want_oam_events) \
129 _(OAM_ADD_DEL, oam_add_del) \
130 _(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \
131 _(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \
132 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
133 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
134 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
135 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
136 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
137 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
138 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
139 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
140 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
141 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
142 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
143 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
144 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
145 _(L2FIB_ADD_DEL, l2fib_add_del) \
146 _(L2_FLAGS, l2_flags) \
147 _(BRIDGE_FLAGS, bridge_flags) \
148 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
149 _(CREATE_SUBIF, create_subif) \
150 _(MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del) \
151 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
152 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
153 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
154 _(RESET_FIB, reset_fib) \
155 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
156 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
157 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
158 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
159 _(CREATE_LOOPBACK, create_loopback) \
160 _(CONTROL_PING, control_ping) \
161 _(CLI_REQUEST, cli_request) \
162 _(CLI_INBAND, cli_inband) \
163 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
164 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
165 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
166 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
167 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
168 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
169 _(GET_NODE_INDEX, get_node_index) \
170 _(ADD_NODE_NEXT, add_node_next) \
171 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
172 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
173 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
174 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
175 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
176 _(SHOW_VERSION, show_version) \
177 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
178 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
179 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
180 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
181 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
182 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
183 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
184 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
185 _(DELETE_LOOPBACK, delete_loopback) \
186 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
187 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
188 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
189 _(GET_NODE_GRAPH, get_node_graph) \
190 _(IOAM_ENABLE, ioam_enable) \
191 _(IOAM_DISABLE, ioam_disable) \
192 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
193 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
194 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
195 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
196 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
197 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
198 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
199 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
200 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
201 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
202 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
203 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
204 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
205 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
206 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
207 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
208 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
209 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
210 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
211 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
212 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
213 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
214 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
215 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
216 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
217 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
218 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
219 _(SHOW_LISP_STATUS, show_lisp_status) \
220 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
221 lisp_add_del_map_request_itr_rlocs) \
222 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
223 _(SHOW_LISP_PITR, show_lisp_pitr) \
224 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
225 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
226 _(POLICER_ADD_DEL, policer_add_del) \
227 _(POLICER_DUMP, policer_dump) \
228 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
229 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
230 _(MPLS_TUNNEL_DUMP, mpls_tunnel_dump) \
231 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
232 _(MPLS_FIB_DUMP, mpls_fib_dump) \
233 _(MPLS_FIB_DETAILS, mpls_fib_details) \
234 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
235 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
236 _(CLASSIFY_TABLE_INFO,classify_table_info) \
237 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
238 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
239 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
240 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
241 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
242 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
243 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
244 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
245 _(GET_NEXT_INDEX, get_next_index) \
246 _(PG_CREATE_INTERFACE, pg_create_interface) \
247 _(PG_CAPTURE, pg_capture) \
248 _(PG_ENABLE_DISABLE, pg_enable_disable) \
249 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
250 ip_source_and_port_range_check_add_del) \
251 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
252 ip_source_and_port_range_check_interface_add_del) \
253 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
254 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
255 _(DELETE_SUBIF, delete_subif) \
256 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
258 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
259 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
260 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
263 #define QUOTE(x) QUOTE_(x)
266 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
267 RESOLVE_IP6_ADD_DEL_ROUTE,
270 static vlib_node_registration_t vpe_resolver_process_node;
271 vpe_api_main_t vpe_api_main;
273 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
274 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
276 /* Clean up all registrations belonging to the indicated client */
278 vl_api_memclnt_delete_callback (u32 client_index)
280 vpe_api_main_t *vam = &vpe_api_main;
281 vpe_client_registration_t *rp;
283 int stats_memclnt_delete_callback (u32 client_index);
285 stats_memclnt_delete_callback (client_index);
288 p = hash_get (vam->a##_registration_hash, client_index); \
290 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
291 pool_put (vam->a##_registrations, rp); \
292 hash_unset (vam->a##_registration_hash, client_index); \
294 foreach_registration_hash;
299 pub_sub_handler (oam_events, OAM_EVENTS);
301 #define RESOLUTION_EVENT 1
302 #define RESOLUTION_PENDING_EVENT 2
303 #define IP4_ARP_EVENT 3
304 #define IP6_ND_EVENT 4
306 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
308 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
311 handle_ip4_arp_event (u32 pool_index)
313 vpe_api_main_t *vam = &vpe_api_main;
314 vnet_main_t *vnm = vam->vnet_main;
315 vlib_main_t *vm = vam->vlib_main;
316 vl_api_ip4_arp_event_t *event;
317 vl_api_ip4_arp_event_t *mp;
318 unix_shared_memory_queue_t *q;
320 /* Client can cancel, die, etc. */
321 if (pool_is_free_index (vam->arp_events, pool_index))
324 event = pool_elt_at_index (vam->arp_events, pool_index);
326 q = vl_api_client_index_to_input_queue (event->client_index);
329 (void) vnet_add_del_ip4_arp_change_event
330 (vnm, arp_change_delete_callback,
331 event->pid, &event->address,
332 vpe_resolver_process_node.index, IP4_ARP_EVENT,
333 ~0 /* pool index, notused */ , 0 /* is_add */ );
337 if (q->cursize < q->maxsize)
339 mp = vl_msg_api_alloc (sizeof (*mp));
340 clib_memcpy (mp, event, sizeof (*mp));
341 vl_msg_api_send_shmem (q, (u8 *) & mp);
345 static f64 last_time;
347 * Throttle syslog msgs.
348 * It's pretty tempting to just revoke the registration...
350 if (vlib_time_now (vm) > last_time + 10.0)
352 clib_warning ("arp event for %U to pid %d: queue stuffed!",
353 format_ip4_address, &event->address, event->pid);
354 last_time = vlib_time_now (vm);
360 handle_ip6_nd_event (u32 pool_index)
362 vpe_api_main_t *vam = &vpe_api_main;
363 vnet_main_t *vnm = vam->vnet_main;
364 vlib_main_t *vm = vam->vlib_main;
365 vl_api_ip6_nd_event_t *event;
366 vl_api_ip6_nd_event_t *mp;
367 unix_shared_memory_queue_t *q;
369 /* Client can cancel, die, etc. */
370 if (pool_is_free_index (vam->nd_events, pool_index))
373 event = pool_elt_at_index (vam->nd_events, pool_index);
375 q = vl_api_client_index_to_input_queue (event->client_index);
378 (void) vnet_add_del_ip6_nd_change_event
379 (vnm, nd_change_delete_callback,
380 event->pid, &event->address,
381 vpe_resolver_process_node.index, IP6_ND_EVENT,
382 ~0 /* pool index, notused */ , 0 /* is_add */ );
386 if (q->cursize < q->maxsize)
388 mp = vl_msg_api_alloc (sizeof (*mp));
389 clib_memcpy (mp, event, sizeof (*mp));
390 vl_msg_api_send_shmem (q, (u8 *) & mp);
394 static f64 last_time;
396 * Throttle syslog msgs.
397 * It's pretty tempting to just revoke the registration...
399 if (vlib_time_now (vm) > last_time + 10.0)
401 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
402 format_ip6_address, &event->address, event->pid);
403 last_time = vlib_time_now (vm);
409 resolver_process (vlib_main_t * vm,
410 vlib_node_runtime_t * rt, vlib_frame_t * f)
413 uword *event_data = 0;
419 vlib_process_wait_for_event_or_clock (vm, timeout);
421 event_type = vlib_process_get_events (vm, &event_data);
425 case RESOLUTION_PENDING_EVENT:
429 case RESOLUTION_EVENT:
430 clib_warning ("resolver: BOGUS TYPE");
434 for (i = 0; i < vec_len (event_data); i++)
435 handle_ip4_arp_event (event_data[i]);
439 for (i = 0; i < vec_len (event_data); i++)
440 handle_ip6_nd_event (event_data[i]);
443 case ~0: /* timeout */
447 vec_reset_length (event_data);
449 return 0; /* or not */
453 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
454 .function = resolver_process,
455 .type = VLIB_NODE_TYPE_PROCESS,
456 .name = "vpe-route-resolver-process",
461 mpls_route_add_del_t_handler (vnet_main_t * vnm,
462 vl_api_mpls_route_add_del_t * mp)
464 u32 fib_index, next_hop_fib_index;
465 mpls_label_t *label_stack = NULL;
466 int rv, ii, n_labels;;
470 .fp_proto = FIB_PROTOCOL_MPLS,
471 .fp_eos = mp->mr_eos,
472 .fp_label = ntohl (mp->mr_label),
476 if (mp->mr_next_hop_proto_is_ip4)
478 pfx.fp_payload_proto = DPO_PROTO_IP4;
482 pfx.fp_payload_proto = DPO_PROTO_IP6;
487 pfx.fp_payload_proto = DPO_PROTO_MPLS;
490 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
492 mp->mr_next_hop_sw_if_index,
493 dpo_proto_to_fib (pfx.fp_payload_proto),
494 mp->mr_next_hop_table_id,
495 mp->mr_create_table_if_needed,
496 &fib_index, &next_hop_fib_index);
502 memset (&nh, 0, sizeof (nh));
504 if (mp->mr_next_hop_proto_is_ip4)
505 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
507 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
509 n_labels = mp->mr_next_hop_n_out_labels;
512 else if (1 == n_labels)
513 vec_add1 (label_stack, ntohl (mp->mr_next_hop_out_label_stack[0]));
516 vec_validate (label_stack, n_labels - 1);
517 for (ii = 0; ii < n_labels; ii++)
518 label_stack[ii] = ntohl (mp->mr_next_hop_out_label_stack[ii]);
521 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
522 0, // mp->is_unreach,
523 0, // mp->is_prohibit,
526 mp->mr_classify_table_index,
527 mp->mr_is_resolve_host,
528 mp->mr_is_resolve_attached,
530 mp->mr_next_hop_proto_is_ip4,
531 &nh, ntohl (mp->mr_next_hop_sw_if_index),
533 mp->mr_next_hop_weight,
534 ntohl (mp->mr_next_hop_via_label),
539 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
541 vl_api_mpls_route_add_del_reply_t *rmp;
545 vnm = vnet_get_main ();
548 rv = mpls_route_add_del_t_handler (vnm, mp);
550 rv = (rv == 0) ? vnm->api_errno : rv;
552 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
556 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
557 vl_api_mpls_ip_bind_unbind_t * mp)
559 u32 mpls_fib_index, ip_fib_index;
562 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
564 if (~0 == mpls_fib_index)
566 if (mp->mb_create_table_if_needed)
569 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
570 ntohl (mp->mb_mpls_table_id));
573 return VNET_API_ERROR_NO_SUCH_FIB;
576 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
579 ntohl (mp->mb_ip_table_id));
580 if (~0 == ip_fib_index)
581 return VNET_API_ERROR_NO_SUCH_FIB;
584 .fp_len = mp->mb_address_length,
589 pfx.fp_proto = FIB_PROTOCOL_IP4;
590 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
591 sizeof (pfx.fp_addr.ip4));
595 pfx.fp_proto = FIB_PROTOCOL_IP6;
596 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
597 sizeof (pfx.fp_addr.ip6));
601 fib_table_entry_local_label_add (ip_fib_index, &pfx,
602 ntohl (mp->mb_label));
604 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
605 ntohl (mp->mb_label));
611 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
613 vl_api_mpls_route_add_del_reply_t *rmp;
617 vnm = vnet_get_main ();
620 rv = mpls_ip_bind_unbind_handler (vnm, mp);
622 rv = (rv == 0) ? vnm->api_errno : rv;
624 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
628 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
630 vl_api_sw_interface_set_vpath_reply_t *rmp;
632 u32 sw_if_index = ntohl (mp->sw_if_index);
634 VALIDATE_SW_IF_INDEX (mp);
636 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
637 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
638 sw_if_index, mp->enable, 0, 0);
639 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
640 sw_if_index, mp->enable, 0, 0);
641 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
642 sw_if_index, mp->enable, 0, 0);
643 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
644 sw_if_index, mp->enable, 0, 0);
646 BAD_SW_IF_INDEX_LABEL;
648 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
652 vl_api_sw_interface_set_vxlan_bypass_t_handler
653 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
655 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
657 u32 sw_if_index = ntohl (mp->sw_if_index);
659 VALIDATE_SW_IF_INDEX (mp);
663 /* not yet implemented */
666 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
667 sw_if_index, mp->enable, 0, 0);
669 BAD_SW_IF_INDEX_LABEL;
671 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
675 vl_api_sw_interface_set_l2_xconnect_t_handler
676 (vl_api_sw_interface_set_l2_xconnect_t * mp)
678 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
680 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
681 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
682 vlib_main_t *vm = vlib_get_main ();
683 vnet_main_t *vnm = vnet_get_main ();
685 VALIDATE_RX_SW_IF_INDEX (mp);
689 VALIDATE_TX_SW_IF_INDEX (mp);
690 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
691 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
695 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
698 BAD_RX_SW_IF_INDEX_LABEL;
699 BAD_TX_SW_IF_INDEX_LABEL;
701 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
705 vl_api_sw_interface_set_l2_bridge_t_handler
706 (vl_api_sw_interface_set_l2_bridge_t * mp)
708 bd_main_t *bdm = &bd_main;
709 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
711 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
712 u32 bd_id = ntohl (mp->bd_id);
716 vlib_main_t *vm = vlib_get_main ();
717 vnet_main_t *vnm = vnet_get_main ();
719 VALIDATE_RX_SW_IF_INDEX (mp);
721 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
725 //VALIDATE_TX_SW_IF_INDEX(mp);
726 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
727 rx_sw_if_index, bd_index, bvi, shg, 0);
731 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
734 BAD_RX_SW_IF_INDEX_LABEL;
736 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
740 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
741 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
743 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
747 dpdk_main_t *dm = &dpdk_main;
750 u32 sw_if_index = ntohl (mp->sw_if_index);
751 u32 subport = ntohl (mp->subport);
752 u32 pipe = ntohl (mp->pipe);
753 u32 profile = ntohl (mp->profile);
754 vnet_hw_interface_t *hw;
756 VALIDATE_SW_IF_INDEX (mp);
758 /* hw_if & dpdk device */
759 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
761 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
763 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
765 BAD_SW_IF_INDEX_LABEL;
767 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
768 rv = VNET_API_ERROR_UNIMPLEMENTED;
771 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
775 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
776 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
778 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
782 dpdk_main_t *dm = &dpdk_main;
784 struct rte_sched_subport_params p;
786 u32 sw_if_index = ntohl (mp->sw_if_index);
787 u32 subport = ntohl (mp->subport);
788 p.tb_rate = ntohl (mp->tb_rate);
789 p.tb_size = ntohl (mp->tb_size);
790 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
791 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
792 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
793 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
794 p.tc_period = ntohl (mp->tc_period);
796 vnet_hw_interface_t *hw;
798 VALIDATE_SW_IF_INDEX (mp);
800 /* hw_if & dpdk device */
801 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
803 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
805 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
807 BAD_SW_IF_INDEX_LABEL;
810 ("setting HQoS subport parameters without DPDK not implemented");
811 rv = VNET_API_ERROR_UNIMPLEMENTED;
814 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
818 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
819 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
821 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
825 dpdk_main_t *dm = &dpdk_main;
826 vlib_thread_main_t *tm = vlib_get_thread_main ();
829 u32 sw_if_index = ntohl (mp->sw_if_index);
830 u32 entry = ntohl (mp->entry);
831 u32 tc = ntohl (mp->tc);
832 u32 queue = ntohl (mp->queue);
835 vnet_hw_interface_t *hw;
837 VALIDATE_SW_IF_INDEX (mp);
839 /* hw_if & dpdk device */
840 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
842 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
844 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
846 clib_warning ("invalid traffic class !!");
847 rv = VNET_API_ERROR_INVALID_VALUE;
850 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
852 clib_warning ("invalid queue !!");
853 rv = VNET_API_ERROR_INVALID_VALUE;
857 /* Detect the set of worker threads */
858 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
862 clib_warning ("worker thread registration AWOL !!");
863 rv = VNET_API_ERROR_INVALID_VALUE_2;
867 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
868 int worker_thread_first = tr->first_index;
869 int worker_thread_count = tr->count;
871 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
872 for (i = 0; i < worker_thread_count; i++)
873 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
875 BAD_SW_IF_INDEX_LABEL;
878 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
879 rv = VNET_API_ERROR_UNIMPLEMENTED;
882 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
886 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
888 vlib_main_t *vm = vlib_get_main ();
889 bd_main_t *bdm = &bd_main;
890 vl_api_bridge_domain_add_del_reply_t *rmp;
892 u32 enable_flags = 0, disable_flags = 0;
893 u32 bd_id = ntohl (mp->bd_id);
898 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
901 enable_flags |= L2_FLOOD;
903 disable_flags |= L2_FLOOD;
906 enable_flags |= L2_UU_FLOOD;
908 disable_flags |= L2_UU_FLOOD;
911 enable_flags |= L2_FWD;
913 disable_flags |= L2_FWD;
916 enable_flags |= L2_ARP_TERM;
918 disable_flags |= L2_ARP_TERM;
921 enable_flags |= L2_LEARN;
923 disable_flags |= L2_LEARN;
926 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
929 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
931 bd_set_mac_age (vm, bd_index, mp->mac_age);
934 rv = bd_delete_bd_index (bdm, bd_id);
936 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
940 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
942 clib_warning ("BUG");
946 vl_api_bridge_domain_sw_if_details_t_handler
947 (vl_api_bridge_domain_sw_if_details_t * mp)
949 clib_warning ("BUG");
953 send_bridge_domain_details (unix_shared_memory_queue_t * q,
954 l2_bridge_domain_t * bd_config,
955 u32 n_sw_ifs, u32 context)
957 vl_api_bridge_domain_details_t *mp;
959 mp = vl_msg_api_alloc (sizeof (*mp));
960 memset (mp, 0, sizeof (*mp));
961 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
962 mp->bd_id = ntohl (bd_config->bd_id);
963 mp->flood = bd_feature_flood (bd_config);
964 mp->uu_flood = bd_feature_uu_flood (bd_config);
965 mp->forward = bd_feature_forward (bd_config);
966 mp->learn = bd_feature_learn (bd_config);
967 mp->arp_term = bd_feature_arp_term (bd_config);
968 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
969 mp->mac_age = bd_config->mac_age;
970 mp->n_sw_ifs = ntohl (n_sw_ifs);
971 mp->context = context;
973 vl_msg_api_send_shmem (q, (u8 *) & mp);
977 send_bd_sw_if_details (l2input_main_t * l2im,
978 unix_shared_memory_queue_t * q,
979 l2_flood_member_t * member, u32 bd_id, u32 context)
981 vl_api_bridge_domain_sw_if_details_t *mp;
982 l2_input_config_t *input_cfg;
984 mp = vl_msg_api_alloc (sizeof (*mp));
985 memset (mp, 0, sizeof (*mp));
986 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
987 mp->bd_id = ntohl (bd_id);
988 mp->sw_if_index = ntohl (member->sw_if_index);
989 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
990 mp->shg = input_cfg->shg;
991 mp->context = context;
993 vl_msg_api_send_shmem (q, (u8 *) & mp);
997 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
999 bd_main_t *bdm = &bd_main;
1000 l2input_main_t *l2im = &l2input_main;
1001 unix_shared_memory_queue_t *q;
1002 l2_bridge_domain_t *bd_config;
1003 u32 bd_id, bd_index;
1006 q = vl_api_client_index_to_input_queue (mp->client_index);
1011 bd_id = ntohl (mp->bd_id);
1013 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1014 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1015 for (; bd_index < end; bd_index++)
1017 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1018 /* skip dummy bd_id 0 */
1019 if (bd_config && (bd_config->bd_id > 0))
1022 l2_flood_member_t *m;
1024 n_sw_ifs = vec_len (bd_config->members);
1025 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1027 vec_foreach (m, bd_config->members)
1029 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1036 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1038 bd_main_t *bdm = &bd_main;
1039 l2input_main_t *l2im = &l2input_main;
1040 vl_api_l2fib_add_del_reply_t *rmp;
1043 u32 sw_if_index = ntohl (mp->sw_if_index);
1044 u32 bd_id = ntohl (mp->bd_id);
1053 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1056 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1057 goto bad_sw_if_index;
1063 filter_mac = mp->filter_mac ? 1 : 0;
1064 if (filter_mac == 0)
1066 VALIDATE_SW_IF_INDEX (mp);
1067 if (vec_len (l2im->configs) <= sw_if_index)
1069 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1070 goto bad_sw_if_index;
1074 l2_input_config_t *config;
1075 config = vec_elt_at_index (l2im->configs, sw_if_index);
1076 if (config->bridge == 0)
1078 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1079 goto bad_sw_if_index;
1083 static_mac = mp->static_mac ? 1 : 0;
1084 bvi_mac = mp->bvi_mac ? 1 : 0;
1085 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1090 l2fib_del_entry (mac, bd_index);
1093 BAD_SW_IF_INDEX_LABEL;
1095 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1099 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1101 vl_api_l2_flags_reply_t *rmp;
1103 u32 sw_if_index = ntohl (mp->sw_if_index);
1104 u32 flags = ntohl (mp->feature_bitmap);
1107 VALIDATE_SW_IF_INDEX (mp);
1110 if (flags & L2INPUT_FEAT_ ## a) \
1111 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1112 foreach_l2input_feat;
1115 BAD_SW_IF_INDEX_LABEL;
1118 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1120 rmp->resulting_feature_bitmap = ntohl(rbm);
1126 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1128 vlib_main_t *vm = vlib_get_main ();
1129 bd_main_t *bdm = &bd_main;
1130 vl_api_bridge_flags_reply_t *rmp;
1132 u32 bd_id = ntohl (mp->bd_id);
1134 u32 flags = ntohl (mp->feature_bitmap);
1137 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1140 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1146 bd_set_flags (vm, bd_index, flags, mp->is_set);
1150 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1152 rmp->resulting_feature_bitmap = ntohl(flags);
1158 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1160 bd_main_t *bdm = &bd_main;
1161 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1163 u32 bd_id = ntohl (mp->bd_id);
1167 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1170 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1175 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1176 mp->mac_address, mp->is_ipv6, mp->is_add))
1177 rv = VNET_API_ERROR_UNSPECIFIED;
1180 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1184 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1186 vl_api_create_vlan_subif_reply_t *rmp;
1187 vnet_main_t *vnm = vnet_get_main ();
1188 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1189 vnet_hw_interface_t *hi;
1192 vnet_sw_interface_t template;
1194 vnet_interface_main_t *im = &vnm->interface_main;
1195 u64 sup_and_sub_key;
1197 unix_shared_memory_queue_t *q;
1198 clib_error_t *error;
1200 VALIDATE_SW_IF_INDEX (mp);
1202 hw_if_index = ntohl (mp->sw_if_index);
1203 hi = vnet_get_hw_interface (vnm, hw_if_index);
1205 id = ntohl (mp->vlan_id);
1206 if (id == 0 || id > 4095)
1208 rv = VNET_API_ERROR_INVALID_VLAN;
1212 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1214 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1217 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1221 kp = clib_mem_alloc (sizeof (*kp));
1222 *kp = sup_and_sub_key;
1224 memset (&template, 0, sizeof (template));
1225 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1226 template.sup_sw_if_index = hi->sw_if_index;
1227 template.sub.id = id;
1228 template.sub.eth.raw_flags = 0;
1229 template.sub.eth.flags.one_tag = 1;
1230 template.sub.eth.outer_vlan_id = id;
1231 template.sub.eth.flags.exact_match = 1;
1233 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1236 clib_error_report (error);
1237 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1240 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1241 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1243 BAD_SW_IF_INDEX_LABEL;
1246 q = vl_api_client_index_to_input_queue (mp->client_index);
1250 rmp = vl_msg_api_alloc (sizeof (*rmp));
1251 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1252 rmp->context = mp->context;
1253 rmp->retval = ntohl (rv);
1254 rmp->sw_if_index = ntohl (sw_if_index);
1255 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1259 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1261 vl_api_create_subif_reply_t *rmp;
1262 vnet_main_t *vnm = vnet_get_main ();
1263 u32 sw_if_index = ~0;
1266 vnet_sw_interface_t *si;
1267 vnet_hw_interface_t *hi;
1268 vnet_sw_interface_t template;
1270 vnet_interface_main_t *im = &vnm->interface_main;
1271 u64 sup_and_sub_key;
1273 clib_error_t *error;
1275 VALIDATE_SW_IF_INDEX (mp);
1277 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1278 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1280 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1282 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1286 sw_if_index = si->sw_if_index;
1287 sub_id = ntohl (mp->sub_id);
1289 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1291 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1295 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1296 sw_if_index, sub_id);
1297 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1301 kp = clib_mem_alloc (sizeof (*kp));
1302 *kp = sup_and_sub_key;
1304 memset (&template, 0, sizeof (template));
1305 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1306 template.sup_sw_if_index = sw_if_index;
1307 template.sub.id = sub_id;
1308 template.sub.eth.flags.no_tags = mp->no_tags;
1309 template.sub.eth.flags.one_tag = mp->one_tag;
1310 template.sub.eth.flags.two_tags = mp->two_tags;
1311 template.sub.eth.flags.dot1ad = mp->dot1ad;
1312 template.sub.eth.flags.exact_match = mp->exact_match;
1313 template.sub.eth.flags.default_sub = mp->default_sub;
1314 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1315 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1316 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1317 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1319 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1322 clib_error_report (error);
1323 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1327 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1328 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1330 BAD_SW_IF_INDEX_LABEL;
1335 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1337 rmp->sw_if_index = ntohl(sw_if_index);
1343 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
1345 vl_api_mpls_tunnel_add_del_reply_t *rmp;
1347 stats_main_t *sm = &stats_main;
1348 u32 tunnel_sw_if_index;
1351 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1355 fib_route_path_t rpath, *rpaths = NULL;
1356 mpls_label_t *label_stack = NULL;
1358 memset (&rpath, 0, sizeof (rpath));
1360 if (mp->mt_next_hop_proto_is_ip4)
1362 rpath.frp_proto = FIB_PROTOCOL_IP4;
1363 clib_memcpy (&rpath.frp_addr.ip4,
1364 mp->mt_next_hop, sizeof (rpath.frp_addr.ip4));
1368 rpath.frp_proto = FIB_PROTOCOL_IP6;
1369 clib_memcpy (&rpath.frp_addr.ip6,
1370 mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
1372 rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
1374 for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
1375 vec_add1 (label_stack, ntohl (mp->mt_next_hop_out_label_stack[ii]));
1377 vec_add1 (rpaths, rpath);
1379 vnet_mpls_tunnel_add (rpaths, label_stack,
1380 mp->mt_l2_only, &tunnel_sw_if_index);
1382 vec_free (label_stack);
1386 tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
1387 vnet_mpls_tunnel_del (tunnel_sw_if_index);
1393 REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
1395 rmp->sw_if_index = ntohl(tunnel_sw_if_index);
1401 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
1403 vl_api_proxy_arp_add_del_reply_t *rmp;
1406 ip4_main_t *im = &ip4_main;
1407 stats_main_t *sm = &stats_main;
1408 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
1409 ip4_address_t * hi_addr,
1410 u32 fib_index, int is_del);
1413 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
1415 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1419 rv = VNET_API_ERROR_NO_SUCH_FIB;
1425 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
1426 (ip4_address_t *) mp->hi_address,
1427 fib_index, mp->is_add == 0);
1431 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
1435 vl_api_proxy_arp_intfc_enable_disable_t_handler
1436 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
1439 vnet_main_t *vnm = vnet_get_main ();
1440 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
1441 vnet_sw_interface_t *si;
1444 VALIDATE_SW_IF_INDEX (mp);
1446 sw_if_index = ntohl (mp->sw_if_index);
1448 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1450 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1454 si = vnet_get_sw_interface (vnm, sw_if_index);
1458 if (mp->enable_disable)
1459 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1461 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1463 BAD_SW_IF_INDEX_LABEL;
1466 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
1470 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
1473 vpe_main_t *rm = &vpe_main;
1474 ip4_main_t *im4 = &ip4_main;
1475 ip6_main_t *im6 = &ip6_main;
1476 ip_lookup_main_t *lm;
1482 u32 adj_index, sw_if_index;
1483 vl_api_is_address_reachable_t *rmp;
1484 ip_adjacency_t *adj;
1485 unix_shared_memory_queue_t *q;
1487 q = vl_api_client_index_to_input_queue (mp->client_index);
1490 increment_missing_api_client_counter (rm->vlib_main);
1494 rmp = vl_msg_api_alloc (sizeof (*rmp));
1495 clib_memcpy (rmp, mp, sizeof (*rmp));
1497 sw_if_index = mp->next_hop_sw_if_index;
1498 clib_memcpy (&addr, mp->address, sizeof (addr));
1501 lm = &im6->lookup_main;
1502 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
1506 lm = &im4->lookup_main;
1508 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
1510 if (adj_index == ~0)
1515 adj = ip_get_adjacency (lm, adj_index);
1517 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
1518 && adj->rewrite_header.sw_if_index == sw_if_index)
1524 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
1525 && adj->rewrite_header.sw_if_index == sw_if_index)
1528 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
1530 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
1532 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
1541 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1546 vl_api_sw_interface_set_mpls_enable_t_handler
1547 (vl_api_sw_interface_set_mpls_enable_t * mp)
1549 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
1552 VALIDATE_SW_IF_INDEX (mp);
1554 mpls_sw_interface_enable_disable (&mpls_main,
1555 ntohl (mp->sw_if_index), mp->enable);
1557 BAD_SW_IF_INDEX_LABEL;
1558 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
1562 send_oam_event (oam_target_t * t)
1564 vpe_api_main_t *vam = &vpe_api_main;
1565 unix_shared_memory_queue_t *q;
1566 vpe_client_registration_t *reg;
1567 vl_api_oam_event_t *mp;
1570 pool_foreach(reg, vam->oam_events_registrations,
1572 q = vl_api_client_index_to_input_queue (reg->client_index);
1575 mp = vl_msg_api_alloc (sizeof (*mp));
1576 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
1577 clib_memcpy (mp->dst_address, &t->dst_address,
1578 sizeof (mp->dst_address));
1579 mp->state = t->state;
1580 vl_msg_api_send_shmem (q, (u8 *)&mp);
1587 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
1589 vl_api_oam_add_del_reply_t *rmp;
1592 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
1593 (ip4_address_t *) mp->dst_address,
1594 ntohl (mp->vrf_id), (int) (mp->is_add));
1596 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
1600 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
1602 stats_main_t *sm = &stats_main;
1603 vnet_interface_main_t *im = sm->interface_main;
1604 vl_api_vnet_summary_stats_reply_t *rmp;
1605 vlib_combined_counter_main_t *cm;
1608 u64 total_pkts[VLIB_N_RX_TX];
1609 u64 total_bytes[VLIB_N_RX_TX];
1611 unix_shared_memory_queue_t *q =
1612 vl_api_client_index_to_input_queue (mp->client_index);
1617 rmp = vl_msg_api_alloc (sizeof (*rmp));
1618 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
1619 rmp->context = mp->context;
1622 memset (total_pkts, 0, sizeof (total_pkts));
1623 memset (total_bytes, 0, sizeof (total_bytes));
1625 vnet_interface_counter_lock (im);
1627 vec_foreach (cm, im->combined_sw_if_counters)
1629 which = cm - im->combined_sw_if_counters;
1631 for (i = 0; i < vec_len (cm->maxi); i++)
1633 vlib_get_combined_counter (cm, i, &v);
1634 total_pkts[which] += v.packets;
1635 total_bytes[which] += v.bytes;
1638 vnet_interface_counter_unlock (im);
1640 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
1641 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
1642 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
1643 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
1645 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
1647 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1651 typedef CLIB_PACKED (struct {
1652 ip4_address_t address;
1653 u32 address_length: 6;
1659 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1661 vnet_main_t *vnm = vnet_get_main ();
1662 vnet_interface_main_t *im = &vnm->interface_main;
1663 ip4_main_t *im4 = &ip4_main;
1664 static u32 *sw_if_indices_to_shut;
1665 stats_main_t *sm = &stats_main;
1666 fib_table_t *fib_table;
1670 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1671 u32 target_fib_id = ntohl (mp->vrf_id);
1673 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
1676 pool_foreach (fib_table, im4->fibs,
1678 fib = &fib_table->v4;
1679 vnet_sw_interface_t * si;
1681 if (fib->table_id != target_fib_id)
1684 /* remove any mpls encap/decap labels */
1685 mpls_fib_reset_labels (fib->table_id);
1687 /* remove any proxy arps in this fib */
1688 vnet_proxy_arp_fib_reset (fib->table_id);
1690 /* Set the flow hash for this fib to the default */
1691 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
1693 vec_reset_length (sw_if_indices_to_shut);
1695 /* Shut down interfaces in this FIB / clean out intfc routes */
1696 pool_foreach (si, im->sw_interfaces,
1698 u32 sw_if_index = si->sw_if_index;
1700 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
1701 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
1703 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1706 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1707 sw_if_index = sw_if_indices_to_shut[i];
1708 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1710 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1711 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1712 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1715 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
1716 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
1720 })); /* pool_foreach (fib) */
1728 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1730 vnet_main_t *vnm = vnet_get_main ();
1731 vnet_interface_main_t *im = &vnm->interface_main;
1732 ip6_main_t *im6 = &ip6_main;
1733 stats_main_t *sm = &stats_main;
1734 static u32 *sw_if_indices_to_shut;
1735 fib_table_t *fib_table;
1739 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1740 u32 target_fib_id = ntohl (mp->vrf_id);
1742 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
1745 pool_foreach (fib_table, im6->fibs,
1747 vnet_sw_interface_t * si;
1748 fib = &(fib_table->v6);
1750 if (fib->table_id != target_fib_id)
1753 vec_reset_length (sw_if_indices_to_shut);
1755 /* Shut down interfaces in this FIB / clean out intfc routes */
1756 pool_foreach (si, im->sw_interfaces,
1758 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1760 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1763 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1764 sw_if_index = sw_if_indices_to_shut[i];
1765 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1767 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1768 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1769 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1772 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1773 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
1777 })); /* pool_foreach (fib) */
1785 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1788 vl_api_reset_fib_reply_t *rmp;
1791 rv = ip6_reset_fib_t_handler (mp);
1793 rv = ip4_reset_fib_t_handler (mp);
1795 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1800 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1802 vl_api_dhcp_proxy_config_reply_t *rmp;
1805 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
1806 (ip4_address_t *) (&mp->dhcp_src_address),
1807 (u32) ntohl (mp->vrf_id),
1808 (int) mp->insert_circuit_id,
1809 (int) (mp->is_add == 0));
1811 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1816 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1818 vl_api_dhcp_proxy_config_reply_t *rmp;
1821 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
1822 (ip6_address_t *) (&mp->dhcp_src_address),
1823 (u32) ntohl (mp->vrf_id),
1824 (int) mp->insert_circuit_id,
1825 (int) (mp->is_add == 0));
1827 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1831 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1833 vl_api_dhcp_proxy_config_reply_t *rmp;
1836 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
1837 (ip4_address_t *) (&mp->dhcp_src_address),
1838 (u32) ntohl (mp->rx_vrf_id),
1839 (u32) ntohl (mp->server_vrf_id),
1840 (int) mp->insert_circuit_id,
1841 (int) (mp->is_add == 0));
1843 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1848 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1850 vl_api_dhcp_proxy_config_reply_t *rmp;
1853 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
1854 (ip6_address_t *) (&mp->dhcp_src_address),
1855 (u32) ntohl (mp->rx_vrf_id),
1856 (u32) ntohl (mp->server_vrf_id),
1857 (int) mp->insert_circuit_id,
1858 (int) (mp->is_add == 0));
1860 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1865 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
1867 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
1870 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
1873 (int) mp->is_add == 0);
1875 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
1877 ntohl (mp->fib_id), (int) mp->is_add == 0);
1879 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
1883 static void vl_api_dhcp_proxy_config_t_handler
1884 (vl_api_dhcp_proxy_config_t * mp)
1886 if (mp->is_ipv6 == 0)
1887 dhcpv4_proxy_config (mp);
1889 dhcpv6_proxy_config (mp);
1892 static void vl_api_dhcp_proxy_config_2_t_handler
1893 (vl_api_dhcp_proxy_config_2_t * mp)
1895 if (mp->is_ipv6 == 0)
1896 dhcpv4_proxy_config_2 (mp);
1898 dhcpv6_proxy_config_2 (mp);
1902 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
1903 u8 is_ipv6, u8 * host_address, u8 * router_address,
1906 unix_shared_memory_queue_t *q;
1907 vl_api_dhcp_compl_event_t *mp;
1909 q = vl_api_client_index_to_input_queue (client_index);
1913 mp = vl_msg_api_alloc (sizeof (*mp));
1914 mp->client_index = client_index;
1916 mp->is_ipv6 = is_ipv6;
1917 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
1918 mp->hostname[vec_len (hostname) + 1] = '\n';
1919 clib_memcpy (&mp->host_address[0], host_address, 16);
1920 clib_memcpy (&mp->router_address[0], router_address, 16);
1922 if (NULL != host_mac)
1923 clib_memcpy (&mp->host_mac[0], host_mac, 6);
1925 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
1927 vl_msg_api_send_shmem (q, (u8 *) & mp);
1930 static void vl_api_dhcp_client_config_t_handler
1931 (vl_api_dhcp_client_config_t * mp)
1933 vlib_main_t *vm = vlib_get_main ();
1934 vl_api_dhcp_client_config_reply_t *rmp;
1937 VALIDATE_SW_IF_INDEX (mp);
1939 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
1940 mp->hostname, mp->is_add, mp->client_index,
1941 mp->want_dhcp_event ? dhcp_compl_event_callback :
1944 BAD_SW_IF_INDEX_LABEL;
1946 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
1950 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1952 vl_api_create_loopback_reply_t *rmp;
1956 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1959 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1961 rmp->sw_if_index = ntohl (sw_if_index);
1967 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1969 vl_api_delete_loopback_reply_t *rmp;
1973 sw_if_index = ntohl (mp->sw_if_index);
1974 rv = vnet_delete_loopback_interface (sw_if_index);
1976 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1980 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1982 vl_api_control_ping_reply_t *rmp;
1986 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1988 rmp->vpe_pid = ntohl (getpid());
1994 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1996 u8 **shmem_vecp = (u8 **) arg;
1999 api_main_t *am = &api_main;
2002 shmem_vec = *shmem_vecp;
2004 offset = vec_len (shmem_vec);
2006 pthread_mutex_lock (&am->vlib_rp->mutex);
2007 oldheap = svm_push_data_heap (am->vlib_rp);
2009 vec_validate (shmem_vec, offset + buffer_bytes - 1);
2011 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
2013 svm_pop_heap (oldheap);
2014 pthread_mutex_unlock (&am->vlib_rp->mutex);
2016 *shmem_vecp = shmem_vec;
2021 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
2023 vl_api_cli_reply_t *rp;
2024 unix_shared_memory_queue_t *q;
2025 vlib_main_t *vm = vlib_get_main ();
2026 api_main_t *am = &api_main;
2027 unformat_input_t input;
2031 q = vl_api_client_index_to_input_queue (mp->client_index);
2035 rp = vl_msg_api_alloc (sizeof (*rp));
2036 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
2037 rp->context = mp->context;
2039 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
2041 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
2043 pthread_mutex_lock (&am->vlib_rp->mutex);
2044 oldheap = svm_push_data_heap (am->vlib_rp);
2046 vec_add1 (shmem_vec, 0);
2048 svm_pop_heap (oldheap);
2049 pthread_mutex_unlock (&am->vlib_rp->mutex);
2051 rp->reply_in_shmem = (uword) shmem_vec;
2053 vl_msg_api_send_shmem (q, (u8 *) & rp);
2057 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2059 u8 **mem_vecp = (u8 **) arg;
2060 u8 *mem_vec = *mem_vecp;
2061 u32 offset = vec_len (mem_vec);
2063 vec_validate (mem_vec, offset + buffer_bytes - 1);
2064 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
2065 *mem_vecp = mem_vec;
2069 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
2071 vl_api_cli_inband_reply_t *rmp;
2073 unix_shared_memory_queue_t *q;
2074 vlib_main_t *vm = vlib_get_main ();
2075 unformat_input_t input;
2078 q = vl_api_client_index_to_input_queue (mp->client_index);
2082 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
2083 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
2085 u32 len = vec_len (out_vec);
2087 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
2089 rmp->length = htonl (len);
2090 clib_memcpy (rmp->reply, out_vec, len);
2097 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2100 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2101 vnet_main_t *vnm = vnet_get_main ();
2102 clib_error_t *error;
2107 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2109 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2113 clib_error_report (error);
2114 rv = VNET_API_ERROR_UNSPECIFIED;
2118 rv = vnm->api_errno;
2121 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2124 static void vl_api_sr_tunnel_add_del_t_handler
2125 (vl_api_sr_tunnel_add_del_t * mp)
2128 clib_warning ("unimplemented");
2130 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
2132 vl_api_sr_tunnel_add_del_reply_t *rmp;
2133 ip6_address_t *segments = 0, *seg;
2134 ip6_address_t *tags = 0, *tag;
2135 ip6_address_t *this_address;
2138 if (mp->n_segments == 0)
2144 memset (a, 0, sizeof (*a));
2145 a->src_address = (ip6_address_t *) & mp->src_address;
2146 a->dst_address = (ip6_address_t *) & mp->dst_address;
2147 a->dst_mask_width = mp->dst_mask_width;
2148 a->flags_net_byte_order = mp->flags_net_byte_order;
2149 a->is_del = (mp->is_add == 0);
2150 a->rx_table_id = ntohl (mp->outer_vrf_id);
2151 a->tx_table_id = ntohl (mp->inner_vrf_id);
2153 a->name = format (0, "%s", mp->name);
2154 if (!(vec_len (a->name)))
2157 a->policy_name = format (0, "%s", mp->policy_name);
2158 if (!(vec_len (a->policy_name)))
2161 /* Yank segments and tags out of the API message */
2162 this_address = (ip6_address_t *) mp->segs_and_tags;
2163 for (i = 0; i < mp->n_segments; i++)
2165 vec_add2 (segments, seg, 1);
2166 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
2169 for (i = 0; i < mp->n_tags; i++)
2171 vec_add2 (tags, tag, 1);
2172 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
2176 a->segments = segments;
2179 rv = ip6_sr_add_del_tunnel (a);
2183 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
2187 static void vl_api_sr_policy_add_del_t_handler
2188 (vl_api_sr_policy_add_del_t * mp)
2191 clib_warning ("unimplemented");
2193 ip6_sr_add_del_policy_args_t _a, *a = &_a;
2195 vl_api_sr_policy_add_del_reply_t *rmp;
2198 memset (a, 0, sizeof (*a));
2199 a->is_del = (mp->is_add == 0);
2201 a->name = format (0, "%s", mp->name);
2202 if (!(vec_len (a->name)))
2204 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2208 if (!(mp->tunnel_names[0]))
2210 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2214 // start deserializing tunnel_names
2215 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
2216 u8 *deser_tun_names = mp->tunnel_names;
2217 deser_tun_names += 1; //moving along
2220 int tun_name_len = 0;
2222 for (i = 0; i < num_tunnels; i++)
2224 tun_name_len = *deser_tun_names;
2225 deser_tun_names += 1;
2226 vec_resize (tun_name, tun_name_len);
2227 memcpy (tun_name, deser_tun_names, tun_name_len);
2228 vec_add1 (a->tunnel_names, tun_name);
2229 deser_tun_names += tun_name_len;
2233 rv = ip6_sr_add_del_policy (a);
2237 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
2241 static void vl_api_sr_multicast_map_add_del_t_handler
2242 (vl_api_sr_multicast_map_add_del_t * mp)
2245 clib_warning ("unimplemented");
2247 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
2249 vl_api_sr_multicast_map_add_del_reply_t *rmp;
2251 memset (a, 0, sizeof (*a));
2252 a->is_del = (mp->is_add == 0);
2254 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
2255 a->policy_name = format (0, "%s", mp->policy_name);
2257 if (a->multicast_address == 0)
2263 if (!(a->policy_name))
2269 #if DPDK > 0 /* Cannot call replicate without DPDK */
2270 rv = ip6_sr_add_del_multicastmap (a);
2272 clib_warning ("multicast replication without DPDK not implemented");
2273 rv = VNET_API_ERROR_UNIMPLEMENTED;
2278 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
2282 #define foreach_classify_add_del_table_field \
2287 _(match_n_vectors) \
2288 _(next_table_index) \
2289 _(miss_next_index) \
2290 _(current_data_flag) \
2291 _(current_data_offset)
2293 static void vl_api_classify_add_del_table_t_handler
2294 (vl_api_classify_add_del_table_t * mp)
2296 vl_api_classify_add_del_table_reply_t *rmp;
2297 vnet_classify_main_t *cm = &vnet_classify_main;
2298 vnet_classify_table_t *t;
2302 foreach_classify_add_del_table_field;
2305 #define _(a) a = ntohl(mp->a);
2306 foreach_classify_add_del_table_field;
2309 /* The underlying API fails silently, on purpose, so check here */
2310 if (mp->is_add == 0) /* delete */
2312 if (pool_is_free_index (cm->tables, table_index))
2314 rv = VNET_API_ERROR_NO_SUCH_TABLE;
2318 else /* add or update */
2320 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
2324 rv = vnet_classify_add_del_table
2325 (cm, mp->mask, nbuckets, memory_size,
2326 skip_n_vectors, match_n_vectors,
2327 next_table_index, miss_next_index, &table_index,
2328 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
2332 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
2334 if (rv == 0 && mp->is_add)
2336 t = pool_elt_at_index (cm->tables, table_index);
2337 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
2338 rmp->match_n_vectors = ntohl(t->match_n_vectors);
2339 rmp->new_table_index = ntohl(table_index);
2343 rmp->skip_n_vectors = ~0;
2344 rmp->match_n_vectors = ~0;
2345 rmp->new_table_index = ~0;
2351 static void vl_api_classify_add_del_session_t_handler
2352 (vl_api_classify_add_del_session_t * mp)
2354 vnet_classify_main_t *cm = &vnet_classify_main;
2355 vl_api_classify_add_del_session_reply_t *rmp;
2357 u32 table_index, hit_next_index, opaque_index, metadata;
2361 table_index = ntohl (mp->table_index);
2362 hit_next_index = ntohl (mp->hit_next_index);
2363 opaque_index = ntohl (mp->opaque_index);
2364 advance = ntohl (mp->advance);
2365 action = mp->action;
2366 metadata = ntohl (mp->metadata);
2368 rv = vnet_classify_add_del_session
2369 (cm, table_index, mp->match, hit_next_index, opaque_index,
2370 advance, action, metadata, mp->is_add);
2372 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
2375 static void vl_api_classify_set_interface_ip_table_t_handler
2376 (vl_api_classify_set_interface_ip_table_t * mp)
2378 vlib_main_t *vm = vlib_get_main ();
2379 vl_api_classify_set_interface_ip_table_reply_t *rmp;
2381 u32 table_index, sw_if_index;
2383 table_index = ntohl (mp->table_index);
2384 sw_if_index = ntohl (mp->sw_if_index);
2386 VALIDATE_SW_IF_INDEX (mp);
2389 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
2391 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
2393 BAD_SW_IF_INDEX_LABEL;
2395 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
2398 static void vl_api_classify_set_interface_l2_tables_t_handler
2399 (vl_api_classify_set_interface_l2_tables_t * mp)
2401 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
2403 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
2406 ip4_table_index = ntohl (mp->ip4_table_index);
2407 ip6_table_index = ntohl (mp->ip6_table_index);
2408 other_table_index = ntohl (mp->other_table_index);
2409 sw_if_index = ntohl (mp->sw_if_index);
2411 VALIDATE_SW_IF_INDEX (mp);
2414 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
2418 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
2424 if (ip4_table_index != ~0 || ip6_table_index != ~0
2425 || other_table_index != ~0)
2431 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
2433 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
2436 BAD_SW_IF_INDEX_LABEL;
2438 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
2442 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
2445 vl_api_l2_fib_clear_table_reply_t *rmp;
2447 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
2448 * that is not currently implemented. When that TODO is fixed
2449 * this call should be changed to pass 1 instead of 0.
2451 l2fib_clear_table (0);
2453 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
2456 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
2457 u32 sw_if_index, u32 enable);
2460 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
2464 vl_api_l2_interface_efp_filter_reply_t *rmp;
2465 vnet_main_t *vnm = vnet_get_main ();
2467 // enable/disable the feature
2468 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
2469 rv = vnm->api_errno;
2471 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
2475 vl_api_l2_interface_vlan_tag_rewrite_t_handler
2476 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
2479 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
2480 vnet_main_t *vnm = vnet_get_main ();
2481 vlib_main_t *vm = vlib_get_main ();
2484 VALIDATE_SW_IF_INDEX (mp);
2486 vtr_op = ntohl (mp->vtr_op);
2488 /* The L2 code is unsuspicious */
2491 case L2_VTR_DISABLED:
2496 case L2_VTR_TRANSLATE_1_1:
2497 case L2_VTR_TRANSLATE_1_2:
2498 case L2_VTR_TRANSLATE_2_1:
2499 case L2_VTR_TRANSLATE_2_2:
2503 rv = VNET_API_ERROR_INVALID_VALUE;
2504 goto bad_sw_if_index;
2507 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
2508 ntohl (mp->push_dot1q), ntohl (mp->tag1),
2511 BAD_SW_IF_INDEX_LABEL;
2513 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
2517 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
2519 clib_warning ("BUG");
2523 send_l2fib_table_entry (vpe_api_main_t * am,
2524 unix_shared_memory_queue_t * q,
2525 l2fib_entry_key_t * l2fe_key,
2526 l2fib_entry_result_t * l2fe_res, u32 context)
2528 vl_api_l2_fib_table_entry_t *mp;
2530 mp = vl_msg_api_alloc (sizeof (*mp));
2531 memset (mp, 0, sizeof (*mp));
2532 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
2535 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
2537 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
2538 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
2539 mp->static_mac = l2fe_res->fields.static_mac;
2540 mp->filter_mac = l2fe_res->fields.filter;
2541 mp->bvi_mac = l2fe_res->fields.bvi;
2542 mp->context = context;
2544 vl_msg_api_send_shmem (q, (u8 *) & mp);
2548 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
2550 vpe_api_main_t *am = &vpe_api_main;
2551 bd_main_t *bdm = &bd_main;
2552 l2fib_entry_key_t *l2fe_key = NULL;
2553 l2fib_entry_result_t *l2fe_res = NULL;
2554 u32 ni, bd_id = ntohl (mp->bd_id);
2556 unix_shared_memory_queue_t *q;
2559 q = vl_api_client_index_to_input_queue (mp->client_index);
2563 /* see l2fib_table_dump: ~0 means "any" */
2568 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2575 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
2577 vec_foreach_index (ni, l2fe_key)
2579 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
2580 vec_elt_at_index (l2fe_res, ni), mp->context);
2582 vec_free (l2fe_key);
2583 vec_free (l2fe_res);
2587 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
2589 vl_api_show_version_reply_t *rmp;
2591 char *vpe_api_get_build_directory (void);
2592 char *vpe_api_get_version (void);
2593 char *vpe_api_get_build_date (void);
2595 unix_shared_memory_queue_t *q =
2596 vl_api_client_index_to_input_queue (mp->client_index);
2602 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
2604 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
2605 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
2606 ARRAY_LEN(rmp->build_directory)-1);
2607 strncpy ((char *) rmp->version, vpe_api_get_version(),
2608 ARRAY_LEN(rmp->version)-1);
2609 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
2610 ARRAY_LEN(rmp->build_date)-1);
2616 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
2618 vlib_main_t *vm = vlib_get_main ();
2619 vl_api_get_node_index_reply_t *rmp;
2622 u32 node_index = ~0;
2624 n = vlib_get_node_by_name (vm, mp->node_name);
2627 rv = VNET_API_ERROR_NO_SUCH_NODE;
2629 node_index = n->index;
2632 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
2634 rmp->node_index = ntohl(node_index);
2640 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
2642 vlib_main_t *vm = vlib_get_main ();
2643 vl_api_get_next_index_reply_t *rmp;
2644 vlib_node_t *node, *next_node;
2646 u32 next_node_index = ~0, next_index = ~0;
2649 node = vlib_get_node_by_name (vm, mp->node_name);
2653 rv = VNET_API_ERROR_NO_SUCH_NODE;
2657 next_node = vlib_get_node_by_name (vm, mp->next_name);
2661 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2665 next_node_index = next_node->index;
2667 p = hash_get (node->next_slot_by_node, next_node_index);
2671 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2679 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
2681 rmp->next_index = ntohl(next_index);
2687 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
2689 vlib_main_t *vm = vlib_get_main ();
2690 vl_api_add_node_next_reply_t *rmp;
2691 vlib_node_t *n, *next;
2693 u32 next_index = ~0;
2695 n = vlib_get_node_by_name (vm, mp->node_name);
2699 rv = VNET_API_ERROR_NO_SUCH_NODE;
2703 next = vlib_get_node_by_name (vm, mp->next_name);
2706 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2708 next_index = vlib_node_add_next (vm, n->index, next->index);
2712 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
2714 rmp->next_index = ntohl(next_index);
2719 static void vl_api_vxlan_add_del_tunnel_t_handler
2720 (vl_api_vxlan_add_del_tunnel_t * mp)
2722 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
2724 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
2725 u32 encap_fib_index;
2727 ip4_main_t *im = &ip4_main;
2728 vnet_main_t *vnm = vnet_get_main ();
2729 u32 sw_if_index = ~0;
2731 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
2734 rv = VNET_API_ERROR_NO_SUCH_FIB;
2737 encap_fib_index = p[0];
2738 memset (a, 0, sizeof (*a));
2740 a->is_add = mp->is_add;
2741 a->is_ip6 = mp->is_ipv6;
2743 /* ip addresses sent in network byte order */
2744 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
2745 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
2747 /* Check src & dst are different */
2748 if (ip46_address_cmp (&a->dst, &a->src) == 0)
2750 rv = VNET_API_ERROR_SAME_SRC_DST;
2753 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
2754 if (ip46_address_is_multicast (&a->dst) &&
2755 pool_is_free_index (vnm->interface_main.sw_interfaces,
2756 a->mcast_sw_if_index))
2758 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2761 a->encap_fib_index = encap_fib_index;
2762 a->decap_next_index = ntohl (mp->decap_next_index);
2763 a->vni = ntohl (mp->vni);
2764 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
2768 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
2770 rmp->sw_if_index = ntohl (sw_if_index);
2775 static void send_vxlan_tunnel_details
2776 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
2778 vl_api_vxlan_tunnel_details_t *rmp;
2779 ip4_main_t *im4 = &ip4_main;
2780 ip6_main_t *im6 = &ip6_main;
2781 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
2783 rmp = vl_msg_api_alloc (sizeof (*rmp));
2784 memset (rmp, 0, sizeof (*rmp));
2785 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
2788 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
2789 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
2790 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
2794 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
2795 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
2796 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
2798 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
2799 rmp->vni = htonl (t->vni);
2800 rmp->decap_next_index = htonl (t->decap_next_index);
2801 rmp->sw_if_index = htonl (t->sw_if_index);
2802 rmp->is_ipv6 = is_ipv6;
2803 rmp->context = context;
2805 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2808 static void vl_api_vxlan_tunnel_dump_t_handler
2809 (vl_api_vxlan_tunnel_dump_t * mp)
2811 unix_shared_memory_queue_t *q;
2812 vxlan_main_t *vxm = &vxlan_main;
2816 q = vl_api_client_index_to_input_queue (mp->client_index);
2822 sw_if_index = ntohl (mp->sw_if_index);
2824 if (~0 == sw_if_index)
2827 pool_foreach (t, vxm->tunnels,
2829 send_vxlan_tunnel_details(t, q, mp->context);
2835 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
2836 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
2840 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
2841 send_vxlan_tunnel_details (t, q, mp->context);
2846 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
2848 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
2850 vl_api_l2_patch_add_del_reply_t *rmp;
2851 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
2855 VALIDATE_RX_SW_IF_INDEX (mp);
2856 VALIDATE_TX_SW_IF_INDEX (mp);
2858 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
2859 ntohl (mp->tx_sw_if_index),
2860 (int) (mp->is_add != 0));
2862 BAD_RX_SW_IF_INDEX_LABEL;
2863 BAD_TX_SW_IF_INDEX_LABEL;
2865 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
2869 vl_api_vxlan_gpe_add_del_tunnel_t_handler
2870 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
2872 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
2874 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
2875 u32 encap_fib_index, decap_fib_index;
2878 ip4_main_t *im = &ip4_main;
2879 u32 sw_if_index = ~0;
2882 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
2885 rv = VNET_API_ERROR_NO_SUCH_FIB;
2888 encap_fib_index = p[0];
2890 protocol = mp->protocol;
2892 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
2893 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
2895 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
2898 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
2901 decap_fib_index = p[0];
2905 decap_fib_index = ntohl (mp->decap_vrf_id);
2908 /* Check src & dst are different */
2909 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
2910 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
2912 rv = VNET_API_ERROR_SAME_SRC_DST;
2915 memset (a, 0, sizeof (*a));
2917 a->is_add = mp->is_add;
2918 a->is_ip6 = mp->is_ipv6;
2919 /* ip addresses sent in network byte order */
2922 clib_memcpy (&(a->local.ip6), mp->local, 16);
2923 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
2927 clib_memcpy (&(a->local.ip4), mp->local, 4);
2928 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
2930 a->encap_fib_index = encap_fib_index;
2931 a->decap_fib_index = decap_fib_index;
2932 a->protocol = protocol;
2933 a->vni = ntohl (mp->vni);
2934 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
2938 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
2940 rmp->sw_if_index = ntohl (sw_if_index);
2945 static void send_vxlan_gpe_tunnel_details
2946 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
2948 vl_api_vxlan_gpe_tunnel_details_t *rmp;
2949 ip4_main_t *im4 = &ip4_main;
2950 ip6_main_t *im6 = &ip6_main;
2951 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
2953 rmp = vl_msg_api_alloc (sizeof (*rmp));
2954 memset (rmp, 0, sizeof (*rmp));
2955 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
2958 memcpy (rmp->local, &(t->local.ip6), 16);
2959 memcpy (rmp->remote, &(t->remote.ip6), 16);
2960 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
2961 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
2965 memcpy (rmp->local, &(t->local.ip4), 4);
2966 memcpy (rmp->remote, &(t->remote.ip4), 4);
2967 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
2968 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
2970 rmp->vni = htonl (t->vni);
2971 rmp->protocol = t->protocol;
2972 rmp->sw_if_index = htonl (t->sw_if_index);
2973 rmp->is_ipv6 = is_ipv6;
2974 rmp->context = context;
2976 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2979 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
2980 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
2982 unix_shared_memory_queue_t *q;
2983 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
2984 vxlan_gpe_tunnel_t *t;
2987 q = vl_api_client_index_to_input_queue (mp->client_index);
2993 sw_if_index = ntohl (mp->sw_if_index);
2995 if (~0 == sw_if_index)
2998 pool_foreach (t, vgm->tunnels,
3000 send_vxlan_gpe_tunnel_details(t, q, mp->context);
3006 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
3007 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
3011 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
3012 send_vxlan_gpe_tunnel_details (t, q, mp->context);
3016 /** Used for transferring locators via VPP API */
3018 typedef CLIB_PACKED (struct {
3019 u32 sw_if_index; /**< locator sw_if_index */
3020 u8 priority; /**< locator priority */
3021 u8 weight; /**< locator weight */
3026 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
3029 vl_api_lisp_add_del_locator_set_reply_t *rmp;
3031 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
3033 ls_locator_t *ls_loc;
3034 u32 ls_index = ~0, locator_num;
3035 u8 *locator_name = NULL;
3038 memset (a, 0, sizeof (a[0]));
3040 locator_name = format (0, "%s", mp->locator_set_name);
3042 a->name = locator_name;
3043 a->is_add = mp->is_add;
3045 locator_num = clib_net_to_host_u32 (mp->locator_num);
3047 memset (&locator, 0, sizeof (locator));
3048 for (i = 0; i < locator_num; i++)
3050 ls_loc = &((ls_locator_t *) mp->locators)[i];
3051 VALIDATE_SW_IF_INDEX (ls_loc);
3053 locator.sw_if_index = htonl (ls_loc->sw_if_index);
3054 locator.priority = ls_loc->priority;
3055 locator.weight = ls_loc->weight;
3057 vec_add1 (a->locators, locator);
3060 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
3062 BAD_SW_IF_INDEX_LABEL;
3064 vec_free (locator_name);
3065 vec_free (a->locators);
3068 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
3070 rmp->ls_index = clib_host_to_net_u32 (ls_index);
3076 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
3078 vl_api_lisp_add_del_locator_reply_t *rmp;
3080 locator_t locator, *locators = NULL;
3081 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
3083 u8 *locator_name = NULL;
3085 memset (&locator, 0, sizeof (locator));
3086 memset (a, 0, sizeof (a[0]));
3088 locator.sw_if_index = ntohl (mp->sw_if_index);
3089 locator.priority = mp->priority;
3090 locator.weight = mp->weight;
3092 vec_add1 (locators, locator);
3094 locator_name = format (0, "%s", mp->locator_set_name);
3096 a->name = locator_name;
3097 a->locators = locators;
3098 a->is_add = mp->is_add;
3101 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
3103 vec_free (locators);
3104 vec_free (locator_name);
3106 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
3110 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
3116 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3117 gid_address_ip_set (dst, src, IP4);
3118 gid_address_ippref_len (dst) = len;
3119 ip_prefix_normalize (&gid_address_ippref (dst));
3122 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3123 gid_address_ip_set (dst, src, IP6);
3124 gid_address_ippref_len (dst) = len;
3125 ip_prefix_normalize (&gid_address_ippref (dst));
3127 case 2: /* l2 mac */
3128 gid_address_type (dst) = GID_ADDR_MAC;
3129 clib_memcpy (&gid_address_mac (dst), src, 6);
3133 return VNET_API_ERROR_INVALID_VALUE;
3136 gid_address_vni (dst) = vni;
3142 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
3144 vl_api_lisp_add_del_local_eid_reply_t *rmp;
3145 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3147 gid_address_t _eid, *eid = &_eid;
3149 u32 locator_set_index = ~0, map_index = ~0;
3150 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
3151 u8 *name = NULL, *key = NULL;
3152 memset (a, 0, sizeof (a[0]));
3153 memset (eid, 0, sizeof (eid[0]));
3155 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3156 mp->eid_type, mp->eid, mp->prefix_len);
3160 name = format (0, "%s", mp->locator_set_name);
3161 p = hash_get_mem (lcm->locator_set_index_by_name, name);
3164 rv = VNET_API_ERROR_INVALID_VALUE;
3167 locator_set_index = p[0];
3170 key = format (0, "%s", mp->key);
3172 /* XXX treat batch configuration */
3173 a->is_add = mp->is_add;
3174 gid_address_copy (&a->eid, eid);
3175 a->locator_set_index = locator_set_index;
3178 a->key_id = clib_net_to_host_u16 (mp->key_id);
3180 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
3185 gid_address_free (&a->eid);
3187 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
3191 vl_api_lisp_eid_table_add_del_map_t_handler
3192 (vl_api_lisp_eid_table_add_del_map_t * mp)
3194 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
3196 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
3197 clib_net_to_host_u32 (mp->dp_table),
3198 mp->is_l2, mp->is_add);
3199 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
3201 /** Used for transferring locators via VPP API */
3203 typedef CLIB_PACKED (struct {
3204 u8 is_ip4; /**< is locator an IPv4 address */
3205 u8 priority; /**< locator priority */
3206 u8 weight; /**< locator weight */
3207 u8 addr[16]; /**< IPv4/IPv6 address */
3211 static locator_pair_t *
3212 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
3215 locator_pair_t *pairs = 0, pair;
3218 for (i = 0; i < rloc_num; i++)
3221 r = &((rloc_t *) lcl_locs)[i];
3222 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
3223 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
3225 /* remote locators */
3226 r = &((rloc_t *) rmt_locs)[i];
3227 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
3228 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
3230 pair.priority = r->priority;
3231 pair.weight = r->weight;
3233 vec_add1 (pairs, pair);
3239 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
3242 locator_t *locs = 0, loc;
3245 for (i = 0; i < rloc_num; i++)
3247 /* remote locators */
3248 r = &((rloc_t *) rmt_locs)[i];
3249 memset (&loc, 0, sizeof (loc));
3250 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
3252 loc.priority = r->priority;
3253 loc.weight = r->weight;
3255 vec_add1 (locs, loc);
3261 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
3262 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
3264 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
3265 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
3266 locator_pair_t *pairs = 0;
3269 memset (a, 0, sizeof (a[0]));
3271 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
3272 mp->rmt_eid, mp->rmt_len);
3273 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
3274 mp->lcl_eid, mp->lcl_len);
3276 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
3278 if (rv || 0 == pairs)
3281 a->is_add = mp->is_add;
3282 a->locator_pairs = pairs;
3283 a->dp_table = mp->dp_table;
3285 a->action = mp->action;
3287 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
3290 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
3294 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
3297 vl_api_lisp_add_del_map_server_reply_t *rmp;
3301 memset (&addr, 0, sizeof (addr));
3303 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
3304 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
3306 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
3310 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
3313 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
3315 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
3317 memset (a, 0, sizeof (a[0]));
3319 a->is_add = mp->is_add;
3320 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
3322 rv = vnet_lisp_add_del_map_resolver (a);
3324 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
3328 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
3331 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
3333 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
3335 a->is_en = mp->is_en;
3336 vnet_lisp_gpe_enable_disable (a);
3338 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
3342 vl_api_lisp_map_register_enable_disable_t_handler
3343 (vl_api_lisp_map_register_enable_disable_t * mp)
3345 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
3348 vnet_lisp_map_register_enable_disable (mp->is_enabled);
3349 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3353 vl_api_lisp_rloc_probe_enable_disable_t_handler
3354 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
3356 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
3359 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
3360 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3364 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
3366 vl_api_lisp_enable_disable_reply_t *rmp;
3369 vnet_lisp_enable_disable (mp->is_en);
3370 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3374 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
3376 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
3384 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
3388 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
3395 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
3399 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
3402 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
3406 vl_api_show_lisp_map_request_mode_t_handler
3407 (vl_api_show_lisp_map_request_mode_t * mp)
3410 vl_api_show_lisp_map_request_mode_reply_t *rmp;
3413 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
3415 rmp->mode = vnet_lisp_get_map_request_mode ();
3421 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
3423 vl_api_lisp_map_request_mode_reply_t *rmp;
3426 rv = vnet_lisp_set_map_request_mode (mp->mode);
3428 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
3432 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
3435 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
3439 ls_name = format (0, "%s", mp->ls_name);
3440 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
3443 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
3447 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
3448 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
3450 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
3452 u8 *locator_set_name = NULL;
3453 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
3455 locator_set_name = format (0, "%s", mp->locator_set_name);
3457 a->is_add = mp->is_add;
3458 a->locator_set_name = locator_set_name;
3460 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
3462 vec_free (locator_set_name);
3464 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
3468 vl_api_lisp_add_del_remote_mapping_t_handler
3469 (vl_api_lisp_add_del_remote_mapping_t * mp)
3471 locator_t *rlocs = 0;
3472 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
3474 gid_address_t _eid, *eid = &_eid;
3475 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
3477 memset (eid, 0, sizeof (eid[0]));
3479 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3480 mp->eid_type, mp->eid, mp->eid_len);
3484 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
3488 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
3489 gid_address_copy (&a->reid, eid);
3491 rv = vnet_lisp_add_del_adjacency (a);
3498 /* NOTE: for now this works as a static remote mapping, i.e.,
3499 * not authoritative and ttl infinite. */
3500 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
3501 mp->is_add, 1 /* is_static */ , 0);
3504 vnet_lisp_clear_all_remote_adjacencies ();
3509 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
3513 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
3515 vl_api_lisp_add_del_adjacency_reply_t *rmp;
3516 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
3519 memset (a, 0, sizeof (a[0]));
3521 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
3522 mp->eid_type, mp->leid, mp->leid_len);
3523 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
3524 mp->eid_type, mp->reid, mp->reid_len);
3529 a->is_add = mp->is_add;
3530 rv = vnet_lisp_add_del_adjacency (a);
3533 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
3537 send_lisp_locator_details (lisp_cp_main_t * lcm,
3539 unix_shared_memory_queue_t * q, u32 context)
3541 vl_api_lisp_locator_details_t *rmp;
3543 rmp = vl_msg_api_alloc (sizeof (*rmp));
3544 memset (rmp, 0, sizeof (*rmp));
3545 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
3546 rmp->context = context;
3548 rmp->local = loc->local;
3551 rmp->sw_if_index = ntohl (loc->sw_if_index);
3555 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
3556 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
3558 rmp->priority = loc->priority;
3559 rmp->weight = loc->weight;
3561 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3565 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
3568 unix_shared_memory_queue_t *q = 0;
3569 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3570 locator_set_t *lsit = 0;
3572 u32 ls_index = ~0, *locit = 0;
3575 q = vl_api_client_index_to_input_queue (mp->client_index);
3581 if (mp->is_index_set)
3582 ls_index = htonl (mp->ls_index);
3585 /* make sure we get a proper C-string */
3586 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
3587 ls_name = format (0, "%s", mp->ls_name);
3588 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
3594 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
3597 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
3599 vec_foreach (locit, lsit->locator_indices)
3601 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
3602 send_lisp_locator_details (lcm, loc, q, mp->context);
3609 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
3610 locator_set_t * lsit,
3611 unix_shared_memory_queue_t * q,
3612 u32 context, u32 ls_index)
3614 vl_api_lisp_locator_set_details_t *rmp;
3617 rmp = vl_msg_api_alloc (sizeof (*rmp));
3618 memset (rmp, 0, sizeof (*rmp));
3619 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
3620 rmp->context = context;
3622 rmp->ls_index = htonl (ls_index);
3625 ASSERT (lsit->name != NULL);
3626 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
3627 vec_len (lsit->name));
3631 str = format (0, "<remote-%d>", ls_index);
3632 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
3636 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3640 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
3642 unix_shared_memory_queue_t *q = NULL;
3643 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3644 locator_set_t *lsit = NULL;
3647 q = vl_api_client_index_to_input_queue (mp->client_index);
3653 filter = mp->filter;
3655 pool_foreach (lsit, lcm->locator_set_pool,
3657 if (filter && !((1 == filter && lsit->local) ||
3658 (2 == filter && !lsit->local)))
3662 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
3663 lsit - lcm->locator_set_pool);
3669 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
3671 ASSERT (prefix_length);
3672 ip_prefix_t *ippref = &fid_addr_ippref (src);
3674 switch (fid_addr_type (src))
3676 case FID_ADDR_IP_PREF:
3677 if (ip_prefix_version (ippref) == IP4)
3678 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
3680 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
3681 prefix_length[0] = ip_prefix_len (ippref);
3685 prefix_length[0] = 0;
3686 clib_memcpy (dst, fid_addr_mac (src), 6);
3690 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
3696 fid_type_to_api_type (fid_address_t * fid)
3698 ip_prefix_t *ippref;
3700 switch (fid_addr_type (fid))
3702 case FID_ADDR_IP_PREF:
3703 ippref = &fid_addr_ippref (fid);
3704 if (ip_prefix_version (ippref) == IP4)
3706 else if (ip_prefix_version (ippref) == IP6)
3719 send_lisp_eid_table_details (mapping_t * mapit,
3720 unix_shared_memory_queue_t * q,
3721 u32 context, u8 filter)
3724 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3725 locator_set_t *ls = 0;
3726 vl_api_lisp_eid_table_details_t *rmp = NULL;
3727 gid_address_t *gid = NULL;
3729 ip_prefix_t *ip_prefix = NULL;
3733 case 0: /* all mappings */
3736 case 1: /* local only */
3740 case 2: /* remote only */
3745 clib_warning ("Filter error, unknown filter: %d", filter);
3750 ip_prefix = &gid_address_ippref (gid);
3751 mac = gid_address_mac (gid);
3753 rmp = vl_msg_api_alloc (sizeof (*rmp));
3754 memset (rmp, 0, sizeof (*rmp));
3755 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
3757 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
3758 if (vec_len (ls->locator_indices) == 0)
3759 rmp->locator_set_index = ~0;
3761 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
3763 rmp->is_local = mapit->local;
3764 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
3765 rmp->action = mapit->action;
3766 rmp->authoritative = mapit->authoritative;
3768 switch (gid_address_type (gid))
3770 case GID_ADDR_SRC_DST:
3771 rmp->is_src_dst = 1;
3772 fid = &gid_address_sd_src (gid);
3773 rmp->eid_type = fid_type_to_api_type (fid);
3774 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
3775 &rmp->seid_prefix_len);
3776 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
3777 &rmp->eid_prefix_len);
3779 case GID_ADDR_IP_PREFIX:
3780 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
3781 if (ip_prefix_version (ip_prefix) == IP4)
3783 rmp->eid_type = 0; /* ipv4 type */
3784 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
3785 sizeof (ip_prefix_v4 (ip_prefix)));
3789 rmp->eid_type = 1; /* ipv6 type */
3790 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
3791 sizeof (ip_prefix_v6 (ip_prefix)));
3795 rmp->eid_type = 2; /* l2 mac type */
3796 clib_memcpy (rmp->eid, mac, 6);
3801 rmp->context = context;
3802 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
3803 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
3804 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
3805 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3809 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
3812 unix_shared_memory_queue_t *q = NULL;
3813 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3814 mapping_t *mapit = NULL;
3815 gid_address_t _eid, *eid = &_eid;
3817 q = vl_api_client_index_to_input_queue (mp->client_index);
3825 memset (eid, 0, sizeof (*eid));
3827 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3828 mp->eid_type, mp->eid, mp->prefix_length);
3830 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
3831 if ((u32) ~ 0 == mi)
3834 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
3835 send_lisp_eid_table_details (mapit, q, mp->context,
3836 0 /* ignore filter */ );
3841 pool_foreach (mapit, lcm->mapping_pool,
3843 send_lisp_eid_table_details(mapit, q, mp->context,
3851 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
3852 unix_shared_memory_queue_t * q, u32 context)
3854 vl_api_lisp_gpe_tunnel_details_t *rmp;
3855 lisp_gpe_main_t *lgm = &lisp_gpe_main;
3857 rmp = vl_msg_api_alloc (sizeof (*rmp));
3858 memset (rmp, 0, sizeof (*rmp));
3859 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
3861 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
3863 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
3864 ip_address_copy_addr (rmp->source_ip,
3865 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
3866 ip_address_copy_addr (rmp->destination_ip,
3867 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
3869 rmp->encap_fib_id = htonl (0);
3870 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
3871 rmp->iid = htonl (lfe->key->vni);
3872 rmp->context = context;
3874 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3878 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
3880 unix_shared_memory_queue_t *q = NULL;
3881 lisp_gpe_main_t *lgm = &lisp_gpe_main;
3882 lisp_gpe_fwd_entry_t *lfe = NULL;
3884 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
3889 q = vl_api_client_index_to_input_queue (mp->client_index);
3896 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
3898 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
3904 send_lisp_map_server_details (ip_address_t * ip,
3905 unix_shared_memory_queue_t * q, u32 context)
3907 vl_api_lisp_map_server_details_t *rmp = NULL;
3909 rmp = vl_msg_api_alloc (sizeof (*rmp));
3910 memset (rmp, 0, sizeof (*rmp));
3911 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
3913 switch (ip_addr_version (ip))
3917 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
3918 sizeof (ip_addr_v4 (ip)));
3923 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
3924 sizeof (ip_addr_v6 (ip)));
3930 rmp->context = context;
3932 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3936 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
3938 unix_shared_memory_queue_t *q = NULL;
3939 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3942 q = vl_api_client_index_to_input_queue (mp->client_index);
3948 vec_foreach (mr, lcm->map_servers)
3950 send_lisp_map_server_details (&mr->address, q, mp->context);
3955 send_lisp_map_resolver_details (ip_address_t * ip,
3956 unix_shared_memory_queue_t * q, u32 context)
3958 vl_api_lisp_map_resolver_details_t *rmp = NULL;
3960 rmp = vl_msg_api_alloc (sizeof (*rmp));
3961 memset (rmp, 0, sizeof (*rmp));
3962 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
3964 switch (ip_addr_version (ip))
3968 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
3969 sizeof (ip_addr_v4 (ip)));
3974 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
3975 sizeof (ip_addr_v6 (ip)));
3981 rmp->context = context;
3983 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3987 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
3989 unix_shared_memory_queue_t *q = NULL;
3990 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3993 q = vl_api_client_index_to_input_queue (mp->client_index);
3999 vec_foreach (mr, lcm->map_resolvers)
4001 send_lisp_map_resolver_details (&mr->address, q, mp->context);
4006 send_eid_table_map_pair (hash_pair_t * p,
4007 unix_shared_memory_queue_t * q, u32 context)
4009 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
4011 rmp = vl_msg_api_alloc (sizeof (*rmp));
4012 memset (rmp, 0, sizeof (*rmp));
4013 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
4015 rmp->vni = clib_host_to_net_u32 (p->key);
4016 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
4017 rmp->context = context;
4018 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4022 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
4025 unix_shared_memory_queue_t *q = NULL;
4026 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4028 uword *vni_table = 0;
4030 q = vl_api_client_index_to_input_queue (mp->client_index);
4038 vni_table = lcm->bd_id_by_vni;
4042 vni_table = lcm->table_id_by_vni;
4046 hash_foreach_pair (p, vni_table,
4048 send_eid_table_map_pair (p, q, mp->context);
4054 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
4056 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
4058 rmp = vl_msg_api_alloc (sizeof (*rmp));
4059 memset (rmp, 0, sizeof (*rmp));
4060 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
4061 rmp->context = context;
4062 rmp->vni = clib_host_to_net_u32 (vni);
4063 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4067 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
4069 lisp_adjacency_t *adj;
4070 vl_api_lisp_adjacency_t a;
4071 u32 i, n = vec_len (adjs);
4073 for (i = 0; i < n; i++)
4075 adj = vec_elt_at_index (adjs, i);
4076 memset (&a, 0, sizeof (a));
4078 switch (gid_address_type (&adj->reid))
4080 case GID_ADDR_IP_PREFIX:
4081 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
4082 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
4083 if (gid_address_ip_version (&adj->reid) == IP4)
4085 a.eid_type = 0; /* ipv4 type */
4086 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
4087 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
4091 a.eid_type = 1; /* ipv6 type */
4092 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
4093 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
4097 a.eid_type = 2; /* l2 mac type */
4098 mac_copy (a.reid, gid_address_mac (&adj->reid));
4099 mac_copy (a.leid, gid_address_mac (&adj->leid));
4109 vl_api_show_lisp_rloc_probe_state_t_handler
4110 (vl_api_show_lisp_rloc_probe_state_t * mp)
4112 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
4116 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
4118 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
4124 vl_api_show_lisp_map_register_state_t_handler
4125 (vl_api_show_lisp_map_register_state_t * mp)
4127 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
4131 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
4133 rmp->is_enabled = vnet_lisp_map_register_state_get ();
4139 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
4141 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
4142 lisp_adjacency_t *adjs = 0;
4144 vl_api_lisp_adjacency_t a;
4146 u32 vni = clib_net_to_host_u32 (mp->vni);
4148 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
4149 size = vec_len (adjs) * sizeof (a);
4152 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
4154 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
4155 lisp_adjacency_copy (rmp->adjacencies, adjs);
4163 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
4168 unix_shared_memory_queue_t *q = 0;
4169 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4171 q = vl_api_client_index_to_input_queue (mp->client_index);
4178 hash_foreach_pair (p, lcm->table_id_by_vni,
4180 hash_set (vnis, p->key, 0);
4183 hash_foreach_pair (p, lcm->bd_id_by_vni,
4185 hash_set (vnis, p->key, 0);
4188 hash_foreach_pair (p, vnis,
4190 send_eid_table_vni (p->key, q, mp->context);
4198 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
4200 unix_shared_memory_queue_t *q = NULL;
4201 vl_api_show_lisp_status_reply_t *rmp = NULL;
4204 q = vl_api_client_index_to_input_queue (mp->client_index);
4211 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
4213 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
4214 rmp->feature_status = vnet_lisp_enable_disable_status ();
4220 vl_api_lisp_get_map_request_itr_rlocs_t_handler
4221 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
4223 unix_shared_memory_queue_t *q = NULL;
4224 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
4225 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4226 locator_set_t *loc_set = 0;
4230 q = vl_api_client_index_to_input_queue (mp->client_index);
4236 if (~0 == lcm->mreq_itr_rlocs)
4238 tmp_str = format (0, " ");
4243 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
4244 tmp_str = format (0, "%s", loc_set->name);
4248 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
4250 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
4251 ARRAY_LEN(rmp->locator_set_name) - 1);
4259 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
4261 unix_shared_memory_queue_t *q = NULL;
4262 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
4263 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4265 locator_set_t *ls = 0;
4269 q = vl_api_client_index_to_input_queue (mp->client_index);
4275 if (!lcm->lisp_pitr)
4277 tmp_str = format (0, "N/A");
4281 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
4282 if (~0 != m->locator_set_index)
4285 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
4286 tmp_str = format (0, "%s", ls->name);
4290 tmp_str = format (0, "N/A");
4293 vec_add1 (tmp_str, 0);
4296 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
4298 rmp->status = lcm->lisp_pitr;
4299 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
4300 ARRAY_LEN(rmp->locator_set_name) - 1);
4306 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
4309 vl_api_interface_name_renumber_reply_t *rmp;
4312 VALIDATE_SW_IF_INDEX (mp);
4314 rv = vnet_interface_name_renumber
4315 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
4317 BAD_SW_IF_INDEX_LABEL;
4319 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4323 arp_change_data_callback (u32 pool_index, u8 * new_mac,
4324 u32 sw_if_index, u32 address)
4326 vpe_api_main_t *am = &vpe_api_main;
4327 vlib_main_t *vm = am->vlib_main;
4328 vl_api_ip4_arp_event_t *event;
4329 static f64 arp_event_last_time;
4330 f64 now = vlib_time_now (vm);
4332 if (pool_is_free_index (am->arp_events, pool_index))
4335 event = pool_elt_at_index (am->arp_events, pool_index);
4337 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
4339 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
4343 if (sw_if_index == event->sw_if_index &&
4345 /* for BD case, also check IP address with 10 sec timeout */
4346 (address == event->address &&
4347 (now - arp_event_last_time) < 10.0)))
4352 arp_event_last_time = now;
4353 event->sw_if_index = sw_if_index;
4355 event->address = address;
4360 nd_change_data_callback (u32 pool_index, u8 * new_mac,
4361 u32 sw_if_index, ip6_address_t * address)
4363 vpe_api_main_t *am = &vpe_api_main;
4364 vlib_main_t *vm = am->vlib_main;
4365 vl_api_ip6_nd_event_t *event;
4366 static f64 nd_event_last_time;
4367 f64 now = vlib_time_now (vm);
4369 if (pool_is_free_index (am->nd_events, pool_index))
4372 event = pool_elt_at_index (am->nd_events, pool_index);
4375 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
4377 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
4381 if (sw_if_index == event->sw_if_index &&
4383 /* for BD case, also check IP address with 10 sec timeout */
4384 (ip6_address_is_equal (address,
4385 (ip6_address_t *) event->address) &&
4386 (now - nd_event_last_time) < 10.0)))
4391 nd_event_last_time = now;
4392 event->sw_if_index = sw_if_index;
4394 clib_memcpy (event->address, address, sizeof (event->address));
4399 arp_change_delete_callback (u32 pool_index, u8 * notused)
4401 vpe_api_main_t *am = &vpe_api_main;
4403 if (pool_is_free_index (am->arp_events, pool_index))
4406 pool_put_index (am->arp_events, pool_index);
4411 nd_change_delete_callback (u32 pool_index, u8 * notused)
4413 vpe_api_main_t *am = &vpe_api_main;
4415 if (pool_is_free_index (am->nd_events, pool_index))
4418 pool_put_index (am->nd_events, pool_index);
4423 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
4425 vpe_api_main_t *am = &vpe_api_main;
4426 vnet_main_t *vnm = vnet_get_main ();
4427 vl_api_want_ip4_arp_events_reply_t *rmp;
4428 vl_api_ip4_arp_event_t *event;
4431 if (mp->enable_disable)
4433 pool_get (am->arp_events, event);
4434 memset (event, 0, sizeof (*event));
4436 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
4437 event->client_index = mp->client_index;
4438 event->context = mp->context;
4439 event->address = mp->address;
4440 event->pid = mp->pid;
4441 if (mp->address == 0)
4444 rv = vnet_add_del_ip4_arp_change_event
4445 (vnm, arp_change_data_callback,
4446 mp->pid, &mp->address /* addr, in net byte order */ ,
4447 vpe_resolver_process_node.index,
4448 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
4452 rv = vnet_add_del_ip4_arp_change_event
4453 (vnm, arp_change_delete_callback,
4454 mp->pid, &mp->address /* addr, in net byte order */ ,
4455 vpe_resolver_process_node.index,
4456 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
4458 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4462 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
4464 vpe_api_main_t *am = &vpe_api_main;
4465 vnet_main_t *vnm = vnet_get_main ();
4466 vl_api_want_ip6_nd_events_reply_t *rmp;
4467 vl_api_ip6_nd_event_t *event;
4470 if (mp->enable_disable)
4472 pool_get (am->nd_events, event);
4473 memset (event, 0, sizeof (*event));
4475 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
4476 event->client_index = mp->client_index;
4477 event->context = mp->context;
4478 clib_memcpy (event->address, mp->address, 16);
4479 event->pid = mp->pid;
4480 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
4483 rv = vnet_add_del_ip6_nd_change_event
4484 (vnm, nd_change_data_callback,
4485 mp->pid, mp->address /* addr, in net byte order */ ,
4486 vpe_resolver_process_node.index,
4487 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
4491 rv = vnet_add_del_ip6_nd_change_event
4492 (vnm, nd_change_delete_callback,
4493 mp->pid, mp->address /* addr, in net byte order */ ,
4494 vpe_resolver_process_node.index,
4495 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
4497 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
4500 static void vl_api_input_acl_set_interface_t_handler
4501 (vl_api_input_acl_set_interface_t * mp)
4503 vlib_main_t *vm = vlib_get_main ();
4504 vl_api_input_acl_set_interface_reply_t *rmp;
4506 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4508 ip4_table_index = ntohl (mp->ip4_table_index);
4509 ip6_table_index = ntohl (mp->ip6_table_index);
4510 l2_table_index = ntohl (mp->l2_table_index);
4511 sw_if_index = ntohl (mp->sw_if_index);
4513 VALIDATE_SW_IF_INDEX (mp);
4515 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4516 ip6_table_index, l2_table_index, mp->is_add);
4518 BAD_SW_IF_INDEX_LABEL;
4520 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4523 static void vl_api_cop_interface_enable_disable_t_handler
4524 (vl_api_cop_interface_enable_disable_t * mp)
4526 vl_api_cop_interface_enable_disable_reply_t *rmp;
4528 u32 sw_if_index = ntohl (mp->sw_if_index);
4531 VALIDATE_SW_IF_INDEX (mp);
4533 enable_disable = (int) mp->enable_disable;
4535 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
4537 BAD_SW_IF_INDEX_LABEL;
4539 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
4542 static void vl_api_cop_whitelist_enable_disable_t_handler
4543 (vl_api_cop_whitelist_enable_disable_t * mp)
4545 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
4546 cop_whitelist_enable_disable_args_t _a, *a = &_a;
4547 u32 sw_if_index = ntohl (mp->sw_if_index);
4550 VALIDATE_SW_IF_INDEX (mp);
4552 a->sw_if_index = sw_if_index;
4555 a->default_cop = mp->default_cop;
4556 a->fib_id = ntohl (mp->fib_id);
4558 rv = cop_whitelist_enable_disable (a);
4560 BAD_SW_IF_INDEX_LABEL;
4562 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
4566 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
4570 api_main_t *am = &api_main;
4571 vlib_main_t *vm = vlib_get_main ();
4573 vl_api_get_node_graph_reply_t *rmp;
4575 pthread_mutex_lock (&am->vlib_rp->mutex);
4576 oldheap = svm_push_data_heap (am->vlib_rp);
4579 * Keep the number of memcpy ops to a minimum (e.g. 1).
4581 vec_validate (vector, 16384);
4582 vec_reset_length (vector);
4585 vector = vlib_node_serialize (&vm->node_main, vector,
4586 (u32) ~ 0 /* all threads */ ,
4587 1 /* include nexts */ ,
4588 1 /* include stats */ );
4590 svm_pop_heap (oldheap);
4591 pthread_mutex_unlock (&am->vlib_rp->mutex);
4594 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
4596 rmp->reply_in_shmem = (uword) vector;
4602 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
4605 vl_api_ioam_enable_reply_t *rmp;
4606 clib_error_t *error;
4608 /* Ignoring the profile id as currently a single profile
4610 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
4611 mp->seqno, mp->analyse);
4614 clib_error_report (error);
4615 rv = clib_error_get_code (error);
4618 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
4622 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
4625 vl_api_ioam_disable_reply_t *rmp;
4626 clib_error_t *error;
4628 error = clear_ioam_rewrite_fn ();
4631 clib_error_report (error);
4632 rv = clib_error_get_code (error);
4635 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
4639 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
4641 vlib_main_t *vm = vlib_get_main ();
4642 vl_api_policer_add_del_reply_t *rmp;
4645 sse2_qos_pol_cfg_params_st cfg;
4646 clib_error_t *error;
4649 name = format (0, "%s", mp->name);
4651 memset (&cfg, 0, sizeof (cfg));
4653 cfg.rnd_type = mp->round_type;
4654 cfg.rate_type = mp->rate_type;
4655 cfg.rb.kbps.cir_kbps = mp->cir;
4656 cfg.rb.kbps.eir_kbps = mp->eir;
4657 cfg.rb.kbps.cb_bytes = mp->cb;
4658 cfg.rb.kbps.eb_bytes = mp->eb;
4659 cfg.conform_action.action_type = mp->conform_action_type;
4660 cfg.conform_action.dscp = mp->conform_dscp;
4661 cfg.exceed_action.action_type = mp->exceed_action_type;
4662 cfg.exceed_action.dscp = mp->exceed_dscp;
4663 cfg.violate_action.action_type = mp->violate_action_type;
4664 cfg.violate_action.dscp = mp->violate_dscp;
4665 cfg.color_aware = mp->color_aware;
4667 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
4670 rv = VNET_API_ERROR_UNSPECIFIED;
4673 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
4675 if (rv == 0 && mp->is_add)
4676 rmp->policer_index = ntohl(policer_index);
4678 rmp->policer_index = ~0;
4684 send_policer_details (u8 * name,
4685 sse2_qos_pol_cfg_params_st * config,
4686 policer_read_response_type_st * templ,
4687 unix_shared_memory_queue_t * q, u32 context)
4689 vl_api_policer_details_t *mp;
4691 mp = vl_msg_api_alloc (sizeof (*mp));
4692 memset (mp, 0, sizeof (*mp));
4693 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
4694 mp->context = context;
4695 mp->cir = htonl (config->rb.kbps.cir_kbps);
4696 mp->eir = htonl (config->rb.kbps.eir_kbps);
4697 mp->cb = htonl (config->rb.kbps.cb_bytes);
4698 mp->eb = htonl (config->rb.kbps.eb_bytes);
4699 mp->rate_type = config->rate_type;
4700 mp->round_type = config->rnd_type;
4701 mp->type = config->rfc;
4702 mp->conform_action_type = config->conform_action.action_type;
4703 mp->conform_dscp = config->conform_action.dscp;
4704 mp->exceed_action_type = config->exceed_action.action_type;
4705 mp->exceed_dscp = config->exceed_action.dscp;
4706 mp->violate_action_type = config->violate_action.action_type;
4707 mp->violate_dscp = config->violate_action.dscp;
4708 mp->single_rate = templ->single_rate ? 1 : 0;
4709 mp->color_aware = templ->color_aware ? 1 : 0;
4710 mp->scale = htonl (templ->scale);
4711 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
4712 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
4713 mp->current_limit = htonl (templ->current_limit);
4714 mp->current_bucket = htonl (templ->current_bucket);
4715 mp->extended_limit = htonl (templ->extended_limit);
4716 mp->extended_bucket = htonl (templ->extended_bucket);
4717 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
4719 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
4721 vl_msg_api_send_shmem (q, (u8 *) & mp);
4725 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
4727 unix_shared_memory_queue_t *q;
4728 vnet_policer_main_t *pm = &vnet_policer_main;
4734 sse2_qos_pol_cfg_params_st *config;
4735 policer_read_response_type_st *templ;
4737 q = vl_api_client_index_to_input_queue (mp->client_index);
4741 if (mp->match_name_valid)
4743 match_name = format (0, "%s%c", mp->match_name, 0);
4746 if (mp->match_name_valid)
4748 p = hash_get_mem (pm->policer_config_by_name, match_name);
4752 config = pool_elt_at_index (pm->configs, pool_index);
4753 templ = pool_elt_at_index (pm->policer_templates, pool_index);
4754 send_policer_details (match_name, config, templ, q, mp->context);
4760 hash_foreach_pair (hp, pm->policer_config_by_name,
4762 name = (u8 *) hp->key;
4763 pool_index = hp->value[0];
4764 config = pool_elt_at_index (pm->configs, pool_index);
4765 templ = pool_elt_at_index (pm->policer_templates, pool_index);
4766 send_policer_details(name, config, templ, q, mp->context);
4773 vl_api_policer_classify_set_interface_t_handler
4774 (vl_api_policer_classify_set_interface_t * mp)
4776 vlib_main_t *vm = vlib_get_main ();
4777 vl_api_policer_classify_set_interface_reply_t *rmp;
4779 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4781 ip4_table_index = ntohl (mp->ip4_table_index);
4782 ip6_table_index = ntohl (mp->ip6_table_index);
4783 l2_table_index = ntohl (mp->l2_table_index);
4784 sw_if_index = ntohl (mp->sw_if_index);
4786 VALIDATE_SW_IF_INDEX (mp);
4788 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
4789 ip6_table_index, l2_table_index,
4792 BAD_SW_IF_INDEX_LABEL;
4794 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
4798 send_policer_classify_details (u32 sw_if_index,
4800 unix_shared_memory_queue_t * q, u32 context)
4802 vl_api_policer_classify_details_t *mp;
4804 mp = vl_msg_api_alloc (sizeof (*mp));
4805 memset (mp, 0, sizeof (*mp));
4806 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
4807 mp->context = context;
4808 mp->sw_if_index = htonl (sw_if_index);
4809 mp->table_index = htonl (table_index);
4811 vl_msg_api_send_shmem (q, (u8 *) & mp);
4815 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
4817 unix_shared_memory_queue_t *q;
4818 policer_classify_main_t *pcm = &policer_classify_main;
4822 q = vl_api_client_index_to_input_queue (mp->client_index);
4826 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
4828 if (vec_len (vec_tbl))
4830 for (i = 0; i < vec_len (vec_tbl); i++)
4832 if (vec_elt (vec_tbl, i) == ~0)
4835 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
4842 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_fib_details_t * mp)
4844 clib_warning ("BUG");
4847 typedef struct mpls_tunnel_send_walk_ctx_t_
4849 unix_shared_memory_queue_t *q;
4852 } mpls_tunnel_send_walk_ctx_t;
4855 send_mpls_tunnel_entry (u32 mti, void *arg)
4857 mpls_tunnel_send_walk_ctx_t *ctx;
4858 vl_api_mpls_tunnel_details_t *mp;
4859 const mpls_tunnel_t *mt;
4864 if (~0 != ctx->index && mti != ctx->index)
4867 mt = mpls_tunnel_get (mti);
4868 nlabels = vec_len (mt->mt_label_stack);
4870 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
4871 memset (mp, 0, sizeof (*mp));
4872 mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
4873 mp->context = ctx->context;
4875 mp->tunnel_index = ntohl (mti);
4876 memcpy (mp->mt_next_hop_out_labels,
4877 mt->mt_label_stack, nlabels * sizeof (u32));
4881 vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
4885 vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
4887 unix_shared_memory_queue_t *q;
4889 q = vl_api_client_index_to_input_queue (mp->client_index);
4893 mpls_tunnel_send_walk_ctx_t ctx = {
4895 .index = ntohl (mp->tunnel_index),
4896 .context = mp->context,
4898 mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
4902 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
4904 clib_warning ("BUG");
4908 vl_api_mpls_fib_details_t_endian (vl_api_mpls_fib_details_t * mp)
4910 clib_warning ("BUG");
4914 vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp)
4916 clib_warning ("BUG");
4920 send_mpls_fib_details (vpe_api_main_t * am,
4921 unix_shared_memory_queue_t * q,
4922 u32 table_id, u32 label, u32 eos,
4923 fib_route_path_encode_t * api_rpaths, u32 context)
4925 vl_api_mpls_fib_details_t *mp;
4926 fib_route_path_encode_t *api_rpath;
4927 vl_api_fib_path2_t *fp;
4930 path_count = vec_len (api_rpaths);
4931 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
4934 memset (mp, 0, sizeof (*mp));
4935 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
4936 mp->context = context;
4938 mp->table_id = htonl (table_id);
4940 mp->label = htonl (label);
4942 mp->count = htonl (path_count);
4944 vec_foreach (api_rpath, api_rpaths)
4946 memset (fp, 0, sizeof (*fp));
4947 fp->weight = htonl (api_rpath->rpath.frp_weight);
4948 fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
4949 copy_fib_next_hop (api_rpath, fp);
4953 vl_msg_api_send_shmem (q, (u8 *) & mp);
4957 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
4959 vpe_api_main_t *am = &vpe_api_main;
4960 unix_shared_memory_queue_t *q;
4961 mpls_main_t *mm = &mpls_main;
4962 fib_table_t *fib_table;
4963 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
4967 fib_route_path_encode_t *api_rpaths;
4969 q = vl_api_client_index_to_input_queue (mp->client_index);
4974 pool_foreach (fib_table, mm->fibs,
4976 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
4978 vec_add1(lfeis, lfei);
4981 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
4983 vec_foreach(lfeip, lfeis)
4985 fib_entry_get_prefix(*lfeip, &pfx);
4986 fib_index = fib_entry_get_fib_index(*lfeip);
4987 fib_table = fib_table_get(fib_index, pfx.fp_proto);
4989 fib_entry_encode(*lfeip, &api_rpaths);
4990 send_mpls_fib_details (am, q,
4991 fib_table->ft_table_id,
4996 vec_free(api_rpaths);
5003 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
5005 unix_shared_memory_queue_t *q;
5007 q = vl_api_client_index_to_input_queue (mp->client_index);
5011 vnet_classify_main_t *cm = &vnet_classify_main;
5012 vnet_classify_table_t *t;
5017 pool_foreach (t, cm->tables,
5019 vec_add1 (table_ids, ntohl(t - cm->tables));
5022 count = vec_len (table_ids);
5024 vl_api_classify_table_ids_reply_t *rmp;
5025 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
5026 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
5027 rmp->context = mp->context;
5028 rmp->count = ntohl (count);
5029 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
5032 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5034 vec_free (table_ids);
5038 vl_api_classify_table_by_interface_t_handler
5039 (vl_api_classify_table_by_interface_t * mp)
5041 vl_api_classify_table_by_interface_reply_t *rmp;
5044 u32 sw_if_index = ntohl (mp->sw_if_index);
5047 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
5050 VALIDATE_SW_IF_INDEX (mp);
5052 input_acl_main_t *am = &input_acl_main;
5057 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
5059 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
5060 if (vec_len (vec_tbl))
5062 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
5064 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
5068 acl[type] = vec_elt (vec_tbl, if_idx);
5073 BAD_SW_IF_INDEX_LABEL;
5076 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
5078 rmp->sw_if_index = ntohl(sw_if_index);
5079 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
5080 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
5081 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
5088 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
5090 unix_shared_memory_queue_t *q;
5092 q = vl_api_client_index_to_input_queue (mp->client_index);
5096 vl_api_classify_table_info_reply_t *rmp = 0;
5098 vnet_classify_main_t *cm = &vnet_classify_main;
5099 u32 table_id = ntohl (mp->table_id);
5100 vnet_classify_table_t *t;
5103 pool_foreach (t, cm->tables,
5105 if (table_id == t - cm->tables)
5107 rmp = vl_msg_api_alloc_as_if_client
5108 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
5109 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
5110 rmp->context = mp->context;
5111 rmp->table_id = ntohl(table_id);
5112 rmp->nbuckets = ntohl(t->nbuckets);
5113 rmp->match_n_vectors = ntohl(t->match_n_vectors);
5114 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
5115 rmp->active_sessions = ntohl(t->active_elements);
5116 rmp->next_table_index = ntohl(t->next_table_index);
5117 rmp->miss_next_index = ntohl(t->miss_next_index);
5118 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
5119 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
5128 rmp = vl_msg_api_alloc (sizeof (*rmp));
5129 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
5130 rmp->context = mp->context;
5131 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
5134 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5138 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
5141 clib_warning ("BUG");
5145 send_classify_session_details (unix_shared_memory_queue_t * q,
5148 vnet_classify_entry_t * e, u32 context)
5150 vl_api_classify_session_details_t *rmp;
5152 rmp = vl_msg_api_alloc (sizeof (*rmp));
5153 memset (rmp, 0, sizeof (*rmp));
5154 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
5155 rmp->context = context;
5156 rmp->table_id = ntohl (table_id);
5157 rmp->hit_next_index = ntohl (e->next_index);
5158 rmp->advance = ntohl (e->advance);
5159 rmp->opaque_index = ntohl (e->opaque_index);
5160 rmp->match_length = ntohl (match_length);
5161 clib_memcpy (rmp->match, e->key, match_length);
5163 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5167 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
5169 vnet_classify_main_t *cm = &vnet_classify_main;
5170 unix_shared_memory_queue_t *q;
5172 u32 table_id = ntohl (mp->table_id);
5173 vnet_classify_table_t *t;
5175 q = vl_api_client_index_to_input_queue (mp->client_index);
5180 pool_foreach (t, cm->tables,
5182 if (table_id == t - cm->tables)
5184 vnet_classify_bucket_t * b;
5185 vnet_classify_entry_t * v, * save_v;
5188 for (i = 0; i < t->nbuckets; i++)
5190 b = &t->buckets [i];
5194 save_v = vnet_classify_get_entry (t, b->offset);
5195 for (j = 0; j < (1<<b->log2_pages); j++)
5197 for (k = 0; k < t->entries_per_page; k++)
5199 v = vnet_classify_entry_at_index
5200 (t, save_v, j*t->entries_per_page + k);
5201 if (vnet_classify_entry_is_free (v))
5204 send_classify_session_details
5205 (q, table_id, t->match_n_vectors * sizeof (u32x4),
5217 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
5219 vlib_main_t *vm = vlib_get_main ();
5220 flow_report_main_t *frm = &flow_report_main;
5221 vl_api_set_ipfix_exporter_reply_t *rmp;
5222 ip4_address_t collector, src;
5223 u16 collector_port = UDP_DST_PORT_ipfix;
5225 u32 template_interval;
5231 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
5232 collector_port = ntohs (mp->collector_port);
5233 if (collector_port == (u16) ~ 0)
5234 collector_port = UDP_DST_PORT_ipfix;
5235 memcpy (src.data, mp->src_address, sizeof (src.data));
5236 fib_id = ntohl (mp->vrf_id);
5238 ip4_main_t *im = &ip4_main;
5245 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
5248 rv = VNET_API_ERROR_NO_SUCH_FIB;
5254 path_mtu = ntohl (mp->path_mtu);
5256 path_mtu = 512; // RFC 7011 section 10.3.3.
5257 template_interval = ntohl (mp->template_interval);
5258 if (template_interval == ~0)
5259 template_interval = 20;
5260 udp_checksum = mp->udp_checksum;
5262 if (collector.as_u32 == 0)
5264 rv = VNET_API_ERROR_INVALID_VALUE;
5268 if (src.as_u32 == 0)
5270 rv = VNET_API_ERROR_INVALID_VALUE;
5274 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
5276 rv = VNET_API_ERROR_INVALID_VALUE;
5282 rv = VNET_API_ERROR_INVALID_VALUE;
5286 /* Reset report streams if we are reconfiguring IP addresses */
5287 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
5288 frm->src_address.as_u32 != src.as_u32 ||
5289 frm->collector_port != collector_port)
5290 vnet_flow_reports_reset (frm);
5292 frm->ipfix_collector.as_u32 = collector.as_u32;
5293 frm->collector_port = collector_port;
5294 frm->src_address.as_u32 = src.as_u32;
5295 frm->fib_index = fib_index;
5296 frm->path_mtu = path_mtu;
5297 frm->template_interval = template_interval;
5298 frm->udp_checksum = udp_checksum;
5300 /* Turn on the flow reporting process */
5301 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
5304 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
5308 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
5310 flow_report_main_t *frm = &flow_report_main;
5311 unix_shared_memory_queue_t *q;
5312 vl_api_ipfix_exporter_details_t *rmp;
5313 ip4_main_t *im = &ip4_main;
5316 q = vl_api_client_index_to_input_queue (mp->client_index);
5320 rmp = vl_msg_api_alloc (sizeof (*rmp));
5321 memset (rmp, 0, sizeof (*rmp));
5322 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
5323 rmp->context = mp->context;
5324 memcpy (rmp->collector_address, frm->ipfix_collector.data,
5325 sizeof (frm->ipfix_collector.data));
5326 rmp->collector_port = htons (frm->collector_port);
5327 memcpy (rmp->src_address, frm->src_address.data,
5328 sizeof (frm->src_address.data));
5329 if (frm->fib_index == ~0)
5332 vrf_id = im->fibs[frm->fib_index].ft_table_id;
5333 rmp->vrf_id = htonl (vrf_id);
5334 rmp->path_mtu = htonl (frm->path_mtu);
5335 rmp->template_interval = htonl (frm->template_interval);
5336 rmp->udp_checksum = (frm->udp_checksum != 0);
5338 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5342 vl_api_set_ipfix_classify_stream_t_handler
5343 (vl_api_set_ipfix_classify_stream_t * mp)
5345 vl_api_set_ipfix_classify_stream_reply_t *rmp;
5346 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5347 flow_report_main_t *frm = &flow_report_main;
5349 u32 src_port = UDP_DST_PORT_ipfix;
5352 domain_id = ntohl (mp->domain_id);
5353 src_port = ntohs (mp->src_port);
5355 if (fcm->src_port != 0 &&
5356 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
5358 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
5359 domain_id, (u16) src_port);
5363 fcm->domain_id = domain_id;
5364 fcm->src_port = (u16) src_port;
5366 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
5370 vl_api_ipfix_classify_stream_dump_t_handler
5371 (vl_api_ipfix_classify_stream_dump_t * mp)
5373 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5374 unix_shared_memory_queue_t *q;
5375 vl_api_ipfix_classify_stream_details_t *rmp;
5377 q = vl_api_client_index_to_input_queue (mp->client_index);
5381 rmp = vl_msg_api_alloc (sizeof (*rmp));
5382 memset (rmp, 0, sizeof (*rmp));
5383 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
5384 rmp->context = mp->context;
5385 rmp->domain_id = htonl (fcm->domain_id);
5386 rmp->src_port = htons (fcm->src_port);
5388 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5392 vl_api_ipfix_classify_table_add_del_t_handler
5393 (vl_api_ipfix_classify_table_add_del_t * mp)
5395 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
5396 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5397 flow_report_main_t *frm = &flow_report_main;
5398 vnet_flow_report_add_del_args_t args;
5399 ipfix_classify_table_t *table;
5401 u32 classify_table_index;
5403 u8 transport_protocol;
5406 classify_table_index = ntohl (mp->table_id);
5407 ip_version = mp->ip_version;
5408 transport_protocol = mp->transport_protocol;
5409 is_add = mp->is_add;
5411 if (fcm->src_port == 0)
5413 /* call set_ipfix_classify_stream first */
5414 rv = VNET_API_ERROR_UNSPECIFIED;
5418 memset (&args, 0, sizeof (args));
5422 for (i = 0; i < vec_len (fcm->tables); i++)
5423 if (ipfix_classify_table_index_valid (i))
5424 if (fcm->tables[i].classify_table_index == classify_table_index)
5426 table = &fcm->tables[i];
5434 rv = VNET_API_ERROR_VALUE_EXIST;
5437 table = ipfix_classify_add_table ();
5438 table->classify_table_index = classify_table_index;
5444 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
5449 table->ip_version = ip_version;
5450 table->transport_protocol = transport_protocol;
5452 args.opaque.as_uword = table - fcm->tables;
5453 args.rewrite_callback = ipfix_classify_template_rewrite;
5454 args.flow_data_callback = ipfix_classify_send_flows;
5455 args.is_add = is_add;
5456 args.domain_id = fcm->domain_id;
5457 args.src_port = fcm->src_port;
5459 rv = vnet_flow_report_add_del (frm, &args);
5461 /* If deleting, or add failed */
5462 if (is_add == 0 || (rv && is_add))
5463 ipfix_classify_delete_table (table - fcm->tables);
5466 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
5470 send_ipfix_classify_table_details (u32 table_index,
5471 unix_shared_memory_queue_t * q,
5474 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5475 vl_api_ipfix_classify_table_details_t *mp;
5477 ipfix_classify_table_t *table = &fcm->tables[table_index];
5479 mp = vl_msg_api_alloc (sizeof (*mp));
5480 memset (mp, 0, sizeof (*mp));
5481 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
5482 mp->context = context;
5483 mp->table_id = htonl (table->classify_table_index);
5484 mp->ip_version = table->ip_version;
5485 mp->transport_protocol = table->transport_protocol;
5487 vl_msg_api_send_shmem (q, (u8 *) & mp);
5491 vl_api_ipfix_classify_table_dump_t_handler
5492 (vl_api_ipfix_classify_table_dump_t * mp)
5494 flow_report_classify_main_t *fcm = &flow_report_classify_main;
5495 unix_shared_memory_queue_t *q;
5498 q = vl_api_client_index_to_input_queue (mp->client_index);
5502 for (i = 0; i < vec_len (fcm->tables); i++)
5503 if (ipfix_classify_table_index_valid (i))
5504 send_ipfix_classify_table_details (i, q, mp->context);
5508 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
5510 vl_api_pg_create_interface_reply_t *rmp;
5513 pg_main_t *pg = &pg_main;
5514 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
5515 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
5518 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
5520 rmp->sw_if_index = ntohl(pi->sw_if_index);
5526 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
5528 vl_api_pg_capture_reply_t *rmp;
5531 vnet_main_t *vnm = vnet_get_main ();
5532 vnet_interface_main_t *im = &vnm->interface_main;
5533 vnet_hw_interface_t *hi = 0;
5535 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
5536 u32 hw_if_index = ~0;
5537 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
5540 vec_free (intf_name);
5542 if (hw_if_index != ~0)
5544 pg_capture_args_t _a, *a = &_a;
5546 u32 len = ntohl (mp->pcap_name_length);
5547 u8 *pcap_file_name = vec_new (u8, len);
5548 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
5550 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
5551 a->hw_if_index = hw_if_index;
5552 a->dev_instance = hi->dev_instance;
5553 a->is_enabled = mp->is_enabled;
5554 a->pcap_file_name = pcap_file_name;
5555 a->count = ntohl (mp->count);
5557 clib_error_t *e = pg_capture (a);
5560 clib_error_report (e);
5561 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
5564 vec_free (pcap_file_name);
5566 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
5570 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
5572 vl_api_pg_enable_disable_reply_t *rmp;
5575 pg_main_t *pg = &pg_main;
5576 u32 stream_index = ~0;
5578 int is_enable = mp->is_enabled != 0;
5579 u32 len = ntohl (mp->stream_name_length) - 1;
5583 u8 *stream_name = vec_new (u8, len);
5584 clib_memcpy (stream_name, mp->stream_name, len);
5585 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
5588 vec_free (stream_name);
5591 pg_enable_disable (stream_index, is_enable);
5593 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
5597 vl_api_ip_source_and_port_range_check_add_del_t_handler
5598 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
5600 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
5603 u8 is_ipv6 = mp->is_ipv6;
5604 u8 is_add = mp->is_add;
5605 u8 mask_length = mp->mask_length;
5606 ip4_address_t ip4_addr;
5607 ip6_address_t ip6_addr;
5609 u16 *high_ports = 0;
5611 u16 tmp_low, tmp_high;
5615 // Validate port range
5616 num_ranges = mp->number_of_ranges;
5617 if (num_ranges > 32)
5618 { // This is size of array in VPE.API
5619 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
5623 vec_reset_length (low_ports);
5624 vec_reset_length (high_ports);
5626 for (i = 0; i < num_ranges; i++)
5628 tmp_low = mp->low_ports[i];
5629 tmp_high = mp->high_ports[i];
5630 // If tmp_low <= tmp_high then only need to check tmp_low = 0
5631 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
5632 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
5634 rv = VNET_API_ERROR_INVALID_VALUE;
5637 vec_add1 (low_ports, tmp_low);
5638 vec_add1 (high_ports, tmp_high + 1);
5641 // Validate mask_length
5642 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
5644 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
5648 vrf_id = ntohl (mp->vrf_id);
5652 rv = VNET_API_ERROR_INVALID_VALUE;
5659 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
5660 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
5664 high_ports, is_add);
5668 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
5669 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
5673 high_ports, is_add);
5677 vec_free (low_ports);
5678 vec_free (high_ports);
5679 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
5683 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
5684 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
5686 vlib_main_t *vm = vlib_get_main ();
5687 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
5688 ip4_main_t *im = &ip4_main;
5691 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
5692 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
5696 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
5697 ntohl (mp->tcp_out_vrf_id);
5698 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
5699 ntohl (mp->udp_out_vrf_id);
5700 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
5701 ntohl (mp->tcp_in_vrf_id);
5702 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
5703 ntohl (mp->udp_in_vrf_id);
5706 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
5708 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
5710 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
5714 rv = VNET_API_ERROR_INVALID_VALUE;
5718 fib_index[i] = p[0];
5723 sw_if_index = ntohl (mp->sw_if_index);
5725 VALIDATE_SW_IF_INDEX (mp);
5728 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
5731 BAD_SW_IF_INDEX_LABEL;
5734 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
5738 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
5741 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
5743 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
5744 u32 sw_if_index = ~0;
5746 /* Check src & dst are different */
5747 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
5749 rv = VNET_API_ERROR_SAME_SRC_DST;
5753 memset (a, 0, sizeof (*a));
5755 /* ip addresses sent in network byte order */
5756 clib_memcpy (&(a->src), mp->src_address, 4);
5757 clib_memcpy (&(a->dst), mp->dst_address, 4);
5758 a->is_add = mp->is_add;
5759 a->lsa = ntohl (mp->local_sa_id);
5760 a->rsa = ntohl (mp->remote_sa_id);
5762 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
5766 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
5768 rmp->sw_if_index = ntohl (sw_if_index);
5773 static void send_ipsec_gre_tunnel_details
5774 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5776 vl_api_ipsec_gre_tunnel_details_t *rmp;
5778 rmp = vl_msg_api_alloc (sizeof (*rmp));
5779 memset (rmp, 0, sizeof (*rmp));
5780 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
5781 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
5782 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
5783 rmp->sw_if_index = htonl (t->sw_if_index);
5784 rmp->local_sa_id = htonl (t->local_sa_id);
5785 rmp->remote_sa_id = htonl (t->remote_sa_id);
5786 rmp->context = context;
5788 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5791 static void vl_api_ipsec_gre_tunnel_dump_t_handler
5792 (vl_api_ipsec_gre_tunnel_dump_t * mp)
5794 unix_shared_memory_queue_t *q;
5795 ipsec_gre_main_t *igm = &ipsec_gre_main;
5796 ipsec_gre_tunnel_t *t;
5799 q = vl_api_client_index_to_input_queue (mp->client_index);
5805 sw_if_index = ntohl (mp->sw_if_index);
5807 if (~0 == sw_if_index)
5810 pool_foreach (t, igm->tunnels,
5812 send_ipsec_gre_tunnel_details(t, q, mp->context);
5818 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
5819 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
5823 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
5824 send_ipsec_gre_tunnel_details (t, q, mp->context);
5829 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
5831 vl_api_delete_subif_reply_t *rmp;
5834 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
5836 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
5840 vl_api_l2_interface_pbb_tag_rewrite_t_handler
5841 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
5843 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
5844 vnet_main_t *vnm = vnet_get_main ();
5845 vlib_main_t *vm = vlib_get_main ();
5849 VALIDATE_SW_IF_INDEX (mp);
5851 vtr_op = ntohl (mp->vtr_op);
5855 case L2_VTR_DISABLED:
5858 case L2_VTR_TRANSLATE_2_1:
5862 rv = VNET_API_ERROR_INVALID_VALUE;
5863 goto bad_sw_if_index;
5866 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
5867 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
5868 ntohl (mp->i_sid), ntohs (mp->outer_tag));
5870 BAD_SW_IF_INDEX_LABEL;
5872 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
5877 vl_api_punt_t_handler (vl_api_punt_t * mp)
5879 vl_api_punt_reply_t *rmp;
5880 vlib_main_t *vm = vlib_get_main ();
5882 clib_error_t *error;
5884 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
5885 ntohs (mp->l4_port), mp->is_add);
5889 clib_error_report (error);
5892 REPLY_MACRO (VL_API_PUNT_REPLY);
5896 vl_api_flow_classify_set_interface_t_handler
5897 (vl_api_flow_classify_set_interface_t * mp)
5899 vlib_main_t *vm = vlib_get_main ();
5900 vl_api_flow_classify_set_interface_reply_t *rmp;
5902 u32 sw_if_index, ip4_table_index, ip6_table_index;
5904 ip4_table_index = ntohl (mp->ip4_table_index);
5905 ip6_table_index = ntohl (mp->ip6_table_index);
5906 sw_if_index = ntohl (mp->sw_if_index);
5908 VALIDATE_SW_IF_INDEX (mp);
5910 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
5911 ip6_table_index, mp->is_add);
5913 BAD_SW_IF_INDEX_LABEL;
5915 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
5919 send_flow_classify_details (u32 sw_if_index,
5921 unix_shared_memory_queue_t * q, u32 context)
5923 vl_api_flow_classify_details_t *mp;
5925 mp = vl_msg_api_alloc (sizeof (*mp));
5926 memset (mp, 0, sizeof (*mp));
5927 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
5928 mp->context = context;
5929 mp->sw_if_index = htonl (sw_if_index);
5930 mp->table_index = htonl (table_index);
5932 vl_msg_api_send_shmem (q, (u8 *) & mp);
5936 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
5938 unix_shared_memory_queue_t *q;
5939 flow_classify_main_t *pcm = &flow_classify_main;
5943 q = vl_api_client_index_to_input_queue (mp->client_index);
5947 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
5949 if (vec_len (vec_tbl))
5951 for (i = 0; i < vec_len (vec_tbl); i++)
5953 if (vec_elt (vec_tbl, i) == ~0)
5956 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
5963 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
5965 vl_api_feature_enable_disable_reply_t *rmp;
5967 u8 *arc_name, *feature_name;
5969 VALIDATE_SW_IF_INDEX (mp);
5971 arc_name = format (0, "%s%c", mp->arc_name, 0);
5972 feature_name = format (0, "%s%c", mp->feature_name, 0);
5974 vnet_feature_registration_t *reg;
5976 vnet_get_feature_reg ((const char *) arc_name,
5977 (const char *) feature_name);
5979 rv = VNET_API_ERROR_INVALID_VALUE;
5983 clib_error_t *error = 0;
5985 sw_if_index = ntohl (mp->sw_if_index);
5986 if (reg->enable_disable_cb)
5987 error = reg->enable_disable_cb (sw_if_index, mp->enable);
5989 vnet_feature_enable_disable ((const char *) arc_name,
5990 (const char *) feature_name,
5991 sw_if_index, mp->enable, 0, 0);
5994 clib_error_report (error);
5995 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
5999 vec_free (feature_name);
6000 vec_free (arc_name);
6002 BAD_SW_IF_INDEX_LABEL;
6004 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
6007 #define BOUNCE_HANDLER(nn) \
6008 static void vl_api_##nn##_t_handler ( \
6009 vl_api_##nn##_t *mp) \
6011 vpe_client_registration_t *reg; \
6012 vpe_api_main_t * vam = &vpe_api_main; \
6013 unix_shared_memory_queue_t * q; \
6015 /* One registration only... */ \
6016 pool_foreach(reg, vam->nn##_registrations, \
6018 q = vl_api_client_index_to_input_queue (reg->client_index); \
6021 * If the queue is stuffed, turf the msg and complain \
6022 * It's unlikely that the intended recipient is \
6023 * alive; avoid deadlock at all costs. \
6025 if (q->cursize == q->maxsize) { \
6026 clib_warning ("ERROR: receiver queue full, drop msg"); \
6027 vl_msg_api_free (mp); \
6030 vl_msg_api_send_shmem (q, (u8 *)&mp); \
6034 vl_msg_api_free (mp); \
6037 static void setup_message_id_table (api_main_t * am);
6041 * Add vpe's API message handlers to the table.
6042 * vlib has alread mapped shared memory and
6043 * added the client registration handlers.
6044 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
6046 static clib_error_t *
6047 vpe_api_hookup (vlib_main_t * vm)
6049 api_main_t *am = &api_main;
6052 vl_msg_api_set_handlers(VL_API_##N, #n, \
6053 vl_api_##n##_t_handler, \
6055 vl_api_##n##_t_endian, \
6056 vl_api_##n##_t_print, \
6057 sizeof(vl_api_##n##_t), 1);
6058 foreach_vpe_api_msg;
6062 * Manually register the sr tunnel add del msg, so we trace
6063 * enough bytes to capture a typical segment list
6065 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6066 "sr_tunnel_add_del",
6067 vl_api_sr_tunnel_add_del_t_handler,
6069 vl_api_sr_tunnel_add_del_t_endian,
6070 vl_api_sr_tunnel_add_del_t_print, 256, 1);
6074 * Manually register the sr policy add del msg, so we trace
6075 * enough bytes to capture a typical tunnel name list
6077 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6078 "sr_policy_add_del",
6079 vl_api_sr_policy_add_del_t_handler,
6081 vl_api_sr_policy_add_del_t_endian,
6082 vl_api_sr_policy_add_del_t_print, 256, 1);
6085 * Trace space for 8 MPLS encap labels, classifier mask+match
6087 am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32);
6088 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
6089 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
6090 += 5 * sizeof (u32x4);
6091 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
6094 * Thread-safe API messages
6096 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
6097 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
6100 * Set up the (msg_name, crc, message-id) table
6102 setup_message_id_table (am);
6107 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
6109 static clib_error_t *
6110 vpe_api_init (vlib_main_t * vm)
6112 vpe_api_main_t *am = &vpe_api_main;
6115 am->vnet_main = vnet_get_main ();
6116 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6117 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6118 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6119 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6120 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6121 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6122 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
6125 vl_set_memory_region_name ("/vpe-api");
6126 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
6131 VLIB_INIT_FUNCTION (vpe_api_init);
6134 static clib_error_t *
6135 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
6138 u64 baseva, size, pvt_heap_size;
6140 const int max_buf_size = 4096;
6142 struct passwd _pw, *pw;
6143 struct group _grp, *grp;
6145 buf = vec_new (char, 128);
6146 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6148 if (unformat (input, "prefix %s", &chroot_path))
6150 vec_add1 (chroot_path, 0);
6151 vl_set_memory_root_path ((char *) chroot_path);
6153 else if (unformat (input, "uid %d", &uid))
6154 vl_set_memory_uid (uid);
6155 else if (unformat (input, "gid %d", &gid))
6156 vl_set_memory_gid (gid);
6157 else if (unformat (input, "baseva %llx", &baseva))
6158 vl_set_global_memory_baseva (baseva);
6159 else if (unformat (input, "global-size %lldM", &size))
6160 vl_set_global_memory_size (size * (1ULL << 20));
6161 else if (unformat (input, "global-size %lldG", &size))
6162 vl_set_global_memory_size (size * (1ULL << 30));
6163 else if (unformat (input, "global-size %lld", &size))
6164 vl_set_global_memory_size (size);
6165 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
6166 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
6167 else if (unformat (input, "global-pvt-heap-size size %lld",
6169 vl_set_global_pvt_heap_size (pvt_heap_size);
6170 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
6171 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
6172 else if (unformat (input, "api-pvt-heap-size size %lld",
6174 vl_set_api_pvt_heap_size (pvt_heap_size);
6175 else if (unformat (input, "api-size %lldM", &size))
6176 vl_set_api_memory_size (size * (1ULL << 20));
6177 else if (unformat (input, "api-size %lldG", &size))
6178 vl_set_api_memory_size (size * (1ULL << 30));
6179 else if (unformat (input, "api-size %lld", &size))
6180 vl_set_api_memory_size (size);
6181 else if (unformat (input, "uid %s", &s))
6183 /* lookup the username */
6186 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
6187 && (vec_len (buf) <= max_buf_size))
6189 vec_resize (buf, vec_len (buf) * 2);
6193 e = clib_error_return_code (0, rv,
6194 CLIB_ERROR_ERRNO_VALID |
6196 "cannot fetch username %s", s);
6204 clib_error_return_fatal (0, "username %s does not exist", s);
6210 vl_set_memory_uid (pw->pw_uid);
6212 else if (unformat (input, "gid %s", &s))
6214 /* lookup the group name */
6217 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
6218 && (vec_len (buf) <= max_buf_size))
6220 vec_resize (buf, vec_len (buf) * 2);
6224 e = clib_error_return_code (0, rv,
6225 CLIB_ERROR_ERRNO_VALID |
6227 "cannot fetch group %s", s);
6234 e = clib_error_return_fatal (0, "group %s does not exist", s);
6241 vl_set_memory_gid (grp->gr_gid);
6244 return clib_error_return (0, "unknown input `%U'",
6245 format_unformat_error, input);
6250 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
6253 get_unformat_vnet_sw_interface (void)
6255 return (void *) &unformat_vnet_sw_interface;
6259 format_arp_event (u8 * s, va_list * args)
6261 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
6263 s = format (s, "pid %d: ", event->pid);
6265 s = format (s, "bd mac/ip4 binding events");
6267 s = format (s, "resolution for %U", format_ip4_address, &event->address);
6272 format_nd_event (u8 * s, va_list * args)
6274 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
6276 s = format (s, "pid %d: ", event->pid);
6278 s = format (s, "bd mac/ip6 binding events");
6280 s = format (s, "resolution for %U", format_ip6_address, event->address);
6284 static clib_error_t *
6285 show_ip_arp_nd_events_fn (vlib_main_t * vm,
6286 unformat_input_t * input, vlib_cli_command_t * cmd)
6288 vpe_api_main_t *am = &vpe_api_main;
6289 vl_api_ip4_arp_event_t *arp_event;
6290 vl_api_ip6_nd_event_t *nd_event;
6292 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
6294 vlib_cli_output (vm, "No active arp or nd event registrations");
6299 pool_foreach (arp_event, am->arp_events,
6301 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
6304 pool_foreach (nd_event, am->nd_events,
6306 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
6314 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
6315 .path = "show arp-nd-event registrations",
6316 .function = show_ip_arp_nd_events_fn,
6317 .short_help = "Show ip4 arp and ip6 nd event registrations",
6321 #define vl_msg_name_crc_list
6322 #include <vpp-api/vpe_all_api_h.h>
6323 #undef vl_msg_name_crc_list
6326 setup_message_id_table (api_main_t * am)
6328 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
6329 foreach_vl_msg_name_crc_memclnt;
6330 foreach_vl_msg_name_crc_vpe;
6336 * fd.io coding-style-patch-verification: ON
6339 * eval: (c-set-style "gnu")