2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010-2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
48 #include <vnet/api_errno.h>
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/l2tp/l2tp.h>
53 #include <vnet/ip/ip.h>
54 #include <vnet/ip/ip6.h>
55 #include <vnet/ip/ip6_neighbor.h>
56 #include <vnet/unix/tuntap.h>
57 #include <vnet/unix/tapcli.h>
58 #include <vnet/mpls/mpls.h>
59 #include <vnet/mpls/mpls_tunnel.h>
60 #include <vnet/dhcp/proxy.h>
61 #include <vnet/dhcp/client.h>
63 #include <vnet/sr/sr.h>
65 #include <vnet/dhcpv6/proxy.h>
66 #include <vlib/vlib.h>
67 #include <vlib/unix/unix.h>
68 #include <vlibapi/api.h>
69 #include <vlibmemory/api.h>
70 #include <vnet/classify/vnet_classify.h>
71 #include <vnet/classify/input_acl.h>
72 #include <vnet/classify/policer_classify.h>
73 #include <vnet/classify/flow_classify.h>
74 #include <vnet/l2/l2_classify.h>
75 #include <vnet/vxlan/vxlan.h>
76 #include <vnet/gre/gre.h>
77 #include <vnet/l2/l2_vtr.h>
78 #include <vnet/vxlan-gpe/vxlan_gpe.h>
79 #include <vnet/lisp-gpe/lisp_gpe.h>
80 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
81 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
82 #include <vnet/lisp-cp/control.h>
83 #include <vnet/map/map.h>
84 #include <vnet/cop/cop.h>
85 #include <vnet/ip/ip6_hop_by_hop.h>
86 #include <vnet/ip/ip_source_and_port_range_check.h>
87 #include <vnet/devices/af_packet/af_packet.h>
88 #include <vnet/policer/policer.h>
89 #include <vnet/devices/netmap/netmap.h>
90 #include <vnet/flow/flow_report.h>
91 #include <vnet/ipsec-gre/ipsec_gre.h>
92 #include <vnet/flow/flow_report_classify.h>
93 #include <vnet/ip/punt.h>
94 #include <vnet/feature/feature.h>
97 #undef __included_bihash_template_h__
98 #include <vnet/l2/l2_fib.h>
101 #include <vnet/devices/dpdk/dpdk.h>
105 #include <vnet/ipsec/ipsec.h>
106 #include <vnet/ipsec/ikev2.h>
108 #include <vnet/devices/virtio/vhost-user.h>
110 #include <stats/stats.h>
113 #include <vnet/ethernet/ethernet.h>
114 #include <vnet/ethernet/arp_packet.h>
115 #include <vnet/interface.h>
117 #include <vnet/l2/l2_fib.h>
118 #include <vnet/l2/l2_bd.h>
119 #include <vpp-api/vpe_msg_enum.h>
120 #include <vnet/span/span.h>
122 #include <vnet/fib/ip6_fib.h>
123 #include <vnet/fib/ip4_fib.h>
124 #include <vnet/dpo/drop_dpo.h>
125 #include <vnet/dpo/receive_dpo.h>
126 #include <vnet/dpo/lookup_dpo.h>
127 #include <vnet/dpo/classify_dpo.h>
128 #include <vnet/dpo/ip_null_dpo.h>
130 #define vl_typedefs /* define message structures */
131 #include <vpp-api/vpe_all_api_h.h>
134 #define vl_endianfun /* define message structures */
135 #include <vpp-api/vpe_all_api_h.h>
138 /* instantiate all the print functions we know about */
139 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
141 #include <vpp-api/vpe_all_api_h.h>
144 #include <vlibapi/api_helper_macros.h>
146 #define foreach_vpe_api_msg \
147 _(WANT_OAM_EVENTS, want_oam_events) \
148 _(OAM_ADD_DEL, oam_add_del) \
149 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
150 _(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \
151 _(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \
152 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
153 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
154 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
155 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
156 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
157 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
158 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
159 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
160 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
161 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
162 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
163 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
164 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
165 _(L2FIB_ADD_DEL, l2fib_add_del) \
166 _(L2_FLAGS, l2_flags) \
167 _(BRIDGE_FLAGS, bridge_flags) \
168 _(TAP_CONNECT, tap_connect) \
169 _(TAP_MODIFY, tap_modify) \
170 _(TAP_DELETE, tap_delete) \
171 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
172 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
173 _(CREATE_SUBIF, create_subif) \
174 _(MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del) \
175 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
176 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
177 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
178 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
179 _(RESET_FIB, reset_fib) \
180 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
181 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
182 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
183 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
184 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
185 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
186 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
187 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
188 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
189 sw_interface_ip6_set_link_local_address) \
190 _(CREATE_LOOPBACK, create_loopback) \
191 _(CONTROL_PING, control_ping) \
192 _(CLI_REQUEST, cli_request) \
193 _(CLI_INBAND, cli_inband) \
194 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
195 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
196 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
197 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
198 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
199 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
200 _(GET_NODE_INDEX, get_node_index) \
201 _(ADD_NODE_NEXT, add_node_next) \
202 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
203 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
204 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
205 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
206 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
207 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
208 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
209 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
210 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
211 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
212 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
213 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
214 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
215 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
216 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
217 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
218 _(IP_ADDRESS_DUMP, ip_address_dump) \
219 _(IP_DUMP, ip_dump) \
220 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
221 _(SHOW_VERSION, show_version) \
222 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
223 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
224 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
225 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
226 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
227 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
228 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
229 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
230 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
231 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
232 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
233 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
234 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
235 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
236 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
237 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
238 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
239 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
240 _(DELETE_LOOPBACK, delete_loopback) \
241 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
242 _(MAP_ADD_DOMAIN, map_add_domain) \
243 _(MAP_DEL_DOMAIN, map_del_domain) \
244 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
245 _(MAP_DOMAIN_DUMP, map_domain_dump) \
246 _(MAP_RULE_DUMP, map_rule_dump) \
247 _(MAP_SUMMARY_STATS, map_summary_stats) \
248 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
249 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
250 _(GET_NODE_GRAPH, get_node_graph) \
251 _(IOAM_ENABLE, ioam_enable) \
252 _(IOAM_DISABLE, ioam_disable) \
253 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
254 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
255 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
256 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
257 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
258 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
259 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
260 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
261 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
262 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
263 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
264 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
265 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
266 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
267 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
268 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
269 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
270 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
271 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
272 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
273 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
274 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
275 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
276 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
277 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
278 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
279 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
280 _(SHOW_LISP_STATUS, show_lisp_status) \
281 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
282 lisp_add_del_map_request_itr_rlocs) \
283 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
284 _(SHOW_LISP_PITR, show_lisp_pitr) \
285 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
286 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
287 _(AF_PACKET_CREATE, af_packet_create) \
288 _(AF_PACKET_DELETE, af_packet_delete) \
289 _(POLICER_ADD_DEL, policer_add_del) \
290 _(POLICER_DUMP, policer_dump) \
291 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
292 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
293 _(NETMAP_CREATE, netmap_create) \
294 _(NETMAP_DELETE, netmap_delete) \
295 _(MPLS_TUNNEL_DUMP, mpls_tunnel_dump) \
296 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
297 _(MPLS_FIB_DUMP, mpls_fib_dump) \
298 _(MPLS_FIB_DETAILS, mpls_fib_details) \
299 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
300 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
301 _(CLASSIFY_TABLE_INFO,classify_table_info) \
302 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
303 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
304 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
305 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
306 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
307 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
308 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
309 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
310 _(SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable) \
311 _(SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump) \
312 _(GET_NEXT_INDEX, get_next_index) \
313 _(PG_CREATE_INTERFACE, pg_create_interface) \
314 _(PG_CAPTURE, pg_capture) \
315 _(PG_ENABLE_DISABLE, pg_enable_disable) \
316 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
317 ip_source_and_port_range_check_add_del) \
318 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
319 ip_source_and_port_range_check_interface_add_del) \
320 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
321 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
322 _(DELETE_SUBIF, delete_subif) \
323 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
325 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
326 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
327 _(IPSEC_SPD_DUMP, ipsec_spd_dump) \
328 _(IP_FIB_DUMP, ip_fib_dump) \
329 _(IP_FIB_DETAILS, ip_fib_details) \
330 _(IP6_FIB_DUMP, ip6_fib_dump) \
331 _(IP6_FIB_DETAILS, ip6_fib_details) \
332 _(FEATURE_ENABLE_DISABLE, feature_enable_disable) \
333 _(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \
334 _(IP_NEIGHBOR_DETAILS, ip_neighbor_details)
337 #define QUOTE(x) QUOTE_(x)
341 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
342 RESOLVE_IP6_ADD_DEL_ROUTE,
345 static vlib_node_registration_t vpe_resolver_process_node;
346 vpe_api_main_t vpe_api_main;
348 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
349 unix_shared_memory_queue_t * q,
352 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
353 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
356 /* Clean up all registrations belonging to the indicated client */
358 vl_api_memclnt_delete_callback (u32 client_index)
360 vpe_api_main_t *vam = &vpe_api_main;
361 vpe_client_registration_t *rp;
363 int stats_memclnt_delete_callback (u32 client_index);
365 stats_memclnt_delete_callback (client_index);
368 p = hash_get (vam->a##_registration_hash, client_index); \
370 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
371 pool_put (vam->a##_registrations, rp); \
372 hash_unset (vam->a##_registration_hash, client_index); \
374 foreach_registration_hash;
379 pub_sub_handler (oam_events, OAM_EVENTS);
381 #define RESOLUTION_EVENT 1
382 #define RESOLUTION_PENDING_EVENT 2
383 #define IP4_ARP_EVENT 3
384 #define IP6_ND_EVENT 4
386 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
388 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
391 handle_ip4_arp_event (u32 pool_index)
393 vpe_api_main_t *vam = &vpe_api_main;
394 vnet_main_t *vnm = vam->vnet_main;
395 vlib_main_t *vm = vam->vlib_main;
396 vl_api_ip4_arp_event_t *event;
397 vl_api_ip4_arp_event_t *mp;
398 unix_shared_memory_queue_t *q;
400 /* Client can cancel, die, etc. */
401 if (pool_is_free_index (vam->arp_events, pool_index))
404 event = pool_elt_at_index (vam->arp_events, pool_index);
406 q = vl_api_client_index_to_input_queue (event->client_index);
409 (void) vnet_add_del_ip4_arp_change_event
410 (vnm, arp_change_delete_callback,
411 event->pid, &event->address,
412 vpe_resolver_process_node.index, IP4_ARP_EVENT,
413 ~0 /* pool index, notused */ , 0 /* is_add */ );
417 if (q->cursize < q->maxsize)
419 mp = vl_msg_api_alloc (sizeof (*mp));
420 clib_memcpy (mp, event, sizeof (*mp));
421 vl_msg_api_send_shmem (q, (u8 *) & mp);
425 static f64 last_time;
427 * Throttle syslog msgs.
428 * It's pretty tempting to just revoke the registration...
430 if (vlib_time_now (vm) > last_time + 10.0)
432 clib_warning ("arp event for %U to pid %d: queue stuffed!",
433 format_ip4_address, &event->address, event->pid);
434 last_time = vlib_time_now (vm);
440 handle_ip6_nd_event (u32 pool_index)
442 vpe_api_main_t *vam = &vpe_api_main;
443 vnet_main_t *vnm = vam->vnet_main;
444 vlib_main_t *vm = vam->vlib_main;
445 vl_api_ip6_nd_event_t *event;
446 vl_api_ip6_nd_event_t *mp;
447 unix_shared_memory_queue_t *q;
449 /* Client can cancel, die, etc. */
450 if (pool_is_free_index (vam->nd_events, pool_index))
453 event = pool_elt_at_index (vam->nd_events, pool_index);
455 q = vl_api_client_index_to_input_queue (event->client_index);
458 (void) vnet_add_del_ip6_nd_change_event
459 (vnm, nd_change_delete_callback,
460 event->pid, &event->address,
461 vpe_resolver_process_node.index, IP6_ND_EVENT,
462 ~0 /* pool index, notused */ , 0 /* is_add */ );
466 if (q->cursize < q->maxsize)
468 mp = vl_msg_api_alloc (sizeof (*mp));
469 clib_memcpy (mp, event, sizeof (*mp));
470 vl_msg_api_send_shmem (q, (u8 *) & mp);
474 static f64 last_time;
476 * Throttle syslog msgs.
477 * It's pretty tempting to just revoke the registration...
479 if (vlib_time_now (vm) > last_time + 10.0)
481 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
482 format_ip6_address, &event->address, event->pid);
483 last_time = vlib_time_now (vm);
489 resolver_process (vlib_main_t * vm,
490 vlib_node_runtime_t * rt, vlib_frame_t * f)
493 uword *event_data = 0;
499 vlib_process_wait_for_event_or_clock (vm, timeout);
501 event_type = vlib_process_get_events (vm, &event_data);
505 case RESOLUTION_PENDING_EVENT:
509 case RESOLUTION_EVENT:
510 clib_warning ("resolver: BOGUS TYPE");
514 for (i = 0; i < vec_len (event_data); i++)
515 handle_ip4_arp_event (event_data[i]);
519 for (i = 0; i < vec_len (event_data); i++)
520 handle_ip6_nd_event (event_data[i]);
523 case ~0: /* timeout */
527 vec_reset_length (event_data);
529 return 0; /* or not */
533 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
534 .function = resolver_process,
535 .type = VLIB_NODE_TYPE_PROCESS,
536 .name = "vpe-route-resolver-process",
541 add_del_route_t_handler (u8 is_multipath,
548 u32 classify_table_index,
550 u8 is_resolve_attached,
552 const fib_prefix_t * prefix,
553 u8 next_hop_proto_is_ip4,
554 const ip46_address_t * next_hop,
555 u32 next_hop_sw_if_index,
556 u8 next_hop_fib_index,
558 mpls_label_t next_hop_via_label,
559 mpls_label_t * next_hop_out_label_stack)
561 vnet_classify_main_t *cm = &vnet_classify_main;
562 stats_main_t *sm = &stats_main;
563 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
564 fib_route_path_t path = {
565 .frp_proto = (next_hop_proto_is_ip4 ?
566 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6),
567 .frp_addr = (NULL == next_hop ? zero_addr : *next_hop),
568 .frp_sw_if_index = next_hop_sw_if_index,
569 .frp_fib_index = next_hop_fib_index,
570 .frp_weight = next_hop_weight,
571 .frp_label_stack = next_hop_out_label_stack,
573 fib_route_path_t *paths = NULL;
575 if (MPLS_LABEL_INVALID != next_hop_via_label)
577 path.frp_proto = FIB_PROTOCOL_MPLS;
578 path.frp_local_label = next_hop_via_label;
581 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
582 if (is_resolve_attached)
583 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
585 path.frp_flags = path_flags;
589 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
592 vec_add1 (paths, path);
595 fib_table_entry_path_add2 (fib_index,
598 FIB_ENTRY_FLAG_NONE, paths);
600 fib_table_entry_path_remove2 (fib_index,
601 prefix, FIB_SOURCE_API, paths);
608 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
610 if (is_drop || is_local || is_classify || is_unreach || is_prohibit)
613 * special route types that link directly to the adj
617 dpo_id_t dpo = DPO_INVALID;
620 dproto = fib_proto_to_dpo (prefix->fp_proto);
623 ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo);
625 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
627 ip_null_dpo_add_and_lock (dproto,
628 IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo);
629 else if (is_prohibit)
630 ip_null_dpo_add_and_lock (dproto,
631 IP_NULL_ACTION_SEND_ICMP_PROHIBIT,
633 else if (is_classify)
635 if (pool_is_free_index (cm->tables,
636 ntohl (classify_table_index)))
639 return VNET_API_ERROR_NO_SUCH_TABLE;
642 dpo_set (&dpo, DPO_CLASSIFY, dproto,
643 classify_dpo_create (dproto,
644 ntohl (classify_table_index)));
649 return VNET_API_ERROR_NO_SUCH_TABLE;
652 fib_table_entry_special_dpo_update (fib_index,
655 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
660 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
667 vec_add1 (paths, path);
668 fib_table_entry_update (fib_index,
670 FIB_SOURCE_API, FIB_ENTRY_FLAG_NONE, paths);
675 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
684 add_del_route_check (fib_protocol_t table_proto,
686 u32 next_hop_sw_if_index,
687 fib_protocol_t next_hop_table_proto,
688 u32 next_hop_table_id,
689 u8 create_missing_tables,
690 u32 * fib_index, u32 * next_hop_fib_index)
692 vnet_main_t *vnm = vnet_get_main ();
694 *fib_index = fib_table_find (table_proto, ntohl (table_id));
695 if (~0 == *fib_index)
697 if (create_missing_tables)
699 *fib_index = fib_table_find_or_create_and_lock (table_proto,
704 /* No such VRF, and we weren't asked to create one */
705 return VNET_API_ERROR_NO_SUCH_FIB;
709 if (~0 != ntohl (next_hop_sw_if_index))
711 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
712 ntohl (next_hop_sw_if_index)))
714 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
719 *next_hop_fib_index = fib_table_find (next_hop_table_proto,
720 ntohl (next_hop_table_id));
722 if (~0 == *next_hop_fib_index)
724 if (create_missing_tables)
726 *next_hop_fib_index =
727 fib_table_find_or_create_and_lock (next_hop_table_proto,
728 ntohl (next_hop_table_id));
732 /* No such VRF, and we weren't asked to create one */
733 return VNET_API_ERROR_NO_SUCH_FIB;
742 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
744 u32 fib_index, next_hop_fib_index;
745 mpls_label_t *label_stack = NULL;
746 int rv, ii, n_labels;;
748 rv = add_del_route_check (FIB_PROTOCOL_IP4,
750 mp->next_hop_sw_if_index,
752 mp->next_hop_table_id,
753 mp->create_vrf_if_needed,
754 &fib_index, &next_hop_fib_index);
760 .fp_len = mp->dst_address_length,
761 .fp_proto = FIB_PROTOCOL_IP4,
763 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
766 memset (&nh, 0, sizeof (nh));
767 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
769 n_labels = mp->next_hop_n_out_labels;
772 else if (1 == n_labels)
773 vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0]));
776 vec_validate (label_stack, n_labels - 1);
777 for (ii = 0; ii < n_labels; ii++)
778 label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]);
781 return (add_del_route_t_handler (mp->is_multipath,
788 mp->classify_table_index,
790 mp->is_resolve_attached,
793 ntohl (mp->next_hop_sw_if_index),
796 ntohl (mp->next_hop_via_label),
801 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
803 u32 fib_index, next_hop_fib_index;
804 mpls_label_t *label_stack = NULL;
805 int rv, ii, n_labels;;
807 rv = add_del_route_check (FIB_PROTOCOL_IP6,
809 mp->next_hop_sw_if_index,
811 mp->next_hop_table_id,
812 mp->create_vrf_if_needed,
813 &fib_index, &next_hop_fib_index);
819 .fp_len = mp->dst_address_length,
820 .fp_proto = FIB_PROTOCOL_IP6,
822 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
825 memset (&nh, 0, sizeof (nh));
826 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
828 n_labels = mp->next_hop_n_out_labels;
831 else if (1 == n_labels)
832 vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0]));
835 vec_validate (label_stack, n_labels - 1);
836 for (ii = 0; ii < n_labels; ii++)
837 label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]);
840 return (add_del_route_t_handler (mp->is_multipath,
847 mp->classify_table_index,
849 mp->is_resolve_attached,
851 &nh, ntohl (mp->next_hop_sw_if_index),
854 ntohl (mp->next_hop_via_label),
859 mpls_route_add_del_t_handler (vnet_main_t * vnm,
860 vl_api_mpls_route_add_del_t * mp)
862 u32 fib_index, next_hop_fib_index;
863 mpls_label_t *label_stack = NULL;
864 int rv, ii, n_labels;;
868 .fp_proto = FIB_PROTOCOL_MPLS,
869 .fp_eos = mp->mr_eos,
870 .fp_label = ntohl (mp->mr_label),
874 if (mp->mr_next_hop_proto_is_ip4)
876 pfx.fp_payload_proto = DPO_PROTO_IP4;
880 pfx.fp_payload_proto = DPO_PROTO_IP6;
885 pfx.fp_payload_proto = DPO_PROTO_MPLS;
888 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
890 mp->mr_next_hop_sw_if_index,
891 dpo_proto_to_fib (pfx.fp_payload_proto),
892 mp->mr_next_hop_table_id,
893 mp->mr_create_table_if_needed,
894 &fib_index, &next_hop_fib_index);
900 memset (&nh, 0, sizeof (nh));
902 if (mp->mr_next_hop_proto_is_ip4)
903 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
905 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
907 n_labels = mp->mr_next_hop_n_out_labels;
910 else if (1 == n_labels)
911 vec_add1 (label_stack, ntohl (mp->mr_next_hop_out_label_stack[0]));
914 vec_validate (label_stack, n_labels - 1);
915 for (ii = 0; ii < n_labels; ii++)
916 label_stack[ii] = ntohl (mp->mr_next_hop_out_label_stack[ii]);
919 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
920 0, // mp->is_unreach,
921 0, // mp->is_prohibit,
924 mp->mr_classify_table_index,
925 mp->mr_is_resolve_host,
926 mp->mr_is_resolve_attached,
928 mp->mr_next_hop_proto_is_ip4,
929 &nh, ntohl (mp->mr_next_hop_sw_if_index),
931 mp->mr_next_hop_weight,
932 ntohl (mp->mr_next_hop_via_label),
937 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
939 vl_api_ip_add_del_route_reply_t *rmp;
941 vnet_main_t *vnm = vnet_get_main ();
946 rv = ip6_add_del_route_t_handler (mp);
948 rv = ip4_add_del_route_t_handler (mp);
950 rv = (rv == 0) ? vnm->api_errno : rv;
952 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
956 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
958 vl_api_mpls_route_add_del_reply_t *rmp;
962 vnm = vnet_get_main ();
965 rv = mpls_route_add_del_t_handler (vnm, mp);
967 rv = (rv == 0) ? vnm->api_errno : rv;
969 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
973 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
974 vl_api_mpls_ip_bind_unbind_t * mp)
976 u32 mpls_fib_index, ip_fib_index;
979 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
981 if (~0 == mpls_fib_index)
983 if (mp->mb_create_table_if_needed)
986 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
987 ntohl (mp->mb_mpls_table_id));
990 return VNET_API_ERROR_NO_SUCH_FIB;
993 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
996 ntohl (mp->mb_ip_table_id));
997 if (~0 == ip_fib_index)
998 return VNET_API_ERROR_NO_SUCH_FIB;
1000 fib_prefix_t pfx = {
1001 .fp_len = mp->mb_address_length,
1006 pfx.fp_proto = FIB_PROTOCOL_IP4;
1007 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
1008 sizeof (pfx.fp_addr.ip4));
1012 pfx.fp_proto = FIB_PROTOCOL_IP6;
1013 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
1014 sizeof (pfx.fp_addr.ip6));
1018 fib_table_entry_local_label_add (ip_fib_index, &pfx,
1019 ntohl (mp->mb_label));
1021 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
1022 ntohl (mp->mb_label));
1028 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
1030 vl_api_mpls_route_add_del_reply_t *rmp;
1034 vnm = vnet_get_main ();
1037 rv = mpls_ip_bind_unbind_handler (vnm, mp);
1039 rv = (rv == 0) ? vnm->api_errno : rv;
1041 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1045 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1047 vl_api_sw_interface_set_vpath_reply_t *rmp;
1049 u32 sw_if_index = ntohl (mp->sw_if_index);
1051 VALIDATE_SW_IF_INDEX (mp);
1053 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1054 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
1055 sw_if_index, mp->enable, 0, 0);
1056 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
1057 sw_if_index, mp->enable, 0, 0);
1058 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
1059 sw_if_index, mp->enable, 0, 0);
1060 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
1061 sw_if_index, mp->enable, 0, 0);
1063 BAD_SW_IF_INDEX_LABEL;
1065 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1069 vl_api_sw_interface_set_vxlan_bypass_t_handler
1070 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
1072 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
1074 u32 sw_if_index = ntohl (mp->sw_if_index);
1076 VALIDATE_SW_IF_INDEX (mp);
1080 /* not yet implemented */
1083 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
1084 sw_if_index, mp->enable, 0, 0);
1086 BAD_SW_IF_INDEX_LABEL;
1088 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
1092 vl_api_sw_interface_set_l2_xconnect_t_handler
1093 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1095 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1097 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1098 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1099 vlib_main_t *vm = vlib_get_main ();
1100 vnet_main_t *vnm = vnet_get_main ();
1102 VALIDATE_RX_SW_IF_INDEX (mp);
1106 VALIDATE_TX_SW_IF_INDEX (mp);
1107 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1108 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1112 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1115 BAD_RX_SW_IF_INDEX_LABEL;
1116 BAD_TX_SW_IF_INDEX_LABEL;
1118 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1122 vl_api_sw_interface_set_l2_bridge_t_handler
1123 (vl_api_sw_interface_set_l2_bridge_t * mp)
1125 bd_main_t *bdm = &bd_main;
1126 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1128 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1129 u32 bd_id = ntohl (mp->bd_id);
1133 vlib_main_t *vm = vlib_get_main ();
1134 vnet_main_t *vnm = vnet_get_main ();
1136 VALIDATE_RX_SW_IF_INDEX (mp);
1138 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1142 //VALIDATE_TX_SW_IF_INDEX(mp);
1143 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1144 rx_sw_if_index, bd_index, bvi, shg, 0);
1148 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1151 BAD_RX_SW_IF_INDEX_LABEL;
1153 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1157 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1158 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1160 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1164 dpdk_main_t *dm = &dpdk_main;
1167 u32 sw_if_index = ntohl (mp->sw_if_index);
1168 u32 subport = ntohl (mp->subport);
1169 u32 pipe = ntohl (mp->pipe);
1170 u32 profile = ntohl (mp->profile);
1171 vnet_hw_interface_t *hw;
1173 VALIDATE_SW_IF_INDEX (mp);
1175 /* hw_if & dpdk device */
1176 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1178 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1180 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1182 BAD_SW_IF_INDEX_LABEL;
1184 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1185 rv = VNET_API_ERROR_UNIMPLEMENTED;
1188 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1192 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1193 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1195 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1199 dpdk_main_t *dm = &dpdk_main;
1201 struct rte_sched_subport_params p;
1203 u32 sw_if_index = ntohl (mp->sw_if_index);
1204 u32 subport = ntohl (mp->subport);
1205 p.tb_rate = ntohl (mp->tb_rate);
1206 p.tb_size = ntohl (mp->tb_size);
1207 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1208 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1209 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1210 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1211 p.tc_period = ntohl (mp->tc_period);
1213 vnet_hw_interface_t *hw;
1215 VALIDATE_SW_IF_INDEX (mp);
1217 /* hw_if & dpdk device */
1218 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1220 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1222 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1224 BAD_SW_IF_INDEX_LABEL;
1227 ("setting HQoS subport parameters without DPDK not implemented");
1228 rv = VNET_API_ERROR_UNIMPLEMENTED;
1231 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1235 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1236 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1238 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1242 dpdk_main_t *dm = &dpdk_main;
1243 vlib_thread_main_t *tm = vlib_get_thread_main ();
1246 u32 sw_if_index = ntohl (mp->sw_if_index);
1247 u32 entry = ntohl (mp->entry);
1248 u32 tc = ntohl (mp->tc);
1249 u32 queue = ntohl (mp->queue);
1252 vnet_hw_interface_t *hw;
1254 VALIDATE_SW_IF_INDEX (mp);
1256 /* hw_if & dpdk device */
1257 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1259 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1261 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1263 clib_warning ("invalid traffic class !!");
1264 rv = VNET_API_ERROR_INVALID_VALUE;
1267 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1269 clib_warning ("invalid queue !!");
1270 rv = VNET_API_ERROR_INVALID_VALUE;
1274 /* Detect the set of worker threads */
1275 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1279 clib_warning ("worker thread registration AWOL !!");
1280 rv = VNET_API_ERROR_INVALID_VALUE_2;
1284 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1285 int worker_thread_first = tr->first_index;
1286 int worker_thread_count = tr->count;
1288 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1289 for (i = 0; i < worker_thread_count; i++)
1290 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1292 BAD_SW_IF_INDEX_LABEL;
1295 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1296 rv = VNET_API_ERROR_UNIMPLEMENTED;
1299 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1303 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1305 vlib_main_t *vm = vlib_get_main ();
1306 bd_main_t *bdm = &bd_main;
1307 vl_api_bridge_domain_add_del_reply_t *rmp;
1309 u32 enable_flags = 0, disable_flags = 0;
1310 u32 bd_id = ntohl (mp->bd_id);
1315 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1318 enable_flags |= L2_FLOOD;
1320 disable_flags |= L2_FLOOD;
1323 enable_flags |= L2_UU_FLOOD;
1325 disable_flags |= L2_UU_FLOOD;
1328 enable_flags |= L2_FWD;
1330 disable_flags |= L2_FWD;
1333 enable_flags |= L2_ARP_TERM;
1335 disable_flags |= L2_ARP_TERM;
1338 enable_flags |= L2_LEARN;
1340 disable_flags |= L2_LEARN;
1343 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1346 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1350 rv = bd_delete_bd_index (bdm, bd_id);
1352 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1356 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1358 clib_warning ("BUG");
1362 vl_api_bridge_domain_sw_if_details_t_handler
1363 (vl_api_bridge_domain_sw_if_details_t * mp)
1365 clib_warning ("BUG");
1369 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1370 l2_bridge_domain_t * bd_config,
1371 u32 n_sw_ifs, u32 context)
1373 vl_api_bridge_domain_details_t *mp;
1375 mp = vl_msg_api_alloc (sizeof (*mp));
1376 memset (mp, 0, sizeof (*mp));
1377 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1378 mp->bd_id = ntohl (bd_config->bd_id);
1379 mp->flood = bd_feature_flood (bd_config);
1380 mp->uu_flood = bd_feature_uu_flood (bd_config);
1381 mp->forward = bd_feature_forward (bd_config);
1382 mp->learn = bd_feature_learn (bd_config);
1383 mp->arp_term = bd_feature_arp_term (bd_config);
1384 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1385 mp->n_sw_ifs = ntohl (n_sw_ifs);
1386 mp->context = context;
1388 vl_msg_api_send_shmem (q, (u8 *) & mp);
1392 send_bd_sw_if_details (l2input_main_t * l2im,
1393 unix_shared_memory_queue_t * q,
1394 l2_flood_member_t * member, u32 bd_id, u32 context)
1396 vl_api_bridge_domain_sw_if_details_t *mp;
1397 l2_input_config_t *input_cfg;
1399 mp = vl_msg_api_alloc (sizeof (*mp));
1400 memset (mp, 0, sizeof (*mp));
1401 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1402 mp->bd_id = ntohl (bd_id);
1403 mp->sw_if_index = ntohl (member->sw_if_index);
1404 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1405 mp->shg = input_cfg->shg;
1406 mp->context = context;
1408 vl_msg_api_send_shmem (q, (u8 *) & mp);
1412 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1414 bd_main_t *bdm = &bd_main;
1415 l2input_main_t *l2im = &l2input_main;
1416 unix_shared_memory_queue_t *q;
1417 l2_bridge_domain_t *bd_config;
1418 u32 bd_id, bd_index;
1421 q = vl_api_client_index_to_input_queue (mp->client_index);
1426 bd_id = ntohl (mp->bd_id);
1428 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1429 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1430 for (; bd_index < end; bd_index++)
1432 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1433 /* skip dummy bd_id 0 */
1434 if (bd_config && (bd_config->bd_id > 0))
1437 l2_flood_member_t *m;
1439 n_sw_ifs = vec_len (bd_config->members);
1440 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1442 vec_foreach (m, bd_config->members)
1444 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1451 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1453 bd_main_t *bdm = &bd_main;
1454 l2input_main_t *l2im = &l2input_main;
1455 vl_api_l2fib_add_del_reply_t *rmp;
1458 u32 sw_if_index = ntohl (mp->sw_if_index);
1459 u32 bd_id = ntohl (mp->bd_id);
1468 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1471 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1472 goto bad_sw_if_index;
1478 filter_mac = mp->filter_mac ? 1 : 0;
1479 if (filter_mac == 0)
1481 VALIDATE_SW_IF_INDEX (mp);
1482 if (vec_len (l2im->configs) <= sw_if_index)
1484 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1485 goto bad_sw_if_index;
1489 l2_input_config_t *config;
1490 config = vec_elt_at_index (l2im->configs, sw_if_index);
1491 if (config->bridge == 0)
1493 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1494 goto bad_sw_if_index;
1498 static_mac = mp->static_mac ? 1 : 0;
1499 bvi_mac = mp->bvi_mac ? 1 : 0;
1500 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1505 l2fib_del_entry (mac, bd_index);
1508 BAD_SW_IF_INDEX_LABEL;
1510 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1514 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1516 vl_api_l2_flags_reply_t *rmp;
1518 u32 sw_if_index = ntohl (mp->sw_if_index);
1519 u32 flags = ntohl (mp->feature_bitmap);
1522 VALIDATE_SW_IF_INDEX (mp);
1525 if (flags & L2INPUT_FEAT_ ## a) \
1526 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1527 foreach_l2input_feat;
1530 BAD_SW_IF_INDEX_LABEL;
1533 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1535 rmp->resulting_feature_bitmap = ntohl(rbm);
1541 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1543 vlib_main_t *vm = vlib_get_main ();
1544 bd_main_t *bdm = &bd_main;
1545 vl_api_bridge_flags_reply_t *rmp;
1547 u32 bd_id = ntohl (mp->bd_id);
1549 u32 flags = ntohl (mp->feature_bitmap);
1552 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1555 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1561 bd_set_flags (vm, bd_index, flags, mp->is_set);
1565 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1567 rmp->resulting_feature_bitmap = ntohl(flags);
1573 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1575 bd_main_t *bdm = &bd_main;
1576 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1578 u32 bd_id = ntohl (mp->bd_id);
1582 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1585 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1590 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1591 mp->mac_address, mp->is_ipv6, mp->is_add))
1592 rv = VNET_API_ERROR_UNSPECIFIED;
1595 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1599 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp)
1601 vlib_main_t *vm = vlib_get_main ();
1603 vl_api_tap_connect_reply_t *rmp;
1604 vnet_main_t *vnm = vnet_get_main ();
1605 unix_shared_memory_queue_t *q;
1606 u32 sw_if_index = (u32) ~ 0;
1609 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1610 mp->use_random_mac ? 0 : mp->mac_address,
1611 &sw_if_index, mp->renumber,
1612 ntohl (mp->custom_dev_instance));
1614 /* Add tag if supplied */
1615 if (rv == 0 && mp->tag[0])
1617 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
1618 tag = format (0, "%s%c", mp->tag, 0);
1619 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1622 q = vl_api_client_index_to_input_queue (mp->client_index);
1626 rmp = vl_msg_api_alloc (sizeof (*rmp));
1627 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1628 rmp->context = mp->context;
1629 rmp->retval = ntohl (rv);
1630 rmp->sw_if_index = ntohl (sw_if_index);
1632 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1636 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp)
1639 vl_api_tap_modify_reply_t *rmp;
1640 unix_shared_memory_queue_t *q;
1641 u32 sw_if_index = (u32) ~ 0;
1642 vlib_main_t *vm = vlib_get_main ();
1644 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1645 mp->use_random_mac ? 0 : mp->mac_address,
1646 &sw_if_index, mp->renumber,
1647 ntohl (mp->custom_dev_instance));
1649 q = vl_api_client_index_to_input_queue (mp->client_index);
1653 rmp = vl_msg_api_alloc (sizeof (*rmp));
1654 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1655 rmp->context = mp->context;
1656 rmp->retval = ntohl (rv);
1657 rmp->sw_if_index = ntohl (sw_if_index);
1659 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1663 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp)
1665 vlib_main_t *vm = vlib_get_main ();
1667 vpe_api_main_t *vam = &vpe_api_main;
1668 vl_api_tap_delete_reply_t *rmp;
1669 unix_shared_memory_queue_t *q;
1670 u32 sw_if_index = ntohl (mp->sw_if_index);
1672 rv = vnet_tap_delete (vm, sw_if_index);
1675 vnet_main_t *vnm = vnet_get_main ();
1676 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1679 q = vl_api_client_index_to_input_queue (mp->client_index);
1683 rmp = vl_msg_api_alloc (sizeof (*rmp));
1684 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1685 rmp->context = mp->context;
1686 rmp->retval = ntohl (rv);
1688 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1691 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1695 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1697 vl_api_create_vlan_subif_reply_t *rmp;
1698 vnet_main_t *vnm = vnet_get_main ();
1699 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1700 vnet_hw_interface_t *hi;
1703 vnet_sw_interface_t template;
1705 vnet_interface_main_t *im = &vnm->interface_main;
1706 u64 sup_and_sub_key;
1708 unix_shared_memory_queue_t *q;
1709 clib_error_t *error;
1711 VALIDATE_SW_IF_INDEX (mp);
1713 hw_if_index = ntohl (mp->sw_if_index);
1714 hi = vnet_get_hw_interface (vnm, hw_if_index);
1716 id = ntohl (mp->vlan_id);
1717 if (id == 0 || id > 4095)
1719 rv = VNET_API_ERROR_INVALID_VLAN;
1723 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1725 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1728 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1732 kp = clib_mem_alloc (sizeof (*kp));
1733 *kp = sup_and_sub_key;
1735 memset (&template, 0, sizeof (template));
1736 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1737 template.sup_sw_if_index = hi->sw_if_index;
1738 template.sub.id = id;
1739 template.sub.eth.raw_flags = 0;
1740 template.sub.eth.flags.one_tag = 1;
1741 template.sub.eth.outer_vlan_id = id;
1742 template.sub.eth.flags.exact_match = 1;
1744 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1747 clib_error_report (error);
1748 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1751 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1752 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1754 BAD_SW_IF_INDEX_LABEL;
1757 q = vl_api_client_index_to_input_queue (mp->client_index);
1761 rmp = vl_msg_api_alloc (sizeof (*rmp));
1762 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1763 rmp->context = mp->context;
1764 rmp->retval = ntohl (rv);
1765 rmp->sw_if_index = ntohl (sw_if_index);
1766 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1770 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1772 vl_api_create_subif_reply_t *rmp;
1773 vnet_main_t *vnm = vnet_get_main ();
1774 u32 sw_if_index = ~0;
1777 vnet_sw_interface_t *si;
1778 vnet_hw_interface_t *hi;
1779 vnet_sw_interface_t template;
1781 vnet_interface_main_t *im = &vnm->interface_main;
1782 u64 sup_and_sub_key;
1784 clib_error_t *error;
1786 VALIDATE_SW_IF_INDEX (mp);
1788 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1789 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1791 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1793 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1797 sw_if_index = si->sw_if_index;
1798 sub_id = ntohl (mp->sub_id);
1800 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1802 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1806 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1807 sw_if_index, sub_id);
1808 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1812 kp = clib_mem_alloc (sizeof (*kp));
1813 *kp = sup_and_sub_key;
1815 memset (&template, 0, sizeof (template));
1816 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1817 template.sup_sw_if_index = sw_if_index;
1818 template.sub.id = sub_id;
1819 template.sub.eth.flags.no_tags = mp->no_tags;
1820 template.sub.eth.flags.one_tag = mp->one_tag;
1821 template.sub.eth.flags.two_tags = mp->two_tags;
1822 template.sub.eth.flags.dot1ad = mp->dot1ad;
1823 template.sub.eth.flags.exact_match = mp->exact_match;
1824 template.sub.eth.flags.default_sub = mp->default_sub;
1825 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1826 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1827 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1828 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1830 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1833 clib_error_report (error);
1834 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1838 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1839 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1841 BAD_SW_IF_INDEX_LABEL;
1846 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1848 rmp->sw_if_index = ntohl(sw_if_index);
1854 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
1856 vl_api_mpls_tunnel_add_del_reply_t *rmp;
1858 stats_main_t *sm = &stats_main;
1859 u32 tunnel_sw_if_index;
1862 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1866 fib_route_path_t rpath, *rpaths = NULL;
1867 mpls_label_t *label_stack = NULL;
1869 memset (&rpath, 0, sizeof (rpath));
1871 if (mp->mt_next_hop_proto_is_ip4)
1873 rpath.frp_proto = FIB_PROTOCOL_IP4;
1874 clib_memcpy (&rpath.frp_addr.ip4,
1875 mp->mt_next_hop, sizeof (rpath.frp_addr.ip4));
1879 rpath.frp_proto = FIB_PROTOCOL_IP6;
1880 clib_memcpy (&rpath.frp_addr.ip6,
1881 mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
1883 rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
1885 for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
1886 vec_add1 (label_stack, ntohl (mp->mt_next_hop_out_label_stack[ii]));
1888 vec_add1 (rpaths, rpath);
1890 vnet_mpls_tunnel_add (rpaths, label_stack,
1891 mp->mt_l2_only, &tunnel_sw_if_index);
1893 vec_free (label_stack);
1897 tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
1898 vnet_mpls_tunnel_del (tunnel_sw_if_index);
1904 REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
1906 rmp->sw_if_index = ntohl(tunnel_sw_if_index);
1912 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
1914 vl_api_proxy_arp_add_del_reply_t *rmp;
1917 ip4_main_t *im = &ip4_main;
1918 stats_main_t *sm = &stats_main;
1919 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
1920 ip4_address_t * hi_addr,
1921 u32 fib_index, int is_del);
1924 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
1926 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1930 rv = VNET_API_ERROR_NO_SUCH_FIB;
1936 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
1937 (ip4_address_t *) mp->hi_address,
1938 fib_index, mp->is_add == 0);
1942 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
1946 vl_api_proxy_arp_intfc_enable_disable_t_handler
1947 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
1950 vnet_main_t *vnm = vnet_get_main ();
1951 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
1952 vnet_sw_interface_t *si;
1955 VALIDATE_SW_IF_INDEX (mp);
1957 sw_if_index = ntohl (mp->sw_if_index);
1959 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1961 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1965 si = vnet_get_sw_interface (vnm, sw_if_index);
1969 if (mp->enable_disable)
1970 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1972 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1974 BAD_SW_IF_INDEX_LABEL;
1977 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
1981 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
1984 vl_api_ip_neighbor_add_del_reply_t *rmp;
1985 vnet_main_t *vnm = vnet_get_main ();
1986 stats_main_t *sm = &stats_main;
1989 VALIDATE_SW_IF_INDEX (mp);
1991 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
1994 * there's no validation here of the ND/ARP entry being added.
1995 * The expectation is that the FIB will ensure that nothing bad
1996 * will come of adding bogus entries.
2001 rv = vnet_set_ip6_ethernet_neighbor
2002 (vm, ntohl (mp->sw_if_index),
2003 (ip6_address_t *) (mp->dst_address),
2004 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2006 rv = vnet_unset_ip6_ethernet_neighbor
2007 (vm, ntohl (mp->sw_if_index),
2008 (ip6_address_t *) (mp->dst_address),
2009 mp->mac_address, sizeof (mp->mac_address));
2013 ethernet_arp_ip4_over_ethernet_address_t a;
2015 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2016 clib_memcpy (&a.ip4, mp->dst_address, 4);
2019 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2023 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2026 BAD_SW_IF_INDEX_LABEL;
2029 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2033 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2036 vpe_main_t *rm = &vpe_main;
2037 ip4_main_t *im4 = &ip4_main;
2038 ip6_main_t *im6 = &ip6_main;
2039 ip_lookup_main_t *lm;
2045 u32 adj_index, sw_if_index;
2046 vl_api_is_address_reachable_t *rmp;
2047 ip_adjacency_t *adj;
2048 unix_shared_memory_queue_t *q;
2050 q = vl_api_client_index_to_input_queue (mp->client_index);
2053 increment_missing_api_client_counter (rm->vlib_main);
2057 rmp = vl_msg_api_alloc (sizeof (*rmp));
2058 clib_memcpy (rmp, mp, sizeof (*rmp));
2060 sw_if_index = mp->next_hop_sw_if_index;
2061 clib_memcpy (&addr, mp->address, sizeof (addr));
2064 lm = &im6->lookup_main;
2065 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2069 lm = &im4->lookup_main;
2071 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2073 if (adj_index == ~0)
2078 adj = ip_get_adjacency (lm, adj_index);
2080 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2081 && adj->rewrite_header.sw_if_index == sw_if_index)
2087 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2088 && adj->rewrite_header.sw_if_index == sw_if_index)
2091 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2093 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2095 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2104 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2109 vl_api_sw_interface_set_mpls_enable_t_handler
2110 (vl_api_sw_interface_set_mpls_enable_t * mp)
2112 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2115 VALIDATE_SW_IF_INDEX (mp);
2117 mpls_sw_interface_enable_disable (&mpls_main,
2118 ntohl (mp->sw_if_index), mp->enable);
2120 BAD_SW_IF_INDEX_LABEL;
2121 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2124 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2125 unix_shared_memory_queue_t * q,
2127 __attribute__ ((unused));
2130 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2131 unix_shared_memory_queue_t * q,
2134 vl_api_sw_interface_set_flags_t *mp;
2136 mp = vl_msg_api_alloc (sizeof (*mp));
2137 memset (mp, 0, sizeof (*mp));
2138 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2139 mp->sw_if_index = ntohl (sw_if_index);
2141 mp->admin_up_down = 0;
2142 mp->link_up_down = 0;
2144 vl_msg_api_send_shmem (q, (u8 *) & mp);
2148 send_oam_event (oam_target_t * t)
2150 vpe_api_main_t *vam = &vpe_api_main;
2151 unix_shared_memory_queue_t *q;
2152 vpe_client_registration_t *reg;
2153 vl_api_oam_event_t *mp;
2156 pool_foreach(reg, vam->oam_events_registrations,
2158 q = vl_api_client_index_to_input_queue (reg->client_index);
2161 mp = vl_msg_api_alloc (sizeof (*mp));
2162 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2163 clib_memcpy (mp->dst_address, &t->dst_address,
2164 sizeof (mp->dst_address));
2165 mp->state = t->state;
2166 vl_msg_api_send_shmem (q, (u8 *)&mp);
2173 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2175 vl_api_oam_add_del_reply_t *rmp;
2178 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2179 (ip4_address_t *) mp->dst_address,
2180 ntohl (mp->vrf_id), (int) (mp->is_add));
2182 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2186 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2188 stats_main_t *sm = &stats_main;
2189 vnet_interface_main_t *im = sm->interface_main;
2190 vl_api_vnet_summary_stats_reply_t *rmp;
2191 vlib_combined_counter_main_t *cm;
2194 u64 total_pkts[VLIB_N_RX_TX];
2195 u64 total_bytes[VLIB_N_RX_TX];
2197 unix_shared_memory_queue_t *q =
2198 vl_api_client_index_to_input_queue (mp->client_index);
2203 rmp = vl_msg_api_alloc (sizeof (*rmp));
2204 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2205 rmp->context = mp->context;
2208 memset (total_pkts, 0, sizeof (total_pkts));
2209 memset (total_bytes, 0, sizeof (total_bytes));
2211 vnet_interface_counter_lock (im);
2213 vec_foreach (cm, im->combined_sw_if_counters)
2215 which = cm - im->combined_sw_if_counters;
2217 for (i = 0; i < vec_len (cm->maxi); i++)
2219 vlib_get_combined_counter (cm, i, &v);
2220 total_pkts[which] += v.packets;
2221 total_bytes[which] += v.bytes;
2224 vnet_interface_counter_unlock (im);
2226 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2227 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2228 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2229 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2231 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2233 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2237 typedef CLIB_PACKED (struct {
2238 ip4_address_t address;
2239 u32 address_length: 6;
2245 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2247 vnet_main_t *vnm = vnet_get_main ();
2248 vnet_interface_main_t *im = &vnm->interface_main;
2249 ip4_main_t *im4 = &ip4_main;
2250 static u32 *sw_if_indices_to_shut;
2251 stats_main_t *sm = &stats_main;
2252 fib_table_t *fib_table;
2256 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2257 u32 target_fib_id = ntohl (mp->vrf_id);
2259 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2262 pool_foreach (fib_table, im4->fibs,
2264 fib = &fib_table->v4;
2265 vnet_sw_interface_t * si;
2267 if (fib->table_id != target_fib_id)
2270 /* remove any mpls encap/decap labels */
2271 mpls_fib_reset_labels (fib->table_id);
2273 /* remove any proxy arps in this fib */
2274 vnet_proxy_arp_fib_reset (fib->table_id);
2276 /* Set the flow hash for this fib to the default */
2277 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2279 vec_reset_length (sw_if_indices_to_shut);
2281 /* Shut down interfaces in this FIB / clean out intfc routes */
2282 pool_foreach (si, im->sw_interfaces,
2284 u32 sw_if_index = si->sw_if_index;
2286 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2287 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2289 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2292 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2293 sw_if_index = sw_if_indices_to_shut[i];
2294 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2296 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2297 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2298 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2301 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
2302 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
2306 })); /* pool_foreach (fib) */
2314 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2316 vnet_main_t *vnm = vnet_get_main ();
2317 vnet_interface_main_t *im = &vnm->interface_main;
2318 ip6_main_t *im6 = &ip6_main;
2319 stats_main_t *sm = &stats_main;
2320 static u32 *sw_if_indices_to_shut;
2321 fib_table_t *fib_table;
2325 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2326 u32 target_fib_id = ntohl (mp->vrf_id);
2328 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
2331 pool_foreach (fib_table, im6->fibs,
2333 vnet_sw_interface_t * si;
2334 fib = &(fib_table->v6);
2336 if (fib->table_id != target_fib_id)
2339 vec_reset_length (sw_if_indices_to_shut);
2341 /* Shut down interfaces in this FIB / clean out intfc routes */
2342 pool_foreach (si, im->sw_interfaces,
2344 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2346 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2349 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2350 sw_if_index = sw_if_indices_to_shut[i];
2351 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2353 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2354 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2355 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2358 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
2359 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
2363 })); /* pool_foreach (fib) */
2371 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2374 vl_api_reset_fib_reply_t *rmp;
2377 rv = ip6_reset_fib_t_handler (mp);
2379 rv = ip4_reset_fib_t_handler (mp);
2381 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
2386 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2388 vl_api_dhcp_proxy_config_reply_t *rmp;
2391 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
2392 (ip4_address_t *) (&mp->dhcp_src_address),
2393 (u32) ntohl (mp->vrf_id),
2394 (int) mp->insert_circuit_id,
2395 (int) (mp->is_add == 0));
2397 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2402 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2404 vl_api_dhcp_proxy_config_reply_t *rmp;
2407 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
2408 (ip6_address_t *) (&mp->dhcp_src_address),
2409 (u32) ntohl (mp->vrf_id),
2410 (int) mp->insert_circuit_id,
2411 (int) (mp->is_add == 0));
2413 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2417 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2419 vl_api_dhcp_proxy_config_reply_t *rmp;
2422 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
2423 (ip4_address_t *) (&mp->dhcp_src_address),
2424 (u32) ntohl (mp->rx_vrf_id),
2425 (u32) ntohl (mp->server_vrf_id),
2426 (int) mp->insert_circuit_id,
2427 (int) (mp->is_add == 0));
2429 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2434 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2436 vl_api_dhcp_proxy_config_reply_t *rmp;
2439 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
2440 (ip6_address_t *) (&mp->dhcp_src_address),
2441 (u32) ntohl (mp->rx_vrf_id),
2442 (u32) ntohl (mp->server_vrf_id),
2443 (int) mp->insert_circuit_id,
2444 (int) (mp->is_add == 0));
2446 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2451 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
2453 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2456 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
2459 (int) mp->is_add == 0);
2461 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
2463 ntohl (mp->fib_id), (int) mp->is_add == 0);
2465 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
2469 static void vl_api_dhcp_proxy_config_t_handler
2470 (vl_api_dhcp_proxy_config_t * mp)
2472 if (mp->is_ipv6 == 0)
2473 dhcpv4_proxy_config (mp);
2475 dhcpv6_proxy_config (mp);
2478 static void vl_api_dhcp_proxy_config_2_t_handler
2479 (vl_api_dhcp_proxy_config_2_t * mp)
2481 if (mp->is_ipv6 == 0)
2482 dhcpv4_proxy_config_2 (mp);
2484 dhcpv6_proxy_config_2 (mp);
2488 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2489 u8 is_ipv6, u8 * host_address, u8 * router_address,
2492 unix_shared_memory_queue_t *q;
2493 vl_api_dhcp_compl_event_t *mp;
2495 q = vl_api_client_index_to_input_queue (client_index);
2499 mp = vl_msg_api_alloc (sizeof (*mp));
2500 mp->client_index = client_index;
2502 mp->is_ipv6 = is_ipv6;
2503 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
2504 mp->hostname[vec_len (hostname) + 1] = '\n';
2505 clib_memcpy (&mp->host_address[0], host_address, 16);
2506 clib_memcpy (&mp->router_address[0], router_address, 16);
2508 if (NULL != host_mac)
2509 clib_memcpy (&mp->host_mac[0], host_mac, 6);
2511 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2513 vl_msg_api_send_shmem (q, (u8 *) & mp);
2516 static void vl_api_dhcp_client_config_t_handler
2517 (vl_api_dhcp_client_config_t * mp)
2519 vlib_main_t *vm = vlib_get_main ();
2520 vl_api_dhcp_client_config_reply_t *rmp;
2523 VALIDATE_SW_IF_INDEX (mp);
2525 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
2526 mp->hostname, mp->is_add, mp->client_index,
2527 mp->want_dhcp_event ? dhcp_compl_event_callback :
2530 BAD_SW_IF_INDEX_LABEL;
2532 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
2536 vl_api_sw_interface_ip6nd_ra_config_t_handler
2537 (vl_api_sw_interface_ip6nd_ra_config_t * mp)
2539 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
2540 vlib_main_t *vm = vlib_get_main ();
2542 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
2545 is_no = mp->is_no == 1;
2546 suppress = mp->suppress == 1;
2547 managed = mp->managed == 1;
2548 other = mp->other == 1;
2549 ll_option = mp->ll_option == 1;
2550 send_unicast = mp->send_unicast == 1;
2551 cease = mp->cease == 1;
2552 default_router = mp->default_router == 1;
2554 VALIDATE_SW_IF_INDEX (mp);
2556 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
2557 suppress, managed, other,
2558 ll_option, send_unicast, cease,
2559 default_router, ntohl (mp->lifetime),
2560 ntohl (mp->initial_count),
2561 ntohl (mp->initial_interval),
2562 ntohl (mp->max_interval),
2563 ntohl (mp->min_interval), is_no);
2565 BAD_SW_IF_INDEX_LABEL;
2567 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2571 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2572 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp)
2574 vlib_main_t *vm = vlib_get_main ();
2575 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
2577 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
2579 VALIDATE_SW_IF_INDEX (mp);
2581 is_no = mp->is_no == 1;
2582 use_default = mp->use_default == 1;
2583 no_advertise = mp->no_advertise == 1;
2584 off_link = mp->off_link == 1;
2585 no_autoconfig = mp->no_autoconfig == 1;
2586 no_onlink = mp->no_onlink == 1;
2588 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
2589 (ip6_address_t *) mp->address,
2590 mp->address_length, use_default,
2591 ntohl (mp->val_lifetime),
2592 ntohl (mp->pref_lifetime), no_advertise,
2593 off_link, no_autoconfig, no_onlink, is_no);
2595 BAD_SW_IF_INDEX_LABEL;
2596 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
2600 vl_api_sw_interface_ip6_enable_disable_t_handler
2601 (vl_api_sw_interface_ip6_enable_disable_t * mp)
2603 vlib_main_t *vm = vlib_get_main ();
2604 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
2605 vnet_main_t *vnm = vnet_get_main ();
2607 clib_error_t *error;
2611 VALIDATE_SW_IF_INDEX (mp);
2614 (mp->enable == 1) ? enable_ip6_interface (vm,
2615 ntohl (mp->sw_if_index)) :
2616 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
2620 clib_error_report (error);
2621 rv = VNET_API_ERROR_UNSPECIFIED;
2625 rv = vnm->api_errno;
2628 BAD_SW_IF_INDEX_LABEL;
2630 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
2634 vl_api_sw_interface_ip6_set_link_local_address_t_handler
2635 (vl_api_sw_interface_ip6_set_link_local_address_t * mp)
2637 vlib_main_t *vm = vlib_get_main ();
2638 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
2640 clib_error_t *error;
2641 vnet_main_t *vnm = vnet_get_main ();
2645 VALIDATE_SW_IF_INDEX (mp);
2647 error = set_ip6_link_local_address (vm,
2648 ntohl (mp->sw_if_index),
2649 (ip6_address_t *) mp->address,
2650 mp->address_length);
2653 clib_error_report (error);
2654 rv = VNET_API_ERROR_UNSPECIFIED;
2658 rv = vnm->api_errno;
2661 BAD_SW_IF_INDEX_LABEL;
2663 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
2667 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
2669 vl_api_set_ip_flow_hash_reply_t *rmp;
2670 int rv = VNET_API_ERROR_UNIMPLEMENTED;
2672 clib_warning ("unimplemented...");
2674 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
2678 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
2680 vl_api_set_ip_flow_hash_reply_t *rmp;
2683 flow_hash_config_t flow_hash_config = 0;
2685 table_id = ntohl (mp->vrf_id);
2687 #define _(a,b) if (mp->a) flow_hash_config |= b;
2688 foreach_flow_hash_bit;
2691 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
2693 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
2698 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
2700 if (mp->is_ipv6 == 0)
2701 set_ip4_flow_hash (mp);
2703 set_ip6_flow_hash (mp);
2707 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
2709 vl_api_create_loopback_reply_t *rmp;
2713 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
2716 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
2718 rmp->sw_if_index = ntohl (sw_if_index);
2724 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
2726 vl_api_delete_loopback_reply_t *rmp;
2730 sw_if_index = ntohl (mp->sw_if_index);
2731 rv = vnet_delete_loopback_interface (sw_if_index);
2733 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
2737 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
2739 vl_api_control_ping_reply_t *rmp;
2743 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
2745 rmp->vpe_pid = ntohl (getpid());
2751 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2753 u8 **shmem_vecp = (u8 **) arg;
2756 api_main_t *am = &api_main;
2759 shmem_vec = *shmem_vecp;
2761 offset = vec_len (shmem_vec);
2763 pthread_mutex_lock (&am->vlib_rp->mutex);
2764 oldheap = svm_push_data_heap (am->vlib_rp);
2766 vec_validate (shmem_vec, offset + buffer_bytes - 1);
2768 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
2770 svm_pop_heap (oldheap);
2771 pthread_mutex_unlock (&am->vlib_rp->mutex);
2773 *shmem_vecp = shmem_vec;
2778 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
2780 vl_api_cli_reply_t *rp;
2781 unix_shared_memory_queue_t *q;
2782 vlib_main_t *vm = vlib_get_main ();
2783 api_main_t *am = &api_main;
2784 unformat_input_t input;
2788 q = vl_api_client_index_to_input_queue (mp->client_index);
2792 rp = vl_msg_api_alloc (sizeof (*rp));
2793 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
2794 rp->context = mp->context;
2796 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
2798 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
2800 pthread_mutex_lock (&am->vlib_rp->mutex);
2801 oldheap = svm_push_data_heap (am->vlib_rp);
2803 vec_add1 (shmem_vec, 0);
2805 svm_pop_heap (oldheap);
2806 pthread_mutex_unlock (&am->vlib_rp->mutex);
2808 rp->reply_in_shmem = (uword) shmem_vec;
2810 vl_msg_api_send_shmem (q, (u8 *) & rp);
2814 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2816 u8 **mem_vecp = (u8 **) arg;
2817 u8 *mem_vec = *mem_vecp;
2818 u32 offset = vec_len (mem_vec);
2820 vec_validate (mem_vec, offset + buffer_bytes - 1);
2821 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
2822 *mem_vecp = mem_vec;
2826 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
2828 vl_api_cli_inband_reply_t *rmp;
2830 unix_shared_memory_queue_t *q;
2831 vlib_main_t *vm = vlib_get_main ();
2832 unformat_input_t input;
2835 q = vl_api_client_index_to_input_queue (mp->client_index);
2839 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
2840 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
2842 u32 len = vec_len (out_vec);
2844 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
2846 rmp->length = htonl (len);
2847 clib_memcpy (rmp->reply, out_vec, len);
2854 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2857 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2858 vnet_main_t *vnm = vnet_get_main ();
2859 clib_error_t *error;
2864 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2866 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2870 clib_error_report (error);
2871 rv = VNET_API_ERROR_UNSPECIFIED;
2875 rv = vnm->api_errno;
2878 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2881 static void vl_api_sr_tunnel_add_del_t_handler
2882 (vl_api_sr_tunnel_add_del_t * mp)
2885 clib_warning ("unimplemented");
2887 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
2889 vl_api_sr_tunnel_add_del_reply_t *rmp;
2890 ip6_address_t *segments = 0, *seg;
2891 ip6_address_t *tags = 0, *tag;
2892 ip6_address_t *this_address;
2895 if (mp->n_segments == 0)
2901 memset (a, 0, sizeof (*a));
2902 a->src_address = (ip6_address_t *) & mp->src_address;
2903 a->dst_address = (ip6_address_t *) & mp->dst_address;
2904 a->dst_mask_width = mp->dst_mask_width;
2905 a->flags_net_byte_order = mp->flags_net_byte_order;
2906 a->is_del = (mp->is_add == 0);
2907 a->rx_table_id = ntohl (mp->outer_vrf_id);
2908 a->tx_table_id = ntohl (mp->inner_vrf_id);
2910 a->name = format (0, "%s", mp->name);
2911 if (!(vec_len (a->name)))
2914 a->policy_name = format (0, "%s", mp->policy_name);
2915 if (!(vec_len (a->policy_name)))
2918 /* Yank segments and tags out of the API message */
2919 this_address = (ip6_address_t *) mp->segs_and_tags;
2920 for (i = 0; i < mp->n_segments; i++)
2922 vec_add2 (segments, seg, 1);
2923 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
2926 for (i = 0; i < mp->n_tags; i++)
2928 vec_add2 (tags, tag, 1);
2929 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
2933 a->segments = segments;
2936 rv = ip6_sr_add_del_tunnel (a);
2940 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
2944 static void vl_api_sr_policy_add_del_t_handler
2945 (vl_api_sr_policy_add_del_t * mp)
2948 clib_warning ("unimplemented");
2950 ip6_sr_add_del_policy_args_t _a, *a = &_a;
2952 vl_api_sr_policy_add_del_reply_t *rmp;
2955 memset (a, 0, sizeof (*a));
2956 a->is_del = (mp->is_add == 0);
2958 a->name = format (0, "%s", mp->name);
2959 if (!(vec_len (a->name)))
2961 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2965 if (!(mp->tunnel_names[0]))
2967 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2971 // start deserializing tunnel_names
2972 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
2973 u8 *deser_tun_names = mp->tunnel_names;
2974 deser_tun_names += 1; //moving along
2977 int tun_name_len = 0;
2979 for (i = 0; i < num_tunnels; i++)
2981 tun_name_len = *deser_tun_names;
2982 deser_tun_names += 1;
2983 vec_resize (tun_name, tun_name_len);
2984 memcpy (tun_name, deser_tun_names, tun_name_len);
2985 vec_add1 (a->tunnel_names, tun_name);
2986 deser_tun_names += tun_name_len;
2990 rv = ip6_sr_add_del_policy (a);
2994 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
2998 static void vl_api_sr_multicast_map_add_del_t_handler
2999 (vl_api_sr_multicast_map_add_del_t * mp)
3002 clib_warning ("unimplemented");
3004 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3006 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3008 memset (a, 0, sizeof (*a));
3009 a->is_del = (mp->is_add == 0);
3011 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3012 a->policy_name = format (0, "%s", mp->policy_name);
3014 if (a->multicast_address == 0)
3020 if (!(a->policy_name))
3026 #if DPDK > 0 /* Cannot call replicate without DPDK */
3027 rv = ip6_sr_add_del_multicastmap (a);
3029 clib_warning ("multicast replication without DPDK not implemented");
3030 rv = VNET_API_ERROR_UNIMPLEMENTED;
3035 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3039 #define foreach_classify_add_del_table_field \
3044 _(match_n_vectors) \
3045 _(next_table_index) \
3046 _(miss_next_index) \
3047 _(current_data_flag) \
3048 _(current_data_offset)
3050 static void vl_api_classify_add_del_table_t_handler
3051 (vl_api_classify_add_del_table_t * mp)
3053 vl_api_classify_add_del_table_reply_t *rmp;
3054 vnet_classify_main_t *cm = &vnet_classify_main;
3055 vnet_classify_table_t *t;
3059 foreach_classify_add_del_table_field;
3062 #define _(a) a = ntohl(mp->a);
3063 foreach_classify_add_del_table_field;
3066 /* The underlying API fails silently, on purpose, so check here */
3067 if (mp->is_add == 0) /* delete */
3069 if (pool_is_free_index (cm->tables, table_index))
3071 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3075 else /* add or update */
3077 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
3081 rv = vnet_classify_add_del_table
3082 (cm, mp->mask, nbuckets, memory_size,
3083 skip_n_vectors, match_n_vectors,
3084 next_table_index, miss_next_index, &table_index,
3085 current_data_flag, current_data_offset, mp->is_add);
3089 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3091 if (rv == 0 && mp->is_add)
3093 t = pool_elt_at_index (cm->tables, table_index);
3094 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3095 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3096 rmp->new_table_index = ntohl(table_index);
3100 rmp->skip_n_vectors = ~0;
3101 rmp->match_n_vectors = ~0;
3102 rmp->new_table_index = ~0;
3108 static void vl_api_classify_add_del_session_t_handler
3109 (vl_api_classify_add_del_session_t * mp)
3111 vnet_classify_main_t *cm = &vnet_classify_main;
3112 vl_api_classify_add_del_session_reply_t *rmp;
3114 u32 table_index, hit_next_index, opaque_index, metadata;
3118 table_index = ntohl (mp->table_index);
3119 hit_next_index = ntohl (mp->hit_next_index);
3120 opaque_index = ntohl (mp->opaque_index);
3121 advance = ntohl (mp->advance);
3122 action = mp->action;
3123 metadata = ntohl (mp->metadata);
3125 rv = vnet_classify_add_del_session
3126 (cm, table_index, mp->match, hit_next_index, opaque_index,
3127 advance, action, metadata, mp->is_add);
3129 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3132 static void vl_api_classify_set_interface_ip_table_t_handler
3133 (vl_api_classify_set_interface_ip_table_t * mp)
3135 vlib_main_t *vm = vlib_get_main ();
3136 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3138 u32 table_index, sw_if_index;
3140 table_index = ntohl (mp->table_index);
3141 sw_if_index = ntohl (mp->sw_if_index);
3143 VALIDATE_SW_IF_INDEX (mp);
3146 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3148 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3150 BAD_SW_IF_INDEX_LABEL;
3152 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3155 static void vl_api_classify_set_interface_l2_tables_t_handler
3156 (vl_api_classify_set_interface_l2_tables_t * mp)
3158 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3160 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3163 ip4_table_index = ntohl (mp->ip4_table_index);
3164 ip6_table_index = ntohl (mp->ip6_table_index);
3165 other_table_index = ntohl (mp->other_table_index);
3166 sw_if_index = ntohl (mp->sw_if_index);
3168 VALIDATE_SW_IF_INDEX (mp);
3171 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
3175 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
3181 if (ip4_table_index != ~0 || ip6_table_index != ~0
3182 || other_table_index != ~0)
3188 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
3190 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
3193 BAD_SW_IF_INDEX_LABEL;
3195 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3199 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3202 vl_api_l2_fib_clear_table_reply_t *rmp;
3204 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3205 * that is not currently implemented. When that TODO is fixed
3206 * this call should be changed to pass 1 instead of 0.
3208 l2fib_clear_table (0);
3210 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3213 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3214 u32 sw_if_index, u32 enable);
3217 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3221 vl_api_l2_interface_efp_filter_reply_t *rmp;
3222 vnet_main_t *vnm = vnet_get_main ();
3224 // enable/disable the feature
3225 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3226 rv = vnm->api_errno;
3228 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3232 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3233 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3236 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3237 vnet_main_t *vnm = vnet_get_main ();
3238 vlib_main_t *vm = vlib_get_main ();
3241 VALIDATE_SW_IF_INDEX (mp);
3243 vtr_op = ntohl (mp->vtr_op);
3245 /* The L2 code is unsuspicious */
3248 case L2_VTR_DISABLED:
3253 case L2_VTR_TRANSLATE_1_1:
3254 case L2_VTR_TRANSLATE_1_2:
3255 case L2_VTR_TRANSLATE_2_1:
3256 case L2_VTR_TRANSLATE_2_2:
3260 rv = VNET_API_ERROR_INVALID_VALUE;
3261 goto bad_sw_if_index;
3264 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
3265 ntohl (mp->push_dot1q), ntohl (mp->tag1),
3268 BAD_SW_IF_INDEX_LABEL;
3270 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3274 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
3277 vl_api_create_vhost_user_if_reply_t *rmp;
3278 u32 sw_if_index = (u32) ~ 0;
3279 vnet_main_t *vnm = vnet_get_main ();
3280 vlib_main_t *vm = vlib_get_main ();
3282 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
3283 mp->is_server, &sw_if_index, (u64) ~ 0,
3284 mp->renumber, ntohl (mp->custom_dev_instance),
3285 (mp->use_custom_mac) ? mp->mac_address : NULL);
3287 /* Remember an interface tag for the new interface */
3290 /* If a tag was supplied... */
3293 /* Make sure it's a proper C-string */
3294 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
3295 u8 *tag = format (0, "%s%c", mp->tag, 0);
3296 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
3301 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3303 rmp->sw_if_index = ntohl (sw_if_index);
3309 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
3312 vl_api_modify_vhost_user_if_reply_t *rmp;
3313 u32 sw_if_index = ntohl (mp->sw_if_index);
3315 vnet_main_t *vnm = vnet_get_main ();
3316 vlib_main_t *vm = vlib_get_main ();
3318 rv = vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
3319 mp->is_server, sw_if_index, (u64) ~ 0,
3320 mp->renumber, ntohl (mp->custom_dev_instance));
3322 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
3326 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
3329 vl_api_delete_vhost_user_if_reply_t *rmp;
3330 vpe_api_main_t *vam = &vpe_api_main;
3331 u32 sw_if_index = ntohl (mp->sw_if_index);
3333 vnet_main_t *vnm = vnet_get_main ();
3334 vlib_main_t *vm = vlib_get_main ();
3336 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
3338 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
3341 unix_shared_memory_queue_t *q =
3342 vl_api_client_index_to_input_queue (mp->client_index);
3346 vnet_clear_sw_interface_tag (vnm, sw_if_index);
3347 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3352 vl_api_sw_interface_vhost_user_details_t_handler
3353 (vl_api_sw_interface_vhost_user_details_t * mp)
3355 clib_warning ("BUG");
3359 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3360 unix_shared_memory_queue_t * q,
3361 vhost_user_intf_details_t * vui,
3364 vl_api_sw_interface_vhost_user_details_t *mp;
3366 mp = vl_msg_api_alloc (sizeof (*mp));
3367 memset (mp, 0, sizeof (*mp));
3368 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3369 mp->sw_if_index = ntohl (vui->sw_if_index);
3370 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3371 mp->features = clib_net_to_host_u64 (vui->features);
3372 mp->is_server = vui->is_server;
3373 mp->num_regions = ntohl (vui->num_regions);
3374 mp->sock_errno = ntohl (vui->sock_errno);
3375 mp->context = context;
3377 strncpy ((char *) mp->sock_filename,
3378 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
3379 strncpy ((char *) mp->interface_name,
3380 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
3382 vl_msg_api_send_shmem (q, (u8 *) & mp);
3386 vl_api_sw_interface_vhost_user_dump_t_handler
3387 (vl_api_sw_interface_vhost_user_dump_t * mp)
3390 vpe_api_main_t *am = &vpe_api_main;
3391 vnet_main_t *vnm = vnet_get_main ();
3392 vlib_main_t *vm = vlib_get_main ();
3393 vhost_user_intf_details_t *ifaces = NULL;
3394 vhost_user_intf_details_t *vuid = NULL;
3395 unix_shared_memory_queue_t *q;
3397 q = vl_api_client_index_to_input_queue (mp->client_index);
3401 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
3405 vec_foreach (vuid, ifaces)
3407 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3413 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3414 unix_shared_memory_queue_t * q,
3416 l2t_main_t * lm, u32 context)
3418 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
3420 vnet_sw_interface_t *si = NULL;
3422 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3424 if_name = format (if_name, "%U",
3425 format_vnet_sw_interface_name, lm->vnet_main, si);
3427 mp = vl_msg_api_alloc (sizeof (*mp));
3428 memset (mp, 0, sizeof (*mp));
3429 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3430 strncpy ((char *) mp->interface_name,
3431 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
3432 mp->sw_if_index = ntohl (si->sw_if_index);
3433 mp->local_session_id = s->local_session_id;
3434 mp->remote_session_id = s->remote_session_id;
3435 mp->local_cookie[0] = s->local_cookie[0];
3436 mp->local_cookie[1] = s->local_cookie[1];
3437 mp->remote_cookie = s->remote_cookie;
3438 clib_memcpy (mp->client_address, &s->client_address,
3439 sizeof (s->client_address));
3440 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
3441 mp->l2_sublayer_present = s->l2_sublayer_present;
3442 mp->context = context;
3444 vl_msg_api_send_shmem (q, (u8 *) & mp);
3448 send_ip_address_details (vpe_api_main_t * am,
3449 unix_shared_memory_queue_t * q,
3450 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
3452 vl_api_ip_address_details_t *mp;
3454 mp = vl_msg_api_alloc (sizeof (*mp));
3455 memset (mp, 0, sizeof (*mp));
3456 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
3460 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
3464 u32 *tp = (u32 *) mp->ip;
3467 mp->prefix_length = prefix_length;
3468 mp->context = context;
3470 vl_msg_api_send_shmem (q, (u8 *) & mp);
3474 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
3476 vpe_api_main_t *am = &vpe_api_main;
3477 unix_shared_memory_queue_t *q;
3480 ip6_main_t *im6 = &ip6_main;
3481 ip4_main_t *im4 = &ip4_main;
3482 ip_lookup_main_t *lm6 = &im6->lookup_main;
3483 ip_lookup_main_t *lm4 = &im4->lookup_main;
3484 ip_interface_address_t *ia = 0;
3485 u32 sw_if_index = ~0;
3486 int rv __attribute__ ((unused)) = 0;
3488 VALIDATE_SW_IF_INDEX (mp);
3490 sw_if_index = ntohl (mp->sw_if_index);
3492 q = vl_api_client_index_to_input_queue (mp->client_index);
3501 foreach_ip_interface_address (lm6, ia, sw_if_index,
3502 1 /* honor unnumbered */,
3504 r6 = ip_interface_address_get_address (lm6, ia);
3505 u16 prefix_length = ia->address_length;
3506 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3513 foreach_ip_interface_address (lm4, ia, sw_if_index,
3514 1 /* honor unnumbered */,
3516 r4 = ip_interface_address_get_address (lm4, ia);
3517 u16 prefix_length = ia->address_length;
3518 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3522 BAD_SW_IF_INDEX_LABEL;
3526 send_ip_details (vpe_api_main_t * am,
3527 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
3529 vl_api_ip_details_t *mp;
3531 mp = vl_msg_api_alloc (sizeof (*mp));
3532 memset (mp, 0, sizeof (*mp));
3533 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
3535 mp->sw_if_index = ntohl (sw_if_index);
3536 mp->context = context;
3538 vl_msg_api_send_shmem (q, (u8 *) & mp);
3542 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
3545 vpe_api_main_t *am = &vpe_api_main;
3546 l2t_main_t *lm = &l2t_main;
3547 unix_shared_memory_queue_t *q;
3548 l2t_session_t *session;
3550 q = vl_api_client_index_to_input_queue (mp->client_index);
3555 pool_foreach (session, lm->sessions,
3557 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
3564 send_sw_interface_tap_details (vpe_api_main_t * am,
3565 unix_shared_memory_queue_t * q,
3566 tapcli_interface_details_t * tap_if,
3569 vl_api_sw_interface_tap_details_t *mp;
3570 mp = vl_msg_api_alloc (sizeof (*mp));
3571 memset (mp, 0, sizeof (*mp));
3572 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
3573 mp->sw_if_index = ntohl (tap_if->sw_if_index);
3574 strncpy ((char *) mp->dev_name,
3575 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
3576 mp->context = context;
3578 vl_msg_api_send_shmem (q, (u8 *) & mp);
3582 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
3585 vpe_api_main_t *am = &vpe_api_main;
3586 unix_shared_memory_queue_t *q;
3587 tapcli_interface_details_t *tapifs = NULL;
3588 tapcli_interface_details_t *tap_if = NULL;
3590 q = vl_api_client_index_to_input_queue (mp->client_index);
3594 rv = vnet_tap_dump_ifs (&tapifs);
3598 vec_foreach (tap_if, tapifs)
3600 send_sw_interface_tap_details (am, q, tap_if, mp->context);
3607 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
3609 vpe_api_main_t *am = &vpe_api_main;
3610 vnet_main_t *vnm = vnet_get_main ();
3611 vlib_main_t *vm = vlib_get_main ();
3612 vnet_interface_main_t *im = &vnm->interface_main;
3613 unix_shared_memory_queue_t *q;
3614 vnet_sw_interface_t *si, *sorted_sis;
3615 u32 sw_if_index = ~0;
3617 q = vl_api_client_index_to_input_queue (mp->client_index);
3623 /* Gather interfaces. */
3624 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3625 _vec_len (sorted_sis) = 0;
3627 pool_foreach (si, im->sw_interfaces,
3629 vec_add1 (sorted_sis, si[0]);
3633 vec_foreach (si, sorted_sis)
3635 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
3637 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
3641 sw_if_index = si->sw_if_index;
3642 send_ip_details (am, q, sw_if_index, mp->context);
3648 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
3650 clib_warning ("BUG");
3654 send_l2fib_table_entry (vpe_api_main_t * am,
3655 unix_shared_memory_queue_t * q,
3656 l2fib_entry_key_t * l2fe_key,
3657 l2fib_entry_result_t * l2fe_res, u32 context)
3659 vl_api_l2_fib_table_entry_t *mp;
3661 mp = vl_msg_api_alloc (sizeof (*mp));
3662 memset (mp, 0, sizeof (*mp));
3663 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
3666 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3668 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3669 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
3670 mp->static_mac = l2fe_res->fields.static_mac;
3671 mp->filter_mac = l2fe_res->fields.filter;
3672 mp->bvi_mac = l2fe_res->fields.bvi;
3673 mp->context = context;
3675 vl_msg_api_send_shmem (q, (u8 *) & mp);
3679 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
3681 vpe_api_main_t *am = &vpe_api_main;
3682 bd_main_t *bdm = &bd_main;
3683 l2fib_entry_key_t *l2fe_key = NULL;
3684 l2fib_entry_result_t *l2fe_res = NULL;
3685 u32 ni, bd_id = ntohl (mp->bd_id);
3687 unix_shared_memory_queue_t *q;
3690 q = vl_api_client_index_to_input_queue (mp->client_index);
3694 /* see l2fib_table_dump: ~0 means "any" */
3699 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3706 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3708 vec_foreach_index (ni, l2fe_key)
3710 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
3711 vec_elt_at_index (l2fe_res, ni), mp->context);
3713 vec_free (l2fe_key);
3714 vec_free (l2fe_res);
3718 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
3720 vl_api_show_version_reply_t *rmp;
3722 char *vpe_api_get_build_directory (void);
3723 char *vpe_api_get_version (void);
3724 char *vpe_api_get_build_date (void);
3726 unix_shared_memory_queue_t *q =
3727 vl_api_client_index_to_input_queue (mp->client_index);
3733 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3735 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3736 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3737 ARRAY_LEN(rmp->build_directory)-1);
3738 strncpy ((char *) rmp->version, vpe_api_get_version(),
3739 ARRAY_LEN(rmp->version)-1);
3740 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3741 ARRAY_LEN(rmp->build_date)-1);
3747 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
3749 vlib_main_t *vm = vlib_get_main ();
3750 vl_api_get_node_index_reply_t *rmp;
3753 u32 node_index = ~0;
3755 n = vlib_get_node_by_name (vm, mp->node_name);
3758 rv = VNET_API_ERROR_NO_SUCH_NODE;
3760 node_index = n->index;
3763 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3765 rmp->node_index = ntohl(node_index);
3771 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
3773 vlib_main_t *vm = vlib_get_main ();
3774 vl_api_get_next_index_reply_t *rmp;
3775 vlib_node_t *node, *next_node;
3777 u32 next_node_index = ~0, next_index = ~0;
3780 node = vlib_get_node_by_name (vm, mp->node_name);
3784 rv = VNET_API_ERROR_NO_SUCH_NODE;
3788 next_node = vlib_get_node_by_name (vm, mp->next_name);
3792 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3796 next_node_index = next_node->index;
3798 p = hash_get (node->next_slot_by_node, next_node_index);
3802 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
3810 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
3812 rmp->next_index = ntohl(next_index);
3818 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
3820 vlib_main_t *vm = vlib_get_main ();
3821 vl_api_add_node_next_reply_t *rmp;
3822 vlib_node_t *n, *next;
3824 u32 next_index = ~0;
3826 n = vlib_get_node_by_name (vm, mp->node_name);
3830 rv = VNET_API_ERROR_NO_SUCH_NODE;
3834 next = vlib_get_node_by_name (vm, mp->next_name);
3837 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3839 next_index = vlib_node_add_next (vm, n->index, next->index);
3843 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3845 rmp->next_index = ntohl(next_index);
3850 static void vl_api_l2tpv3_create_tunnel_t_handler
3851 (vl_api_l2tpv3_create_tunnel_t * mp)
3853 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
3854 l2t_main_t *lm = &l2t_main;
3855 u32 sw_if_index = (u32) ~ 0;
3858 if (mp->is_ipv6 != 1)
3860 rv = VNET_API_ERROR_UNIMPLEMENTED;
3864 u32 encap_fib_index;
3866 if (mp->encap_vrf_id != ~0)
3869 ip6_main_t *im = &ip6_main;
3872 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
3874 rv = VNET_API_ERROR_NO_SUCH_FIB;
3877 encap_fib_index = p[0];
3881 encap_fib_index = ~0;
3884 rv = create_l2tpv3_ipv6_tunnel (lm,
3885 (ip6_address_t *) mp->client_address,
3886 (ip6_address_t *) mp->our_address,
3887 ntohl (mp->local_session_id),
3888 ntohl (mp->remote_session_id),
3889 clib_net_to_host_u64 (mp->local_cookie),
3890 clib_net_to_host_u64 (mp->remote_cookie),
3891 mp->l2_sublayer_present,
3892 encap_fib_index, &sw_if_index);
3896 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
3898 rmp->sw_if_index = ntohl (sw_if_index);
3903 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
3904 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
3906 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
3907 l2t_main_t *lm = &l2t_main;
3910 VALIDATE_SW_IF_INDEX (mp);
3912 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
3913 clib_net_to_host_u64 (mp->new_local_cookie),
3914 clib_net_to_host_u64
3915 (mp->new_remote_cookie));
3917 BAD_SW_IF_INDEX_LABEL;
3919 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
3922 static void vl_api_l2tpv3_interface_enable_disable_t_handler
3923 (vl_api_l2tpv3_interface_enable_disable_t * mp)
3926 vnet_main_t *vnm = vnet_get_main ();
3927 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
3929 VALIDATE_SW_IF_INDEX (mp);
3931 rv = l2tpv3_interface_enable_disable
3932 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
3934 BAD_SW_IF_INDEX_LABEL;
3936 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
3939 static void vl_api_l2tpv3_set_lookup_key_t_handler
3940 (vl_api_l2tpv3_set_lookup_key_t * mp)
3943 l2t_main_t *lm = &l2t_main;
3944 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
3946 if (mp->key > L2T_LOOKUP_SESSION_ID)
3948 rv = VNET_API_ERROR_INVALID_VALUE;
3952 lm->lookup_type = mp->key;
3955 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
3958 static void vl_api_vxlan_add_del_tunnel_t_handler
3959 (vl_api_vxlan_add_del_tunnel_t * mp)
3961 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
3963 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
3964 u32 encap_fib_index;
3966 ip4_main_t *im = &ip4_main;
3967 u32 sw_if_index = ~0;
3969 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
3972 rv = VNET_API_ERROR_NO_SUCH_FIB;
3975 encap_fib_index = p[0];
3976 memset (a, 0, sizeof (*a));
3978 a->is_add = mp->is_add;
3979 a->is_ip6 = mp->is_ipv6;
3981 /* ip addresses sent in network byte order */
3982 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
3983 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
3985 /* Check src & dst are different */
3986 if (ip46_address_cmp (&a->dst, &a->src) == 0)
3988 rv = VNET_API_ERROR_SAME_SRC_DST;
3991 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
3992 a->encap_fib_index = encap_fib_index;
3993 a->decap_next_index = ntohl (mp->decap_next_index);
3994 a->vni = ntohl (mp->vni);
3995 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
3999 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4001 rmp->sw_if_index = ntohl (sw_if_index);
4006 static void send_vxlan_tunnel_details
4007 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4009 vl_api_vxlan_tunnel_details_t *rmp;
4010 ip4_main_t *im4 = &ip4_main;
4011 ip6_main_t *im6 = &ip6_main;
4012 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
4014 rmp = vl_msg_api_alloc (sizeof (*rmp));
4015 memset (rmp, 0, sizeof (*rmp));
4016 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4019 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
4020 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
4021 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4025 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
4026 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
4027 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4029 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
4030 rmp->vni = htonl (t->vni);
4031 rmp->decap_next_index = htonl (t->decap_next_index);
4032 rmp->sw_if_index = htonl (t->sw_if_index);
4033 rmp->is_ipv6 = is_ipv6;
4034 rmp->context = context;
4036 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4039 static void vl_api_vxlan_tunnel_dump_t_handler
4040 (vl_api_vxlan_tunnel_dump_t * mp)
4042 unix_shared_memory_queue_t *q;
4043 vxlan_main_t *vxm = &vxlan_main;
4047 q = vl_api_client_index_to_input_queue (mp->client_index);
4053 sw_if_index = ntohl (mp->sw_if_index);
4055 if (~0 == sw_if_index)
4058 pool_foreach (t, vxm->tunnels,
4060 send_vxlan_tunnel_details(t, q, mp->context);
4066 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4067 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4071 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4072 send_vxlan_tunnel_details (t, q, mp->context);
4076 static void vl_api_gre_add_del_tunnel_t_handler
4077 (vl_api_gre_add_del_tunnel_t * mp)
4079 vl_api_gre_add_del_tunnel_reply_t *rmp;
4081 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4084 ip4_main_t *im = &ip4_main;
4085 u32 sw_if_index = ~0;
4087 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4090 rv = VNET_API_ERROR_NO_SUCH_FIB;
4093 outer_fib_id = p[0];
4095 /* Check src & dst are different */
4096 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4097 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4099 rv = VNET_API_ERROR_SAME_SRC_DST;
4102 memset (a, 0, sizeof (*a));
4104 a->is_add = mp->is_add;
4107 /* ip addresses sent in network byte order */
4108 clib_memcpy (&(a->src), mp->src_address, 4);
4109 clib_memcpy (&(a->dst), mp->dst_address, 4);
4111 a->outer_fib_id = outer_fib_id;
4112 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4116 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4118 rmp->sw_if_index = ntohl (sw_if_index);
4123 static void send_gre_tunnel_details
4124 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4126 vl_api_gre_tunnel_details_t *rmp;
4127 ip4_main_t *im = &ip4_main;
4129 rmp = vl_msg_api_alloc (sizeof (*rmp));
4130 memset (rmp, 0, sizeof (*rmp));
4131 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4132 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4133 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4134 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4135 rmp->teb = (GRE_TUNNEL_TYPE_TEB == t->type);
4136 rmp->sw_if_index = htonl (t->sw_if_index);
4137 rmp->context = context;
4139 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4143 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4145 unix_shared_memory_queue_t *q;
4146 gre_main_t *gm = &gre_main;
4150 q = vl_api_client_index_to_input_queue (mp->client_index);
4156 sw_if_index = ntohl (mp->sw_if_index);
4158 if (~0 == sw_if_index)
4161 pool_foreach (t, gm->tunnels,
4163 send_gre_tunnel_details(t, q, mp->context);
4169 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4170 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4174 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4175 send_gre_tunnel_details (t, q, mp->context);
4180 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4182 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4184 vl_api_l2_patch_add_del_reply_t *rmp;
4185 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4189 VALIDATE_RX_SW_IF_INDEX (mp);
4190 VALIDATE_TX_SW_IF_INDEX (mp);
4192 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4193 ntohl (mp->tx_sw_if_index),
4194 (int) (mp->is_add != 0));
4196 BAD_RX_SW_IF_INDEX_LABEL;
4197 BAD_TX_SW_IF_INDEX_LABEL;
4199 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4203 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4204 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4206 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4208 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4209 u32 encap_fib_index, decap_fib_index;
4212 ip4_main_t *im = &ip4_main;
4213 u32 sw_if_index = ~0;
4216 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4219 rv = VNET_API_ERROR_NO_SUCH_FIB;
4222 encap_fib_index = p[0];
4224 protocol = mp->protocol;
4226 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4227 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4229 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4232 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4235 decap_fib_index = p[0];
4239 decap_fib_index = ntohl (mp->decap_vrf_id);
4242 /* Check src & dst are different */
4243 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4244 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
4246 rv = VNET_API_ERROR_SAME_SRC_DST;
4249 memset (a, 0, sizeof (*a));
4251 a->is_add = mp->is_add;
4252 a->is_ip6 = mp->is_ipv6;
4253 /* ip addresses sent in network byte order */
4256 clib_memcpy (&(a->local.ip6), mp->local, 16);
4257 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
4261 clib_memcpy (&(a->local.ip4), mp->local, 4);
4262 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
4264 a->encap_fib_index = encap_fib_index;
4265 a->decap_fib_index = decap_fib_index;
4266 a->protocol = protocol;
4267 a->vni = ntohl (mp->vni);
4268 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4272 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4274 rmp->sw_if_index = ntohl (sw_if_index);
4279 static void send_vxlan_gpe_tunnel_details
4280 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4282 vl_api_vxlan_gpe_tunnel_details_t *rmp;
4283 ip4_main_t *im4 = &ip4_main;
4284 ip6_main_t *im6 = &ip6_main;
4285 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4287 rmp = vl_msg_api_alloc (sizeof (*rmp));
4288 memset (rmp, 0, sizeof (*rmp));
4289 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4292 memcpy (rmp->local, &(t->local.ip6), 16);
4293 memcpy (rmp->remote, &(t->remote.ip6), 16);
4294 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4295 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
4299 memcpy (rmp->local, &(t->local.ip4), 4);
4300 memcpy (rmp->remote, &(t->remote.ip4), 4);
4301 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4302 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
4304 rmp->vni = htonl (t->vni);
4305 rmp->protocol = t->protocol;
4306 rmp->sw_if_index = htonl (t->sw_if_index);
4307 rmp->is_ipv6 = is_ipv6;
4308 rmp->context = context;
4310 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4313 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4314 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4316 unix_shared_memory_queue_t *q;
4317 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
4318 vxlan_gpe_tunnel_t *t;
4321 q = vl_api_client_index_to_input_queue (mp->client_index);
4327 sw_if_index = ntohl (mp->sw_if_index);
4329 if (~0 == sw_if_index)
4332 pool_foreach (t, vgm->tunnels,
4334 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4340 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
4341 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
4345 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4346 send_vxlan_gpe_tunnel_details (t, q, mp->context);
4350 /** Used for transferring locators via VPP API */
4352 typedef CLIB_PACKED (struct {
4353 u32 sw_if_index; /**< locator sw_if_index */
4354 u8 priority; /**< locator priority */
4355 u8 weight; /**< locator weight */
4360 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
4363 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4365 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4367 ls_locator_t *ls_loc;
4368 u32 ls_index = ~0, locator_num;
4369 u8 *locator_name = NULL;
4372 memset (a, 0, sizeof (a[0]));
4374 locator_name = format (0, "%s", mp->locator_set_name);
4376 a->name = locator_name;
4377 a->is_add = mp->is_add;
4379 locator_num = clib_net_to_host_u32 (mp->locator_num);
4381 memset (&locator, 0, sizeof (locator));
4382 for (i = 0; i < locator_num; i++)
4384 ls_loc = &((ls_locator_t *) mp->locators)[i];
4385 VALIDATE_SW_IF_INDEX (ls_loc);
4387 locator.sw_if_index = htonl (ls_loc->sw_if_index);
4388 locator.priority = ls_loc->priority;
4389 locator.weight = ls_loc->weight;
4391 vec_add1 (a->locators, locator);
4394 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
4396 BAD_SW_IF_INDEX_LABEL;
4398 vec_free (locator_name);
4399 vec_free (a->locators);
4402 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
4404 rmp->ls_index = clib_host_to_net_u32 (ls_index);
4410 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
4412 vl_api_lisp_add_del_locator_reply_t *rmp;
4414 locator_t locator, *locators = NULL;
4415 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4417 u8 *locator_name = NULL;
4419 memset (&locator, 0, sizeof (locator));
4420 memset (a, 0, sizeof (a[0]));
4422 locator.sw_if_index = ntohl (mp->sw_if_index);
4423 locator.priority = mp->priority;
4424 locator.weight = mp->weight;
4426 vec_add1 (locators, locator);
4428 locator_name = format (0, "%s", mp->locator_set_name);
4430 a->name = locator_name;
4431 a->locators = locators;
4432 a->is_add = mp->is_add;
4435 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
4437 vec_free (locators);
4438 vec_free (locator_name);
4440 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4444 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
4450 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
4451 gid_address_ip_set (dst, src, IP4);
4452 gid_address_ippref_len (dst) = len;
4453 ip_prefix_normalize (&gid_address_ippref (dst));
4456 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
4457 gid_address_ip_set (dst, src, IP6);
4458 gid_address_ippref_len (dst) = len;
4459 ip_prefix_normalize (&gid_address_ippref (dst));
4461 case 2: /* l2 mac */
4462 gid_address_type (dst) = GID_ADDR_MAC;
4463 clib_memcpy (&gid_address_mac (dst), src, 6);
4467 return VNET_API_ERROR_INVALID_VALUE;
4470 gid_address_vni (dst) = vni;
4476 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
4478 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4479 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4481 gid_address_t _eid, *eid = &_eid;
4483 u32 locator_set_index = ~0, map_index = ~0;
4484 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4485 u8 *name = NULL, *key = NULL;
4486 memset (a, 0, sizeof (a[0]));
4487 memset (eid, 0, sizeof (eid[0]));
4489 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4490 mp->eid_type, mp->eid, mp->prefix_len);
4494 name = format (0, "%s", mp->locator_set_name);
4495 p = hash_get_mem (lcm->locator_set_index_by_name, name);
4498 rv = VNET_API_ERROR_INVALID_VALUE;
4501 locator_set_index = p[0];
4504 key = format (0, "%s", mp->key);
4506 /* XXX treat batch configuration */
4507 a->is_add = mp->is_add;
4508 gid_address_copy (&a->eid, eid);
4509 a->locator_set_index = locator_set_index;
4512 a->key_id = clib_net_to_host_u16 (mp->key_id);
4514 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
4519 gid_address_free (&a->eid);
4521 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4525 vl_api_lisp_eid_table_add_del_map_t_handler
4526 (vl_api_lisp_eid_table_add_del_map_t * mp)
4528 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4530 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4531 clib_net_to_host_u32 (mp->dp_table),
4532 mp->is_l2, mp->is_add);
4533 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
4535 /** Used for transferring locators via VPP API */
4537 typedef CLIB_PACKED (struct {
4538 u8 is_ip4; /**< is locator an IPv4 address */
4539 u8 priority; /**< locator priority */
4540 u8 weight; /**< locator weight */
4541 u8 addr[16]; /**< IPv4/IPv6 address */
4545 static locator_pair_t *
4546 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
4549 locator_pair_t *pairs = 0, pair;
4552 for (i = 0; i < rloc_num; i++)
4555 r = &((rloc_t *) lcl_locs)[i];
4556 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
4557 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
4559 /* remote locators */
4560 r = &((rloc_t *) rmt_locs)[i];
4561 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
4562 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
4564 pair.priority = r->priority;
4565 pair.weight = r->weight;
4567 vec_add1 (pairs, pair);
4573 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
4576 locator_t *locs = 0, loc;
4579 for (i = 0; i < rloc_num; i++)
4581 /* remote locators */
4582 r = &((rloc_t *) rmt_locs)[i];
4583 memset (&loc, 0, sizeof (loc));
4584 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
4586 loc.priority = r->priority;
4587 loc.weight = r->weight;
4589 vec_add1 (locs, loc);
4595 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
4596 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
4598 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4599 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
4600 locator_pair_t *pairs = 0;
4603 memset (a, 0, sizeof (a[0]));
4605 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
4606 mp->rmt_eid, mp->rmt_len);
4607 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
4608 mp->lcl_eid, mp->lcl_len);
4610 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
4612 if (rv || 0 == pairs)
4615 a->is_add = mp->is_add;
4616 a->locator_pairs = pairs;
4617 a->dp_table = mp->dp_table;
4619 a->action = mp->action;
4621 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
4624 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4628 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
4631 vl_api_lisp_add_del_map_server_reply_t *rmp;
4635 memset (&addr, 0, sizeof (addr));
4637 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
4638 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
4640 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
4644 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
4647 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4649 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
4651 memset (a, 0, sizeof (a[0]));
4653 a->is_add = mp->is_add;
4654 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
4656 rv = vnet_lisp_add_del_map_resolver (a);
4658 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4662 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
4665 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4667 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
4669 a->is_en = mp->is_en;
4670 vnet_lisp_gpe_enable_disable (a);
4672 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4676 vl_api_lisp_map_register_enable_disable_t_handler
4677 (vl_api_lisp_map_register_enable_disable_t * mp)
4679 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
4682 vnet_lisp_map_register_enable_disable (mp->is_enabled);
4683 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4687 vl_api_lisp_rloc_probe_enable_disable_t_handler
4688 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
4690 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
4693 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
4694 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4698 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
4700 vl_api_lisp_enable_disable_reply_t *rmp;
4703 vnet_lisp_enable_disable (mp->is_en);
4704 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4708 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
4710 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4718 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
4722 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
4729 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
4733 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
4736 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4740 vl_api_show_lisp_map_request_mode_t_handler
4741 (vl_api_show_lisp_map_request_mode_t * mp)
4744 vl_api_show_lisp_map_request_mode_reply_t *rmp;
4747 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
4749 rmp->mode = vnet_lisp_get_map_request_mode ();
4755 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
4757 vl_api_lisp_map_request_mode_reply_t *rmp;
4760 rv = vnet_lisp_set_map_request_mode (mp->mode);
4762 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
4766 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
4769 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4773 ls_name = format (0, "%s", mp->ls_name);
4774 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4777 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4781 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
4782 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
4784 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
4786 u8 *locator_set_name = NULL;
4787 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
4789 locator_set_name = format (0, "%s", mp->locator_set_name);
4791 a->is_add = mp->is_add;
4792 a->locator_set_name = locator_set_name;
4794 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
4796 vec_free (locator_set_name);
4798 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
4802 vl_api_lisp_add_del_remote_mapping_t_handler
4803 (vl_api_lisp_add_del_remote_mapping_t * mp)
4805 locator_t *rlocs = 0;
4806 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
4808 gid_address_t _eid, *eid = &_eid;
4809 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
4811 memset (eid, 0, sizeof (eid[0]));
4813 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4814 mp->eid_type, mp->eid, mp->eid_len);
4818 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
4822 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
4823 gid_address_copy (&a->reid, eid);
4825 rv = vnet_lisp_add_del_adjacency (a);
4832 /* NOTE: for now this works as a static remote mapping, i.e.,
4833 * not authoritative and ttl infinite. */
4834 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
4835 mp->is_add, 1 /* is_static */ , 0);
4838 vnet_lisp_clear_all_remote_adjacencies ();
4843 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
4847 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
4849 vl_api_lisp_add_del_adjacency_reply_t *rmp;
4850 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
4853 memset (a, 0, sizeof (a[0]));
4855 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
4856 mp->eid_type, mp->leid, mp->leid_len);
4857 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
4858 mp->eid_type, mp->reid, mp->reid_len);
4863 a->is_add = mp->is_add;
4864 rv = vnet_lisp_add_del_adjacency (a);
4867 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
4871 send_lisp_locator_details (lisp_cp_main_t * lcm,
4873 unix_shared_memory_queue_t * q, u32 context)
4875 vl_api_lisp_locator_details_t *rmp;
4877 rmp = vl_msg_api_alloc (sizeof (*rmp));
4878 memset (rmp, 0, sizeof (*rmp));
4879 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
4880 rmp->context = context;
4882 rmp->local = loc->local;
4885 rmp->sw_if_index = ntohl (loc->sw_if_index);
4889 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
4890 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
4892 rmp->priority = loc->priority;
4893 rmp->weight = loc->weight;
4895 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4899 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
4902 unix_shared_memory_queue_t *q = 0;
4903 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4904 locator_set_t *lsit = 0;
4906 u32 ls_index = ~0, *locit = 0;
4909 q = vl_api_client_index_to_input_queue (mp->client_index);
4915 if (mp->is_index_set)
4916 ls_index = htonl (mp->ls_index);
4919 /* make sure we get a proper C-string */
4920 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
4921 ls_name = format (0, "%s", mp->ls_name);
4922 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
4928 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
4931 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
4933 vec_foreach (locit, lsit->locator_indices)
4935 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4936 send_lisp_locator_details (lcm, loc, q, mp->context);
4943 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
4944 locator_set_t * lsit,
4945 unix_shared_memory_queue_t * q,
4946 u32 context, u32 ls_index)
4948 vl_api_lisp_locator_set_details_t *rmp;
4951 rmp = vl_msg_api_alloc (sizeof (*rmp));
4952 memset (rmp, 0, sizeof (*rmp));
4953 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
4954 rmp->context = context;
4956 rmp->ls_index = htonl (ls_index);
4959 ASSERT (lsit->name != NULL);
4960 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
4961 vec_len (lsit->name));
4965 str = format (0, "<remote-%d>", ls_index);
4966 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
4970 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4974 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
4976 unix_shared_memory_queue_t *q = NULL;
4977 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4978 locator_set_t *lsit = NULL;
4981 q = vl_api_client_index_to_input_queue (mp->client_index);
4987 filter = mp->filter;
4989 pool_foreach (lsit, lcm->locator_set_pool,
4991 if (filter && !((1 == filter && lsit->local) ||
4992 (2 == filter && !lsit->local)))
4996 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
4997 lsit - lcm->locator_set_pool);
5003 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5005 ASSERT (prefix_length);
5006 ip_prefix_t *ippref = &fid_addr_ippref (src);
5008 switch (fid_addr_type (src))
5010 case FID_ADDR_IP_PREF:
5011 if (ip_prefix_version (ippref) == IP4)
5012 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5014 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5015 prefix_length[0] = ip_prefix_len (ippref);
5019 prefix_length[0] = 0;
5020 clib_memcpy (dst, fid_addr_mac (src), 6);
5024 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5030 fid_type_to_api_type (fid_address_t * fid)
5032 ip_prefix_t *ippref;
5034 switch (fid_addr_type (fid))
5036 case FID_ADDR_IP_PREF:
5037 ippref = &fid_addr_ippref (fid);
5038 if (ip_prefix_version (ippref) == IP4)
5040 else if (ip_prefix_version (ippref) == IP6)
5053 send_lisp_eid_table_details (mapping_t * mapit,
5054 unix_shared_memory_queue_t * q,
5055 u32 context, u8 filter)
5058 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5059 locator_set_t *ls = 0;
5060 vl_api_lisp_eid_table_details_t *rmp = NULL;
5061 gid_address_t *gid = NULL;
5063 ip_prefix_t *ip_prefix = NULL;
5067 case 0: /* all mappings */
5070 case 1: /* local only */
5074 case 2: /* remote only */
5079 clib_warning ("Filter error, unknown filter: %d", filter);
5084 ip_prefix = &gid_address_ippref (gid);
5085 mac = gid_address_mac (gid);
5087 rmp = vl_msg_api_alloc (sizeof (*rmp));
5088 memset (rmp, 0, sizeof (*rmp));
5089 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5091 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5092 if (vec_len (ls->locator_indices) == 0)
5093 rmp->locator_set_index = ~0;
5095 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5097 rmp->is_local = mapit->local;
5098 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5099 rmp->action = mapit->action;
5100 rmp->authoritative = mapit->authoritative;
5102 switch (gid_address_type (gid))
5104 case GID_ADDR_SRC_DST:
5105 rmp->is_src_dst = 1;
5106 fid = &gid_address_sd_src (gid);
5107 rmp->eid_type = fid_type_to_api_type (fid);
5108 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5109 &rmp->seid_prefix_len);
5110 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5111 &rmp->eid_prefix_len);
5113 case GID_ADDR_IP_PREFIX:
5114 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5115 if (ip_prefix_version (ip_prefix) == IP4)
5117 rmp->eid_type = 0; /* ipv4 type */
5118 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5119 sizeof (ip_prefix_v4 (ip_prefix)));
5123 rmp->eid_type = 1; /* ipv6 type */
5124 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5125 sizeof (ip_prefix_v6 (ip_prefix)));
5129 rmp->eid_type = 2; /* l2 mac type */
5130 clib_memcpy (rmp->eid, mac, 6);
5135 rmp->context = context;
5136 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5137 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
5138 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
5139 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5143 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5146 unix_shared_memory_queue_t *q = NULL;
5147 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5148 mapping_t *mapit = NULL;
5149 gid_address_t _eid, *eid = &_eid;
5151 q = vl_api_client_index_to_input_queue (mp->client_index);
5159 memset (eid, 0, sizeof (*eid));
5161 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5162 mp->eid_type, mp->eid, mp->prefix_length);
5164 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5165 if ((u32) ~ 0 == mi)
5168 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5169 send_lisp_eid_table_details (mapit, q, mp->context,
5170 0 /* ignore filter */ );
5175 pool_foreach (mapit, lcm->mapping_pool,
5177 send_lisp_eid_table_details(mapit, q, mp->context,
5185 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
5186 unix_shared_memory_queue_t * q, u32 context)
5188 vl_api_lisp_gpe_tunnel_details_t *rmp;
5189 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5191 rmp = vl_msg_api_alloc (sizeof (*rmp));
5192 memset (rmp, 0, sizeof (*rmp));
5193 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5195 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
5197 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
5198 ip_address_copy_addr (rmp->source_ip,
5199 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5200 ip_address_copy_addr (rmp->destination_ip,
5201 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5203 rmp->encap_fib_id = htonl (0);
5204 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
5205 rmp->iid = htonl (lfe->key->vni);
5206 rmp->context = context;
5208 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5212 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5214 unix_shared_memory_queue_t *q = NULL;
5215 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5216 lisp_gpe_fwd_entry_t *lfe = NULL;
5218 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
5223 q = vl_api_client_index_to_input_queue (mp->client_index);
5230 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
5232 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
5238 send_lisp_map_server_details (ip_address_t * ip,
5239 unix_shared_memory_queue_t * q, u32 context)
5241 vl_api_lisp_map_server_details_t *rmp = NULL;
5243 rmp = vl_msg_api_alloc (sizeof (*rmp));
5244 memset (rmp, 0, sizeof (*rmp));
5245 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
5247 switch (ip_addr_version (ip))
5251 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5252 sizeof (ip_addr_v4 (ip)));
5257 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5258 sizeof (ip_addr_v6 (ip)));
5264 rmp->context = context;
5266 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5270 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
5272 unix_shared_memory_queue_t *q = NULL;
5273 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5276 q = vl_api_client_index_to_input_queue (mp->client_index);
5282 vec_foreach (mr, lcm->map_servers)
5284 send_lisp_map_server_details (&mr->address, q, mp->context);
5289 send_lisp_map_resolver_details (ip_address_t * ip,
5290 unix_shared_memory_queue_t * q, u32 context)
5292 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5294 rmp = vl_msg_api_alloc (sizeof (*rmp));
5295 memset (rmp, 0, sizeof (*rmp));
5296 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5298 switch (ip_addr_version (ip))
5302 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5303 sizeof (ip_addr_v4 (ip)));
5308 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5309 sizeof (ip_addr_v6 (ip)));
5315 rmp->context = context;
5317 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5321 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5323 unix_shared_memory_queue_t *q = NULL;
5324 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5327 q = vl_api_client_index_to_input_queue (mp->client_index);
5333 vec_foreach (mr, lcm->map_resolvers)
5335 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5340 send_eid_table_map_pair (hash_pair_t * p,
5341 unix_shared_memory_queue_t * q, u32 context)
5343 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5345 rmp = vl_msg_api_alloc (sizeof (*rmp));
5346 memset (rmp, 0, sizeof (*rmp));
5347 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5349 rmp->vni = clib_host_to_net_u32 (p->key);
5350 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5351 rmp->context = context;
5352 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5356 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5359 unix_shared_memory_queue_t *q = NULL;
5360 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5362 uword *vni_table = 0;
5364 q = vl_api_client_index_to_input_queue (mp->client_index);
5372 vni_table = lcm->bd_id_by_vni;
5376 vni_table = lcm->table_id_by_vni;
5380 hash_foreach_pair (p, vni_table,
5382 send_eid_table_map_pair (p, q, mp->context);
5388 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
5390 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
5392 rmp = vl_msg_api_alloc (sizeof (*rmp));
5393 memset (rmp, 0, sizeof (*rmp));
5394 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
5395 rmp->context = context;
5396 rmp->vni = clib_host_to_net_u32 (vni);
5397 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5401 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
5403 lisp_adjacency_t *adj;
5404 vl_api_lisp_adjacency_t a;
5405 u32 i, n = vec_len (adjs);
5407 for (i = 0; i < n; i++)
5409 adj = vec_elt_at_index (adjs, i);
5410 memset (&a, 0, sizeof (a));
5412 switch (gid_address_type (&adj->reid))
5414 case GID_ADDR_IP_PREFIX:
5415 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
5416 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
5417 if (gid_address_ip_version (&adj->reid) == IP4)
5419 a.eid_type = 0; /* ipv4 type */
5420 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
5421 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
5425 a.eid_type = 1; /* ipv6 type */
5426 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
5427 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
5431 a.eid_type = 2; /* l2 mac type */
5432 mac_copy (a.reid, gid_address_mac (&adj->reid));
5433 mac_copy (a.leid, gid_address_mac (&adj->leid));
5443 vl_api_show_lisp_rloc_probe_state_t_handler
5444 (vl_api_show_lisp_rloc_probe_state_t * mp)
5446 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
5450 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
5452 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
5458 vl_api_show_lisp_map_register_state_t_handler
5459 (vl_api_show_lisp_map_register_state_t * mp)
5461 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
5465 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
5467 rmp->is_enabled = vnet_lisp_map_register_state_get ();
5473 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
5475 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
5476 lisp_adjacency_t *adjs = 0;
5478 vl_api_lisp_adjacency_t a;
5480 u32 vni = clib_net_to_host_u32 (mp->vni);
5482 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
5483 size = vec_len (adjs) * sizeof (a);
5486 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
5488 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
5489 lisp_adjacency_copy (rmp->adjacencies, adjs);
5497 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
5502 unix_shared_memory_queue_t *q = 0;
5503 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5505 q = vl_api_client_index_to_input_queue (mp->client_index);
5512 hash_foreach_pair (p, lcm->table_id_by_vni,
5514 hash_set (vnis, p->key, 0);
5517 hash_foreach_pair (p, lcm->bd_id_by_vni,
5519 hash_set (vnis, p->key, 0);
5522 hash_foreach_pair (p, vnis,
5524 send_eid_table_vni (p->key, q, mp->context);
5532 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
5534 unix_shared_memory_queue_t *q = NULL;
5535 vl_api_show_lisp_status_reply_t *rmp = NULL;
5538 q = vl_api_client_index_to_input_queue (mp->client_index);
5545 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5547 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5548 rmp->feature_status = vnet_lisp_enable_disable_status ();
5554 vl_api_lisp_get_map_request_itr_rlocs_t_handler
5555 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
5557 unix_shared_memory_queue_t *q = NULL;
5558 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5559 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5560 locator_set_t *loc_set = 0;
5564 q = vl_api_client_index_to_input_queue (mp->client_index);
5570 if (~0 == lcm->mreq_itr_rlocs)
5572 tmp_str = format (0, " ");
5577 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5578 tmp_str = format (0, "%s", loc_set->name);
5582 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5584 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5585 ARRAY_LEN(rmp->locator_set_name) - 1);
5593 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5595 unix_shared_memory_queue_t *q = NULL;
5596 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
5597 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5599 locator_set_t *ls = 0;
5603 q = vl_api_client_index_to_input_queue (mp->client_index);
5609 if (!lcm->lisp_pitr)
5611 tmp_str = format (0, "N/A");
5615 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5616 if (~0 != m->locator_set_index)
5619 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5620 tmp_str = format (0, "%s", ls->name);
5624 tmp_str = format (0, "N/A");
5627 vec_add1 (tmp_str, 0);
5630 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5632 rmp->status = lcm->lisp_pitr;
5633 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5634 ARRAY_LEN(rmp->locator_set_name) - 1);
5640 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
5643 vl_api_interface_name_renumber_reply_t *rmp;
5646 VALIDATE_SW_IF_INDEX (mp);
5648 rv = vnet_interface_name_renumber
5649 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
5651 BAD_SW_IF_INDEX_LABEL;
5653 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5657 arp_change_data_callback (u32 pool_index, u8 * new_mac,
5658 u32 sw_if_index, u32 address)
5660 vpe_api_main_t *am = &vpe_api_main;
5661 vlib_main_t *vm = am->vlib_main;
5662 vl_api_ip4_arp_event_t *event;
5663 static f64 arp_event_last_time;
5664 f64 now = vlib_time_now (vm);
5666 if (pool_is_free_index (am->arp_events, pool_index))
5669 event = pool_elt_at_index (am->arp_events, pool_index);
5671 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
5673 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
5677 if (sw_if_index == event->sw_if_index &&
5679 /* for BD case, also check IP address with 10 sec timeout */
5680 (address == event->address &&
5681 (now - arp_event_last_time) < 10.0)))
5686 arp_event_last_time = now;
5687 event->sw_if_index = sw_if_index;
5689 event->address = address;
5694 nd_change_data_callback (u32 pool_index, u8 * new_mac,
5695 u32 sw_if_index, ip6_address_t * address)
5697 vpe_api_main_t *am = &vpe_api_main;
5698 vlib_main_t *vm = am->vlib_main;
5699 vl_api_ip6_nd_event_t *event;
5700 static f64 nd_event_last_time;
5701 f64 now = vlib_time_now (vm);
5703 if (pool_is_free_index (am->nd_events, pool_index))
5706 event = pool_elt_at_index (am->nd_events, pool_index);
5709 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
5711 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
5715 if (sw_if_index == event->sw_if_index &&
5717 /* for BD case, also check IP address with 10 sec timeout */
5718 (ip6_address_is_equal (address,
5719 (ip6_address_t *) event->address) &&
5720 (now - nd_event_last_time) < 10.0)))
5725 nd_event_last_time = now;
5726 event->sw_if_index = sw_if_index;
5728 clib_memcpy (event->address, address, sizeof (event->address));
5733 arp_change_delete_callback (u32 pool_index, u8 * notused)
5735 vpe_api_main_t *am = &vpe_api_main;
5737 if (pool_is_free_index (am->arp_events, pool_index))
5740 pool_put_index (am->arp_events, pool_index);
5745 nd_change_delete_callback (u32 pool_index, u8 * notused)
5747 vpe_api_main_t *am = &vpe_api_main;
5749 if (pool_is_free_index (am->nd_events, pool_index))
5752 pool_put_index (am->nd_events, pool_index);
5757 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
5759 vpe_api_main_t *am = &vpe_api_main;
5760 vnet_main_t *vnm = vnet_get_main ();
5761 vl_api_want_ip4_arp_events_reply_t *rmp;
5762 vl_api_ip4_arp_event_t *event;
5765 if (mp->enable_disable)
5767 pool_get (am->arp_events, event);
5768 memset (event, 0, sizeof (*event));
5770 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
5771 event->client_index = mp->client_index;
5772 event->context = mp->context;
5773 event->address = mp->address;
5774 event->pid = mp->pid;
5775 if (mp->address == 0)
5778 rv = vnet_add_del_ip4_arp_change_event
5779 (vnm, arp_change_data_callback,
5780 mp->pid, &mp->address /* addr, in net byte order */ ,
5781 vpe_resolver_process_node.index,
5782 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
5786 rv = vnet_add_del_ip4_arp_change_event
5787 (vnm, arp_change_delete_callback,
5788 mp->pid, &mp->address /* addr, in net byte order */ ,
5789 vpe_resolver_process_node.index,
5790 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
5792 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5796 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
5798 vpe_api_main_t *am = &vpe_api_main;
5799 vnet_main_t *vnm = vnet_get_main ();
5800 vl_api_want_ip6_nd_events_reply_t *rmp;
5801 vl_api_ip6_nd_event_t *event;
5804 if (mp->enable_disable)
5806 pool_get (am->nd_events, event);
5807 memset (event, 0, sizeof (*event));
5809 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
5810 event->client_index = mp->client_index;
5811 event->context = mp->context;
5812 clib_memcpy (event->address, mp->address, 16);
5813 event->pid = mp->pid;
5814 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
5817 rv = vnet_add_del_ip6_nd_change_event
5818 (vnm, nd_change_data_callback,
5819 mp->pid, mp->address /* addr, in net byte order */ ,
5820 vpe_resolver_process_node.index,
5821 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
5825 rv = vnet_add_del_ip6_nd_change_event
5826 (vnm, nd_change_delete_callback,
5827 mp->pid, mp->address /* addr, in net byte order */ ,
5828 vpe_resolver_process_node.index,
5829 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
5831 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
5834 static void vl_api_input_acl_set_interface_t_handler
5835 (vl_api_input_acl_set_interface_t * mp)
5837 vlib_main_t *vm = vlib_get_main ();
5838 vl_api_input_acl_set_interface_reply_t *rmp;
5840 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5842 ip4_table_index = ntohl (mp->ip4_table_index);
5843 ip6_table_index = ntohl (mp->ip6_table_index);
5844 l2_table_index = ntohl (mp->l2_table_index);
5845 sw_if_index = ntohl (mp->sw_if_index);
5847 VALIDATE_SW_IF_INDEX (mp);
5849 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5850 ip6_table_index, l2_table_index, mp->is_add);
5852 BAD_SW_IF_INDEX_LABEL;
5854 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5857 static void vl_api_ipsec_spd_add_del_t_handler
5858 (vl_api_ipsec_spd_add_del_t * mp)
5861 clib_warning ("unimplemented");
5864 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5865 vl_api_ipsec_spd_add_del_reply_t *rmp;
5869 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
5871 rv = VNET_API_ERROR_UNIMPLEMENTED;
5874 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5878 static void vl_api_ipsec_interface_add_del_spd_t_handler
5879 (vl_api_ipsec_interface_add_del_spd_t * mp)
5881 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5882 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
5884 u32 sw_if_index __attribute__ ((unused));
5885 u32 spd_id __attribute__ ((unused));
5887 sw_if_index = ntohl (mp->sw_if_index);
5888 spd_id = ntohl (mp->spd_id);
5890 VALIDATE_SW_IF_INDEX (mp);
5893 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
5895 rv = VNET_API_ERROR_UNIMPLEMENTED;
5898 BAD_SW_IF_INDEX_LABEL;
5900 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5903 static void vl_api_ipsec_spd_add_del_entry_t_handler
5904 (vl_api_ipsec_spd_add_del_entry_t * mp)
5906 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5907 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
5913 memset (&p, 0, sizeof (p));
5915 p.id = ntohl (mp->spd_id);
5916 p.priority = ntohl (mp->priority);
5917 p.is_outbound = mp->is_outbound;
5918 p.is_ipv6 = mp->is_ipv6;
5920 if (mp->is_ipv6 || mp->is_ip_any)
5922 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
5923 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
5924 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
5925 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
5929 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5930 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5931 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
5932 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5934 p.protocol = mp->protocol;
5935 p.rport.start = ntohs (mp->remote_port_start);
5936 p.rport.stop = ntohs (mp->remote_port_stop);
5937 p.lport.start = ntohs (mp->local_port_start);
5938 p.lport.stop = ntohs (mp->local_port_stop);
5939 /* policy action resolve unsupported */
5940 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
5942 clib_warning ("unsupported action: 'resolve'");
5943 rv = VNET_API_ERROR_UNIMPLEMENTED;
5946 p.policy = mp->policy;
5947 p.sa_id = ntohl (mp->sa_id);
5949 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5956 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5959 rv = VNET_API_ERROR_UNIMPLEMENTED;
5964 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5967 static void vl_api_ipsec_sad_add_del_entry_t_handler
5968 (vl_api_ipsec_sad_add_del_entry_t * mp)
5970 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5971 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
5976 memset (&sa, 0, sizeof (sa));
5978 sa.id = ntohl (mp->sad_id);
5979 sa.spi = ntohl (mp->spi);
5980 /* security protocol AH unsupported */
5981 if (mp->protocol == IPSEC_PROTOCOL_AH)
5983 clib_warning ("unsupported security protocol 'AH'");
5984 rv = VNET_API_ERROR_UNIMPLEMENTED;
5987 sa.protocol = mp->protocol;
5988 /* check for unsupported crypto-alg */
5989 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5990 mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
5992 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5993 mp->crypto_algorithm);
5994 rv = VNET_API_ERROR_UNIMPLEMENTED;
5997 sa.crypto_alg = mp->crypto_algorithm;
5998 sa.crypto_key_len = mp->crypto_key_length;
5999 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6000 /* check for unsupported integ-alg */
6002 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_NONE ||
6004 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6006 mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
6008 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6009 mp->integrity_algorithm);
6010 rv = VNET_API_ERROR_UNIMPLEMENTED;
6015 /*Special cases, aes-gcm-128 encryption */
6016 if (mp->crypto_algorithm == IPSEC_CRYPTO_ALG_AES_GCM_128)
6018 if (mp->integrity_algorithm != IPSEC_INTEG_ALG_NONE
6019 && mp->integrity_algorithm != IPSEC_INTEG_ALG_AES_GCM_128)
6022 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
6023 rv = VNET_API_ERROR_UNIMPLEMENTED;
6026 else /*set integ-alg internally to aes-gcm-128 */
6027 mp->integrity_algorithm = IPSEC_INTEG_ALG_AES_GCM_128;
6029 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_AES_GCM_128)
6031 clib_warning ("unsupported integ-alg: aes-gcm-128");
6032 rv = VNET_API_ERROR_UNIMPLEMENTED;
6035 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_NONE)
6037 clib_warning ("unsupported integ-alg: none");
6038 rv = VNET_API_ERROR_UNIMPLEMENTED;
6043 sa.integ_alg = mp->integrity_algorithm;
6044 sa.integ_key_len = mp->integrity_key_length;
6045 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6046 sa.use_esn = mp->use_extended_sequence_number;
6047 sa.is_tunnel = mp->is_tunnel;
6048 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6049 if (sa.is_tunnel_ip6)
6051 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6052 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6056 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6057 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6060 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6062 rv = VNET_API_ERROR_UNIMPLEMENTED;
6067 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6071 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6073 vl_api_ikev2_profile_add_del_reply_t *rmp;
6077 vlib_main_t *vm = vlib_get_main ();
6078 clib_error_t *error;
6079 u8 *tmp = format (0, "%s", mp->name);
6080 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6083 rv = VNET_API_ERROR_UNSPECIFIED;
6085 rv = VNET_API_ERROR_UNIMPLEMENTED;
6088 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6092 vl_api_ikev2_profile_set_auth_t_handler
6093 (vl_api_ikev2_profile_set_auth_t * mp)
6095 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6099 vlib_main_t *vm = vlib_get_main ();
6100 clib_error_t *error;
6101 u8 *tmp = format (0, "%s", mp->name);
6102 u8 *data = vec_new (u8, mp->data_len);
6103 clib_memcpy (data, mp->data, mp->data_len);
6104 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6108 rv = VNET_API_ERROR_UNSPECIFIED;
6110 rv = VNET_API_ERROR_UNIMPLEMENTED;
6113 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6117 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6119 vl_api_ikev2_profile_add_del_reply_t *rmp;
6123 vlib_main_t *vm = vlib_get_main ();
6124 clib_error_t *error;
6125 u8 *tmp = format (0, "%s", mp->name);
6126 u8 *data = vec_new (u8, mp->data_len);
6127 clib_memcpy (data, mp->data, mp->data_len);
6128 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6132 rv = VNET_API_ERROR_UNSPECIFIED;
6134 rv = VNET_API_ERROR_UNIMPLEMENTED;
6137 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6141 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6143 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6147 vlib_main_t *vm = vlib_get_main ();
6148 clib_error_t *error;
6149 u8 *tmp = format (0, "%s", mp->name);
6150 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6151 mp->end_port, (ip4_address_t) mp->start_addr,
6152 (ip4_address_t) mp->end_addr, mp->is_local);
6155 rv = VNET_API_ERROR_UNSPECIFIED;
6157 rv = VNET_API_ERROR_UNIMPLEMENTED;
6160 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6164 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6166 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6170 vlib_main_t *vm = vlib_get_main ();
6171 clib_error_t *error;
6173 error = ikev2_set_local_key (vm, mp->key_file);
6175 rv = VNET_API_ERROR_UNSPECIFIED;
6177 rv = VNET_API_ERROR_UNIMPLEMENTED;
6180 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6184 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6186 vl_api_map_add_domain_reply_t *rmp;
6189 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6191 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6192 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6193 (ip6_address_t *) & mp->ip6_src,
6194 mp->ip6_src_prefix_len, mp->ea_bits_len,
6195 mp->psid_offset, mp->psid_length, &index,
6196 ntohs (mp->mtu), flags);
6199 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6201 rmp->index = ntohl(index);
6207 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6209 vl_api_map_del_domain_reply_t *rmp;
6212 rv = map_delete_domain (ntohl (mp->index));
6214 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6218 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6220 vl_api_map_del_domain_reply_t *rmp;
6224 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6225 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6227 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6231 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6233 vl_api_map_domain_details_t *rmp;
6234 map_main_t *mm = &map_main;
6236 unix_shared_memory_queue_t *q;
6238 if (pool_elts (mm->domains) == 0)
6241 q = vl_api_client_index_to_input_queue (mp->client_index);
6248 pool_foreach(d, mm->domains,
6250 /* Make sure every field is initiated (or don't skip the memset()) */
6251 rmp = vl_msg_api_alloc (sizeof (*rmp));
6252 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6253 rmp->domain_index = htonl(d - mm->domains);
6254 rmp->ea_bits_len = d->ea_bits_len;
6255 rmp->psid_offset = d->psid_offset;
6256 rmp->psid_length = d->psid_length;
6257 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6258 rmp->ip4_prefix_len = d->ip4_prefix_len;
6259 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6260 rmp->ip6_prefix_len = d->ip6_prefix_len;
6261 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6262 rmp->ip6_src_len = d->ip6_src_len;
6263 rmp->mtu = htons(d->mtu);
6264 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6265 rmp->context = mp->context;
6267 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6273 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6275 unix_shared_memory_queue_t *q;
6278 vl_api_map_rule_details_t *rmp;
6279 map_main_t *mm = &map_main;
6280 u32 domain_index = ntohl (mp->domain_index);
6283 if (pool_elts (mm->domains) == 0)
6286 d = pool_elt_at_index (mm->domains, domain_index);
6287 if (!d || !d->rules)
6292 q = vl_api_client_index_to_input_queue (mp->client_index);
6298 for (i = 0; i < (0x1 << d->psid_length); i++)
6301 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6305 rmp = vl_msg_api_alloc (sizeof (*rmp));
6306 memset (rmp, 0, sizeof (*rmp));
6307 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6308 rmp->psid = htons (i);
6309 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6310 rmp->context = mp->context;
6311 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6316 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6318 vl_api_map_summary_stats_reply_t *rmp;
6319 vlib_combined_counter_main_t *cm;
6322 u64 total_pkts[VLIB_N_RX_TX];
6323 u64 total_bytes[VLIB_N_RX_TX];
6324 map_main_t *mm = &map_main;
6325 unix_shared_memory_queue_t *q =
6326 vl_api_client_index_to_input_queue (mp->client_index);
6331 rmp = vl_msg_api_alloc (sizeof (*rmp));
6332 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6333 rmp->context = mp->context;
6336 memset (total_pkts, 0, sizeof (total_pkts));
6337 memset (total_bytes, 0, sizeof (total_bytes));
6339 map_domain_counter_lock (mm);
6340 vec_foreach (cm, mm->domain_counters)
6342 which = cm - mm->domain_counters;
6344 for (i = 0; i < vec_len (cm->maxi); i++)
6346 vlib_get_combined_counter (cm, i, &v);
6347 total_pkts[which] += v.packets;
6348 total_bytes[which] += v.bytes;
6352 map_domain_counter_unlock (mm);
6354 /* Note: in network byte order! */
6355 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6356 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6357 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6358 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6359 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6360 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6361 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6362 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6363 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6364 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6365 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6366 clib_host_to_net_u64 (map_error_counter_get
6367 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6368 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6369 clib_host_to_net_u64 (map_error_counter_get
6370 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6372 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6376 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6378 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6379 vl_api_ipsec_sa_set_key_reply_t *rmp;
6383 sa.id = ntohl (mp->sa_id);
6384 sa.crypto_key_len = mp->crypto_key_length;
6385 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6386 sa.integ_key_len = mp->integrity_key_length;
6387 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6389 rv = ipsec_set_sa_key (vm, &sa);
6391 rv = VNET_API_ERROR_UNIMPLEMENTED;
6394 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6397 static void vl_api_cop_interface_enable_disable_t_handler
6398 (vl_api_cop_interface_enable_disable_t * mp)
6400 vl_api_cop_interface_enable_disable_reply_t *rmp;
6402 u32 sw_if_index = ntohl (mp->sw_if_index);
6405 VALIDATE_SW_IF_INDEX (mp);
6407 enable_disable = (int) mp->enable_disable;
6409 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6411 BAD_SW_IF_INDEX_LABEL;
6413 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6416 static void vl_api_cop_whitelist_enable_disable_t_handler
6417 (vl_api_cop_whitelist_enable_disable_t * mp)
6419 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6420 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6421 u32 sw_if_index = ntohl (mp->sw_if_index);
6424 VALIDATE_SW_IF_INDEX (mp);
6426 a->sw_if_index = sw_if_index;
6429 a->default_cop = mp->default_cop;
6430 a->fib_id = ntohl (mp->fib_id);
6432 rv = cop_whitelist_enable_disable (a);
6434 BAD_SW_IF_INDEX_LABEL;
6436 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6440 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6444 api_main_t *am = &api_main;
6445 vlib_main_t *vm = vlib_get_main ();
6447 vl_api_get_node_graph_reply_t *rmp;
6449 pthread_mutex_lock (&am->vlib_rp->mutex);
6450 oldheap = svm_push_data_heap (am->vlib_rp);
6453 * Keep the number of memcpy ops to a minimum (e.g. 1).
6455 vec_validate (vector, 16384);
6456 vec_reset_length (vector);
6459 vector = vlib_node_serialize (&vm->node_main, vector,
6460 (u32) ~ 0 /* all threads */ ,
6461 1 /* include nexts */ ,
6462 1 /* include stats */ );
6464 svm_pop_heap (oldheap);
6465 pthread_mutex_unlock (&am->vlib_rp->mutex);
6468 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6470 rmp->reply_in_shmem = (uword) vector;
6476 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
6479 vl_api_ioam_enable_reply_t *rmp;
6480 clib_error_t *error;
6482 /* Ignoring the profile id as currently a single profile
6484 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
6485 mp->seqno, mp->analyse);
6488 clib_error_report (error);
6489 rv = clib_error_get_code (error);
6492 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
6496 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
6499 vl_api_ioam_disable_reply_t *rmp;
6500 clib_error_t *error;
6502 error = clear_ioam_rewrite_fn ();
6505 clib_error_report (error);
6506 rv = clib_error_get_code (error);
6509 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
6513 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6515 vlib_main_t *vm = vlib_get_main ();
6516 vl_api_af_packet_create_reply_t *rmp;
6518 u8 *host_if_name = NULL;
6521 host_if_name = format (0, "%s", mp->host_if_name);
6522 vec_add1 (host_if_name, 0);
6524 rv = af_packet_create_if (vm, host_if_name,
6525 mp->use_random_hw_addr ? 0 : mp->hw_addr,
6528 vec_free (host_if_name);
6531 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6533 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
6539 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
6541 vlib_main_t *vm = vlib_get_main ();
6542 vl_api_af_packet_delete_reply_t *rmp;
6544 u8 *host_if_name = NULL;
6546 host_if_name = format (0, "%s", mp->host_if_name);
6547 vec_add1 (host_if_name, 0);
6549 rv = af_packet_delete_if (vm, host_if_name);
6551 vec_free (host_if_name);
6553 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
6557 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
6559 vlib_main_t *vm = vlib_get_main ();
6560 vl_api_policer_add_del_reply_t *rmp;
6563 sse2_qos_pol_cfg_params_st cfg;
6564 clib_error_t *error;
6567 name = format (0, "%s", mp->name);
6569 memset (&cfg, 0, sizeof (cfg));
6571 cfg.rnd_type = mp->round_type;
6572 cfg.rate_type = mp->rate_type;
6573 cfg.rb.kbps.cir_kbps = mp->cir;
6574 cfg.rb.kbps.eir_kbps = mp->eir;
6575 cfg.rb.kbps.cb_bytes = mp->cb;
6576 cfg.rb.kbps.eb_bytes = mp->eb;
6577 cfg.conform_action.action_type = mp->conform_action_type;
6578 cfg.conform_action.dscp = mp->conform_dscp;
6579 cfg.exceed_action.action_type = mp->exceed_action_type;
6580 cfg.exceed_action.dscp = mp->exceed_dscp;
6581 cfg.violate_action.action_type = mp->violate_action_type;
6582 cfg.violate_action.dscp = mp->violate_dscp;
6583 cfg.color_aware = mp->color_aware;
6585 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
6588 rv = VNET_API_ERROR_UNSPECIFIED;
6591 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6593 if (rv == 0 && mp->is_add)
6594 rmp->policer_index = ntohl(policer_index);
6596 rmp->policer_index = ~0;
6602 send_policer_details (u8 * name,
6603 sse2_qos_pol_cfg_params_st * config,
6604 policer_read_response_type_st * templ,
6605 unix_shared_memory_queue_t * q, u32 context)
6607 vl_api_policer_details_t *mp;
6609 mp = vl_msg_api_alloc (sizeof (*mp));
6610 memset (mp, 0, sizeof (*mp));
6611 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6612 mp->context = context;
6613 mp->cir = htonl (config->rb.kbps.cir_kbps);
6614 mp->eir = htonl (config->rb.kbps.eir_kbps);
6615 mp->cb = htonl (config->rb.kbps.cb_bytes);
6616 mp->eb = htonl (config->rb.kbps.eb_bytes);
6617 mp->rate_type = config->rate_type;
6618 mp->round_type = config->rnd_type;
6619 mp->type = config->rfc;
6620 mp->conform_action_type = config->conform_action.action_type;
6621 mp->conform_dscp = config->conform_action.dscp;
6622 mp->exceed_action_type = config->exceed_action.action_type;
6623 mp->exceed_dscp = config->exceed_action.dscp;
6624 mp->violate_action_type = config->violate_action.action_type;
6625 mp->violate_dscp = config->violate_action.dscp;
6626 mp->single_rate = templ->single_rate ? 1 : 0;
6627 mp->color_aware = templ->color_aware ? 1 : 0;
6628 mp->scale = htonl (templ->scale);
6629 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
6630 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
6631 mp->current_limit = htonl (templ->current_limit);
6632 mp->current_bucket = htonl (templ->current_bucket);
6633 mp->extended_limit = htonl (templ->extended_limit);
6634 mp->extended_bucket = htonl (templ->extended_bucket);
6635 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
6637 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
6639 vl_msg_api_send_shmem (q, (u8 *) & mp);
6643 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
6645 unix_shared_memory_queue_t *q;
6646 vnet_policer_main_t *pm = &vnet_policer_main;
6652 sse2_qos_pol_cfg_params_st *config;
6653 policer_read_response_type_st *templ;
6655 q = vl_api_client_index_to_input_queue (mp->client_index);
6659 if (mp->match_name_valid)
6661 match_name = format (0, "%s%c", mp->match_name, 0);
6664 if (mp->match_name_valid)
6666 p = hash_get_mem (pm->policer_config_by_name, match_name);
6670 config = pool_elt_at_index (pm->configs, pool_index);
6671 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6672 send_policer_details (match_name, config, templ, q, mp->context);
6678 hash_foreach_pair (hp, pm->policer_config_by_name,
6680 name = (u8 *) hp->key;
6681 pool_index = hp->value[0];
6682 config = pool_elt_at_index (pm->configs, pool_index);
6683 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6684 send_policer_details(name, config, templ, q, mp->context);
6691 vl_api_policer_classify_set_interface_t_handler
6692 (vl_api_policer_classify_set_interface_t * mp)
6694 vlib_main_t *vm = vlib_get_main ();
6695 vl_api_policer_classify_set_interface_reply_t *rmp;
6697 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6699 ip4_table_index = ntohl (mp->ip4_table_index);
6700 ip6_table_index = ntohl (mp->ip6_table_index);
6701 l2_table_index = ntohl (mp->l2_table_index);
6702 sw_if_index = ntohl (mp->sw_if_index);
6704 VALIDATE_SW_IF_INDEX (mp);
6706 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
6707 ip6_table_index, l2_table_index,
6710 BAD_SW_IF_INDEX_LABEL;
6712 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
6716 send_policer_classify_details (u32 sw_if_index,
6718 unix_shared_memory_queue_t * q, u32 context)
6720 vl_api_policer_classify_details_t *mp;
6722 mp = vl_msg_api_alloc (sizeof (*mp));
6723 memset (mp, 0, sizeof (*mp));
6724 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
6725 mp->context = context;
6726 mp->sw_if_index = htonl (sw_if_index);
6727 mp->table_index = htonl (table_index);
6729 vl_msg_api_send_shmem (q, (u8 *) & mp);
6733 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
6735 unix_shared_memory_queue_t *q;
6736 policer_classify_main_t *pcm = &policer_classify_main;
6740 q = vl_api_client_index_to_input_queue (mp->client_index);
6744 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6746 if (vec_len (vec_tbl))
6748 for (i = 0; i < vec_len (vec_tbl); i++)
6750 if (vec_elt (vec_tbl, i) == ~0)
6753 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
6760 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
6762 vlib_main_t *vm = vlib_get_main ();
6763 vl_api_netmap_create_reply_t *rmp;
6767 if_name = format (0, "%s", mp->netmap_if_name);
6768 vec_add1 (if_name, 0);
6771 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6772 mp->is_pipe, mp->is_master, 0);
6776 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
6780 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
6782 vlib_main_t *vm = vlib_get_main ();
6783 vl_api_netmap_delete_reply_t *rmp;
6787 if_name = format (0, "%s", mp->netmap_if_name);
6788 vec_add1 (if_name, 0);
6790 rv = netmap_delete_if (vm, if_name);
6794 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
6798 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_fib_details_t * mp)
6800 clib_warning ("BUG");
6803 typedef struct mpls_tunnel_send_walk_ctx_t_
6805 unix_shared_memory_queue_t *q;
6808 } mpls_tunnel_send_walk_ctx_t;
6811 send_mpls_tunnel_entry (u32 mti, void *arg)
6813 mpls_tunnel_send_walk_ctx_t *ctx;
6814 vl_api_mpls_tunnel_details_t *mp;
6815 const mpls_tunnel_t *mt;
6820 if (~0 != ctx->index && mti != ctx->index)
6823 mt = mpls_tunnel_get (mti);
6824 nlabels = vec_len (mt->mt_label_stack);
6826 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
6827 memset (mp, 0, sizeof (*mp));
6828 mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
6829 mp->context = ctx->context;
6831 mp->tunnel_index = ntohl (mti);
6832 memcpy (mp->mt_next_hop_out_labels,
6833 mt->mt_label_stack, nlabels * sizeof (u32));
6837 vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
6841 vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
6843 unix_shared_memory_queue_t *q;
6845 q = vl_api_client_index_to_input_queue (mp->client_index);
6849 mpls_tunnel_send_walk_ctx_t ctx = {
6851 .index = ntohl (mp->tunnel_index),
6852 .context = mp->context,
6854 mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
6858 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
6860 clib_warning ("BUG");
6864 vl_api_mpls_fib_details_t_endian (vl_api_mpls_fib_details_t * mp)
6866 clib_warning ("BUG");
6870 vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp)
6872 clib_warning ("BUG");
6877 copy_fib_next_hop (fib_route_path_encode_t * api_rpath,
6878 vl_api_fib_path_t * fp)
6882 if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4)
6883 fp->afi = IP46_TYPE_IP4;
6884 else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6)
6885 fp->afi = IP46_TYPE_IP6;
6888 is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr);
6890 fp->afi = IP46_TYPE_IP4;
6892 fp->afi = IP46_TYPE_IP6;
6894 if (fp->afi == IP46_TYPE_IP4)
6895 memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip4,
6896 sizeof (api_rpath->rpath.frp_addr.ip4));
6898 memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip6,
6899 sizeof (api_rpath->rpath.frp_addr.ip6));
6903 send_mpls_fib_details (vpe_api_main_t * am,
6904 unix_shared_memory_queue_t * q,
6905 u32 table_id, u32 label, u32 eos,
6906 fib_route_path_encode_t * api_rpaths, u32 context)
6908 vl_api_mpls_fib_details_t *mp;
6909 fib_route_path_encode_t *api_rpath;
6910 vl_api_fib_path_t *fp;
6913 path_count = vec_len (api_rpaths);
6914 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
6917 memset (mp, 0, sizeof (*mp));
6918 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
6919 mp->context = context;
6921 mp->table_id = htonl (table_id);
6923 mp->label = htonl (label);
6925 mp->count = htonl (path_count);
6927 vec_foreach (api_rpath, api_rpaths)
6929 memset (fp, 0, sizeof (*fp));
6930 fp->weight = htonl (api_rpath->rpath.frp_weight);
6931 fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
6932 copy_fib_next_hop (api_rpath, fp);
6936 vl_msg_api_send_shmem (q, (u8 *) & mp);
6940 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
6942 vpe_api_main_t *am = &vpe_api_main;
6943 unix_shared_memory_queue_t *q;
6944 mpls_main_t *mm = &mpls_main;
6945 fib_table_t *fib_table;
6946 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
6950 fib_route_path_encode_t *api_rpaths;
6952 q = vl_api_client_index_to_input_queue (mp->client_index);
6957 pool_foreach (fib_table, mm->fibs,
6959 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
6961 vec_add1(lfeis, lfei);
6964 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
6966 vec_foreach(lfeip, lfeis)
6968 fib_entry_get_prefix(*lfeip, &pfx);
6969 fib_index = fib_entry_get_fib_index(*lfeip);
6970 fib_table = fib_table_get(fib_index, pfx.fp_proto);
6972 fib_entry_encode(*lfeip, &api_rpaths);
6973 send_mpls_fib_details (am, q,
6974 fib_table->ft_table_id,
6979 vec_free(api_rpaths);
6986 vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
6988 clib_warning ("BUG");
6992 vl_api_ip_fib_details_t_endian (vl_api_ip_fib_details_t * mp)
6994 clib_warning ("BUG");
6998 vl_api_ip_fib_details_t_print (vl_api_ip_fib_details_t * mp)
7000 clib_warning ("BUG");
7004 send_ip_fib_details (vpe_api_main_t * am,
7005 unix_shared_memory_queue_t * q,
7006 u32 table_id, fib_prefix_t *pfx,
7007 fib_route_path_encode_t *api_rpaths, u32 context)
7009 vl_api_ip_fib_details_t *mp;
7010 fib_route_path_encode_t *api_rpath;
7011 vl_api_fib_path_t *fp;
7014 path_count = vec_len(api_rpaths);
7015 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
7018 memset (mp, 0, sizeof (*mp));
7019 mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS);
7020 mp->context = context;
7022 mp->table_id = htonl (table_id);
7023 mp->address_length = pfx->fp_len;
7024 memcpy(mp->address, &pfx->fp_addr.ip4, sizeof(pfx->fp_addr.ip4));
7026 mp->count = htonl (path_count);
7028 vec_foreach(api_rpath, api_rpaths)
7030 memset (fp, 0, sizeof (*fp));
7031 switch (api_rpath->dpo.dpoi_type)
7034 fp->is_local = true;
7040 switch (api_rpath->dpo.dpoi_index)
7042 case IP_NULL_ACTION_NONE:
7045 case IP_NULL_ACTION_SEND_ICMP_UNREACH:
7046 fp->is_unreach = true;
7048 case IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
7049 fp->is_prohibit = true;
7058 fp->weight = htonl(api_rpath->rpath.frp_weight);
7059 fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
7060 copy_fib_next_hop (api_rpath, fp);
7064 vl_msg_api_send_shmem (q, (u8 *) & mp);
7068 vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp)
7070 vpe_api_main_t *am = &vpe_api_main;
7071 unix_shared_memory_queue_t *q;
7072 ip4_main_t *im = &ip4_main;
7073 fib_table_t *fib_table;
7074 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
7078 fib_route_path_encode_t *api_rpaths;
7081 q = vl_api_client_index_to_input_queue (mp->client_index);
7086 pool_foreach (fib_table, im->fibs,
7088 for (i = 0; i < ARRAY_LEN (fib_table->v4.fib_entry_by_dst_address); i++)
7090 hash_foreach(key, lfei, fib_table->v4.fib_entry_by_dst_address[i],
7092 vec_add1(lfeis, lfei);
7097 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
7099 vec_foreach(lfeip, lfeis)
7101 fib_entry_get_prefix(*lfeip, &pfx);
7102 fib_index = fib_entry_get_fib_index(*lfeip);
7103 fib_table = fib_table_get(fib_index, pfx.fp_proto);
7105 fib_entry_encode(*lfeip, &api_rpaths);
7106 send_ip_fib_details (am, q,
7107 fib_table->ft_table_id,
7111 vec_free(api_rpaths);
7118 vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
7120 clib_warning ("BUG");
7124 vl_api_ip6_fib_details_t_endian (vl_api_ip6_fib_details_t * mp)
7126 clib_warning ("BUG");
7130 vl_api_ip6_fib_details_t_print (vl_api_ip6_fib_details_t * mp)
7132 clib_warning ("BUG");
7136 send_ip6_fib_details (vpe_api_main_t * am,
7137 unix_shared_memory_queue_t * q,
7138 u32 table_id, fib_prefix_t *pfx,
7139 fib_route_path_encode_t *api_rpaths, u32 context)
7141 vl_api_ip6_fib_details_t *mp;
7142 fib_route_path_encode_t *api_rpath;
7143 vl_api_fib_path_t *fp;
7146 path_count = vec_len(api_rpaths);
7147 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
7150 memset (mp, 0, sizeof (*mp));
7151 mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS);
7152 mp->context = context;
7154 mp->table_id = htonl (table_id);
7155 mp->address_length = pfx->fp_len;
7156 memcpy(mp->address, &pfx->fp_addr.ip6, sizeof(pfx->fp_addr.ip6));
7158 mp->count = htonl (path_count);
7160 vec_foreach(api_rpath, api_rpaths)
7162 memset (fp, 0, sizeof (*fp));
7163 switch (api_rpath->dpo.dpoi_type)
7166 fp->is_local = true;
7172 switch (api_rpath->dpo.dpoi_index)
7174 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_NONE:
7177 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_UNREACH:
7178 fp->is_unreach = true;
7180 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
7181 fp->is_prohibit = true;
7190 fp->weight = htonl(api_rpath->rpath.frp_weight);
7191 fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
7192 copy_fib_next_hop (api_rpath, fp);
7196 vl_msg_api_send_shmem (q, (u8 *) & mp);
7199 typedef struct apt_ip6_fib_show_ctx_t_ {
7201 fib_node_index_t *entries;
7202 } api_ip6_fib_show_ctx_t;
7205 api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp,
7208 api_ip6_fib_show_ctx_t *ctx = arg;
7210 if ((kvp->key[2] >> 32) == ctx->fib_index)
7212 vec_add1(ctx->entries, kvp->value);
7217 api_ip6_fib_table_get_all (unix_shared_memory_queue_t *q,
7218 vl_api_ip6_fib_dump_t *mp,
7219 fib_table_t *fib_table)
7221 vpe_api_main_t *am = &vpe_api_main;
7222 ip6_main_t *im6 = &ip6_main;
7223 ip6_fib_t *fib = &fib_table->v6;
7224 fib_node_index_t *fib_entry_index;
7225 api_ip6_fib_show_ctx_t ctx = {
7226 .fib_index = fib->index,
7229 fib_route_path_encode_t *api_rpaths;
7232 BV(clib_bihash_foreach_key_value_pair)
7233 ((BVT(clib_bihash) *) &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
7234 api_ip6_fib_table_put_entries,
7237 vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort);
7239 vec_foreach(fib_entry_index, ctx.entries)
7241 fib_entry_get_prefix(*fib_entry_index, &pfx);
7243 fib_entry_encode(*fib_entry_index, &api_rpaths);
7244 send_ip6_fib_details (am, q,
7245 fib_table->ft_table_id,
7249 vec_free(api_rpaths);
7252 vec_free(ctx.entries);
7256 vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp)
7258 unix_shared_memory_queue_t *q;
7259 ip6_main_t *im6 = &ip6_main;
7260 fib_table_t *fib_table;
7262 q = vl_api_client_index_to_input_queue (mp->client_index);
7267 pool_foreach (fib_table, im6->fibs,
7269 api_ip6_fib_table_get_all(q, mp, fib_table);
7274 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7276 unix_shared_memory_queue_t *q;
7278 q = vl_api_client_index_to_input_queue (mp->client_index);
7282 vnet_classify_main_t *cm = &vnet_classify_main;
7283 vnet_classify_table_t *t;
7288 pool_foreach (t, cm->tables,
7290 vec_add1 (table_ids, ntohl(t - cm->tables));
7293 count = vec_len (table_ids);
7295 vl_api_classify_table_ids_reply_t *rmp;
7296 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7297 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7298 rmp->context = mp->context;
7299 rmp->count = ntohl (count);
7300 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7303 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7305 vec_free (table_ids);
7309 vl_api_classify_table_by_interface_t_handler
7310 (vl_api_classify_table_by_interface_t * mp)
7312 vl_api_classify_table_by_interface_reply_t *rmp;
7315 u32 sw_if_index = ntohl (mp->sw_if_index);
7318 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7321 VALIDATE_SW_IF_INDEX (mp);
7323 input_acl_main_t *am = &input_acl_main;
7328 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7330 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7331 if (vec_len (vec_tbl))
7333 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7335 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7339 acl[type] = vec_elt (vec_tbl, if_idx);
7344 BAD_SW_IF_INDEX_LABEL;
7347 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7349 rmp->sw_if_index = ntohl(sw_if_index);
7350 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7351 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7352 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7359 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7361 unix_shared_memory_queue_t *q;
7363 q = vl_api_client_index_to_input_queue (mp->client_index);
7367 vl_api_classify_table_info_reply_t *rmp = 0;
7369 vnet_classify_main_t *cm = &vnet_classify_main;
7370 u32 table_id = ntohl (mp->table_id);
7371 vnet_classify_table_t *t;
7374 pool_foreach (t, cm->tables,
7376 if (table_id == t - cm->tables)
7378 rmp = vl_msg_api_alloc_as_if_client
7379 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7380 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7381 rmp->context = mp->context;
7382 rmp->table_id = ntohl(table_id);
7383 rmp->nbuckets = ntohl(t->nbuckets);
7384 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7385 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7386 rmp->active_sessions = ntohl(t->active_elements);
7387 rmp->next_table_index = ntohl(t->next_table_index);
7388 rmp->miss_next_index = ntohl(t->miss_next_index);
7389 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7390 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7399 rmp = vl_msg_api_alloc (sizeof (*rmp));
7400 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7401 rmp->context = mp->context;
7402 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7405 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7409 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7412 clib_warning ("BUG");
7416 send_classify_session_details (unix_shared_memory_queue_t * q,
7419 vnet_classify_entry_t * e, u32 context)
7421 vl_api_classify_session_details_t *rmp;
7423 rmp = vl_msg_api_alloc (sizeof (*rmp));
7424 memset (rmp, 0, sizeof (*rmp));
7425 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7426 rmp->context = context;
7427 rmp->table_id = ntohl (table_id);
7428 rmp->hit_next_index = ntohl (e->next_index);
7429 rmp->advance = ntohl (e->advance);
7430 rmp->opaque_index = ntohl (e->opaque_index);
7431 rmp->match_length = ntohl (match_length);
7432 clib_memcpy (rmp->match, e->key, match_length);
7434 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7438 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7440 vnet_classify_main_t *cm = &vnet_classify_main;
7441 unix_shared_memory_queue_t *q;
7443 u32 table_id = ntohl (mp->table_id);
7444 vnet_classify_table_t *t;
7446 q = vl_api_client_index_to_input_queue (mp->client_index);
7451 pool_foreach (t, cm->tables,
7453 if (table_id == t - cm->tables)
7455 vnet_classify_bucket_t * b;
7456 vnet_classify_entry_t * v, * save_v;
7459 for (i = 0; i < t->nbuckets; i++)
7461 b = &t->buckets [i];
7465 save_v = vnet_classify_get_entry (t, b->offset);
7466 for (j = 0; j < (1<<b->log2_pages); j++)
7468 for (k = 0; k < t->entries_per_page; k++)
7470 v = vnet_classify_entry_at_index
7471 (t, save_v, j*t->entries_per_page + k);
7472 if (vnet_classify_entry_is_free (v))
7475 send_classify_session_details
7476 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7488 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7490 vlib_main_t *vm = vlib_get_main ();
7491 flow_report_main_t *frm = &flow_report_main;
7492 vl_api_set_ipfix_exporter_reply_t *rmp;
7493 ip4_address_t collector, src;
7494 u16 collector_port = UDP_DST_PORT_ipfix;
7496 u32 template_interval;
7502 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7503 collector_port = ntohs (mp->collector_port);
7504 if (collector_port == (u16) ~ 0)
7505 collector_port = UDP_DST_PORT_ipfix;
7506 memcpy (src.data, mp->src_address, sizeof (src.data));
7507 fib_id = ntohl (mp->vrf_id);
7509 ip4_main_t *im = &ip4_main;
7516 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7519 rv = VNET_API_ERROR_NO_SUCH_FIB;
7525 path_mtu = ntohl (mp->path_mtu);
7527 path_mtu = 512; // RFC 7011 section 10.3.3.
7528 template_interval = ntohl (mp->template_interval);
7529 if (template_interval == ~0)
7530 template_interval = 20;
7531 udp_checksum = mp->udp_checksum;
7533 if (collector.as_u32 == 0)
7535 rv = VNET_API_ERROR_INVALID_VALUE;
7539 if (src.as_u32 == 0)
7541 rv = VNET_API_ERROR_INVALID_VALUE;
7545 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7547 rv = VNET_API_ERROR_INVALID_VALUE;
7553 rv = VNET_API_ERROR_INVALID_VALUE;
7557 /* Reset report streams if we are reconfiguring IP addresses */
7558 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7559 frm->src_address.as_u32 != src.as_u32 ||
7560 frm->collector_port != collector_port)
7561 vnet_flow_reports_reset (frm);
7563 frm->ipfix_collector.as_u32 = collector.as_u32;
7564 frm->collector_port = collector_port;
7565 frm->src_address.as_u32 = src.as_u32;
7566 frm->fib_index = fib_index;
7567 frm->path_mtu = path_mtu;
7568 frm->template_interval = template_interval;
7569 frm->udp_checksum = udp_checksum;
7571 /* Turn on the flow reporting process */
7572 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7575 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
7579 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
7581 flow_report_main_t *frm = &flow_report_main;
7582 unix_shared_memory_queue_t *q;
7583 vl_api_ipfix_exporter_details_t *rmp;
7584 ip4_main_t *im = &ip4_main;
7587 q = vl_api_client_index_to_input_queue (mp->client_index);
7591 rmp = vl_msg_api_alloc (sizeof (*rmp));
7592 memset (rmp, 0, sizeof (*rmp));
7593 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
7594 rmp->context = mp->context;
7595 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7596 sizeof (frm->ipfix_collector.data));
7597 rmp->collector_port = htons (frm->collector_port);
7598 memcpy (rmp->src_address, frm->src_address.data,
7599 sizeof (frm->src_address.data));
7600 if (frm->fib_index == ~0)
7603 vrf_id = im->fibs[frm->fib_index].ft_table_id;
7604 rmp->vrf_id = htonl (vrf_id);
7605 rmp->path_mtu = htonl (frm->path_mtu);
7606 rmp->template_interval = htonl (frm->template_interval);
7607 rmp->udp_checksum = (frm->udp_checksum != 0);
7609 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7613 vl_api_set_ipfix_classify_stream_t_handler
7614 (vl_api_set_ipfix_classify_stream_t * mp)
7616 vl_api_set_ipfix_classify_stream_reply_t *rmp;
7617 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7618 flow_report_main_t *frm = &flow_report_main;
7620 u32 src_port = UDP_DST_PORT_ipfix;
7623 domain_id = ntohl (mp->domain_id);
7624 src_port = ntohs (mp->src_port);
7626 if (fcm->src_port != 0 &&
7627 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
7629 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
7630 domain_id, (u16) src_port);
7634 fcm->domain_id = domain_id;
7635 fcm->src_port = (u16) src_port;
7637 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7641 vl_api_ipfix_classify_stream_dump_t_handler
7642 (vl_api_ipfix_classify_stream_dump_t * mp)
7644 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7645 unix_shared_memory_queue_t *q;
7646 vl_api_ipfix_classify_stream_details_t *rmp;
7648 q = vl_api_client_index_to_input_queue (mp->client_index);
7652 rmp = vl_msg_api_alloc (sizeof (*rmp));
7653 memset (rmp, 0, sizeof (*rmp));
7654 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
7655 rmp->context = mp->context;
7656 rmp->domain_id = htonl (fcm->domain_id);
7657 rmp->src_port = htons (fcm->src_port);
7659 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7663 vl_api_ipfix_classify_table_add_del_t_handler
7664 (vl_api_ipfix_classify_table_add_del_t * mp)
7666 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
7667 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7668 flow_report_main_t *frm = &flow_report_main;
7669 vnet_flow_report_add_del_args_t args;
7670 ipfix_classify_table_t *table;
7672 u32 classify_table_index;
7674 u8 transport_protocol;
7677 classify_table_index = ntohl (mp->table_id);
7678 ip_version = mp->ip_version;
7679 transport_protocol = mp->transport_protocol;
7680 is_add = mp->is_add;
7682 if (fcm->src_port == 0)
7684 /* call set_ipfix_classify_stream first */
7685 rv = VNET_API_ERROR_UNSPECIFIED;
7689 memset (&args, 0, sizeof (args));
7693 for (i = 0; i < vec_len (fcm->tables); i++)
7694 if (ipfix_classify_table_index_valid (i))
7695 if (fcm->tables[i].classify_table_index == classify_table_index)
7697 table = &fcm->tables[i];
7705 rv = VNET_API_ERROR_VALUE_EXIST;
7708 table = ipfix_classify_add_table ();
7709 table->classify_table_index = classify_table_index;
7715 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
7720 table->ip_version = ip_version;
7721 table->transport_protocol = transport_protocol;
7723 args.opaque.as_uword = table - fcm->tables;
7724 args.rewrite_callback = ipfix_classify_template_rewrite;
7725 args.flow_data_callback = ipfix_classify_send_flows;
7726 args.is_add = is_add;
7727 args.domain_id = fcm->domain_id;
7728 args.src_port = fcm->src_port;
7730 rv = vnet_flow_report_add_del (frm, &args);
7732 /* If deleting, or add failed */
7733 if (is_add == 0 || (rv && is_add))
7734 ipfix_classify_delete_table (table - fcm->tables);
7737 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7741 send_ipfix_classify_table_details (u32 table_index,
7742 unix_shared_memory_queue_t * q,
7745 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7746 vl_api_ipfix_classify_table_details_t *mp;
7748 ipfix_classify_table_t *table = &fcm->tables[table_index];
7750 mp = vl_msg_api_alloc (sizeof (*mp));
7751 memset (mp, 0, sizeof (*mp));
7752 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
7753 mp->context = context;
7754 mp->table_id = htonl (table->classify_table_index);
7755 mp->ip_version = table->ip_version;
7756 mp->transport_protocol = table->transport_protocol;
7758 vl_msg_api_send_shmem (q, (u8 *) & mp);
7762 vl_api_ipfix_classify_table_dump_t_handler
7763 (vl_api_ipfix_classify_table_dump_t * mp)
7765 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7766 unix_shared_memory_queue_t *q;
7769 q = vl_api_client_index_to_input_queue (mp->client_index);
7773 for (i = 0; i < vec_len (fcm->tables); i++)
7774 if (ipfix_classify_table_index_valid (i))
7775 send_ipfix_classify_table_details (i, q, mp->context);
7779 vl_api_sw_interface_span_enable_disable_t_handler
7780 (vl_api_sw_interface_span_enable_disable_t * mp)
7782 vl_api_sw_interface_span_enable_disable_reply_t *rmp;
7785 vlib_main_t *vm = vlib_get_main ();
7787 rv = span_add_delete_entry (vm, ntohl (mp->sw_if_index_from),
7788 ntohl (mp->sw_if_index_to), mp->enable);
7790 REPLY_MACRO (VL_API_SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY);
7794 vl_api_sw_interface_span_dump_t_handler (vl_api_sw_interface_span_dump_t * mp)
7797 unix_shared_memory_queue_t *q;
7798 vl_api_sw_interface_span_details_t *rmp;
7799 span_main_t *sm = &span_main;
7800 u32 src_sw_if_index = 0, *dst_sw_if_index;
7802 q = vl_api_client_index_to_input_queue (mp->client_index);
7806 vec_foreach (dst_sw_if_index, sm->dst_by_src_sw_if_index)
7808 if (*dst_sw_if_index > 0)
7810 rmp = vl_msg_api_alloc (sizeof (*rmp));
7811 memset (rmp, 0, sizeof (*rmp));
7812 rmp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SPAN_DETAILS);
7813 rmp->context = mp->context;
7815 rmp->sw_if_index_from = htonl (src_sw_if_index);
7816 rmp->sw_if_index_to = htonl (*dst_sw_if_index);
7818 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7825 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
7827 vl_api_pg_create_interface_reply_t *rmp;
7830 pg_main_t *pg = &pg_main;
7831 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
7832 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
7835 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7837 rmp->sw_if_index = ntohl(pi->sw_if_index);
7843 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
7845 vl_api_pg_capture_reply_t *rmp;
7848 vnet_main_t *vnm = vnet_get_main ();
7849 vnet_interface_main_t *im = &vnm->interface_main;
7850 vnet_hw_interface_t *hi = 0;
7852 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
7853 u32 hw_if_index = ~0;
7854 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
7857 vec_free (intf_name);
7859 if (hw_if_index != ~0)
7861 pg_capture_args_t _a, *a = &_a;
7863 u32 len = ntohl (mp->pcap_name_length);
7864 u8 *pcap_file_name = vec_new (u8, len);
7865 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
7867 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7868 a->hw_if_index = hw_if_index;
7869 a->dev_instance = hi->dev_instance;
7870 a->is_enabled = mp->is_enabled;
7871 a->pcap_file_name = pcap_file_name;
7872 a->count = ntohl (mp->count);
7874 clib_error_t *e = pg_capture (a);
7877 clib_error_report (e);
7878 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7881 vec_free (pcap_file_name);
7883 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
7887 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
7889 vl_api_pg_enable_disable_reply_t *rmp;
7892 pg_main_t *pg = &pg_main;
7893 u32 stream_index = ~0;
7895 int is_enable = mp->is_enabled != 0;
7896 u32 len = ntohl (mp->stream_name_length) - 1;
7900 u8 *stream_name = vec_new (u8, len);
7901 clib_memcpy (stream_name, mp->stream_name, len);
7902 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
7905 vec_free (stream_name);
7908 pg_enable_disable (stream_index, is_enable);
7910 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
7914 vl_api_ip_source_and_port_range_check_add_del_t_handler
7915 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
7917 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
7920 u8 is_ipv6 = mp->is_ipv6;
7921 u8 is_add = mp->is_add;
7922 u8 mask_length = mp->mask_length;
7923 ip4_address_t ip4_addr;
7924 ip6_address_t ip6_addr;
7926 u16 *high_ports = 0;
7928 u16 tmp_low, tmp_high;
7932 // Validate port range
7933 num_ranges = mp->number_of_ranges;
7934 if (num_ranges > 32)
7935 { // This is size of array in VPE.API
7936 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
7940 vec_reset_length (low_ports);
7941 vec_reset_length (high_ports);
7943 for (i = 0; i < num_ranges; i++)
7945 tmp_low = mp->low_ports[i];
7946 tmp_high = mp->high_ports[i];
7947 // If tmp_low <= tmp_high then only need to check tmp_low = 0
7948 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
7949 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
7951 rv = VNET_API_ERROR_INVALID_VALUE;
7954 vec_add1 (low_ports, tmp_low);
7955 vec_add1 (high_ports, tmp_high + 1);
7958 // Validate mask_length
7959 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
7961 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
7965 vrf_id = ntohl (mp->vrf_id);
7969 rv = VNET_API_ERROR_INVALID_VALUE;
7976 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
7977 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
7981 high_ports, is_add);
7985 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
7986 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
7990 high_ports, is_add);
7994 vec_free (low_ports);
7995 vec_free (high_ports);
7996 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8000 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8001 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8003 vlib_main_t *vm = vlib_get_main ();
8004 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8005 ip4_main_t *im = &ip4_main;
8008 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8009 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8013 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8014 ntohl (mp->tcp_out_vrf_id);
8015 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8016 ntohl (mp->udp_out_vrf_id);
8017 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8018 ntohl (mp->tcp_in_vrf_id);
8019 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8020 ntohl (mp->udp_in_vrf_id);
8023 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8025 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8027 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8031 rv = VNET_API_ERROR_INVALID_VALUE;
8035 fib_index[i] = p[0];
8040 sw_if_index = ntohl (mp->sw_if_index);
8042 VALIDATE_SW_IF_INDEX (mp);
8045 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8048 BAD_SW_IF_INDEX_LABEL;
8051 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8055 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8058 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8060 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8061 u32 sw_if_index = ~0;
8063 /* Check src & dst are different */
8064 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8066 rv = VNET_API_ERROR_SAME_SRC_DST;
8070 memset (a, 0, sizeof (*a));
8072 /* ip addresses sent in network byte order */
8073 clib_memcpy (&(a->src), mp->src_address, 4);
8074 clib_memcpy (&(a->dst), mp->dst_address, 4);
8075 a->is_add = mp->is_add;
8076 a->lsa = ntohl (mp->local_sa_id);
8077 a->rsa = ntohl (mp->remote_sa_id);
8079 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8083 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8085 rmp->sw_if_index = ntohl (sw_if_index);
8090 static void send_ipsec_gre_tunnel_details
8091 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8093 vl_api_ipsec_gre_tunnel_details_t *rmp;
8095 rmp = vl_msg_api_alloc (sizeof (*rmp));
8096 memset (rmp, 0, sizeof (*rmp));
8097 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8098 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8099 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8100 rmp->sw_if_index = htonl (t->sw_if_index);
8101 rmp->local_sa_id = htonl (t->local_sa_id);
8102 rmp->remote_sa_id = htonl (t->remote_sa_id);
8103 rmp->context = context;
8105 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8108 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8109 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8111 unix_shared_memory_queue_t *q;
8112 ipsec_gre_main_t *igm = &ipsec_gre_main;
8113 ipsec_gre_tunnel_t *t;
8116 q = vl_api_client_index_to_input_queue (mp->client_index);
8122 sw_if_index = ntohl (mp->sw_if_index);
8124 if (~0 == sw_if_index)
8127 pool_foreach (t, igm->tunnels,
8129 send_ipsec_gre_tunnel_details(t, q, mp->context);
8135 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8136 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8140 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8141 send_ipsec_gre_tunnel_details (t, q, mp->context);
8146 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8148 vl_api_delete_subif_reply_t *rmp;
8151 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8153 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8157 vl_api_l2_interface_pbb_tag_rewrite_t_handler
8158 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
8160 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
8161 vnet_main_t *vnm = vnet_get_main ();
8162 vlib_main_t *vm = vlib_get_main ();
8166 VALIDATE_SW_IF_INDEX (mp);
8168 vtr_op = ntohl (mp->vtr_op);
8172 case L2_VTR_DISABLED:
8175 case L2_VTR_TRANSLATE_2_1:
8179 rv = VNET_API_ERROR_INVALID_VALUE;
8180 goto bad_sw_if_index;
8183 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
8184 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
8185 ntohl (mp->i_sid), ntohs (mp->outer_tag));
8187 BAD_SW_IF_INDEX_LABEL;
8189 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
8193 vl_api_punt_t_handler (vl_api_punt_t * mp)
8195 vl_api_punt_reply_t *rmp;
8196 vlib_main_t *vm = vlib_get_main ();
8198 clib_error_t *error;
8200 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8201 ntohs (mp->l4_port), mp->is_add);
8205 clib_error_report (error);
8208 REPLY_MACRO (VL_API_PUNT_REPLY);
8212 vl_api_flow_classify_set_interface_t_handler
8213 (vl_api_flow_classify_set_interface_t * mp)
8215 vlib_main_t *vm = vlib_get_main ();
8216 vl_api_flow_classify_set_interface_reply_t *rmp;
8218 u32 sw_if_index, ip4_table_index, ip6_table_index;
8220 ip4_table_index = ntohl (mp->ip4_table_index);
8221 ip6_table_index = ntohl (mp->ip6_table_index);
8222 sw_if_index = ntohl (mp->sw_if_index);
8224 VALIDATE_SW_IF_INDEX (mp);
8226 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
8227 ip6_table_index, mp->is_add);
8229 BAD_SW_IF_INDEX_LABEL;
8231 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
8235 send_flow_classify_details (u32 sw_if_index,
8237 unix_shared_memory_queue_t * q, u32 context)
8239 vl_api_flow_classify_details_t *mp;
8241 mp = vl_msg_api_alloc (sizeof (*mp));
8242 memset (mp, 0, sizeof (*mp));
8243 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
8244 mp->context = context;
8245 mp->sw_if_index = htonl (sw_if_index);
8246 mp->table_index = htonl (table_index);
8248 vl_msg_api_send_shmem (q, (u8 *) & mp);
8252 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8254 unix_shared_memory_queue_t *q;
8255 flow_classify_main_t *pcm = &flow_classify_main;
8259 q = vl_api_client_index_to_input_queue (mp->client_index);
8263 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8265 if (vec_len (vec_tbl))
8267 for (i = 0; i < vec_len (vec_tbl); i++)
8269 if (vec_elt (vec_tbl, i) == ~0)
8272 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8279 send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
8282 vl_api_ipsec_spd_details_t *mp;
8284 mp = vl_msg_api_alloc (sizeof (*mp));
8285 memset (mp, 0, sizeof (*mp));
8286 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
8287 mp->context = context;
8289 mp->spd_id = htonl (p->id);
8290 mp->priority = htonl (p->priority);
8291 mp->is_outbound = p->is_outbound;
8292 mp->is_ipv6 = p->is_ipv6;
8295 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
8296 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
8297 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
8298 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
8302 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
8303 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
8304 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
8305 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
8307 mp->local_start_port = htons (p->lport.start);
8308 mp->local_stop_port = htons (p->lport.stop);
8309 mp->remote_start_port = htons (p->rport.start);
8310 mp->remote_stop_port = htons (p->rport.stop);
8311 mp->protocol = p->protocol;
8312 mp->policy = p->policy;
8313 mp->sa_id = htonl (p->sa_id);
8314 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
8315 mp->packets = clib_host_to_net_u64 (p->counter.packets);
8317 vl_msg_api_send_shmem (q, (u8 *) & mp);
8321 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
8323 unix_shared_memory_queue_t *q;
8324 ipsec_main_t *im = &ipsec_main;
8325 ipsec_policy_t *policy;
8330 q = vl_api_client_index_to_input_queue (mp->client_index);
8334 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
8339 spd = pool_elt_at_index (im->spds, spd_index);
8342 pool_foreach (policy, spd->policies,
8344 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
8345 send_ipsec_spd_details (policy, q,
8350 clib_warning ("unimplemented");
8355 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
8357 vl_api_feature_enable_disable_reply_t *rmp;
8359 u8 *arc_name, *feature_name;
8361 VALIDATE_SW_IF_INDEX (mp);
8363 arc_name = format (0, "%s%c", mp->arc_name, 0);
8364 feature_name = format (0, "%s%c", mp->feature_name, 0);
8366 vnet_feature_registration_t *reg;
8368 vnet_get_feature_reg ((const char *) arc_name,
8369 (const char *) feature_name);
8371 rv = VNET_API_ERROR_INVALID_VALUE;
8375 clib_error_t *error = 0;
8377 sw_if_index = ntohl (mp->sw_if_index);
8378 if (reg->enable_disable_cb)
8379 error = reg->enable_disable_cb (sw_if_index, mp->enable);
8381 vnet_feature_enable_disable ((const char *) arc_name,
8382 (const char *) feature_name,
8383 sw_if_index, mp->enable, 0, 0);
8386 clib_error_report (error);
8387 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
8391 vec_free (feature_name);
8392 vec_free (arc_name);
8394 BAD_SW_IF_INDEX_LABEL;
8396 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
8400 send_ip_neighbor_details (u8 is_ipv6,
8404 unix_shared_memory_queue_t * q, u32 context)
8406 vl_api_ip_neighbor_details_t *mp;
8408 mp = vl_msg_api_alloc (sizeof (*mp));
8409 memset (mp, 0, sizeof (*mp));
8410 mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS);
8411 mp->context = context;
8412 mp->is_ipv6 = is_ipv6;
8413 mp->is_static = is_static;
8414 memcpy (mp->mac_address, mac_address, 6);
8415 memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
8417 vl_msg_api_send_shmem (q, (u8 *) & mp);
8421 vl_api_ip_neighbor_details_t_handler (vl_api_ip_neighbor_details_t * mp)
8423 clib_warning ("BUG");
8427 vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp)
8429 unix_shared_memory_queue_t *q;
8431 q = vl_api_client_index_to_input_queue (mp->client_index);
8435 u32 sw_if_index = ntohl (mp->sw_if_index);
8439 ip6_neighbor_t *n, *ns;
8441 ns = ip6_neighbors_entries (sw_if_index);
8445 send_ip_neighbor_details (mp->is_ipv6,
8446 ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0),
8447 (u8 *) n->link_layer_address,
8448 (u8 *) & (n->key.ip6_address.as_u8),
8456 ethernet_arp_ip4_entry_t *n, *ns;
8458 ns = ip4_neighbor_entries (sw_if_index);
8462 send_ip_neighbor_details (mp->is_ipv6,
8463 ((n->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) ? 1 : 0),
8464 (u8*) n->ethernet_address,
8465 (u8*) & (n->ip4_address.as_u8),
8473 #define BOUNCE_HANDLER(nn) \
8474 static void vl_api_##nn##_t_handler ( \
8475 vl_api_##nn##_t *mp) \
8477 vpe_client_registration_t *reg; \
8478 vpe_api_main_t * vam = &vpe_api_main; \
8479 unix_shared_memory_queue_t * q; \
8481 /* One registration only... */ \
8482 pool_foreach(reg, vam->nn##_registrations, \
8484 q = vl_api_client_index_to_input_queue (reg->client_index); \
8487 * If the queue is stuffed, turf the msg and complain \
8488 * It's unlikely that the intended recipient is \
8489 * alive; avoid deadlock at all costs. \
8491 if (q->cursize == q->maxsize) { \
8492 clib_warning ("ERROR: receiver queue full, drop msg"); \
8493 vl_msg_api_free (mp); \
8496 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8500 vl_msg_api_free (mp); \
8503 static void setup_message_id_table (api_main_t * am);
8507 * Add vpe's API message handlers to the table.
8508 * vlib has alread mapped shared memory and
8509 * added the client registration handlers.
8510 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8512 static clib_error_t *
8513 vpe_api_hookup (vlib_main_t * vm)
8515 api_main_t *am = &api_main;
8518 vl_msg_api_set_handlers(VL_API_##N, #n, \
8519 vl_api_##n##_t_handler, \
8521 vl_api_##n##_t_endian, \
8522 vl_api_##n##_t_print, \
8523 sizeof(vl_api_##n##_t), 1);
8524 foreach_vpe_api_msg;
8528 * Manually register the sr tunnel add del msg, so we trace
8529 * enough bytes to capture a typical segment list
8531 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8532 "sr_tunnel_add_del",
8533 vl_api_sr_tunnel_add_del_t_handler,
8535 vl_api_sr_tunnel_add_del_t_endian,
8536 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8540 * Manually register the sr policy add del msg, so we trace
8541 * enough bytes to capture a typical tunnel name list
8543 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8544 "sr_policy_add_del",
8545 vl_api_sr_policy_add_del_t_handler,
8547 vl_api_sr_policy_add_del_t_endian,
8548 vl_api_sr_policy_add_del_t_print, 256, 1);
8551 * Trace space for 8 MPLS encap labels, classifier mask+match
8553 am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32);
8554 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8555 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8556 += 5 * sizeof (u32x4);
8557 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8560 * Thread-safe API messages
8562 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8563 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8566 * Set up the (msg_name, crc, message-id) table
8568 setup_message_id_table (am);
8573 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8575 static clib_error_t *
8576 vpe_api_init (vlib_main_t * vm)
8578 vpe_api_main_t *am = &vpe_api_main;
8581 am->vnet_main = vnet_get_main ();
8582 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8583 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8584 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8585 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8586 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8587 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8590 vl_set_memory_region_name ("/vpe-api");
8591 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8596 VLIB_INIT_FUNCTION (vpe_api_init);
8599 static clib_error_t *
8600 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8603 u64 baseva, size, pvt_heap_size;
8605 const int max_buf_size = 4096;
8607 struct passwd _pw, *pw;
8608 struct group _grp, *grp;
8610 buf = vec_new (char, 128);
8611 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8613 if (unformat (input, "prefix %s", &chroot_path))
8615 vec_add1 (chroot_path, 0);
8616 vl_set_memory_root_path ((char *) chroot_path);
8618 else if (unformat (input, "uid %d", &uid))
8619 vl_set_memory_uid (uid);
8620 else if (unformat (input, "gid %d", &gid))
8621 vl_set_memory_gid (gid);
8622 else if (unformat (input, "baseva %llx", &baseva))
8623 vl_set_global_memory_baseva (baseva);
8624 else if (unformat (input, "global-size %lldM", &size))
8625 vl_set_global_memory_size (size * (1ULL << 20));
8626 else if (unformat (input, "global-size %lldG", &size))
8627 vl_set_global_memory_size (size * (1ULL << 30));
8628 else if (unformat (input, "global-size %lld", &size))
8629 vl_set_global_memory_size (size);
8630 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8631 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8632 else if (unformat (input, "global-pvt-heap-size size %lld",
8634 vl_set_global_pvt_heap_size (pvt_heap_size);
8635 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8636 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8637 else if (unformat (input, "api-pvt-heap-size size %lld",
8639 vl_set_api_pvt_heap_size (pvt_heap_size);
8640 else if (unformat (input, "api-size %lldM", &size))
8641 vl_set_api_memory_size (size * (1ULL << 20));
8642 else if (unformat (input, "api-size %lldG", &size))
8643 vl_set_api_memory_size (size * (1ULL << 30));
8644 else if (unformat (input, "api-size %lld", &size))
8645 vl_set_api_memory_size (size);
8646 else if (unformat (input, "uid %s", &s))
8648 /* lookup the username */
8651 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8652 && (vec_len (buf) <= max_buf_size))
8654 vec_resize (buf, vec_len (buf) * 2);
8658 e = clib_error_return_code (0, rv,
8659 CLIB_ERROR_ERRNO_VALID |
8661 "cannot fetch username %s", s);
8669 clib_error_return_fatal (0, "username %s does not exist", s);
8675 vl_set_memory_uid (pw->pw_uid);
8677 else if (unformat (input, "gid %s", &s))
8679 /* lookup the group name */
8682 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8683 && (vec_len (buf) <= max_buf_size))
8685 vec_resize (buf, vec_len (buf) * 2);
8689 e = clib_error_return_code (0, rv,
8690 CLIB_ERROR_ERRNO_VALID |
8692 "cannot fetch group %s", s);
8699 e = clib_error_return_fatal (0, "group %s does not exist", s);
8706 vl_set_memory_gid (grp->gr_gid);
8709 return clib_error_return (0, "unknown input `%U'",
8710 format_unformat_error, input);
8715 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8718 get_unformat_vnet_sw_interface (void)
8720 return (void *) &unformat_vnet_sw_interface;
8724 format_arp_event (u8 * s, va_list * args)
8726 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8728 s = format (s, "pid %d: ", event->pid);
8730 s = format (s, "bd mac/ip4 binding events");
8732 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8737 format_nd_event (u8 * s, va_list * args)
8739 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8741 s = format (s, "pid %d: ", event->pid);
8743 s = format (s, "bd mac/ip6 binding events");
8745 s = format (s, "resolution for %U", format_ip6_address, event->address);
8749 static clib_error_t *
8750 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8751 unformat_input_t * input, vlib_cli_command_t * cmd)
8753 vpe_api_main_t *am = &vpe_api_main;
8754 vl_api_ip4_arp_event_t *arp_event;
8755 vl_api_ip6_nd_event_t *nd_event;
8757 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8759 vlib_cli_output (vm, "No active arp or nd event registrations");
8764 pool_foreach (arp_event, am->arp_events,
8766 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8769 pool_foreach (nd_event, am->nd_events,
8771 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8779 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8780 .path = "show arp-nd-event registrations",
8781 .function = show_ip_arp_nd_events_fn,
8782 .short_help = "Show ip4 arp and ip6 nd event registrations",
8786 #define vl_msg_name_crc_list
8787 #include <vpp-api/vpe_all_api_h.h>
8788 #undef vl_msg_name_crc_list
8791 setup_message_id_table (api_main_t * am)
8793 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
8794 foreach_vl_msg_name_crc_memclnt;
8795 foreach_vl_msg_name_crc_vpe;
8801 * fd.io coding-style-patch-verification: ON
8804 * eval: (c-set-style "gnu")