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/unix/tuntap.h>
56 #include <vnet/unix/tapcli.h>
57 #include <vnet/mpls/mpls.h>
58 #include <vnet/mpls/mpls_tunnel.h>
59 #include <vnet/dhcp/proxy.h>
60 #include <vnet/dhcp/client.h>
62 #include <vnet/sr/sr.h>
64 #include <vnet/dhcpv6/proxy.h>
65 #include <vlib/vlib.h>
66 #include <vlib/unix/unix.h>
67 #include <vlibapi/api.h>
68 #include <vlibmemory/api.h>
69 #include <vnet/classify/vnet_classify.h>
70 #include <vnet/classify/input_acl.h>
71 #include <vnet/classify/policer_classify.h>
72 #include <vnet/classify/flow_classify.h>
73 #include <vnet/l2/l2_classify.h>
74 #include <vnet/vxlan/vxlan.h>
75 #include <vnet/gre/gre.h>
76 #include <vnet/l2/l2_vtr.h>
77 #include <vnet/vxlan-gpe/vxlan_gpe.h>
78 #include <vnet/lisp-gpe/lisp_gpe.h>
79 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
80 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
81 #include <vnet/lisp-cp/control.h>
82 #include <vnet/map/map.h>
83 #include <vnet/cop/cop.h>
84 #include <vnet/ip/ip6_hop_by_hop.h>
85 #include <vnet/ip/ip_source_and_port_range_check.h>
86 #include <vnet/devices/af_packet/af_packet.h>
87 #include <vnet/policer/policer.h>
88 #include <vnet/devices/netmap/netmap.h>
89 #include <vnet/flow/flow_report.h>
90 #include <vnet/ipsec-gre/ipsec_gre.h>
91 #include <vnet/flow/flow_report_classify.h>
92 #include <vnet/ip/punt.h>
93 #include <vnet/feature/feature.h>
96 #undef __included_bihash_template_h__
97 #include <vnet/l2/l2_fib.h>
100 #include <vnet/devices/dpdk/dpdk.h>
104 #include <vnet/ipsec/ipsec.h>
105 #include <vnet/ipsec/ikev2.h>
107 #include <vnet/devices/virtio/vhost-user.h>
109 #include <stats/stats.h>
112 #include <vnet/ethernet/ethernet.h>
113 #include <vnet/ethernet/arp_packet.h>
114 #include <vnet/interface.h>
116 #include <vnet/l2/l2_fib.h>
117 #include <vnet/l2/l2_bd.h>
118 #include <vpp-api/vpe_msg_enum.h>
119 #include <vnet/span/span.h>
121 #include <vnet/fib/ip6_fib.h>
122 #include <vnet/fib/ip4_fib.h>
123 #include <vnet/dpo/drop_dpo.h>
124 #include <vnet/dpo/receive_dpo.h>
125 #include <vnet/dpo/lookup_dpo.h>
126 #include <vnet/dpo/classify_dpo.h>
127 #include <vnet/dpo/ip_null_dpo.h>
129 #define vl_typedefs /* define message structures */
130 #include <vpp-api/vpe_all_api_h.h>
133 #define vl_endianfun /* define message structures */
134 #include <vpp-api/vpe_all_api_h.h>
137 /* instantiate all the print functions we know about */
138 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
140 #include <vpp-api/vpe_all_api_h.h>
143 #include <vlibapi/api_helper_macros.h>
145 #define foreach_vpe_api_msg \
146 _(WANT_OAM_EVENTS, want_oam_events) \
147 _(OAM_ADD_DEL, oam_add_del) \
148 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
149 _(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \
150 _(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \
151 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
152 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
153 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
154 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
155 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
156 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
157 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
158 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
159 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
160 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
161 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
162 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
163 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
164 _(L2FIB_ADD_DEL, l2fib_add_del) \
165 _(L2_FLAGS, l2_flags) \
166 _(BRIDGE_FLAGS, bridge_flags) \
167 _(TAP_CONNECT, tap_connect) \
168 _(TAP_MODIFY, tap_modify) \
169 _(TAP_DELETE, tap_delete) \
170 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
171 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
172 _(CREATE_SUBIF, create_subif) \
173 _(MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del) \
174 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
175 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
176 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
177 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
178 _(RESET_FIB, reset_fib) \
179 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
180 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
181 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
182 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
183 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
184 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
185 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
186 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
187 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
188 sw_interface_ip6_set_link_local_address) \
189 _(CREATE_LOOPBACK, create_loopback) \
190 _(CONTROL_PING, control_ping) \
191 _(CLI_REQUEST, cli_request) \
192 _(CLI_INBAND, cli_inband) \
193 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
194 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
195 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
196 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
197 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
198 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
199 _(GET_NODE_INDEX, get_node_index) \
200 _(ADD_NODE_NEXT, add_node_next) \
201 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
202 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
203 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
204 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
205 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
206 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
207 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
208 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
209 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
210 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
211 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
212 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
213 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
214 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
215 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
216 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
217 _(IP_ADDRESS_DUMP, ip_address_dump) \
218 _(IP_DUMP, ip_dump) \
219 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
220 _(SHOW_VERSION, show_version) \
221 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
222 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
223 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
224 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
225 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
226 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
227 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
228 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
229 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
230 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
231 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
232 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
233 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
234 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
235 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
236 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
237 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
238 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
239 _(DELETE_LOOPBACK, delete_loopback) \
240 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
241 _(MAP_ADD_DOMAIN, map_add_domain) \
242 _(MAP_DEL_DOMAIN, map_del_domain) \
243 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
244 _(MAP_DOMAIN_DUMP, map_domain_dump) \
245 _(MAP_RULE_DUMP, map_rule_dump) \
246 _(MAP_SUMMARY_STATS, map_summary_stats) \
247 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
248 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
249 _(GET_NODE_GRAPH, get_node_graph) \
250 _(IOAM_ENABLE, ioam_enable) \
251 _(IOAM_DISABLE, ioam_disable) \
252 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
253 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
254 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
255 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
256 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
257 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
258 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
259 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
260 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
261 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
262 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
263 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
264 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
265 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
266 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
267 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
268 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
269 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
270 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
271 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
272 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
273 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
274 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
275 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
276 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
277 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
278 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
279 _(SHOW_LISP_STATUS, show_lisp_status) \
280 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
281 lisp_add_del_map_request_itr_rlocs) \
282 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
283 _(SHOW_LISP_PITR, show_lisp_pitr) \
284 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
285 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
286 _(AF_PACKET_CREATE, af_packet_create) \
287 _(AF_PACKET_DELETE, af_packet_delete) \
288 _(POLICER_ADD_DEL, policer_add_del) \
289 _(POLICER_DUMP, policer_dump) \
290 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
291 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
292 _(NETMAP_CREATE, netmap_create) \
293 _(NETMAP_DELETE, netmap_delete) \
294 _(MPLS_TUNNEL_DUMP, mpls_tunnel_dump) \
295 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
296 _(MPLS_FIB_DUMP, mpls_fib_dump) \
297 _(MPLS_FIB_DETAILS, mpls_fib_details) \
298 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
299 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
300 _(CLASSIFY_TABLE_INFO,classify_table_info) \
301 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
302 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
303 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
304 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
305 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
306 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
307 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
308 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
309 _(SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable) \
310 _(SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump) \
311 _(GET_NEXT_INDEX, get_next_index) \
312 _(PG_CREATE_INTERFACE, pg_create_interface) \
313 _(PG_CAPTURE, pg_capture) \
314 _(PG_ENABLE_DISABLE, pg_enable_disable) \
315 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
316 ip_source_and_port_range_check_add_del) \
317 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
318 ip_source_and_port_range_check_interface_add_del) \
319 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
320 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
321 _(DELETE_SUBIF, delete_subif) \
322 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
324 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
325 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
326 _(IPSEC_SPD_DUMP, ipsec_spd_dump) \
327 _(IP_FIB_DUMP, ip_fib_dump) \
328 _(IP_FIB_DETAILS, ip_fib_details) \
329 _(IP6_FIB_DUMP, ip6_fib_dump) \
330 _(IP6_FIB_DETAILS, ip6_fib_details) \
331 _(FEATURE_ENABLE_DISABLE, feature_enable_disable) \
334 #define QUOTE(x) QUOTE_(x)
338 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
339 RESOLVE_IP6_ADD_DEL_ROUTE,
342 static vlib_node_registration_t vpe_resolver_process_node;
343 vpe_api_main_t vpe_api_main;
345 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
346 unix_shared_memory_queue_t * q,
349 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
350 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
353 /* Clean up all registrations belonging to the indicated client */
355 vl_api_memclnt_delete_callback (u32 client_index)
357 vpe_api_main_t *vam = &vpe_api_main;
358 vpe_client_registration_t *rp;
360 int stats_memclnt_delete_callback (u32 client_index);
362 stats_memclnt_delete_callback (client_index);
365 p = hash_get (vam->a##_registration_hash, client_index); \
367 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
368 pool_put (vam->a##_registrations, rp); \
369 hash_unset (vam->a##_registration_hash, client_index); \
371 foreach_registration_hash;
376 pub_sub_handler (oam_events, OAM_EVENTS);
378 #define RESOLUTION_EVENT 1
379 #define RESOLUTION_PENDING_EVENT 2
380 #define IP4_ARP_EVENT 3
381 #define IP6_ND_EVENT 4
383 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
385 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
388 handle_ip4_arp_event (u32 pool_index)
390 vpe_api_main_t *vam = &vpe_api_main;
391 vnet_main_t *vnm = vam->vnet_main;
392 vlib_main_t *vm = vam->vlib_main;
393 vl_api_ip4_arp_event_t *event;
394 vl_api_ip4_arp_event_t *mp;
395 unix_shared_memory_queue_t *q;
397 /* Client can cancel, die, etc. */
398 if (pool_is_free_index (vam->arp_events, pool_index))
401 event = pool_elt_at_index (vam->arp_events, pool_index);
403 q = vl_api_client_index_to_input_queue (event->client_index);
406 (void) vnet_add_del_ip4_arp_change_event
407 (vnm, arp_change_delete_callback,
408 event->pid, &event->address,
409 vpe_resolver_process_node.index, IP4_ARP_EVENT,
410 ~0 /* pool index, notused */ , 0 /* is_add */ );
414 if (q->cursize < q->maxsize)
416 mp = vl_msg_api_alloc (sizeof (*mp));
417 clib_memcpy (mp, event, sizeof (*mp));
418 vl_msg_api_send_shmem (q, (u8 *) & mp);
422 static f64 last_time;
424 * Throttle syslog msgs.
425 * It's pretty tempting to just revoke the registration...
427 if (vlib_time_now (vm) > last_time + 10.0)
429 clib_warning ("arp event for %U to pid %d: queue stuffed!",
430 format_ip4_address, &event->address, event->pid);
431 last_time = vlib_time_now (vm);
437 handle_ip6_nd_event (u32 pool_index)
439 vpe_api_main_t *vam = &vpe_api_main;
440 vnet_main_t *vnm = vam->vnet_main;
441 vlib_main_t *vm = vam->vlib_main;
442 vl_api_ip6_nd_event_t *event;
443 vl_api_ip6_nd_event_t *mp;
444 unix_shared_memory_queue_t *q;
446 /* Client can cancel, die, etc. */
447 if (pool_is_free_index (vam->nd_events, pool_index))
450 event = pool_elt_at_index (vam->nd_events, pool_index);
452 q = vl_api_client_index_to_input_queue (event->client_index);
455 (void) vnet_add_del_ip6_nd_change_event
456 (vnm, nd_change_delete_callback,
457 event->pid, &event->address,
458 vpe_resolver_process_node.index, IP6_ND_EVENT,
459 ~0 /* pool index, notused */ , 0 /* is_add */ );
463 if (q->cursize < q->maxsize)
465 mp = vl_msg_api_alloc (sizeof (*mp));
466 clib_memcpy (mp, event, sizeof (*mp));
467 vl_msg_api_send_shmem (q, (u8 *) & mp);
471 static f64 last_time;
473 * Throttle syslog msgs.
474 * It's pretty tempting to just revoke the registration...
476 if (vlib_time_now (vm) > last_time + 10.0)
478 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
479 format_ip6_address, &event->address, event->pid);
480 last_time = vlib_time_now (vm);
486 resolver_process (vlib_main_t * vm,
487 vlib_node_runtime_t * rt, vlib_frame_t * f)
490 uword *event_data = 0;
496 vlib_process_wait_for_event_or_clock (vm, timeout);
498 event_type = vlib_process_get_events (vm, &event_data);
502 case RESOLUTION_PENDING_EVENT:
506 case RESOLUTION_EVENT:
507 clib_warning ("resolver: BOGUS TYPE");
511 for (i = 0; i < vec_len (event_data); i++)
512 handle_ip4_arp_event (event_data[i]);
516 for (i = 0; i < vec_len (event_data); i++)
517 handle_ip6_nd_event (event_data[i]);
520 case ~0: /* timeout */
524 vec_reset_length (event_data);
526 return 0; /* or not */
530 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
531 .function = resolver_process,
532 .type = VLIB_NODE_TYPE_PROCESS,
533 .name = "vpe-route-resolver-process",
538 add_del_route_t_handler (u8 is_multipath,
545 u32 classify_table_index,
547 u8 is_resolve_attached,
549 const fib_prefix_t * prefix,
550 u8 next_hop_proto_is_ip4,
551 const ip46_address_t * next_hop,
552 u32 next_hop_sw_if_index,
553 u8 next_hop_fib_index,
555 mpls_label_t next_hop_via_label,
556 mpls_label_t * next_hop_out_label_stack)
558 vnet_classify_main_t *cm = &vnet_classify_main;
559 stats_main_t *sm = &stats_main;
560 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
561 fib_route_path_t path = {
562 .frp_proto = (next_hop_proto_is_ip4 ?
563 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6),
564 .frp_addr = (NULL == next_hop ? zero_addr : *next_hop),
565 .frp_sw_if_index = next_hop_sw_if_index,
566 .frp_fib_index = next_hop_fib_index,
567 .frp_weight = next_hop_weight,
568 .frp_label_stack = next_hop_out_label_stack,
570 fib_route_path_t *paths = NULL;
572 if (MPLS_LABEL_INVALID != next_hop_via_label)
574 path.frp_proto = FIB_PROTOCOL_MPLS;
575 path.frp_local_label = next_hop_via_label;
578 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
579 if (is_resolve_attached)
580 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
582 path.frp_flags = path_flags;
586 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
589 vec_add1 (paths, path);
592 fib_table_entry_path_add2 (fib_index,
595 FIB_ENTRY_FLAG_NONE, paths);
597 fib_table_entry_path_remove2 (fib_index,
598 prefix, FIB_SOURCE_API, paths);
605 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
607 if (is_drop || is_local || is_classify || is_unreach || is_prohibit)
610 * special route types that link directly to the adj
614 dpo_id_t dpo = DPO_INVALID;
617 dproto = fib_proto_to_dpo (prefix->fp_proto);
620 ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo);
622 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
624 ip_null_dpo_add_and_lock (dproto,
625 IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo);
626 else if (is_prohibit)
627 ip_null_dpo_add_and_lock (dproto,
628 IP_NULL_ACTION_SEND_ICMP_PROHIBIT,
630 else if (is_classify)
632 if (pool_is_free_index (cm->tables,
633 ntohl (classify_table_index)))
636 return VNET_API_ERROR_NO_SUCH_TABLE;
639 dpo_set (&dpo, DPO_CLASSIFY, dproto,
640 classify_dpo_create (dproto,
641 ntohl (classify_table_index)));
646 return VNET_API_ERROR_NO_SUCH_TABLE;
649 fib_table_entry_special_dpo_update (fib_index,
652 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
657 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
664 vec_add1 (paths, path);
665 fib_table_entry_update (fib_index,
667 FIB_SOURCE_API, FIB_ENTRY_FLAG_NONE, paths);
672 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
681 add_del_route_check (fib_protocol_t table_proto,
683 u32 next_hop_sw_if_index,
684 fib_protocol_t next_hop_table_proto,
685 u32 next_hop_table_id,
686 u8 create_missing_tables,
687 u32 * fib_index, u32 * next_hop_fib_index)
689 vnet_main_t *vnm = vnet_get_main ();
691 *fib_index = fib_table_find (table_proto, ntohl (table_id));
692 if (~0 == *fib_index)
694 if (create_missing_tables)
696 *fib_index = fib_table_find_or_create_and_lock (table_proto,
701 /* No such VRF, and we weren't asked to create one */
702 return VNET_API_ERROR_NO_SUCH_FIB;
706 if (~0 != ntohl (next_hop_sw_if_index))
708 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
709 ntohl (next_hop_sw_if_index)))
711 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
716 *next_hop_fib_index = fib_table_find (next_hop_table_proto,
717 ntohl (next_hop_table_id));
719 if (~0 == *next_hop_fib_index)
721 if (create_missing_tables)
723 *next_hop_fib_index =
724 fib_table_find_or_create_and_lock (next_hop_table_proto,
725 ntohl (next_hop_table_id));
729 /* No such VRF, and we weren't asked to create one */
730 return VNET_API_ERROR_NO_SUCH_FIB;
739 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
741 u32 fib_index, next_hop_fib_index;
742 mpls_label_t *label_stack = NULL;
743 int rv, ii, n_labels;;
745 rv = add_del_route_check (FIB_PROTOCOL_IP4,
747 mp->next_hop_sw_if_index,
749 mp->next_hop_table_id,
750 mp->create_vrf_if_needed,
751 &fib_index, &next_hop_fib_index);
757 .fp_len = mp->dst_address_length,
758 .fp_proto = FIB_PROTOCOL_IP4,
760 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
763 memset (&nh, 0, sizeof (nh));
764 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
766 n_labels = mp->next_hop_n_out_labels;
769 else if (1 == n_labels)
770 vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0]));
773 vec_validate (label_stack, n_labels - 1);
774 for (ii = 0; ii < n_labels; ii++)
775 label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]);
778 return (add_del_route_t_handler (mp->is_multipath,
785 mp->classify_table_index,
787 mp->is_resolve_attached,
790 ntohl (mp->next_hop_sw_if_index),
793 ntohl (mp->next_hop_via_label),
798 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
800 u32 fib_index, next_hop_fib_index;
801 mpls_label_t *label_stack = NULL;
802 int rv, ii, n_labels;;
804 rv = add_del_route_check (FIB_PROTOCOL_IP6,
806 mp->next_hop_sw_if_index,
808 mp->next_hop_table_id,
809 mp->create_vrf_if_needed,
810 &fib_index, &next_hop_fib_index);
816 .fp_len = mp->dst_address_length,
817 .fp_proto = FIB_PROTOCOL_IP6,
819 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
822 memset (&nh, 0, sizeof (nh));
823 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
825 n_labels = mp->next_hop_n_out_labels;
828 else if (1 == n_labels)
829 vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0]));
832 vec_validate (label_stack, n_labels - 1);
833 for (ii = 0; ii < n_labels; ii++)
834 label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]);
837 return (add_del_route_t_handler (mp->is_multipath,
844 mp->classify_table_index,
846 mp->is_resolve_attached,
848 &nh, ntohl (mp->next_hop_sw_if_index),
851 ntohl (mp->next_hop_via_label),
856 mpls_route_add_del_t_handler (vnet_main_t * vnm,
857 vl_api_mpls_route_add_del_t * mp)
859 u32 fib_index, next_hop_fib_index;
860 mpls_label_t *label_stack = NULL;
861 int rv, ii, n_labels;;
865 .fp_proto = FIB_PROTOCOL_MPLS,
866 .fp_eos = mp->mr_eos,
867 .fp_label = ntohl (mp->mr_label),
871 if (mp->mr_next_hop_proto_is_ip4)
873 pfx.fp_payload_proto = DPO_PROTO_IP4;
877 pfx.fp_payload_proto = DPO_PROTO_IP6;
882 pfx.fp_payload_proto = DPO_PROTO_MPLS;
885 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
887 mp->mr_next_hop_sw_if_index,
888 dpo_proto_to_fib (pfx.fp_payload_proto),
889 mp->mr_next_hop_table_id,
890 mp->mr_create_table_if_needed,
891 &fib_index, &next_hop_fib_index);
897 memset (&nh, 0, sizeof (nh));
899 if (mp->mr_next_hop_proto_is_ip4)
900 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
902 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
904 n_labels = mp->mr_next_hop_n_out_labels;
907 else if (1 == n_labels)
908 vec_add1 (label_stack, ntohl (mp->mr_next_hop_out_label_stack[0]));
911 vec_validate (label_stack, n_labels - 1);
912 for (ii = 0; ii < n_labels; ii++)
913 label_stack[ii] = ntohl (mp->mr_next_hop_out_label_stack[ii]);
916 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
917 0, // mp->is_unreach,
918 0, // mp->is_prohibit,
921 mp->mr_classify_table_index,
922 mp->mr_is_resolve_host,
923 mp->mr_is_resolve_attached,
925 mp->mr_next_hop_proto_is_ip4,
926 &nh, ntohl (mp->mr_next_hop_sw_if_index),
928 mp->mr_next_hop_weight,
929 ntohl (mp->mr_next_hop_via_label),
934 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
936 vl_api_ip_add_del_route_reply_t *rmp;
938 vnet_main_t *vnm = vnet_get_main ();
943 rv = ip6_add_del_route_t_handler (mp);
945 rv = ip4_add_del_route_t_handler (mp);
947 rv = (rv == 0) ? vnm->api_errno : rv;
949 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
953 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
955 vl_api_mpls_route_add_del_reply_t *rmp;
959 vnm = vnet_get_main ();
962 rv = mpls_route_add_del_t_handler (vnm, mp);
964 rv = (rv == 0) ? vnm->api_errno : rv;
966 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
970 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
971 vl_api_mpls_ip_bind_unbind_t * mp)
973 u32 mpls_fib_index, ip_fib_index;
976 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
978 if (~0 == mpls_fib_index)
980 if (mp->mb_create_table_if_needed)
983 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
984 ntohl (mp->mb_mpls_table_id));
987 return VNET_API_ERROR_NO_SUCH_FIB;
990 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
993 ntohl (mp->mb_ip_table_id));
994 if (~0 == ip_fib_index)
995 return VNET_API_ERROR_NO_SUCH_FIB;
998 .fp_len = mp->mb_address_length,
1003 pfx.fp_proto = FIB_PROTOCOL_IP4;
1004 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
1005 sizeof (pfx.fp_addr.ip4));
1009 pfx.fp_proto = FIB_PROTOCOL_IP6;
1010 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
1011 sizeof (pfx.fp_addr.ip6));
1015 fib_table_entry_local_label_add (ip_fib_index, &pfx,
1016 ntohl (mp->mb_label));
1018 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
1019 ntohl (mp->mb_label));
1025 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
1027 vl_api_mpls_route_add_del_reply_t *rmp;
1031 vnm = vnet_get_main ();
1034 rv = mpls_ip_bind_unbind_handler (vnm, mp);
1036 rv = (rv == 0) ? vnm->api_errno : rv;
1038 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1042 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1044 vl_api_sw_interface_set_vpath_reply_t *rmp;
1046 u32 sw_if_index = ntohl (mp->sw_if_index);
1048 VALIDATE_SW_IF_INDEX (mp);
1050 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1051 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
1052 sw_if_index, mp->enable, 0, 0);
1053 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
1054 sw_if_index, mp->enable, 0, 0);
1055 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
1056 sw_if_index, mp->enable, 0, 0);
1057 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
1058 sw_if_index, mp->enable, 0, 0);
1060 BAD_SW_IF_INDEX_LABEL;
1062 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1066 vl_api_sw_interface_set_vxlan_bypass_t_handler
1067 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
1069 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
1071 u32 sw_if_index = ntohl (mp->sw_if_index);
1073 VALIDATE_SW_IF_INDEX (mp);
1077 /* not yet implemented */
1080 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
1081 sw_if_index, mp->enable, 0, 0);
1083 BAD_SW_IF_INDEX_LABEL;
1085 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
1089 vl_api_sw_interface_set_l2_xconnect_t_handler
1090 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1092 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1094 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1095 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1096 vlib_main_t *vm = vlib_get_main ();
1097 vnet_main_t *vnm = vnet_get_main ();
1099 VALIDATE_RX_SW_IF_INDEX (mp);
1103 VALIDATE_TX_SW_IF_INDEX (mp);
1104 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1105 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1109 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1112 BAD_RX_SW_IF_INDEX_LABEL;
1113 BAD_TX_SW_IF_INDEX_LABEL;
1115 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1119 vl_api_sw_interface_set_l2_bridge_t_handler
1120 (vl_api_sw_interface_set_l2_bridge_t * mp)
1122 bd_main_t *bdm = &bd_main;
1123 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1125 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1126 u32 bd_id = ntohl (mp->bd_id);
1130 vlib_main_t *vm = vlib_get_main ();
1131 vnet_main_t *vnm = vnet_get_main ();
1133 VALIDATE_RX_SW_IF_INDEX (mp);
1135 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1139 //VALIDATE_TX_SW_IF_INDEX(mp);
1140 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1141 rx_sw_if_index, bd_index, bvi, shg, 0);
1145 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1148 BAD_RX_SW_IF_INDEX_LABEL;
1150 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1154 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1155 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1157 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1161 dpdk_main_t *dm = &dpdk_main;
1164 u32 sw_if_index = ntohl (mp->sw_if_index);
1165 u32 subport = ntohl (mp->subport);
1166 u32 pipe = ntohl (mp->pipe);
1167 u32 profile = ntohl (mp->profile);
1168 vnet_hw_interface_t *hw;
1170 VALIDATE_SW_IF_INDEX (mp);
1172 /* hw_if & dpdk device */
1173 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1175 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1177 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1179 BAD_SW_IF_INDEX_LABEL;
1181 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1182 rv = VNET_API_ERROR_UNIMPLEMENTED;
1185 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1189 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1190 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1192 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1196 dpdk_main_t *dm = &dpdk_main;
1198 struct rte_sched_subport_params p;
1200 u32 sw_if_index = ntohl (mp->sw_if_index);
1201 u32 subport = ntohl (mp->subport);
1202 p.tb_rate = ntohl (mp->tb_rate);
1203 p.tb_size = ntohl (mp->tb_size);
1204 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1205 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1206 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1207 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1208 p.tc_period = ntohl (mp->tc_period);
1210 vnet_hw_interface_t *hw;
1212 VALIDATE_SW_IF_INDEX (mp);
1214 /* hw_if & dpdk device */
1215 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1217 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1219 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1221 BAD_SW_IF_INDEX_LABEL;
1224 ("setting HQoS subport parameters without DPDK not implemented");
1225 rv = VNET_API_ERROR_UNIMPLEMENTED;
1228 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1232 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1233 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1235 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1239 dpdk_main_t *dm = &dpdk_main;
1240 vlib_thread_main_t *tm = vlib_get_thread_main ();
1243 u32 sw_if_index = ntohl (mp->sw_if_index);
1244 u32 entry = ntohl (mp->entry);
1245 u32 tc = ntohl (mp->tc);
1246 u32 queue = ntohl (mp->queue);
1249 vnet_hw_interface_t *hw;
1251 VALIDATE_SW_IF_INDEX (mp);
1253 /* hw_if & dpdk device */
1254 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1256 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1258 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1260 clib_warning ("invalid traffic class !!");
1261 rv = VNET_API_ERROR_INVALID_VALUE;
1264 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1266 clib_warning ("invalid queue !!");
1267 rv = VNET_API_ERROR_INVALID_VALUE;
1271 /* Detect the set of worker threads */
1272 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1276 clib_warning ("worker thread registration AWOL !!");
1277 rv = VNET_API_ERROR_INVALID_VALUE_2;
1281 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1282 int worker_thread_first = tr->first_index;
1283 int worker_thread_count = tr->count;
1285 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1286 for (i = 0; i < worker_thread_count; i++)
1287 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1289 BAD_SW_IF_INDEX_LABEL;
1292 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1293 rv = VNET_API_ERROR_UNIMPLEMENTED;
1296 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1300 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1302 vlib_main_t *vm = vlib_get_main ();
1303 bd_main_t *bdm = &bd_main;
1304 vl_api_bridge_domain_add_del_reply_t *rmp;
1306 u32 enable_flags = 0, disable_flags = 0;
1307 u32 bd_id = ntohl (mp->bd_id);
1312 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1315 enable_flags |= L2_FLOOD;
1317 disable_flags |= L2_FLOOD;
1320 enable_flags |= L2_UU_FLOOD;
1322 disable_flags |= L2_UU_FLOOD;
1325 enable_flags |= L2_FWD;
1327 disable_flags |= L2_FWD;
1330 enable_flags |= L2_ARP_TERM;
1332 disable_flags |= L2_ARP_TERM;
1335 enable_flags |= L2_LEARN;
1337 disable_flags |= L2_LEARN;
1340 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1343 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1347 rv = bd_delete_bd_index (bdm, bd_id);
1349 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1353 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1355 clib_warning ("BUG");
1359 vl_api_bridge_domain_sw_if_details_t_handler
1360 (vl_api_bridge_domain_sw_if_details_t * mp)
1362 clib_warning ("BUG");
1366 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1367 l2_bridge_domain_t * bd_config,
1368 u32 n_sw_ifs, u32 context)
1370 vl_api_bridge_domain_details_t *mp;
1372 mp = vl_msg_api_alloc (sizeof (*mp));
1373 memset (mp, 0, sizeof (*mp));
1374 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1375 mp->bd_id = ntohl (bd_config->bd_id);
1376 mp->flood = bd_feature_flood (bd_config);
1377 mp->uu_flood = bd_feature_uu_flood (bd_config);
1378 mp->forward = bd_feature_forward (bd_config);
1379 mp->learn = bd_feature_learn (bd_config);
1380 mp->arp_term = bd_feature_arp_term (bd_config);
1381 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1382 mp->n_sw_ifs = ntohl (n_sw_ifs);
1383 mp->context = context;
1385 vl_msg_api_send_shmem (q, (u8 *) & mp);
1389 send_bd_sw_if_details (l2input_main_t * l2im,
1390 unix_shared_memory_queue_t * q,
1391 l2_flood_member_t * member, u32 bd_id, u32 context)
1393 vl_api_bridge_domain_sw_if_details_t *mp;
1394 l2_input_config_t *input_cfg;
1396 mp = vl_msg_api_alloc (sizeof (*mp));
1397 memset (mp, 0, sizeof (*mp));
1398 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1399 mp->bd_id = ntohl (bd_id);
1400 mp->sw_if_index = ntohl (member->sw_if_index);
1401 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1402 mp->shg = input_cfg->shg;
1403 mp->context = context;
1405 vl_msg_api_send_shmem (q, (u8 *) & mp);
1409 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1411 bd_main_t *bdm = &bd_main;
1412 l2input_main_t *l2im = &l2input_main;
1413 unix_shared_memory_queue_t *q;
1414 l2_bridge_domain_t *bd_config;
1415 u32 bd_id, bd_index;
1418 q = vl_api_client_index_to_input_queue (mp->client_index);
1423 bd_id = ntohl (mp->bd_id);
1425 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1426 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1427 for (; bd_index < end; bd_index++)
1429 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1430 /* skip dummy bd_id 0 */
1431 if (bd_config && (bd_config->bd_id > 0))
1434 l2_flood_member_t *m;
1436 n_sw_ifs = vec_len (bd_config->members);
1437 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1439 vec_foreach (m, bd_config->members)
1441 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1448 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1450 bd_main_t *bdm = &bd_main;
1451 l2input_main_t *l2im = &l2input_main;
1452 vl_api_l2fib_add_del_reply_t *rmp;
1455 u32 sw_if_index = ntohl (mp->sw_if_index);
1456 u32 bd_id = ntohl (mp->bd_id);
1465 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1468 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1469 goto bad_sw_if_index;
1475 filter_mac = mp->filter_mac ? 1 : 0;
1476 if (filter_mac == 0)
1478 VALIDATE_SW_IF_INDEX (mp);
1479 if (vec_len (l2im->configs) <= sw_if_index)
1481 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1482 goto bad_sw_if_index;
1486 l2_input_config_t *config;
1487 config = vec_elt_at_index (l2im->configs, sw_if_index);
1488 if (config->bridge == 0)
1490 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1491 goto bad_sw_if_index;
1495 static_mac = mp->static_mac ? 1 : 0;
1496 bvi_mac = mp->bvi_mac ? 1 : 0;
1497 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1502 l2fib_del_entry (mac, bd_index);
1505 BAD_SW_IF_INDEX_LABEL;
1507 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1511 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1513 vl_api_l2_flags_reply_t *rmp;
1515 u32 sw_if_index = ntohl (mp->sw_if_index);
1516 u32 flags = ntohl (mp->feature_bitmap);
1519 VALIDATE_SW_IF_INDEX (mp);
1522 if (flags & L2INPUT_FEAT_ ## a) \
1523 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1524 foreach_l2input_feat;
1527 BAD_SW_IF_INDEX_LABEL;
1530 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1532 rmp->resulting_feature_bitmap = ntohl(rbm);
1538 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1540 vlib_main_t *vm = vlib_get_main ();
1541 bd_main_t *bdm = &bd_main;
1542 vl_api_bridge_flags_reply_t *rmp;
1544 u32 bd_id = ntohl (mp->bd_id);
1546 u32 flags = ntohl (mp->feature_bitmap);
1549 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1552 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1558 bd_set_flags (vm, bd_index, flags, mp->is_set);
1562 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1564 rmp->resulting_feature_bitmap = ntohl(flags);
1570 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1572 bd_main_t *bdm = &bd_main;
1573 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1575 u32 bd_id = ntohl (mp->bd_id);
1579 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1582 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1587 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1588 mp->mac_address, mp->is_ipv6, mp->is_add))
1589 rv = VNET_API_ERROR_UNSPECIFIED;
1592 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1596 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp)
1598 vlib_main_t *vm = vlib_get_main ();
1600 vl_api_tap_connect_reply_t *rmp;
1601 vnet_main_t *vnm = vnet_get_main ();
1602 unix_shared_memory_queue_t *q;
1603 u32 sw_if_index = (u32) ~ 0;
1606 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1607 mp->use_random_mac ? 0 : mp->mac_address,
1608 &sw_if_index, mp->renumber,
1609 ntohl (mp->custom_dev_instance));
1611 /* Add tag if supplied */
1612 if (rv == 0 && mp->tag[0])
1614 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
1615 tag = format (0, "%s%c", mp->tag, 0);
1616 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1619 q = vl_api_client_index_to_input_queue (mp->client_index);
1623 rmp = vl_msg_api_alloc (sizeof (*rmp));
1624 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1625 rmp->context = mp->context;
1626 rmp->retval = ntohl (rv);
1627 rmp->sw_if_index = ntohl (sw_if_index);
1629 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1633 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp)
1636 vl_api_tap_modify_reply_t *rmp;
1637 unix_shared_memory_queue_t *q;
1638 u32 sw_if_index = (u32) ~ 0;
1639 vlib_main_t *vm = vlib_get_main ();
1641 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1642 mp->use_random_mac ? 0 : mp->mac_address,
1643 &sw_if_index, mp->renumber,
1644 ntohl (mp->custom_dev_instance));
1646 q = vl_api_client_index_to_input_queue (mp->client_index);
1650 rmp = vl_msg_api_alloc (sizeof (*rmp));
1651 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1652 rmp->context = mp->context;
1653 rmp->retval = ntohl (rv);
1654 rmp->sw_if_index = ntohl (sw_if_index);
1656 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1660 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp)
1662 vlib_main_t *vm = vlib_get_main ();
1664 vpe_api_main_t *vam = &vpe_api_main;
1665 vl_api_tap_delete_reply_t *rmp;
1666 unix_shared_memory_queue_t *q;
1667 u32 sw_if_index = ntohl (mp->sw_if_index);
1669 rv = vnet_tap_delete (vm, sw_if_index);
1672 vnet_main_t *vnm = vnet_get_main ();
1673 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1676 q = vl_api_client_index_to_input_queue (mp->client_index);
1680 rmp = vl_msg_api_alloc (sizeof (*rmp));
1681 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1682 rmp->context = mp->context;
1683 rmp->retval = ntohl (rv);
1685 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1688 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1692 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1694 vl_api_create_vlan_subif_reply_t *rmp;
1695 vnet_main_t *vnm = vnet_get_main ();
1696 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1697 vnet_hw_interface_t *hi;
1700 vnet_sw_interface_t template;
1702 vnet_interface_main_t *im = &vnm->interface_main;
1703 u64 sup_and_sub_key;
1705 unix_shared_memory_queue_t *q;
1706 clib_error_t *error;
1708 VALIDATE_SW_IF_INDEX (mp);
1710 hw_if_index = ntohl (mp->sw_if_index);
1711 hi = vnet_get_hw_interface (vnm, hw_if_index);
1713 id = ntohl (mp->vlan_id);
1714 if (id == 0 || id > 4095)
1716 rv = VNET_API_ERROR_INVALID_VLAN;
1720 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1722 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1725 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1729 kp = clib_mem_alloc (sizeof (*kp));
1730 *kp = sup_and_sub_key;
1732 memset (&template, 0, sizeof (template));
1733 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1734 template.sup_sw_if_index = hi->sw_if_index;
1735 template.sub.id = id;
1736 template.sub.eth.raw_flags = 0;
1737 template.sub.eth.flags.one_tag = 1;
1738 template.sub.eth.outer_vlan_id = id;
1739 template.sub.eth.flags.exact_match = 1;
1741 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1744 clib_error_report (error);
1745 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1748 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1749 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1751 BAD_SW_IF_INDEX_LABEL;
1754 q = vl_api_client_index_to_input_queue (mp->client_index);
1758 rmp = vl_msg_api_alloc (sizeof (*rmp));
1759 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1760 rmp->context = mp->context;
1761 rmp->retval = ntohl (rv);
1762 rmp->sw_if_index = ntohl (sw_if_index);
1763 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1767 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1769 vl_api_create_subif_reply_t *rmp;
1770 vnet_main_t *vnm = vnet_get_main ();
1771 u32 sw_if_index = ~0;
1774 vnet_sw_interface_t *si;
1775 vnet_hw_interface_t *hi;
1776 vnet_sw_interface_t template;
1778 vnet_interface_main_t *im = &vnm->interface_main;
1779 u64 sup_and_sub_key;
1781 clib_error_t *error;
1783 VALIDATE_SW_IF_INDEX (mp);
1785 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1786 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1788 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1790 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1794 sw_if_index = si->sw_if_index;
1795 sub_id = ntohl (mp->sub_id);
1797 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1799 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1803 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1804 sw_if_index, sub_id);
1805 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1809 kp = clib_mem_alloc (sizeof (*kp));
1810 *kp = sup_and_sub_key;
1812 memset (&template, 0, sizeof (template));
1813 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1814 template.sup_sw_if_index = sw_if_index;
1815 template.sub.id = sub_id;
1816 template.sub.eth.flags.no_tags = mp->no_tags;
1817 template.sub.eth.flags.one_tag = mp->one_tag;
1818 template.sub.eth.flags.two_tags = mp->two_tags;
1819 template.sub.eth.flags.dot1ad = mp->dot1ad;
1820 template.sub.eth.flags.exact_match = mp->exact_match;
1821 template.sub.eth.flags.default_sub = mp->default_sub;
1822 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1823 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1824 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1825 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1827 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1830 clib_error_report (error);
1831 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1835 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1836 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1838 BAD_SW_IF_INDEX_LABEL;
1843 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1845 rmp->sw_if_index = ntohl(sw_if_index);
1851 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
1853 vl_api_mpls_tunnel_add_del_reply_t *rmp;
1855 stats_main_t *sm = &stats_main;
1856 u32 tunnel_sw_if_index;
1859 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1863 fib_route_path_t rpath, *rpaths = NULL;
1864 mpls_label_t *label_stack = NULL;
1866 memset (&rpath, 0, sizeof (rpath));
1868 if (mp->mt_next_hop_proto_is_ip4)
1870 rpath.frp_proto = FIB_PROTOCOL_IP4;
1871 clib_memcpy (&rpath.frp_addr.ip4,
1872 mp->mt_next_hop, sizeof (rpath.frp_addr.ip4));
1876 rpath.frp_proto = FIB_PROTOCOL_IP6;
1877 clib_memcpy (&rpath.frp_addr.ip6,
1878 mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
1880 rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
1882 for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
1883 vec_add1 (label_stack, ntohl (mp->mt_next_hop_out_label_stack[ii]));
1885 vec_add1 (rpaths, rpath);
1887 vnet_mpls_tunnel_add (rpaths, label_stack,
1888 mp->mt_l2_only, &tunnel_sw_if_index);
1890 vec_free (label_stack);
1894 tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
1895 vnet_mpls_tunnel_del (tunnel_sw_if_index);
1901 REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
1903 rmp->sw_if_index = ntohl(tunnel_sw_if_index);
1909 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
1911 vl_api_proxy_arp_add_del_reply_t *rmp;
1914 ip4_main_t *im = &ip4_main;
1915 stats_main_t *sm = &stats_main;
1916 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
1917 ip4_address_t * hi_addr,
1918 u32 fib_index, int is_del);
1921 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
1923 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1927 rv = VNET_API_ERROR_NO_SUCH_FIB;
1933 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
1934 (ip4_address_t *) mp->hi_address,
1935 fib_index, mp->is_add == 0);
1939 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
1943 vl_api_proxy_arp_intfc_enable_disable_t_handler
1944 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
1947 vnet_main_t *vnm = vnet_get_main ();
1948 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
1949 vnet_sw_interface_t *si;
1952 VALIDATE_SW_IF_INDEX (mp);
1954 sw_if_index = ntohl (mp->sw_if_index);
1956 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1958 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1962 si = vnet_get_sw_interface (vnm, sw_if_index);
1966 if (mp->enable_disable)
1967 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1969 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1971 BAD_SW_IF_INDEX_LABEL;
1974 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
1978 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
1981 vl_api_ip_neighbor_add_del_reply_t *rmp;
1982 vnet_main_t *vnm = vnet_get_main ();
1983 stats_main_t *sm = &stats_main;
1986 VALIDATE_SW_IF_INDEX (mp);
1988 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
1991 * there's no validation here of the ND/ARP entry being added.
1992 * The expectation is that the FIB will ensure that nothing bad
1993 * will come of adding bogus entries.
1998 rv = vnet_set_ip6_ethernet_neighbor
1999 (vm, ntohl (mp->sw_if_index),
2000 (ip6_address_t *) (mp->dst_address),
2001 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2003 rv = vnet_unset_ip6_ethernet_neighbor
2004 (vm, ntohl (mp->sw_if_index),
2005 (ip6_address_t *) (mp->dst_address),
2006 mp->mac_address, sizeof (mp->mac_address));
2010 ethernet_arp_ip4_over_ethernet_address_t a;
2012 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2013 clib_memcpy (&a.ip4, mp->dst_address, 4);
2016 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2020 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2023 BAD_SW_IF_INDEX_LABEL;
2026 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2030 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2033 vpe_main_t *rm = &vpe_main;
2034 ip4_main_t *im4 = &ip4_main;
2035 ip6_main_t *im6 = &ip6_main;
2036 ip_lookup_main_t *lm;
2042 u32 adj_index, sw_if_index;
2043 vl_api_is_address_reachable_t *rmp;
2044 ip_adjacency_t *adj;
2045 unix_shared_memory_queue_t *q;
2047 q = vl_api_client_index_to_input_queue (mp->client_index);
2050 increment_missing_api_client_counter (rm->vlib_main);
2054 rmp = vl_msg_api_alloc (sizeof (*rmp));
2055 clib_memcpy (rmp, mp, sizeof (*rmp));
2057 sw_if_index = mp->next_hop_sw_if_index;
2058 clib_memcpy (&addr, mp->address, sizeof (addr));
2061 lm = &im6->lookup_main;
2062 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2066 lm = &im4->lookup_main;
2068 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2070 if (adj_index == ~0)
2075 adj = ip_get_adjacency (lm, adj_index);
2077 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2078 && adj->rewrite_header.sw_if_index == sw_if_index)
2084 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2085 && adj->rewrite_header.sw_if_index == sw_if_index)
2088 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2090 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2092 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2101 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2106 vl_api_sw_interface_set_mpls_enable_t_handler
2107 (vl_api_sw_interface_set_mpls_enable_t * mp)
2109 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2112 VALIDATE_SW_IF_INDEX (mp);
2114 mpls_sw_interface_enable_disable (&mpls_main,
2115 ntohl (mp->sw_if_index), mp->enable);
2117 BAD_SW_IF_INDEX_LABEL;
2118 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2121 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2122 unix_shared_memory_queue_t * q,
2124 __attribute__ ((unused));
2127 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2128 unix_shared_memory_queue_t * q,
2131 vl_api_sw_interface_set_flags_t *mp;
2133 mp = vl_msg_api_alloc (sizeof (*mp));
2134 memset (mp, 0, sizeof (*mp));
2135 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2136 mp->sw_if_index = ntohl (sw_if_index);
2138 mp->admin_up_down = 0;
2139 mp->link_up_down = 0;
2141 vl_msg_api_send_shmem (q, (u8 *) & mp);
2145 send_oam_event (oam_target_t * t)
2147 vpe_api_main_t *vam = &vpe_api_main;
2148 unix_shared_memory_queue_t *q;
2149 vpe_client_registration_t *reg;
2150 vl_api_oam_event_t *mp;
2153 pool_foreach(reg, vam->oam_events_registrations,
2155 q = vl_api_client_index_to_input_queue (reg->client_index);
2158 mp = vl_msg_api_alloc (sizeof (*mp));
2159 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2160 clib_memcpy (mp->dst_address, &t->dst_address,
2161 sizeof (mp->dst_address));
2162 mp->state = t->state;
2163 vl_msg_api_send_shmem (q, (u8 *)&mp);
2170 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2172 vl_api_oam_add_del_reply_t *rmp;
2175 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2176 (ip4_address_t *) mp->dst_address,
2177 ntohl (mp->vrf_id), (int) (mp->is_add));
2179 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2183 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2185 stats_main_t *sm = &stats_main;
2186 vnet_interface_main_t *im = sm->interface_main;
2187 vl_api_vnet_summary_stats_reply_t *rmp;
2188 vlib_combined_counter_main_t *cm;
2191 u64 total_pkts[VLIB_N_RX_TX];
2192 u64 total_bytes[VLIB_N_RX_TX];
2194 unix_shared_memory_queue_t *q =
2195 vl_api_client_index_to_input_queue (mp->client_index);
2200 rmp = vl_msg_api_alloc (sizeof (*rmp));
2201 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2202 rmp->context = mp->context;
2205 memset (total_pkts, 0, sizeof (total_pkts));
2206 memset (total_bytes, 0, sizeof (total_bytes));
2208 vnet_interface_counter_lock (im);
2210 vec_foreach (cm, im->combined_sw_if_counters)
2212 which = cm - im->combined_sw_if_counters;
2214 for (i = 0; i < vec_len (cm->maxi); i++)
2216 vlib_get_combined_counter (cm, i, &v);
2217 total_pkts[which] += v.packets;
2218 total_bytes[which] += v.bytes;
2221 vnet_interface_counter_unlock (im);
2223 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2224 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2225 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2226 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2228 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2230 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2234 typedef CLIB_PACKED (struct {
2235 ip4_address_t address;
2236 u32 address_length: 6;
2242 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2244 vnet_main_t *vnm = vnet_get_main ();
2245 vnet_interface_main_t *im = &vnm->interface_main;
2246 ip4_main_t *im4 = &ip4_main;
2247 static u32 *sw_if_indices_to_shut;
2248 stats_main_t *sm = &stats_main;
2249 fib_table_t *fib_table;
2253 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2254 u32 target_fib_id = ntohl (mp->vrf_id);
2256 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2259 pool_foreach (fib_table, im4->fibs,
2261 fib = &fib_table->v4;
2262 vnet_sw_interface_t * si;
2264 if (fib->table_id != target_fib_id)
2267 /* remove any mpls encap/decap labels */
2268 mpls_fib_reset_labels (fib->table_id);
2270 /* remove any proxy arps in this fib */
2271 vnet_proxy_arp_fib_reset (fib->table_id);
2273 /* Set the flow hash for this fib to the default */
2274 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2276 vec_reset_length (sw_if_indices_to_shut);
2278 /* Shut down interfaces in this FIB / clean out intfc routes */
2279 pool_foreach (si, im->sw_interfaces,
2281 u32 sw_if_index = si->sw_if_index;
2283 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2284 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2286 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2289 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2290 sw_if_index = sw_if_indices_to_shut[i];
2291 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2293 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2294 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2295 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2298 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
2299 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
2303 })); /* pool_foreach (fib) */
2311 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2313 vnet_main_t *vnm = vnet_get_main ();
2314 vnet_interface_main_t *im = &vnm->interface_main;
2315 ip6_main_t *im6 = &ip6_main;
2316 stats_main_t *sm = &stats_main;
2317 static u32 *sw_if_indices_to_shut;
2318 fib_table_t *fib_table;
2322 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2323 u32 target_fib_id = ntohl (mp->vrf_id);
2325 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
2328 pool_foreach (fib_table, im6->fibs,
2330 vnet_sw_interface_t * si;
2331 fib = &(fib_table->v6);
2333 if (fib->table_id != target_fib_id)
2336 vec_reset_length (sw_if_indices_to_shut);
2338 /* Shut down interfaces in this FIB / clean out intfc routes */
2339 pool_foreach (si, im->sw_interfaces,
2341 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2343 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2346 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2347 sw_if_index = sw_if_indices_to_shut[i];
2348 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2350 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2351 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2352 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2355 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
2356 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
2360 })); /* pool_foreach (fib) */
2368 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2371 vl_api_reset_fib_reply_t *rmp;
2374 rv = ip6_reset_fib_t_handler (mp);
2376 rv = ip4_reset_fib_t_handler (mp);
2378 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
2383 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2385 vl_api_dhcp_proxy_config_reply_t *rmp;
2388 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
2389 (ip4_address_t *) (&mp->dhcp_src_address),
2390 (u32) ntohl (mp->vrf_id),
2391 (int) mp->insert_circuit_id,
2392 (int) (mp->is_add == 0));
2394 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2399 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2401 vl_api_dhcp_proxy_config_reply_t *rmp;
2404 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
2405 (ip6_address_t *) (&mp->dhcp_src_address),
2406 (u32) ntohl (mp->vrf_id),
2407 (int) mp->insert_circuit_id,
2408 (int) (mp->is_add == 0));
2410 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2414 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2416 vl_api_dhcp_proxy_config_reply_t *rmp;
2419 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
2420 (ip4_address_t *) (&mp->dhcp_src_address),
2421 (u32) ntohl (mp->rx_vrf_id),
2422 (u32) ntohl (mp->server_vrf_id),
2423 (int) mp->insert_circuit_id,
2424 (int) (mp->is_add == 0));
2426 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2431 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2433 vl_api_dhcp_proxy_config_reply_t *rmp;
2436 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
2437 (ip6_address_t *) (&mp->dhcp_src_address),
2438 (u32) ntohl (mp->rx_vrf_id),
2439 (u32) ntohl (mp->server_vrf_id),
2440 (int) mp->insert_circuit_id,
2441 (int) (mp->is_add == 0));
2443 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2448 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
2450 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2453 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
2456 (int) mp->is_add == 0);
2458 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
2460 ntohl (mp->fib_id), (int) mp->is_add == 0);
2462 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
2466 static void vl_api_dhcp_proxy_config_t_handler
2467 (vl_api_dhcp_proxy_config_t * mp)
2469 if (mp->is_ipv6 == 0)
2470 dhcpv4_proxy_config (mp);
2472 dhcpv6_proxy_config (mp);
2475 static void vl_api_dhcp_proxy_config_2_t_handler
2476 (vl_api_dhcp_proxy_config_2_t * mp)
2478 if (mp->is_ipv6 == 0)
2479 dhcpv4_proxy_config_2 (mp);
2481 dhcpv6_proxy_config_2 (mp);
2485 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2486 u8 is_ipv6, u8 * host_address, u8 * router_address,
2489 unix_shared_memory_queue_t *q;
2490 vl_api_dhcp_compl_event_t *mp;
2492 q = vl_api_client_index_to_input_queue (client_index);
2496 mp = vl_msg_api_alloc (sizeof (*mp));
2497 mp->client_index = client_index;
2499 mp->is_ipv6 = is_ipv6;
2500 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
2501 mp->hostname[vec_len (hostname) + 1] = '\n';
2502 clib_memcpy (&mp->host_address[0], host_address, 16);
2503 clib_memcpy (&mp->router_address[0], router_address, 16);
2505 if (NULL != host_mac)
2506 clib_memcpy (&mp->host_mac[0], host_mac, 6);
2508 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2510 vl_msg_api_send_shmem (q, (u8 *) & mp);
2513 static void vl_api_dhcp_client_config_t_handler
2514 (vl_api_dhcp_client_config_t * mp)
2516 vlib_main_t *vm = vlib_get_main ();
2517 vl_api_dhcp_client_config_reply_t *rmp;
2520 VALIDATE_SW_IF_INDEX (mp);
2522 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
2523 mp->hostname, mp->is_add, mp->client_index,
2524 mp->want_dhcp_event ? dhcp_compl_event_callback :
2527 BAD_SW_IF_INDEX_LABEL;
2529 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
2533 vl_api_sw_interface_ip6nd_ra_config_t_handler
2534 (vl_api_sw_interface_ip6nd_ra_config_t * mp)
2536 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
2537 vlib_main_t *vm = vlib_get_main ();
2539 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
2542 is_no = mp->is_no == 1;
2543 suppress = mp->suppress == 1;
2544 managed = mp->managed == 1;
2545 other = mp->other == 1;
2546 ll_option = mp->ll_option == 1;
2547 send_unicast = mp->send_unicast == 1;
2548 cease = mp->cease == 1;
2549 default_router = mp->default_router == 1;
2551 VALIDATE_SW_IF_INDEX (mp);
2553 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
2554 suppress, managed, other,
2555 ll_option, send_unicast, cease,
2556 default_router, ntohl (mp->lifetime),
2557 ntohl (mp->initial_count),
2558 ntohl (mp->initial_interval),
2559 ntohl (mp->max_interval),
2560 ntohl (mp->min_interval), is_no);
2562 BAD_SW_IF_INDEX_LABEL;
2564 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2568 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2569 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp)
2571 vlib_main_t *vm = vlib_get_main ();
2572 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
2574 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
2576 VALIDATE_SW_IF_INDEX (mp);
2578 is_no = mp->is_no == 1;
2579 use_default = mp->use_default == 1;
2580 no_advertise = mp->no_advertise == 1;
2581 off_link = mp->off_link == 1;
2582 no_autoconfig = mp->no_autoconfig == 1;
2583 no_onlink = mp->no_onlink == 1;
2585 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
2586 (ip6_address_t *) mp->address,
2587 mp->address_length, use_default,
2588 ntohl (mp->val_lifetime),
2589 ntohl (mp->pref_lifetime), no_advertise,
2590 off_link, no_autoconfig, no_onlink, is_no);
2592 BAD_SW_IF_INDEX_LABEL;
2593 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
2597 vl_api_sw_interface_ip6_enable_disable_t_handler
2598 (vl_api_sw_interface_ip6_enable_disable_t * mp)
2600 vlib_main_t *vm = vlib_get_main ();
2601 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
2602 vnet_main_t *vnm = vnet_get_main ();
2604 clib_error_t *error;
2608 VALIDATE_SW_IF_INDEX (mp);
2611 (mp->enable == 1) ? enable_ip6_interface (vm,
2612 ntohl (mp->sw_if_index)) :
2613 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
2617 clib_error_report (error);
2618 rv = VNET_API_ERROR_UNSPECIFIED;
2622 rv = vnm->api_errno;
2625 BAD_SW_IF_INDEX_LABEL;
2627 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
2631 vl_api_sw_interface_ip6_set_link_local_address_t_handler
2632 (vl_api_sw_interface_ip6_set_link_local_address_t * mp)
2634 vlib_main_t *vm = vlib_get_main ();
2635 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
2637 clib_error_t *error;
2638 vnet_main_t *vnm = vnet_get_main ();
2642 VALIDATE_SW_IF_INDEX (mp);
2644 error = set_ip6_link_local_address (vm,
2645 ntohl (mp->sw_if_index),
2646 (ip6_address_t *) mp->address,
2647 mp->address_length);
2650 clib_error_report (error);
2651 rv = VNET_API_ERROR_UNSPECIFIED;
2655 rv = vnm->api_errno;
2658 BAD_SW_IF_INDEX_LABEL;
2660 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
2664 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
2666 vl_api_set_ip_flow_hash_reply_t *rmp;
2667 int rv = VNET_API_ERROR_UNIMPLEMENTED;
2669 clib_warning ("unimplemented...");
2671 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
2675 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
2677 vl_api_set_ip_flow_hash_reply_t *rmp;
2680 flow_hash_config_t flow_hash_config = 0;
2682 table_id = ntohl (mp->vrf_id);
2684 #define _(a,b) if (mp->a) flow_hash_config |= b;
2685 foreach_flow_hash_bit;
2688 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
2690 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
2695 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
2697 if (mp->is_ipv6 == 0)
2698 set_ip4_flow_hash (mp);
2700 set_ip6_flow_hash (mp);
2704 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
2706 vl_api_create_loopback_reply_t *rmp;
2710 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
2713 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
2715 rmp->sw_if_index = ntohl (sw_if_index);
2721 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
2723 vl_api_delete_loopback_reply_t *rmp;
2727 sw_if_index = ntohl (mp->sw_if_index);
2728 rv = vnet_delete_loopback_interface (sw_if_index);
2730 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
2734 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
2736 vl_api_control_ping_reply_t *rmp;
2740 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
2742 rmp->vpe_pid = ntohl (getpid());
2748 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2750 u8 **shmem_vecp = (u8 **) arg;
2753 api_main_t *am = &api_main;
2756 shmem_vec = *shmem_vecp;
2758 offset = vec_len (shmem_vec);
2760 pthread_mutex_lock (&am->vlib_rp->mutex);
2761 oldheap = svm_push_data_heap (am->vlib_rp);
2763 vec_validate (shmem_vec, offset + buffer_bytes - 1);
2765 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
2767 svm_pop_heap (oldheap);
2768 pthread_mutex_unlock (&am->vlib_rp->mutex);
2770 *shmem_vecp = shmem_vec;
2775 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
2777 vl_api_cli_reply_t *rp;
2778 unix_shared_memory_queue_t *q;
2779 vlib_main_t *vm = vlib_get_main ();
2780 api_main_t *am = &api_main;
2781 unformat_input_t input;
2785 q = vl_api_client_index_to_input_queue (mp->client_index);
2789 rp = vl_msg_api_alloc (sizeof (*rp));
2790 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
2791 rp->context = mp->context;
2793 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
2795 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
2797 pthread_mutex_lock (&am->vlib_rp->mutex);
2798 oldheap = svm_push_data_heap (am->vlib_rp);
2800 vec_add1 (shmem_vec, 0);
2802 svm_pop_heap (oldheap);
2803 pthread_mutex_unlock (&am->vlib_rp->mutex);
2805 rp->reply_in_shmem = (uword) shmem_vec;
2807 vl_msg_api_send_shmem (q, (u8 *) & rp);
2811 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2813 u8 **mem_vecp = (u8 **) arg;
2814 u8 *mem_vec = *mem_vecp;
2815 u32 offset = vec_len (mem_vec);
2817 vec_validate (mem_vec, offset + buffer_bytes - 1);
2818 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
2819 *mem_vecp = mem_vec;
2823 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
2825 vl_api_cli_inband_reply_t *rmp;
2827 unix_shared_memory_queue_t *q;
2828 vlib_main_t *vm = vlib_get_main ();
2829 unformat_input_t input;
2832 q = vl_api_client_index_to_input_queue (mp->client_index);
2836 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
2837 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
2839 u32 len = vec_len (out_vec);
2841 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
2843 rmp->length = htonl (len);
2844 clib_memcpy (rmp->reply, out_vec, len);
2851 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2854 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2855 vnet_main_t *vnm = vnet_get_main ();
2856 clib_error_t *error;
2861 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2863 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2867 clib_error_report (error);
2868 rv = VNET_API_ERROR_UNSPECIFIED;
2872 rv = vnm->api_errno;
2875 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2878 static void vl_api_sr_tunnel_add_del_t_handler
2879 (vl_api_sr_tunnel_add_del_t * mp)
2882 clib_warning ("unimplemented");
2884 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
2886 vl_api_sr_tunnel_add_del_reply_t *rmp;
2887 ip6_address_t *segments = 0, *seg;
2888 ip6_address_t *tags = 0, *tag;
2889 ip6_address_t *this_address;
2892 if (mp->n_segments == 0)
2898 memset (a, 0, sizeof (*a));
2899 a->src_address = (ip6_address_t *) & mp->src_address;
2900 a->dst_address = (ip6_address_t *) & mp->dst_address;
2901 a->dst_mask_width = mp->dst_mask_width;
2902 a->flags_net_byte_order = mp->flags_net_byte_order;
2903 a->is_del = (mp->is_add == 0);
2904 a->rx_table_id = ntohl (mp->outer_vrf_id);
2905 a->tx_table_id = ntohl (mp->inner_vrf_id);
2907 a->name = format (0, "%s", mp->name);
2908 if (!(vec_len (a->name)))
2911 a->policy_name = format (0, "%s", mp->policy_name);
2912 if (!(vec_len (a->policy_name)))
2915 /* Yank segments and tags out of the API message */
2916 this_address = (ip6_address_t *) mp->segs_and_tags;
2917 for (i = 0; i < mp->n_segments; i++)
2919 vec_add2 (segments, seg, 1);
2920 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
2923 for (i = 0; i < mp->n_tags; i++)
2925 vec_add2 (tags, tag, 1);
2926 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
2930 a->segments = segments;
2933 rv = ip6_sr_add_del_tunnel (a);
2937 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
2941 static void vl_api_sr_policy_add_del_t_handler
2942 (vl_api_sr_policy_add_del_t * mp)
2945 clib_warning ("unimplemented");
2947 ip6_sr_add_del_policy_args_t _a, *a = &_a;
2949 vl_api_sr_policy_add_del_reply_t *rmp;
2952 memset (a, 0, sizeof (*a));
2953 a->is_del = (mp->is_add == 0);
2955 a->name = format (0, "%s", mp->name);
2956 if (!(vec_len (a->name)))
2958 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2962 if (!(mp->tunnel_names[0]))
2964 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2968 // start deserializing tunnel_names
2969 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
2970 u8 *deser_tun_names = mp->tunnel_names;
2971 deser_tun_names += 1; //moving along
2974 int tun_name_len = 0;
2976 for (i = 0; i < num_tunnels; i++)
2978 tun_name_len = *deser_tun_names;
2979 deser_tun_names += 1;
2980 vec_resize (tun_name, tun_name_len);
2981 memcpy (tun_name, deser_tun_names, tun_name_len);
2982 vec_add1 (a->tunnel_names, tun_name);
2983 deser_tun_names += tun_name_len;
2987 rv = ip6_sr_add_del_policy (a);
2991 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
2995 static void vl_api_sr_multicast_map_add_del_t_handler
2996 (vl_api_sr_multicast_map_add_del_t * mp)
2999 clib_warning ("unimplemented");
3001 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3003 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3005 memset (a, 0, sizeof (*a));
3006 a->is_del = (mp->is_add == 0);
3008 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3009 a->policy_name = format (0, "%s", mp->policy_name);
3011 if (a->multicast_address == 0)
3017 if (!(a->policy_name))
3023 #if DPDK > 0 /* Cannot call replicate without DPDK */
3024 rv = ip6_sr_add_del_multicastmap (a);
3026 clib_warning ("multicast replication without DPDK not implemented");
3027 rv = VNET_API_ERROR_UNIMPLEMENTED;
3032 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3036 #define foreach_classify_add_del_table_field \
3041 _(match_n_vectors) \
3042 _(next_table_index) \
3043 _(miss_next_index) \
3044 _(current_data_flag) \
3045 _(current_data_offset)
3047 static void vl_api_classify_add_del_table_t_handler
3048 (vl_api_classify_add_del_table_t * mp)
3050 vl_api_classify_add_del_table_reply_t *rmp;
3051 vnet_classify_main_t *cm = &vnet_classify_main;
3052 vnet_classify_table_t *t;
3056 foreach_classify_add_del_table_field;
3059 #define _(a) a = ntohl(mp->a);
3060 foreach_classify_add_del_table_field;
3063 /* The underlying API fails silently, on purpose, so check here */
3064 if (mp->is_add == 0) /* delete */
3066 if (pool_is_free_index (cm->tables, table_index))
3068 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3072 else /* add or update */
3074 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
3078 rv = vnet_classify_add_del_table
3079 (cm, mp->mask, nbuckets, memory_size,
3080 skip_n_vectors, match_n_vectors,
3081 next_table_index, miss_next_index, &table_index,
3082 current_data_flag, current_data_offset, mp->is_add);
3086 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3088 if (rv == 0 && mp->is_add)
3090 t = pool_elt_at_index (cm->tables, table_index);
3091 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3092 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3093 rmp->new_table_index = ntohl(table_index);
3097 rmp->skip_n_vectors = ~0;
3098 rmp->match_n_vectors = ~0;
3099 rmp->new_table_index = ~0;
3105 static void vl_api_classify_add_del_session_t_handler
3106 (vl_api_classify_add_del_session_t * mp)
3108 vnet_classify_main_t *cm = &vnet_classify_main;
3109 vl_api_classify_add_del_session_reply_t *rmp;
3111 u32 table_index, hit_next_index, opaque_index, metadata;
3115 table_index = ntohl (mp->table_index);
3116 hit_next_index = ntohl (mp->hit_next_index);
3117 opaque_index = ntohl (mp->opaque_index);
3118 advance = ntohl (mp->advance);
3119 action = mp->action;
3120 metadata = ntohl (mp->metadata);
3122 rv = vnet_classify_add_del_session
3123 (cm, table_index, mp->match, hit_next_index, opaque_index,
3124 advance, action, metadata, mp->is_add);
3126 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3129 static void vl_api_classify_set_interface_ip_table_t_handler
3130 (vl_api_classify_set_interface_ip_table_t * mp)
3132 vlib_main_t *vm = vlib_get_main ();
3133 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3135 u32 table_index, sw_if_index;
3137 table_index = ntohl (mp->table_index);
3138 sw_if_index = ntohl (mp->sw_if_index);
3140 VALIDATE_SW_IF_INDEX (mp);
3143 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3145 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3147 BAD_SW_IF_INDEX_LABEL;
3149 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3152 static void vl_api_classify_set_interface_l2_tables_t_handler
3153 (vl_api_classify_set_interface_l2_tables_t * mp)
3155 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3157 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3160 ip4_table_index = ntohl (mp->ip4_table_index);
3161 ip6_table_index = ntohl (mp->ip6_table_index);
3162 other_table_index = ntohl (mp->other_table_index);
3163 sw_if_index = ntohl (mp->sw_if_index);
3165 VALIDATE_SW_IF_INDEX (mp);
3168 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
3172 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
3178 if (ip4_table_index != ~0 || ip6_table_index != ~0
3179 || other_table_index != ~0)
3185 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
3187 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
3190 BAD_SW_IF_INDEX_LABEL;
3192 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3196 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3199 vl_api_l2_fib_clear_table_reply_t *rmp;
3201 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3202 * that is not currently implemented. When that TODO is fixed
3203 * this call should be changed to pass 1 instead of 0.
3205 l2fib_clear_table (0);
3207 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3210 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3211 u32 sw_if_index, u32 enable);
3214 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3218 vl_api_l2_interface_efp_filter_reply_t *rmp;
3219 vnet_main_t *vnm = vnet_get_main ();
3221 // enable/disable the feature
3222 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3223 rv = vnm->api_errno;
3225 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3229 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3230 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3233 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3234 vnet_main_t *vnm = vnet_get_main ();
3235 vlib_main_t *vm = vlib_get_main ();
3238 VALIDATE_SW_IF_INDEX (mp);
3240 vtr_op = ntohl (mp->vtr_op);
3242 /* The L2 code is unsuspicious */
3245 case L2_VTR_DISABLED:
3250 case L2_VTR_TRANSLATE_1_1:
3251 case L2_VTR_TRANSLATE_1_2:
3252 case L2_VTR_TRANSLATE_2_1:
3253 case L2_VTR_TRANSLATE_2_2:
3257 rv = VNET_API_ERROR_INVALID_VALUE;
3258 goto bad_sw_if_index;
3261 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
3262 ntohl (mp->push_dot1q), ntohl (mp->tag1),
3265 BAD_SW_IF_INDEX_LABEL;
3267 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3271 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
3274 vl_api_create_vhost_user_if_reply_t *rmp;
3275 u32 sw_if_index = (u32) ~ 0;
3276 vnet_main_t *vnm = vnet_get_main ();
3277 vlib_main_t *vm = vlib_get_main ();
3279 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
3280 mp->is_server, &sw_if_index, (u64) ~ 0,
3281 mp->renumber, ntohl (mp->custom_dev_instance),
3282 (mp->use_custom_mac) ? mp->mac_address : NULL);
3284 /* Remember an interface tag for the new interface */
3287 /* If a tag was supplied... */
3290 /* Make sure it's a proper C-string */
3291 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
3292 u8 *tag = format (0, "%s%c", mp->tag, 0);
3293 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
3298 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3300 rmp->sw_if_index = ntohl (sw_if_index);
3306 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
3309 vl_api_modify_vhost_user_if_reply_t *rmp;
3310 u32 sw_if_index = ntohl (mp->sw_if_index);
3312 vnet_main_t *vnm = vnet_get_main ();
3313 vlib_main_t *vm = vlib_get_main ();
3315 rv = vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
3316 mp->is_server, sw_if_index, (u64) ~ 0,
3317 mp->renumber, ntohl (mp->custom_dev_instance));
3319 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
3323 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
3326 vl_api_delete_vhost_user_if_reply_t *rmp;
3327 vpe_api_main_t *vam = &vpe_api_main;
3328 u32 sw_if_index = ntohl (mp->sw_if_index);
3330 vnet_main_t *vnm = vnet_get_main ();
3331 vlib_main_t *vm = vlib_get_main ();
3333 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
3335 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
3338 unix_shared_memory_queue_t *q =
3339 vl_api_client_index_to_input_queue (mp->client_index);
3343 vnet_clear_sw_interface_tag (vnm, sw_if_index);
3344 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3349 vl_api_sw_interface_vhost_user_details_t_handler
3350 (vl_api_sw_interface_vhost_user_details_t * mp)
3352 clib_warning ("BUG");
3356 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3357 unix_shared_memory_queue_t * q,
3358 vhost_user_intf_details_t * vui,
3361 vl_api_sw_interface_vhost_user_details_t *mp;
3363 mp = vl_msg_api_alloc (sizeof (*mp));
3364 memset (mp, 0, sizeof (*mp));
3365 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3366 mp->sw_if_index = ntohl (vui->sw_if_index);
3367 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3368 mp->features = clib_net_to_host_u64 (vui->features);
3369 mp->is_server = vui->is_server;
3370 mp->num_regions = ntohl (vui->num_regions);
3371 mp->sock_errno = ntohl (vui->sock_errno);
3372 mp->context = context;
3374 strncpy ((char *) mp->sock_filename,
3375 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
3376 strncpy ((char *) mp->interface_name,
3377 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
3379 vl_msg_api_send_shmem (q, (u8 *) & mp);
3383 vl_api_sw_interface_vhost_user_dump_t_handler
3384 (vl_api_sw_interface_vhost_user_dump_t * mp)
3387 vpe_api_main_t *am = &vpe_api_main;
3388 vnet_main_t *vnm = vnet_get_main ();
3389 vlib_main_t *vm = vlib_get_main ();
3390 vhost_user_intf_details_t *ifaces = NULL;
3391 vhost_user_intf_details_t *vuid = NULL;
3392 unix_shared_memory_queue_t *q;
3394 q = vl_api_client_index_to_input_queue (mp->client_index);
3398 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
3402 vec_foreach (vuid, ifaces)
3404 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3410 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3411 unix_shared_memory_queue_t * q,
3413 l2t_main_t * lm, u32 context)
3415 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
3417 vnet_sw_interface_t *si = NULL;
3419 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3421 if_name = format (if_name, "%U",
3422 format_vnet_sw_interface_name, lm->vnet_main, si);
3424 mp = vl_msg_api_alloc (sizeof (*mp));
3425 memset (mp, 0, sizeof (*mp));
3426 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3427 strncpy ((char *) mp->interface_name,
3428 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
3429 mp->sw_if_index = ntohl (si->sw_if_index);
3430 mp->local_session_id = s->local_session_id;
3431 mp->remote_session_id = s->remote_session_id;
3432 mp->local_cookie[0] = s->local_cookie[0];
3433 mp->local_cookie[1] = s->local_cookie[1];
3434 mp->remote_cookie = s->remote_cookie;
3435 clib_memcpy (mp->client_address, &s->client_address,
3436 sizeof (s->client_address));
3437 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
3438 mp->l2_sublayer_present = s->l2_sublayer_present;
3439 mp->context = context;
3441 vl_msg_api_send_shmem (q, (u8 *) & mp);
3445 send_ip_address_details (vpe_api_main_t * am,
3446 unix_shared_memory_queue_t * q,
3447 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
3449 vl_api_ip_address_details_t *mp;
3451 mp = vl_msg_api_alloc (sizeof (*mp));
3452 memset (mp, 0, sizeof (*mp));
3453 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
3457 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
3461 u32 *tp = (u32 *) mp->ip;
3464 mp->prefix_length = prefix_length;
3465 mp->context = context;
3467 vl_msg_api_send_shmem (q, (u8 *) & mp);
3471 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
3473 vpe_api_main_t *am = &vpe_api_main;
3474 unix_shared_memory_queue_t *q;
3477 ip6_main_t *im6 = &ip6_main;
3478 ip4_main_t *im4 = &ip4_main;
3479 ip_lookup_main_t *lm6 = &im6->lookup_main;
3480 ip_lookup_main_t *lm4 = &im4->lookup_main;
3481 ip_interface_address_t *ia = 0;
3482 u32 sw_if_index = ~0;
3483 int rv __attribute__ ((unused)) = 0;
3485 VALIDATE_SW_IF_INDEX (mp);
3487 sw_if_index = ntohl (mp->sw_if_index);
3489 q = vl_api_client_index_to_input_queue (mp->client_index);
3498 foreach_ip_interface_address (lm6, ia, sw_if_index,
3499 1 /* honor unnumbered */,
3501 r6 = ip_interface_address_get_address (lm6, ia);
3502 u16 prefix_length = ia->address_length;
3503 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3510 foreach_ip_interface_address (lm4, ia, sw_if_index,
3511 1 /* honor unnumbered */,
3513 r4 = ip_interface_address_get_address (lm4, ia);
3514 u16 prefix_length = ia->address_length;
3515 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3519 BAD_SW_IF_INDEX_LABEL;
3523 send_ip_details (vpe_api_main_t * am,
3524 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
3526 vl_api_ip_details_t *mp;
3528 mp = vl_msg_api_alloc (sizeof (*mp));
3529 memset (mp, 0, sizeof (*mp));
3530 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
3532 mp->sw_if_index = ntohl (sw_if_index);
3533 mp->context = context;
3535 vl_msg_api_send_shmem (q, (u8 *) & mp);
3539 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
3542 vpe_api_main_t *am = &vpe_api_main;
3543 l2t_main_t *lm = &l2t_main;
3544 unix_shared_memory_queue_t *q;
3545 l2t_session_t *session;
3547 q = vl_api_client_index_to_input_queue (mp->client_index);
3552 pool_foreach (session, lm->sessions,
3554 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
3561 send_sw_interface_tap_details (vpe_api_main_t * am,
3562 unix_shared_memory_queue_t * q,
3563 tapcli_interface_details_t * tap_if,
3566 vl_api_sw_interface_tap_details_t *mp;
3567 mp = vl_msg_api_alloc (sizeof (*mp));
3568 memset (mp, 0, sizeof (*mp));
3569 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
3570 mp->sw_if_index = ntohl (tap_if->sw_if_index);
3571 strncpy ((char *) mp->dev_name,
3572 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
3573 mp->context = context;
3575 vl_msg_api_send_shmem (q, (u8 *) & mp);
3579 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
3582 vpe_api_main_t *am = &vpe_api_main;
3583 unix_shared_memory_queue_t *q;
3584 tapcli_interface_details_t *tapifs = NULL;
3585 tapcli_interface_details_t *tap_if = NULL;
3587 q = vl_api_client_index_to_input_queue (mp->client_index);
3591 rv = vnet_tap_dump_ifs (&tapifs);
3595 vec_foreach (tap_if, tapifs)
3597 send_sw_interface_tap_details (am, q, tap_if, mp->context);
3604 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
3606 vpe_api_main_t *am = &vpe_api_main;
3607 vnet_main_t *vnm = vnet_get_main ();
3608 vlib_main_t *vm = vlib_get_main ();
3609 vnet_interface_main_t *im = &vnm->interface_main;
3610 unix_shared_memory_queue_t *q;
3611 vnet_sw_interface_t *si, *sorted_sis;
3612 u32 sw_if_index = ~0;
3614 q = vl_api_client_index_to_input_queue (mp->client_index);
3620 /* Gather interfaces. */
3621 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3622 _vec_len (sorted_sis) = 0;
3624 pool_foreach (si, im->sw_interfaces,
3626 vec_add1 (sorted_sis, si[0]);
3630 vec_foreach (si, sorted_sis)
3632 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
3634 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
3638 sw_if_index = si->sw_if_index;
3639 send_ip_details (am, q, sw_if_index, mp->context);
3645 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
3647 clib_warning ("BUG");
3651 send_l2fib_table_entry (vpe_api_main_t * am,
3652 unix_shared_memory_queue_t * q,
3653 l2fib_entry_key_t * l2fe_key,
3654 l2fib_entry_result_t * l2fe_res, u32 context)
3656 vl_api_l2_fib_table_entry_t *mp;
3658 mp = vl_msg_api_alloc (sizeof (*mp));
3659 memset (mp, 0, sizeof (*mp));
3660 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
3663 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3665 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3666 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
3667 mp->static_mac = l2fe_res->fields.static_mac;
3668 mp->filter_mac = l2fe_res->fields.filter;
3669 mp->bvi_mac = l2fe_res->fields.bvi;
3670 mp->context = context;
3672 vl_msg_api_send_shmem (q, (u8 *) & mp);
3676 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
3678 vpe_api_main_t *am = &vpe_api_main;
3679 bd_main_t *bdm = &bd_main;
3680 l2fib_entry_key_t *l2fe_key = NULL;
3681 l2fib_entry_result_t *l2fe_res = NULL;
3682 u32 ni, bd_id = ntohl (mp->bd_id);
3684 unix_shared_memory_queue_t *q;
3687 q = vl_api_client_index_to_input_queue (mp->client_index);
3691 /* see l2fib_table_dump: ~0 means "any" */
3696 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3703 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3705 vec_foreach_index (ni, l2fe_key)
3707 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
3708 vec_elt_at_index (l2fe_res, ni), mp->context);
3710 vec_free (l2fe_key);
3711 vec_free (l2fe_res);
3715 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
3717 vl_api_show_version_reply_t *rmp;
3719 char *vpe_api_get_build_directory (void);
3720 char *vpe_api_get_version (void);
3721 char *vpe_api_get_build_date (void);
3723 unix_shared_memory_queue_t *q =
3724 vl_api_client_index_to_input_queue (mp->client_index);
3730 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3732 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3733 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3734 ARRAY_LEN(rmp->build_directory)-1);
3735 strncpy ((char *) rmp->version, vpe_api_get_version(),
3736 ARRAY_LEN(rmp->version)-1);
3737 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3738 ARRAY_LEN(rmp->build_date)-1);
3744 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
3746 vlib_main_t *vm = vlib_get_main ();
3747 vl_api_get_node_index_reply_t *rmp;
3750 u32 node_index = ~0;
3752 n = vlib_get_node_by_name (vm, mp->node_name);
3755 rv = VNET_API_ERROR_NO_SUCH_NODE;
3757 node_index = n->index;
3760 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3762 rmp->node_index = ntohl(node_index);
3768 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
3770 vlib_main_t *vm = vlib_get_main ();
3771 vl_api_get_next_index_reply_t *rmp;
3772 vlib_node_t *node, *next_node;
3774 u32 next_node_index = ~0, next_index = ~0;
3777 node = vlib_get_node_by_name (vm, mp->node_name);
3781 rv = VNET_API_ERROR_NO_SUCH_NODE;
3785 next_node = vlib_get_node_by_name (vm, mp->next_name);
3789 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3793 next_node_index = next_node->index;
3795 p = hash_get (node->next_slot_by_node, next_node_index);
3799 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
3807 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
3809 rmp->next_index = ntohl(next_index);
3815 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
3817 vlib_main_t *vm = vlib_get_main ();
3818 vl_api_add_node_next_reply_t *rmp;
3819 vlib_node_t *n, *next;
3821 u32 next_index = ~0;
3823 n = vlib_get_node_by_name (vm, mp->node_name);
3827 rv = VNET_API_ERROR_NO_SUCH_NODE;
3831 next = vlib_get_node_by_name (vm, mp->next_name);
3834 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3836 next_index = vlib_node_add_next (vm, n->index, next->index);
3840 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3842 rmp->next_index = ntohl(next_index);
3847 static void vl_api_l2tpv3_create_tunnel_t_handler
3848 (vl_api_l2tpv3_create_tunnel_t * mp)
3850 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
3851 l2t_main_t *lm = &l2t_main;
3852 u32 sw_if_index = (u32) ~ 0;
3855 if (mp->is_ipv6 != 1)
3857 rv = VNET_API_ERROR_UNIMPLEMENTED;
3861 u32 encap_fib_index;
3863 if (mp->encap_vrf_id != ~0)
3866 ip6_main_t *im = &ip6_main;
3869 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
3871 rv = VNET_API_ERROR_NO_SUCH_FIB;
3874 encap_fib_index = p[0];
3878 encap_fib_index = ~0;
3881 rv = create_l2tpv3_ipv6_tunnel (lm,
3882 (ip6_address_t *) mp->client_address,
3883 (ip6_address_t *) mp->our_address,
3884 ntohl (mp->local_session_id),
3885 ntohl (mp->remote_session_id),
3886 clib_net_to_host_u64 (mp->local_cookie),
3887 clib_net_to_host_u64 (mp->remote_cookie),
3888 mp->l2_sublayer_present,
3889 encap_fib_index, &sw_if_index);
3893 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
3895 rmp->sw_if_index = ntohl (sw_if_index);
3900 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
3901 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
3903 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
3904 l2t_main_t *lm = &l2t_main;
3907 VALIDATE_SW_IF_INDEX (mp);
3909 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
3910 clib_net_to_host_u64 (mp->new_local_cookie),
3911 clib_net_to_host_u64
3912 (mp->new_remote_cookie));
3914 BAD_SW_IF_INDEX_LABEL;
3916 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
3919 static void vl_api_l2tpv3_interface_enable_disable_t_handler
3920 (vl_api_l2tpv3_interface_enable_disable_t * mp)
3923 vnet_main_t *vnm = vnet_get_main ();
3924 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
3926 VALIDATE_SW_IF_INDEX (mp);
3928 rv = l2tpv3_interface_enable_disable
3929 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
3931 BAD_SW_IF_INDEX_LABEL;
3933 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
3936 static void vl_api_l2tpv3_set_lookup_key_t_handler
3937 (vl_api_l2tpv3_set_lookup_key_t * mp)
3940 l2t_main_t *lm = &l2t_main;
3941 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
3943 if (mp->key > L2T_LOOKUP_SESSION_ID)
3945 rv = VNET_API_ERROR_INVALID_VALUE;
3949 lm->lookup_type = mp->key;
3952 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
3955 static void vl_api_vxlan_add_del_tunnel_t_handler
3956 (vl_api_vxlan_add_del_tunnel_t * mp)
3958 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
3960 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
3961 u32 encap_fib_index;
3963 ip4_main_t *im = &ip4_main;
3964 u32 sw_if_index = ~0;
3966 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
3969 rv = VNET_API_ERROR_NO_SUCH_FIB;
3972 encap_fib_index = p[0];
3973 memset (a, 0, sizeof (*a));
3975 a->is_add = mp->is_add;
3976 a->is_ip6 = mp->is_ipv6;
3978 /* ip addresses sent in network byte order */
3979 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
3980 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
3982 /* Check src & dst are different */
3983 if (ip46_address_cmp (&a->dst, &a->src) == 0)
3985 rv = VNET_API_ERROR_SAME_SRC_DST;
3988 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
3989 a->encap_fib_index = encap_fib_index;
3990 a->decap_next_index = ntohl (mp->decap_next_index);
3991 a->vni = ntohl (mp->vni);
3992 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
3996 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
3998 rmp->sw_if_index = ntohl (sw_if_index);
4003 static void send_vxlan_tunnel_details
4004 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4006 vl_api_vxlan_tunnel_details_t *rmp;
4007 ip4_main_t *im4 = &ip4_main;
4008 ip6_main_t *im6 = &ip6_main;
4009 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
4011 rmp = vl_msg_api_alloc (sizeof (*rmp));
4012 memset (rmp, 0, sizeof (*rmp));
4013 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4016 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
4017 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
4018 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4022 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
4023 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
4024 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4026 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
4027 rmp->vni = htonl (t->vni);
4028 rmp->decap_next_index = htonl (t->decap_next_index);
4029 rmp->sw_if_index = htonl (t->sw_if_index);
4030 rmp->is_ipv6 = is_ipv6;
4031 rmp->context = context;
4033 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4036 static void vl_api_vxlan_tunnel_dump_t_handler
4037 (vl_api_vxlan_tunnel_dump_t * mp)
4039 unix_shared_memory_queue_t *q;
4040 vxlan_main_t *vxm = &vxlan_main;
4044 q = vl_api_client_index_to_input_queue (mp->client_index);
4050 sw_if_index = ntohl (mp->sw_if_index);
4052 if (~0 == sw_if_index)
4055 pool_foreach (t, vxm->tunnels,
4057 send_vxlan_tunnel_details(t, q, mp->context);
4063 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4064 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4068 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4069 send_vxlan_tunnel_details (t, q, mp->context);
4073 static void vl_api_gre_add_del_tunnel_t_handler
4074 (vl_api_gre_add_del_tunnel_t * mp)
4076 vl_api_gre_add_del_tunnel_reply_t *rmp;
4078 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4081 ip4_main_t *im = &ip4_main;
4082 u32 sw_if_index = ~0;
4084 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4087 rv = VNET_API_ERROR_NO_SUCH_FIB;
4090 outer_fib_id = p[0];
4092 /* Check src & dst are different */
4093 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4094 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4096 rv = VNET_API_ERROR_SAME_SRC_DST;
4099 memset (a, 0, sizeof (*a));
4101 a->is_add = mp->is_add;
4104 /* ip addresses sent in network byte order */
4105 clib_memcpy (&(a->src), mp->src_address, 4);
4106 clib_memcpy (&(a->dst), mp->dst_address, 4);
4108 a->outer_fib_id = outer_fib_id;
4109 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4113 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4115 rmp->sw_if_index = ntohl (sw_if_index);
4120 static void send_gre_tunnel_details
4121 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4123 vl_api_gre_tunnel_details_t *rmp;
4124 ip4_main_t *im = &ip4_main;
4126 rmp = vl_msg_api_alloc (sizeof (*rmp));
4127 memset (rmp, 0, sizeof (*rmp));
4128 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4129 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4130 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4131 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4132 rmp->teb = (GRE_TUNNEL_TYPE_TEB == t->type);
4133 rmp->sw_if_index = htonl (t->sw_if_index);
4134 rmp->context = context;
4136 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4140 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4142 unix_shared_memory_queue_t *q;
4143 gre_main_t *gm = &gre_main;
4147 q = vl_api_client_index_to_input_queue (mp->client_index);
4153 sw_if_index = ntohl (mp->sw_if_index);
4155 if (~0 == sw_if_index)
4158 pool_foreach (t, gm->tunnels,
4160 send_gre_tunnel_details(t, q, mp->context);
4166 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4167 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4171 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4172 send_gre_tunnel_details (t, q, mp->context);
4177 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4179 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4181 vl_api_l2_patch_add_del_reply_t *rmp;
4182 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4186 VALIDATE_RX_SW_IF_INDEX (mp);
4187 VALIDATE_TX_SW_IF_INDEX (mp);
4189 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4190 ntohl (mp->tx_sw_if_index),
4191 (int) (mp->is_add != 0));
4193 BAD_RX_SW_IF_INDEX_LABEL;
4194 BAD_TX_SW_IF_INDEX_LABEL;
4196 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4200 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4201 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4203 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4205 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4206 u32 encap_fib_index, decap_fib_index;
4209 ip4_main_t *im = &ip4_main;
4210 u32 sw_if_index = ~0;
4213 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4216 rv = VNET_API_ERROR_NO_SUCH_FIB;
4219 encap_fib_index = p[0];
4221 protocol = mp->protocol;
4223 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4224 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4226 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4229 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4232 decap_fib_index = p[0];
4236 decap_fib_index = ntohl (mp->decap_vrf_id);
4239 /* Check src & dst are different */
4240 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4241 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
4243 rv = VNET_API_ERROR_SAME_SRC_DST;
4246 memset (a, 0, sizeof (*a));
4248 a->is_add = mp->is_add;
4249 a->is_ip6 = mp->is_ipv6;
4250 /* ip addresses sent in network byte order */
4253 clib_memcpy (&(a->local.ip6), mp->local, 16);
4254 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
4258 clib_memcpy (&(a->local.ip4), mp->local, 4);
4259 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
4261 a->encap_fib_index = encap_fib_index;
4262 a->decap_fib_index = decap_fib_index;
4263 a->protocol = protocol;
4264 a->vni = ntohl (mp->vni);
4265 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4269 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4271 rmp->sw_if_index = ntohl (sw_if_index);
4276 static void send_vxlan_gpe_tunnel_details
4277 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4279 vl_api_vxlan_gpe_tunnel_details_t *rmp;
4280 ip4_main_t *im4 = &ip4_main;
4281 ip6_main_t *im6 = &ip6_main;
4282 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4284 rmp = vl_msg_api_alloc (sizeof (*rmp));
4285 memset (rmp, 0, sizeof (*rmp));
4286 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4289 memcpy (rmp->local, &(t->local.ip6), 16);
4290 memcpy (rmp->remote, &(t->remote.ip6), 16);
4291 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4292 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
4296 memcpy (rmp->local, &(t->local.ip4), 4);
4297 memcpy (rmp->remote, &(t->remote.ip4), 4);
4298 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4299 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
4301 rmp->vni = htonl (t->vni);
4302 rmp->protocol = t->protocol;
4303 rmp->sw_if_index = htonl (t->sw_if_index);
4304 rmp->is_ipv6 = is_ipv6;
4305 rmp->context = context;
4307 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4310 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4311 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4313 unix_shared_memory_queue_t *q;
4314 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
4315 vxlan_gpe_tunnel_t *t;
4318 q = vl_api_client_index_to_input_queue (mp->client_index);
4324 sw_if_index = ntohl (mp->sw_if_index);
4326 if (~0 == sw_if_index)
4329 pool_foreach (t, vgm->tunnels,
4331 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4337 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
4338 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
4342 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4343 send_vxlan_gpe_tunnel_details (t, q, mp->context);
4347 /** Used for transferring locators via VPP API */
4349 typedef CLIB_PACKED (struct {
4350 u32 sw_if_index; /**< locator sw_if_index */
4351 u8 priority; /**< locator priority */
4352 u8 weight; /**< locator weight */
4357 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
4360 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4362 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4364 ls_locator_t *ls_loc;
4365 u32 ls_index = ~0, locator_num;
4366 u8 *locator_name = NULL;
4369 memset (a, 0, sizeof (a[0]));
4371 locator_name = format (0, "%s", mp->locator_set_name);
4373 a->name = locator_name;
4374 a->is_add = mp->is_add;
4376 locator_num = clib_net_to_host_u32 (mp->locator_num);
4378 memset (&locator, 0, sizeof (locator));
4379 for (i = 0; i < locator_num; i++)
4381 ls_loc = &((ls_locator_t *) mp->locators)[i];
4382 VALIDATE_SW_IF_INDEX (ls_loc);
4384 locator.sw_if_index = htonl (ls_loc->sw_if_index);
4385 locator.priority = ls_loc->priority;
4386 locator.weight = ls_loc->weight;
4388 vec_add1 (a->locators, locator);
4391 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
4393 BAD_SW_IF_INDEX_LABEL;
4395 vec_free (locator_name);
4396 vec_free (a->locators);
4399 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
4401 rmp->ls_index = clib_host_to_net_u32 (ls_index);
4407 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
4409 vl_api_lisp_add_del_locator_reply_t *rmp;
4411 locator_t locator, *locators = NULL;
4412 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4414 u8 *locator_name = NULL;
4416 memset (&locator, 0, sizeof (locator));
4417 memset (a, 0, sizeof (a[0]));
4419 locator.sw_if_index = ntohl (mp->sw_if_index);
4420 locator.priority = mp->priority;
4421 locator.weight = mp->weight;
4423 vec_add1 (locators, locator);
4425 locator_name = format (0, "%s", mp->locator_set_name);
4427 a->name = locator_name;
4428 a->locators = locators;
4429 a->is_add = mp->is_add;
4432 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
4434 vec_free (locators);
4435 vec_free (locator_name);
4437 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4441 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
4447 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
4448 gid_address_ip_set (dst, src, IP4);
4449 gid_address_ippref_len (dst) = len;
4450 ip_prefix_normalize (&gid_address_ippref (dst));
4453 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
4454 gid_address_ip_set (dst, src, IP6);
4455 gid_address_ippref_len (dst) = len;
4456 ip_prefix_normalize (&gid_address_ippref (dst));
4458 case 2: /* l2 mac */
4459 gid_address_type (dst) = GID_ADDR_MAC;
4460 clib_memcpy (&gid_address_mac (dst), src, 6);
4464 return VNET_API_ERROR_INVALID_VALUE;
4467 gid_address_vni (dst) = vni;
4473 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
4475 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4476 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4478 gid_address_t _eid, *eid = &_eid;
4480 u32 locator_set_index = ~0, map_index = ~0;
4481 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4482 u8 *name = NULL, *key = NULL;
4483 memset (a, 0, sizeof (a[0]));
4484 memset (eid, 0, sizeof (eid[0]));
4486 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4487 mp->eid_type, mp->eid, mp->prefix_len);
4491 name = format (0, "%s", mp->locator_set_name);
4492 p = hash_get_mem (lcm->locator_set_index_by_name, name);
4495 rv = VNET_API_ERROR_INVALID_VALUE;
4498 locator_set_index = p[0];
4501 key = format (0, "%s", mp->key);
4503 /* XXX treat batch configuration */
4504 a->is_add = mp->is_add;
4505 gid_address_copy (&a->eid, eid);
4506 a->locator_set_index = locator_set_index;
4509 a->key_id = clib_net_to_host_u16 (mp->key_id);
4511 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
4516 gid_address_free (&a->eid);
4518 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4522 vl_api_lisp_eid_table_add_del_map_t_handler
4523 (vl_api_lisp_eid_table_add_del_map_t * mp)
4525 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4527 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4528 clib_net_to_host_u32 (mp->dp_table),
4529 mp->is_l2, mp->is_add);
4530 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
4532 /** Used for transferring locators via VPP API */
4534 typedef CLIB_PACKED (struct {
4535 u8 is_ip4; /**< is locator an IPv4 address */
4536 u8 priority; /**< locator priority */
4537 u8 weight; /**< locator weight */
4538 u8 addr[16]; /**< IPv4/IPv6 address */
4542 static locator_pair_t *
4543 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
4546 locator_pair_t *pairs = 0, pair;
4549 for (i = 0; i < rloc_num; i++)
4552 r = &((rloc_t *) lcl_locs)[i];
4553 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
4554 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
4556 /* remote locators */
4557 r = &((rloc_t *) rmt_locs)[i];
4558 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
4559 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
4561 pair.priority = r->priority;
4562 pair.weight = r->weight;
4564 vec_add1 (pairs, pair);
4570 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
4573 locator_t *locs = 0, loc;
4576 for (i = 0; i < rloc_num; i++)
4578 /* remote locators */
4579 r = &((rloc_t *) rmt_locs)[i];
4580 memset (&loc, 0, sizeof (loc));
4581 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
4583 loc.priority = r->priority;
4584 loc.weight = r->weight;
4586 vec_add1 (locs, loc);
4592 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
4593 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
4595 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4596 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
4597 locator_pair_t *pairs = 0;
4600 memset (a, 0, sizeof (a[0]));
4602 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
4603 mp->rmt_eid, mp->rmt_len);
4604 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
4605 mp->lcl_eid, mp->lcl_len);
4607 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
4609 if (rv || 0 == pairs)
4612 a->is_add = mp->is_add;
4613 a->locator_pairs = pairs;
4614 a->dp_table = mp->dp_table;
4616 a->action = mp->action;
4618 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
4621 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4625 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
4628 vl_api_lisp_add_del_map_server_reply_t *rmp;
4632 memset (&addr, 0, sizeof (addr));
4634 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
4635 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
4637 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
4641 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
4644 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4646 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
4648 memset (a, 0, sizeof (a[0]));
4650 a->is_add = mp->is_add;
4651 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
4653 rv = vnet_lisp_add_del_map_resolver (a);
4655 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4659 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
4662 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4664 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
4666 a->is_en = mp->is_en;
4667 vnet_lisp_gpe_enable_disable (a);
4669 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4673 vl_api_lisp_map_register_enable_disable_t_handler
4674 (vl_api_lisp_map_register_enable_disable_t * mp)
4676 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
4679 vnet_lisp_map_register_enable_disable (mp->is_enabled);
4680 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4684 vl_api_lisp_rloc_probe_enable_disable_t_handler
4685 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
4687 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
4690 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
4691 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4695 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
4697 vl_api_lisp_enable_disable_reply_t *rmp;
4700 vnet_lisp_enable_disable (mp->is_en);
4701 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
4705 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
4707 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4715 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
4719 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
4726 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
4730 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
4733 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4737 vl_api_show_lisp_map_request_mode_t_handler
4738 (vl_api_show_lisp_map_request_mode_t * mp)
4741 vl_api_show_lisp_map_request_mode_reply_t *rmp;
4744 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
4746 rmp->mode = vnet_lisp_get_map_request_mode ();
4752 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
4754 vl_api_lisp_map_request_mode_reply_t *rmp;
4757 rv = vnet_lisp_set_map_request_mode (mp->mode);
4759 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
4763 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
4766 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4770 ls_name = format (0, "%s", mp->ls_name);
4771 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4774 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4778 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
4779 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
4781 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
4783 u8 *locator_set_name = NULL;
4784 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
4786 locator_set_name = format (0, "%s", mp->locator_set_name);
4788 a->is_add = mp->is_add;
4789 a->locator_set_name = locator_set_name;
4791 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
4793 vec_free (locator_set_name);
4795 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
4799 vl_api_lisp_add_del_remote_mapping_t_handler
4800 (vl_api_lisp_add_del_remote_mapping_t * mp)
4802 locator_t *rlocs = 0;
4803 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
4805 gid_address_t _eid, *eid = &_eid;
4806 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
4808 memset (eid, 0, sizeof (eid[0]));
4810 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4811 mp->eid_type, mp->eid, mp->eid_len);
4815 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
4819 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
4820 gid_address_copy (&a->reid, eid);
4822 rv = vnet_lisp_add_del_adjacency (a);
4829 /* NOTE: for now this works as a static remote mapping, i.e.,
4830 * not authoritative and ttl infinite. */
4831 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
4832 mp->is_add, 1 /* is_static */ , 0);
4835 vnet_lisp_clear_all_remote_adjacencies ();
4840 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
4844 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
4846 vl_api_lisp_add_del_adjacency_reply_t *rmp;
4847 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
4850 memset (a, 0, sizeof (a[0]));
4852 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
4853 mp->eid_type, mp->leid, mp->leid_len);
4854 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
4855 mp->eid_type, mp->reid, mp->reid_len);
4860 a->is_add = mp->is_add;
4861 rv = vnet_lisp_add_del_adjacency (a);
4864 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
4868 send_lisp_locator_details (lisp_cp_main_t * lcm,
4870 unix_shared_memory_queue_t * q, u32 context)
4872 vl_api_lisp_locator_details_t *rmp;
4874 rmp = vl_msg_api_alloc (sizeof (*rmp));
4875 memset (rmp, 0, sizeof (*rmp));
4876 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
4877 rmp->context = context;
4879 rmp->local = loc->local;
4882 rmp->sw_if_index = ntohl (loc->sw_if_index);
4886 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
4887 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
4889 rmp->priority = loc->priority;
4890 rmp->weight = loc->weight;
4892 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4896 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
4899 unix_shared_memory_queue_t *q = 0;
4900 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4901 locator_set_t *lsit = 0;
4903 u32 ls_index = ~0, *locit = 0;
4906 q = vl_api_client_index_to_input_queue (mp->client_index);
4912 if (mp->is_index_set)
4913 ls_index = htonl (mp->ls_index);
4916 /* make sure we get a proper C-string */
4917 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
4918 ls_name = format (0, "%s", mp->ls_name);
4919 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
4925 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
4928 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
4930 vec_foreach (locit, lsit->locator_indices)
4932 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4933 send_lisp_locator_details (lcm, loc, q, mp->context);
4940 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
4941 locator_set_t * lsit,
4942 unix_shared_memory_queue_t * q,
4943 u32 context, u32 ls_index)
4945 vl_api_lisp_locator_set_details_t *rmp;
4948 rmp = vl_msg_api_alloc (sizeof (*rmp));
4949 memset (rmp, 0, sizeof (*rmp));
4950 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
4951 rmp->context = context;
4953 rmp->ls_index = htonl (ls_index);
4956 ASSERT (lsit->name != NULL);
4957 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
4958 vec_len (lsit->name));
4962 str = format (0, "<remote-%d>", ls_index);
4963 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
4967 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4971 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
4973 unix_shared_memory_queue_t *q = NULL;
4974 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4975 locator_set_t *lsit = NULL;
4978 q = vl_api_client_index_to_input_queue (mp->client_index);
4984 filter = mp->filter;
4986 pool_foreach (lsit, lcm->locator_set_pool,
4988 if (filter && !((1 == filter && lsit->local) ||
4989 (2 == filter && !lsit->local)))
4993 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
4994 lsit - lcm->locator_set_pool);
5000 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5002 ASSERT (prefix_length);
5003 ip_prefix_t *ippref = &fid_addr_ippref (src);
5005 switch (fid_addr_type (src))
5007 case FID_ADDR_IP_PREF:
5008 if (ip_prefix_version (ippref) == IP4)
5009 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5011 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5012 prefix_length[0] = ip_prefix_len (ippref);
5016 prefix_length[0] = 0;
5017 clib_memcpy (dst, fid_addr_mac (src), 6);
5021 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5027 fid_type_to_api_type (fid_address_t * fid)
5029 ip_prefix_t *ippref;
5031 switch (fid_addr_type (fid))
5033 case FID_ADDR_IP_PREF:
5034 ippref = &fid_addr_ippref (fid);
5035 if (ip_prefix_version (ippref) == IP4)
5037 else if (ip_prefix_version (ippref) == IP6)
5050 send_lisp_eid_table_details (mapping_t * mapit,
5051 unix_shared_memory_queue_t * q,
5052 u32 context, u8 filter)
5055 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5056 locator_set_t *ls = 0;
5057 vl_api_lisp_eid_table_details_t *rmp = NULL;
5058 gid_address_t *gid = NULL;
5060 ip_prefix_t *ip_prefix = NULL;
5064 case 0: /* all mappings */
5067 case 1: /* local only */
5071 case 2: /* remote only */
5076 clib_warning ("Filter error, unknown filter: %d", filter);
5081 ip_prefix = &gid_address_ippref (gid);
5082 mac = gid_address_mac (gid);
5084 rmp = vl_msg_api_alloc (sizeof (*rmp));
5085 memset (rmp, 0, sizeof (*rmp));
5086 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5088 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5089 if (vec_len (ls->locator_indices) == 0)
5090 rmp->locator_set_index = ~0;
5092 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5094 rmp->is_local = mapit->local;
5095 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5096 rmp->action = mapit->action;
5097 rmp->authoritative = mapit->authoritative;
5099 switch (gid_address_type (gid))
5101 case GID_ADDR_SRC_DST:
5102 rmp->is_src_dst = 1;
5103 fid = &gid_address_sd_src (gid);
5104 rmp->eid_type = fid_type_to_api_type (fid);
5105 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5106 &rmp->seid_prefix_len);
5107 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5108 &rmp->eid_prefix_len);
5110 case GID_ADDR_IP_PREFIX:
5111 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5112 if (ip_prefix_version (ip_prefix) == IP4)
5114 rmp->eid_type = 0; /* ipv4 type */
5115 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5116 sizeof (ip_prefix_v4 (ip_prefix)));
5120 rmp->eid_type = 1; /* ipv6 type */
5121 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5122 sizeof (ip_prefix_v6 (ip_prefix)));
5126 rmp->eid_type = 2; /* l2 mac type */
5127 clib_memcpy (rmp->eid, mac, 6);
5132 rmp->context = context;
5133 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5134 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
5135 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
5136 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5140 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5143 unix_shared_memory_queue_t *q = NULL;
5144 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5145 mapping_t *mapit = NULL;
5146 gid_address_t _eid, *eid = &_eid;
5148 q = vl_api_client_index_to_input_queue (mp->client_index);
5156 memset (eid, 0, sizeof (*eid));
5158 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5159 mp->eid_type, mp->eid, mp->prefix_length);
5161 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5162 if ((u32) ~ 0 == mi)
5165 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5166 send_lisp_eid_table_details (mapit, q, mp->context,
5167 0 /* ignore filter */ );
5172 pool_foreach (mapit, lcm->mapping_pool,
5174 send_lisp_eid_table_details(mapit, q, mp->context,
5182 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
5183 unix_shared_memory_queue_t * q, u32 context)
5185 vl_api_lisp_gpe_tunnel_details_t *rmp;
5186 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5188 rmp = vl_msg_api_alloc (sizeof (*rmp));
5189 memset (rmp, 0, sizeof (*rmp));
5190 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5192 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
5194 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
5195 ip_address_copy_addr (rmp->source_ip,
5196 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5197 ip_address_copy_addr (rmp->destination_ip,
5198 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5200 rmp->encap_fib_id = htonl (0);
5201 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
5202 rmp->iid = htonl (lfe->key->vni);
5203 rmp->context = context;
5205 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5209 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5211 unix_shared_memory_queue_t *q = NULL;
5212 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5213 lisp_gpe_fwd_entry_t *lfe = NULL;
5215 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
5220 q = vl_api_client_index_to_input_queue (mp->client_index);
5227 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
5229 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
5235 send_lisp_map_server_details (ip_address_t * ip,
5236 unix_shared_memory_queue_t * q, u32 context)
5238 vl_api_lisp_map_server_details_t *rmp = NULL;
5240 rmp = vl_msg_api_alloc (sizeof (*rmp));
5241 memset (rmp, 0, sizeof (*rmp));
5242 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
5244 switch (ip_addr_version (ip))
5248 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5249 sizeof (ip_addr_v4 (ip)));
5254 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5255 sizeof (ip_addr_v6 (ip)));
5261 rmp->context = context;
5263 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5267 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
5269 unix_shared_memory_queue_t *q = NULL;
5270 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5273 q = vl_api_client_index_to_input_queue (mp->client_index);
5279 vec_foreach (mr, lcm->map_servers)
5281 send_lisp_map_server_details (&mr->address, q, mp->context);
5286 send_lisp_map_resolver_details (ip_address_t * ip,
5287 unix_shared_memory_queue_t * q, u32 context)
5289 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5291 rmp = vl_msg_api_alloc (sizeof (*rmp));
5292 memset (rmp, 0, sizeof (*rmp));
5293 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5295 switch (ip_addr_version (ip))
5299 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5300 sizeof (ip_addr_v4 (ip)));
5305 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5306 sizeof (ip_addr_v6 (ip)));
5312 rmp->context = context;
5314 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5318 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5320 unix_shared_memory_queue_t *q = NULL;
5321 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5324 q = vl_api_client_index_to_input_queue (mp->client_index);
5330 vec_foreach (mr, lcm->map_resolvers)
5332 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5337 send_eid_table_map_pair (hash_pair_t * p,
5338 unix_shared_memory_queue_t * q, u32 context)
5340 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5342 rmp = vl_msg_api_alloc (sizeof (*rmp));
5343 memset (rmp, 0, sizeof (*rmp));
5344 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5346 rmp->vni = clib_host_to_net_u32 (p->key);
5347 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5348 rmp->context = context;
5349 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5353 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5356 unix_shared_memory_queue_t *q = NULL;
5357 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5359 uword *vni_table = 0;
5361 q = vl_api_client_index_to_input_queue (mp->client_index);
5369 vni_table = lcm->bd_id_by_vni;
5373 vni_table = lcm->table_id_by_vni;
5377 hash_foreach_pair (p, vni_table,
5379 send_eid_table_map_pair (p, q, mp->context);
5385 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
5387 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
5389 rmp = vl_msg_api_alloc (sizeof (*rmp));
5390 memset (rmp, 0, sizeof (*rmp));
5391 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
5392 rmp->context = context;
5393 rmp->vni = clib_host_to_net_u32 (vni);
5394 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5398 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
5400 lisp_adjacency_t *adj;
5401 vl_api_lisp_adjacency_t a;
5402 u32 i, n = vec_len (adjs);
5404 for (i = 0; i < n; i++)
5406 adj = vec_elt_at_index (adjs, i);
5407 memset (&a, 0, sizeof (a));
5409 switch (gid_address_type (&adj->reid))
5411 case GID_ADDR_IP_PREFIX:
5412 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
5413 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
5414 if (gid_address_ip_version (&adj->reid) == IP4)
5416 a.eid_type = 0; /* ipv4 type */
5417 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
5418 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
5422 a.eid_type = 1; /* ipv6 type */
5423 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
5424 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
5428 a.eid_type = 2; /* l2 mac type */
5429 mac_copy (a.reid, gid_address_mac (&adj->reid));
5430 mac_copy (a.leid, gid_address_mac (&adj->leid));
5440 vl_api_show_lisp_rloc_probe_state_t_handler
5441 (vl_api_show_lisp_rloc_probe_state_t * mp)
5443 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
5447 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
5449 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
5455 vl_api_show_lisp_map_register_state_t_handler
5456 (vl_api_show_lisp_map_register_state_t * mp)
5458 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
5462 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
5464 rmp->is_enabled = vnet_lisp_map_register_state_get ();
5470 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
5472 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
5473 lisp_adjacency_t *adjs = 0;
5475 vl_api_lisp_adjacency_t a;
5477 u32 vni = clib_net_to_host_u32 (mp->vni);
5479 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
5480 size = vec_len (adjs) * sizeof (a);
5483 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
5485 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
5486 lisp_adjacency_copy (rmp->adjacencies, adjs);
5494 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
5499 unix_shared_memory_queue_t *q = 0;
5500 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5502 q = vl_api_client_index_to_input_queue (mp->client_index);
5509 hash_foreach_pair (p, lcm->table_id_by_vni,
5511 hash_set (vnis, p->key, 0);
5514 hash_foreach_pair (p, lcm->bd_id_by_vni,
5516 hash_set (vnis, p->key, 0);
5519 hash_foreach_pair (p, vnis,
5521 send_eid_table_vni (p->key, q, mp->context);
5529 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
5531 unix_shared_memory_queue_t *q = NULL;
5532 vl_api_show_lisp_status_reply_t *rmp = NULL;
5535 q = vl_api_client_index_to_input_queue (mp->client_index);
5542 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5544 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5545 rmp->feature_status = vnet_lisp_enable_disable_status ();
5551 vl_api_lisp_get_map_request_itr_rlocs_t_handler
5552 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
5554 unix_shared_memory_queue_t *q = NULL;
5555 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5556 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5557 locator_set_t *loc_set = 0;
5561 q = vl_api_client_index_to_input_queue (mp->client_index);
5567 if (~0 == lcm->mreq_itr_rlocs)
5569 tmp_str = format (0, " ");
5574 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5575 tmp_str = format (0, "%s", loc_set->name);
5579 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5581 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5582 ARRAY_LEN(rmp->locator_set_name) - 1);
5590 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5592 unix_shared_memory_queue_t *q = NULL;
5593 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
5594 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5596 locator_set_t *ls = 0;
5600 q = vl_api_client_index_to_input_queue (mp->client_index);
5606 if (!lcm->lisp_pitr)
5608 tmp_str = format (0, "N/A");
5612 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5613 if (~0 != m->locator_set_index)
5616 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5617 tmp_str = format (0, "%s", ls->name);
5621 tmp_str = format (0, "N/A");
5624 vec_add1 (tmp_str, 0);
5627 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5629 rmp->status = lcm->lisp_pitr;
5630 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5631 ARRAY_LEN(rmp->locator_set_name) - 1);
5637 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
5640 vl_api_interface_name_renumber_reply_t *rmp;
5643 VALIDATE_SW_IF_INDEX (mp);
5645 rv = vnet_interface_name_renumber
5646 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
5648 BAD_SW_IF_INDEX_LABEL;
5650 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5654 arp_change_data_callback (u32 pool_index, u8 * new_mac,
5655 u32 sw_if_index, u32 address)
5657 vpe_api_main_t *am = &vpe_api_main;
5658 vlib_main_t *vm = am->vlib_main;
5659 vl_api_ip4_arp_event_t *event;
5660 static f64 arp_event_last_time;
5661 f64 now = vlib_time_now (vm);
5663 if (pool_is_free_index (am->arp_events, pool_index))
5666 event = pool_elt_at_index (am->arp_events, pool_index);
5668 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
5670 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
5674 if (sw_if_index == event->sw_if_index &&
5676 /* for BD case, also check IP address with 10 sec timeout */
5677 (address == event->address &&
5678 (now - arp_event_last_time) < 10.0)))
5683 arp_event_last_time = now;
5684 event->sw_if_index = sw_if_index;
5686 event->address = address;
5691 nd_change_data_callback (u32 pool_index, u8 * new_mac,
5692 u32 sw_if_index, ip6_address_t * address)
5694 vpe_api_main_t *am = &vpe_api_main;
5695 vlib_main_t *vm = am->vlib_main;
5696 vl_api_ip6_nd_event_t *event;
5697 static f64 nd_event_last_time;
5698 f64 now = vlib_time_now (vm);
5700 if (pool_is_free_index (am->nd_events, pool_index))
5703 event = pool_elt_at_index (am->nd_events, pool_index);
5706 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
5708 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
5712 if (sw_if_index == event->sw_if_index &&
5714 /* for BD case, also check IP address with 10 sec timeout */
5715 (ip6_address_is_equal (address,
5716 (ip6_address_t *) event->address) &&
5717 (now - nd_event_last_time) < 10.0)))
5722 nd_event_last_time = now;
5723 event->sw_if_index = sw_if_index;
5725 clib_memcpy (event->address, address, sizeof (event->address));
5730 arp_change_delete_callback (u32 pool_index, u8 * notused)
5732 vpe_api_main_t *am = &vpe_api_main;
5734 if (pool_is_free_index (am->arp_events, pool_index))
5737 pool_put_index (am->arp_events, pool_index);
5742 nd_change_delete_callback (u32 pool_index, u8 * notused)
5744 vpe_api_main_t *am = &vpe_api_main;
5746 if (pool_is_free_index (am->nd_events, pool_index))
5749 pool_put_index (am->nd_events, pool_index);
5754 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
5756 vpe_api_main_t *am = &vpe_api_main;
5757 vnet_main_t *vnm = vnet_get_main ();
5758 vl_api_want_ip4_arp_events_reply_t *rmp;
5759 vl_api_ip4_arp_event_t *event;
5762 if (mp->enable_disable)
5764 pool_get (am->arp_events, event);
5765 memset (event, 0, sizeof (*event));
5767 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
5768 event->client_index = mp->client_index;
5769 event->context = mp->context;
5770 event->address = mp->address;
5771 event->pid = mp->pid;
5772 if (mp->address == 0)
5775 rv = vnet_add_del_ip4_arp_change_event
5776 (vnm, arp_change_data_callback,
5777 mp->pid, &mp->address /* addr, in net byte order */ ,
5778 vpe_resolver_process_node.index,
5779 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
5783 rv = vnet_add_del_ip4_arp_change_event
5784 (vnm, arp_change_delete_callback,
5785 mp->pid, &mp->address /* addr, in net byte order */ ,
5786 vpe_resolver_process_node.index,
5787 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
5789 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5793 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
5795 vpe_api_main_t *am = &vpe_api_main;
5796 vnet_main_t *vnm = vnet_get_main ();
5797 vl_api_want_ip6_nd_events_reply_t *rmp;
5798 vl_api_ip6_nd_event_t *event;
5801 if (mp->enable_disable)
5803 pool_get (am->nd_events, event);
5804 memset (event, 0, sizeof (*event));
5806 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
5807 event->client_index = mp->client_index;
5808 event->context = mp->context;
5809 clib_memcpy (event->address, mp->address, 16);
5810 event->pid = mp->pid;
5811 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
5814 rv = vnet_add_del_ip6_nd_change_event
5815 (vnm, nd_change_data_callback,
5816 mp->pid, mp->address /* addr, in net byte order */ ,
5817 vpe_resolver_process_node.index,
5818 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
5822 rv = vnet_add_del_ip6_nd_change_event
5823 (vnm, nd_change_delete_callback,
5824 mp->pid, mp->address /* addr, in net byte order */ ,
5825 vpe_resolver_process_node.index,
5826 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
5828 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
5831 static void vl_api_input_acl_set_interface_t_handler
5832 (vl_api_input_acl_set_interface_t * mp)
5834 vlib_main_t *vm = vlib_get_main ();
5835 vl_api_input_acl_set_interface_reply_t *rmp;
5837 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5839 ip4_table_index = ntohl (mp->ip4_table_index);
5840 ip6_table_index = ntohl (mp->ip6_table_index);
5841 l2_table_index = ntohl (mp->l2_table_index);
5842 sw_if_index = ntohl (mp->sw_if_index);
5844 VALIDATE_SW_IF_INDEX (mp);
5846 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5847 ip6_table_index, l2_table_index, mp->is_add);
5849 BAD_SW_IF_INDEX_LABEL;
5851 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5854 static void vl_api_ipsec_spd_add_del_t_handler
5855 (vl_api_ipsec_spd_add_del_t * mp)
5858 clib_warning ("unimplemented");
5861 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5862 vl_api_ipsec_spd_add_del_reply_t *rmp;
5866 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
5868 rv = VNET_API_ERROR_UNIMPLEMENTED;
5871 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5875 static void vl_api_ipsec_interface_add_del_spd_t_handler
5876 (vl_api_ipsec_interface_add_del_spd_t * mp)
5878 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5879 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
5881 u32 sw_if_index __attribute__ ((unused));
5882 u32 spd_id __attribute__ ((unused));
5884 sw_if_index = ntohl (mp->sw_if_index);
5885 spd_id = ntohl (mp->spd_id);
5887 VALIDATE_SW_IF_INDEX (mp);
5890 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
5892 rv = VNET_API_ERROR_UNIMPLEMENTED;
5895 BAD_SW_IF_INDEX_LABEL;
5897 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5900 static void vl_api_ipsec_spd_add_del_entry_t_handler
5901 (vl_api_ipsec_spd_add_del_entry_t * mp)
5903 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5904 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
5910 memset (&p, 0, sizeof (p));
5912 p.id = ntohl (mp->spd_id);
5913 p.priority = ntohl (mp->priority);
5914 p.is_outbound = mp->is_outbound;
5915 p.is_ipv6 = mp->is_ipv6;
5917 if (mp->is_ipv6 || mp->is_ip_any)
5919 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
5920 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
5921 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
5922 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
5926 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5927 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5928 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
5929 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5931 p.protocol = mp->protocol;
5932 p.rport.start = ntohs (mp->remote_port_start);
5933 p.rport.stop = ntohs (mp->remote_port_stop);
5934 p.lport.start = ntohs (mp->local_port_start);
5935 p.lport.stop = ntohs (mp->local_port_stop);
5936 /* policy action resolve unsupported */
5937 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
5939 clib_warning ("unsupported action: 'resolve'");
5940 rv = VNET_API_ERROR_UNIMPLEMENTED;
5943 p.policy = mp->policy;
5944 p.sa_id = ntohl (mp->sa_id);
5946 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5953 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5956 rv = VNET_API_ERROR_UNIMPLEMENTED;
5961 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5964 static void vl_api_ipsec_sad_add_del_entry_t_handler
5965 (vl_api_ipsec_sad_add_del_entry_t * mp)
5967 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5968 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
5973 memset (&sa, 0, sizeof (sa));
5975 sa.id = ntohl (mp->sad_id);
5976 sa.spi = ntohl (mp->spi);
5977 /* security protocol AH unsupported */
5978 if (mp->protocol == IPSEC_PROTOCOL_AH)
5980 clib_warning ("unsupported security protocol 'AH'");
5981 rv = VNET_API_ERROR_UNIMPLEMENTED;
5984 sa.protocol = mp->protocol;
5985 /* check for unsupported crypto-alg */
5986 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5987 mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
5989 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5990 mp->crypto_algorithm);
5991 rv = VNET_API_ERROR_UNIMPLEMENTED;
5994 sa.crypto_alg = mp->crypto_algorithm;
5995 sa.crypto_key_len = mp->crypto_key_length;
5996 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
5997 /* check for unsupported integ-alg */
5999 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_NONE ||
6001 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6003 mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
6005 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6006 mp->integrity_algorithm);
6007 rv = VNET_API_ERROR_UNIMPLEMENTED;
6012 /*Special cases, aes-gcm-128 encryption */
6013 if (mp->crypto_algorithm == IPSEC_CRYPTO_ALG_AES_GCM_128)
6015 if (mp->integrity_algorithm != IPSEC_INTEG_ALG_NONE
6016 && mp->integrity_algorithm != IPSEC_INTEG_ALG_AES_GCM_128)
6019 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
6020 rv = VNET_API_ERROR_UNIMPLEMENTED;
6023 else /*set integ-alg internally to aes-gcm-128 */
6024 mp->integrity_algorithm = IPSEC_INTEG_ALG_AES_GCM_128;
6026 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_AES_GCM_128)
6028 clib_warning ("unsupported integ-alg: aes-gcm-128");
6029 rv = VNET_API_ERROR_UNIMPLEMENTED;
6032 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_NONE)
6034 clib_warning ("unsupported integ-alg: none");
6035 rv = VNET_API_ERROR_UNIMPLEMENTED;
6040 sa.integ_alg = mp->integrity_algorithm;
6041 sa.integ_key_len = mp->integrity_key_length;
6042 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6043 sa.use_esn = mp->use_extended_sequence_number;
6044 sa.is_tunnel = mp->is_tunnel;
6045 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6046 if (sa.is_tunnel_ip6)
6048 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6049 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6053 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6054 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6057 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6059 rv = VNET_API_ERROR_UNIMPLEMENTED;
6064 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6068 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6070 vl_api_ikev2_profile_add_del_reply_t *rmp;
6074 vlib_main_t *vm = vlib_get_main ();
6075 clib_error_t *error;
6076 u8 *tmp = format (0, "%s", mp->name);
6077 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6080 rv = VNET_API_ERROR_UNSPECIFIED;
6082 rv = VNET_API_ERROR_UNIMPLEMENTED;
6085 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6089 vl_api_ikev2_profile_set_auth_t_handler
6090 (vl_api_ikev2_profile_set_auth_t * mp)
6092 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6096 vlib_main_t *vm = vlib_get_main ();
6097 clib_error_t *error;
6098 u8 *tmp = format (0, "%s", mp->name);
6099 u8 *data = vec_new (u8, mp->data_len);
6100 clib_memcpy (data, mp->data, mp->data_len);
6101 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6105 rv = VNET_API_ERROR_UNSPECIFIED;
6107 rv = VNET_API_ERROR_UNIMPLEMENTED;
6110 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6114 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6116 vl_api_ikev2_profile_add_del_reply_t *rmp;
6120 vlib_main_t *vm = vlib_get_main ();
6121 clib_error_t *error;
6122 u8 *tmp = format (0, "%s", mp->name);
6123 u8 *data = vec_new (u8, mp->data_len);
6124 clib_memcpy (data, mp->data, mp->data_len);
6125 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6129 rv = VNET_API_ERROR_UNSPECIFIED;
6131 rv = VNET_API_ERROR_UNIMPLEMENTED;
6134 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6138 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6140 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6144 vlib_main_t *vm = vlib_get_main ();
6145 clib_error_t *error;
6146 u8 *tmp = format (0, "%s", mp->name);
6147 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6148 mp->end_port, (ip4_address_t) mp->start_addr,
6149 (ip4_address_t) mp->end_addr, mp->is_local);
6152 rv = VNET_API_ERROR_UNSPECIFIED;
6154 rv = VNET_API_ERROR_UNIMPLEMENTED;
6157 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6161 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6163 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6167 vlib_main_t *vm = vlib_get_main ();
6168 clib_error_t *error;
6170 error = ikev2_set_local_key (vm, mp->key_file);
6172 rv = VNET_API_ERROR_UNSPECIFIED;
6174 rv = VNET_API_ERROR_UNIMPLEMENTED;
6177 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6181 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6183 vl_api_map_add_domain_reply_t *rmp;
6186 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6188 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6189 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6190 (ip6_address_t *) & mp->ip6_src,
6191 mp->ip6_src_prefix_len, mp->ea_bits_len,
6192 mp->psid_offset, mp->psid_length, &index,
6193 ntohs (mp->mtu), flags);
6196 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6198 rmp->index = ntohl(index);
6204 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6206 vl_api_map_del_domain_reply_t *rmp;
6209 rv = map_delete_domain (ntohl (mp->index));
6211 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6215 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6217 vl_api_map_del_domain_reply_t *rmp;
6221 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6222 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6224 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6228 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6230 vl_api_map_domain_details_t *rmp;
6231 map_main_t *mm = &map_main;
6233 unix_shared_memory_queue_t *q;
6235 if (pool_elts (mm->domains) == 0)
6238 q = vl_api_client_index_to_input_queue (mp->client_index);
6245 pool_foreach(d, mm->domains,
6247 /* Make sure every field is initiated (or don't skip the memset()) */
6248 rmp = vl_msg_api_alloc (sizeof (*rmp));
6249 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6250 rmp->domain_index = htonl(d - mm->domains);
6251 rmp->ea_bits_len = d->ea_bits_len;
6252 rmp->psid_offset = d->psid_offset;
6253 rmp->psid_length = d->psid_length;
6254 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6255 rmp->ip4_prefix_len = d->ip4_prefix_len;
6256 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6257 rmp->ip6_prefix_len = d->ip6_prefix_len;
6258 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6259 rmp->ip6_src_len = d->ip6_src_len;
6260 rmp->mtu = htons(d->mtu);
6261 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6262 rmp->context = mp->context;
6264 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6270 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6272 unix_shared_memory_queue_t *q;
6275 vl_api_map_rule_details_t *rmp;
6276 map_main_t *mm = &map_main;
6277 u32 domain_index = ntohl (mp->domain_index);
6280 if (pool_elts (mm->domains) == 0)
6283 d = pool_elt_at_index (mm->domains, domain_index);
6284 if (!d || !d->rules)
6289 q = vl_api_client_index_to_input_queue (mp->client_index);
6295 for (i = 0; i < (0x1 << d->psid_length); i++)
6298 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6302 rmp = vl_msg_api_alloc (sizeof (*rmp));
6303 memset (rmp, 0, sizeof (*rmp));
6304 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6305 rmp->psid = htons (i);
6306 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6307 rmp->context = mp->context;
6308 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6313 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6315 vl_api_map_summary_stats_reply_t *rmp;
6316 vlib_combined_counter_main_t *cm;
6319 u64 total_pkts[VLIB_N_RX_TX];
6320 u64 total_bytes[VLIB_N_RX_TX];
6321 map_main_t *mm = &map_main;
6322 unix_shared_memory_queue_t *q =
6323 vl_api_client_index_to_input_queue (mp->client_index);
6328 rmp = vl_msg_api_alloc (sizeof (*rmp));
6329 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6330 rmp->context = mp->context;
6333 memset (total_pkts, 0, sizeof (total_pkts));
6334 memset (total_bytes, 0, sizeof (total_bytes));
6336 map_domain_counter_lock (mm);
6337 vec_foreach (cm, mm->domain_counters)
6339 which = cm - mm->domain_counters;
6341 for (i = 0; i < vec_len (cm->maxi); i++)
6343 vlib_get_combined_counter (cm, i, &v);
6344 total_pkts[which] += v.packets;
6345 total_bytes[which] += v.bytes;
6349 map_domain_counter_unlock (mm);
6351 /* Note: in network byte order! */
6352 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6353 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6354 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6355 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6356 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6357 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6358 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6359 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6360 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6361 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6362 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6363 clib_host_to_net_u64 (map_error_counter_get
6364 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6365 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6366 clib_host_to_net_u64 (map_error_counter_get
6367 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6369 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6373 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6375 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6376 vl_api_ipsec_sa_set_key_reply_t *rmp;
6380 sa.id = ntohl (mp->sa_id);
6381 sa.crypto_key_len = mp->crypto_key_length;
6382 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6383 sa.integ_key_len = mp->integrity_key_length;
6384 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6386 rv = ipsec_set_sa_key (vm, &sa);
6388 rv = VNET_API_ERROR_UNIMPLEMENTED;
6391 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6394 static void vl_api_cop_interface_enable_disable_t_handler
6395 (vl_api_cop_interface_enable_disable_t * mp)
6397 vl_api_cop_interface_enable_disable_reply_t *rmp;
6399 u32 sw_if_index = ntohl (mp->sw_if_index);
6402 VALIDATE_SW_IF_INDEX (mp);
6404 enable_disable = (int) mp->enable_disable;
6406 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6408 BAD_SW_IF_INDEX_LABEL;
6410 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6413 static void vl_api_cop_whitelist_enable_disable_t_handler
6414 (vl_api_cop_whitelist_enable_disable_t * mp)
6416 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6417 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6418 u32 sw_if_index = ntohl (mp->sw_if_index);
6421 VALIDATE_SW_IF_INDEX (mp);
6423 a->sw_if_index = sw_if_index;
6426 a->default_cop = mp->default_cop;
6427 a->fib_id = ntohl (mp->fib_id);
6429 rv = cop_whitelist_enable_disable (a);
6431 BAD_SW_IF_INDEX_LABEL;
6433 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6437 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6441 api_main_t *am = &api_main;
6442 vlib_main_t *vm = vlib_get_main ();
6444 vl_api_get_node_graph_reply_t *rmp;
6446 pthread_mutex_lock (&am->vlib_rp->mutex);
6447 oldheap = svm_push_data_heap (am->vlib_rp);
6450 * Keep the number of memcpy ops to a minimum (e.g. 1).
6452 vec_validate (vector, 16384);
6453 vec_reset_length (vector);
6456 vector = vlib_node_serialize (&vm->node_main, vector,
6457 (u32) ~ 0 /* all threads */ ,
6458 1 /* include nexts */ ,
6459 1 /* include stats */ );
6461 svm_pop_heap (oldheap);
6462 pthread_mutex_unlock (&am->vlib_rp->mutex);
6465 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6467 rmp->reply_in_shmem = (uword) vector;
6473 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
6476 vl_api_ioam_enable_reply_t *rmp;
6477 clib_error_t *error;
6479 /* Ignoring the profile id as currently a single profile
6481 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
6482 mp->seqno, mp->analyse);
6485 clib_error_report (error);
6486 rv = clib_error_get_code (error);
6489 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
6493 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
6496 vl_api_ioam_disable_reply_t *rmp;
6497 clib_error_t *error;
6499 error = clear_ioam_rewrite_fn ();
6502 clib_error_report (error);
6503 rv = clib_error_get_code (error);
6506 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
6510 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6512 vlib_main_t *vm = vlib_get_main ();
6513 vl_api_af_packet_create_reply_t *rmp;
6515 u8 *host_if_name = NULL;
6518 host_if_name = format (0, "%s", mp->host_if_name);
6519 vec_add1 (host_if_name, 0);
6521 rv = af_packet_create_if (vm, host_if_name,
6522 mp->use_random_hw_addr ? 0 : mp->hw_addr,
6525 vec_free (host_if_name);
6528 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6530 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
6536 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
6538 vlib_main_t *vm = vlib_get_main ();
6539 vl_api_af_packet_delete_reply_t *rmp;
6541 u8 *host_if_name = NULL;
6543 host_if_name = format (0, "%s", mp->host_if_name);
6544 vec_add1 (host_if_name, 0);
6546 rv = af_packet_delete_if (vm, host_if_name);
6548 vec_free (host_if_name);
6550 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
6554 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
6556 vlib_main_t *vm = vlib_get_main ();
6557 vl_api_policer_add_del_reply_t *rmp;
6560 sse2_qos_pol_cfg_params_st cfg;
6561 clib_error_t *error;
6564 name = format (0, "%s", mp->name);
6566 memset (&cfg, 0, sizeof (cfg));
6568 cfg.rnd_type = mp->round_type;
6569 cfg.rate_type = mp->rate_type;
6570 cfg.rb.kbps.cir_kbps = mp->cir;
6571 cfg.rb.kbps.eir_kbps = mp->eir;
6572 cfg.rb.kbps.cb_bytes = mp->cb;
6573 cfg.rb.kbps.eb_bytes = mp->eb;
6574 cfg.conform_action.action_type = mp->conform_action_type;
6575 cfg.conform_action.dscp = mp->conform_dscp;
6576 cfg.exceed_action.action_type = mp->exceed_action_type;
6577 cfg.exceed_action.dscp = mp->exceed_dscp;
6578 cfg.violate_action.action_type = mp->violate_action_type;
6579 cfg.violate_action.dscp = mp->violate_dscp;
6580 cfg.color_aware = mp->color_aware;
6582 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
6585 rv = VNET_API_ERROR_UNSPECIFIED;
6588 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6590 if (rv == 0 && mp->is_add)
6591 rmp->policer_index = ntohl(policer_index);
6593 rmp->policer_index = ~0;
6599 send_policer_details (u8 * name,
6600 sse2_qos_pol_cfg_params_st * config,
6601 policer_read_response_type_st * templ,
6602 unix_shared_memory_queue_t * q, u32 context)
6604 vl_api_policer_details_t *mp;
6606 mp = vl_msg_api_alloc (sizeof (*mp));
6607 memset (mp, 0, sizeof (*mp));
6608 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6609 mp->context = context;
6610 mp->cir = htonl (config->rb.kbps.cir_kbps);
6611 mp->eir = htonl (config->rb.kbps.eir_kbps);
6612 mp->cb = htonl (config->rb.kbps.cb_bytes);
6613 mp->eb = htonl (config->rb.kbps.eb_bytes);
6614 mp->rate_type = config->rate_type;
6615 mp->round_type = config->rnd_type;
6616 mp->type = config->rfc;
6617 mp->conform_action_type = config->conform_action.action_type;
6618 mp->conform_dscp = config->conform_action.dscp;
6619 mp->exceed_action_type = config->exceed_action.action_type;
6620 mp->exceed_dscp = config->exceed_action.dscp;
6621 mp->violate_action_type = config->violate_action.action_type;
6622 mp->violate_dscp = config->violate_action.dscp;
6623 mp->single_rate = templ->single_rate ? 1 : 0;
6624 mp->color_aware = templ->color_aware ? 1 : 0;
6625 mp->scale = htonl (templ->scale);
6626 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
6627 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
6628 mp->current_limit = htonl (templ->current_limit);
6629 mp->current_bucket = htonl (templ->current_bucket);
6630 mp->extended_limit = htonl (templ->extended_limit);
6631 mp->extended_bucket = htonl (templ->extended_bucket);
6632 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
6634 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
6636 vl_msg_api_send_shmem (q, (u8 *) & mp);
6640 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
6642 unix_shared_memory_queue_t *q;
6643 vnet_policer_main_t *pm = &vnet_policer_main;
6649 sse2_qos_pol_cfg_params_st *config;
6650 policer_read_response_type_st *templ;
6652 q = vl_api_client_index_to_input_queue (mp->client_index);
6656 if (mp->match_name_valid)
6658 match_name = format (0, "%s%c", mp->match_name, 0);
6661 if (mp->match_name_valid)
6663 p = hash_get_mem (pm->policer_config_by_name, match_name);
6667 config = pool_elt_at_index (pm->configs, pool_index);
6668 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6669 send_policer_details (match_name, config, templ, q, mp->context);
6675 hash_foreach_pair (hp, pm->policer_config_by_name,
6677 name = (u8 *) hp->key;
6678 pool_index = hp->value[0];
6679 config = pool_elt_at_index (pm->configs, pool_index);
6680 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6681 send_policer_details(name, config, templ, q, mp->context);
6688 vl_api_policer_classify_set_interface_t_handler
6689 (vl_api_policer_classify_set_interface_t * mp)
6691 vlib_main_t *vm = vlib_get_main ();
6692 vl_api_policer_classify_set_interface_reply_t *rmp;
6694 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6696 ip4_table_index = ntohl (mp->ip4_table_index);
6697 ip6_table_index = ntohl (mp->ip6_table_index);
6698 l2_table_index = ntohl (mp->l2_table_index);
6699 sw_if_index = ntohl (mp->sw_if_index);
6701 VALIDATE_SW_IF_INDEX (mp);
6703 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
6704 ip6_table_index, l2_table_index,
6707 BAD_SW_IF_INDEX_LABEL;
6709 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
6713 send_policer_classify_details (u32 sw_if_index,
6715 unix_shared_memory_queue_t * q, u32 context)
6717 vl_api_policer_classify_details_t *mp;
6719 mp = vl_msg_api_alloc (sizeof (*mp));
6720 memset (mp, 0, sizeof (*mp));
6721 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
6722 mp->context = context;
6723 mp->sw_if_index = htonl (sw_if_index);
6724 mp->table_index = htonl (table_index);
6726 vl_msg_api_send_shmem (q, (u8 *) & mp);
6730 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
6732 unix_shared_memory_queue_t *q;
6733 policer_classify_main_t *pcm = &policer_classify_main;
6737 q = vl_api_client_index_to_input_queue (mp->client_index);
6741 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6743 if (vec_len (vec_tbl))
6745 for (i = 0; i < vec_len (vec_tbl); i++)
6747 if (vec_elt (vec_tbl, i) == ~0)
6750 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
6757 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
6759 vlib_main_t *vm = vlib_get_main ();
6760 vl_api_netmap_create_reply_t *rmp;
6764 if_name = format (0, "%s", mp->netmap_if_name);
6765 vec_add1 (if_name, 0);
6768 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6769 mp->is_pipe, mp->is_master, 0);
6773 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
6777 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
6779 vlib_main_t *vm = vlib_get_main ();
6780 vl_api_netmap_delete_reply_t *rmp;
6784 if_name = format (0, "%s", mp->netmap_if_name);
6785 vec_add1 (if_name, 0);
6787 rv = netmap_delete_if (vm, if_name);
6791 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
6795 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_fib_details_t * mp)
6797 clib_warning ("BUG");
6800 typedef struct mpls_tunnel_send_walk_ctx_t_
6802 unix_shared_memory_queue_t *q;
6805 } mpls_tunnel_send_walk_ctx_t;
6808 send_mpls_tunnel_entry (u32 mti, void *arg)
6810 mpls_tunnel_send_walk_ctx_t *ctx;
6811 vl_api_mpls_tunnel_details_t *mp;
6812 const mpls_tunnel_t *mt;
6817 if (~0 != ctx->index && mti != ctx->index)
6820 mt = mpls_tunnel_get (mti);
6821 nlabels = vec_len (mt->mt_label_stack);
6823 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
6824 memset (mp, 0, sizeof (*mp));
6825 mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
6826 mp->context = ctx->context;
6828 mp->tunnel_index = ntohl (mti);
6829 memcpy (mp->mt_next_hop_out_labels,
6830 mt->mt_label_stack, nlabels * sizeof (u32));
6834 vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
6838 vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
6840 unix_shared_memory_queue_t *q;
6842 q = vl_api_client_index_to_input_queue (mp->client_index);
6846 mpls_tunnel_send_walk_ctx_t ctx = {
6848 .index = ntohl (mp->tunnel_index),
6849 .context = mp->context,
6851 mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
6855 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
6857 clib_warning ("BUG");
6861 vl_api_mpls_fib_details_t_endian (vl_api_mpls_fib_details_t * mp)
6863 clib_warning ("BUG");
6867 vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp)
6869 clib_warning ("BUG");
6874 copy_fib_next_hop (fib_route_path_encode_t * api_rpath,
6875 vl_api_fib_path_t * fp)
6879 if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4)
6880 fp->afi = IP46_TYPE_IP4;
6881 else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6)
6882 fp->afi = IP46_TYPE_IP6;
6885 is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr);
6887 fp->afi = IP46_TYPE_IP4;
6889 fp->afi = IP46_TYPE_IP6;
6891 if (fp->afi == IP46_TYPE_IP4)
6892 memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip4,
6893 sizeof (api_rpath->rpath.frp_addr.ip4));
6895 memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip6,
6896 sizeof (api_rpath->rpath.frp_addr.ip6));
6900 send_mpls_fib_details (vpe_api_main_t * am,
6901 unix_shared_memory_queue_t * q,
6902 u32 table_id, u32 label, u32 eos,
6903 fib_route_path_encode_t * api_rpaths, u32 context)
6905 vl_api_mpls_fib_details_t *mp;
6906 fib_route_path_encode_t *api_rpath;
6907 vl_api_fib_path_t *fp;
6910 path_count = vec_len (api_rpaths);
6911 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
6914 memset (mp, 0, sizeof (*mp));
6915 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
6916 mp->context = context;
6918 mp->table_id = htonl (table_id);
6920 mp->label = htonl (label);
6922 mp->count = htonl (path_count);
6924 vec_foreach (api_rpath, api_rpaths)
6926 memset (fp, 0, sizeof (*fp));
6927 fp->weight = htonl (api_rpath->rpath.frp_weight);
6928 fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
6929 copy_fib_next_hop (api_rpath, fp);
6933 vl_msg_api_send_shmem (q, (u8 *) & mp);
6937 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
6939 vpe_api_main_t *am = &vpe_api_main;
6940 unix_shared_memory_queue_t *q;
6941 mpls_main_t *mm = &mpls_main;
6942 fib_table_t *fib_table;
6943 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
6947 fib_route_path_encode_t *api_rpaths;
6949 q = vl_api_client_index_to_input_queue (mp->client_index);
6954 pool_foreach (fib_table, mm->fibs,
6956 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
6958 vec_add1(lfeis, lfei);
6961 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
6963 vec_foreach(lfeip, lfeis)
6965 fib_entry_get_prefix(*lfeip, &pfx);
6966 fib_index = fib_entry_get_fib_index(*lfeip);
6967 fib_table = fib_table_get(fib_index, pfx.fp_proto);
6969 fib_entry_encode(*lfeip, &api_rpaths);
6970 send_mpls_fib_details (am, q,
6971 fib_table->ft_table_id,
6976 vec_free(api_rpaths);
6983 vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
6985 clib_warning ("BUG");
6989 vl_api_ip_fib_details_t_endian (vl_api_ip_fib_details_t * mp)
6991 clib_warning ("BUG");
6995 vl_api_ip_fib_details_t_print (vl_api_ip_fib_details_t * mp)
6997 clib_warning ("BUG");
7001 send_ip_fib_details (vpe_api_main_t * am,
7002 unix_shared_memory_queue_t * q,
7003 u32 table_id, fib_prefix_t *pfx,
7004 fib_route_path_encode_t *api_rpaths, u32 context)
7006 vl_api_ip_fib_details_t *mp;
7007 fib_route_path_encode_t *api_rpath;
7008 vl_api_fib_path_t *fp;
7011 path_count = vec_len(api_rpaths);
7012 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
7015 memset (mp, 0, sizeof (*mp));
7016 mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS);
7017 mp->context = context;
7019 mp->table_id = htonl (table_id);
7020 mp->address_length = pfx->fp_len;
7021 memcpy(mp->address, &pfx->fp_addr.ip4, sizeof(pfx->fp_addr.ip4));
7023 mp->count = htonl (path_count);
7025 vec_foreach(api_rpath, api_rpaths)
7027 memset (fp, 0, sizeof (*fp));
7028 switch (api_rpath->dpo.dpoi_type)
7031 fp->is_local = true;
7037 switch (api_rpath->dpo.dpoi_index)
7039 case IP_NULL_ACTION_NONE:
7042 case IP_NULL_ACTION_SEND_ICMP_UNREACH:
7043 fp->is_unreach = true;
7045 case IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
7046 fp->is_prohibit = true;
7055 fp->weight = htonl(api_rpath->rpath.frp_weight);
7056 fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
7057 copy_fib_next_hop (api_rpath, fp);
7061 vl_msg_api_send_shmem (q, (u8 *) & mp);
7065 vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp)
7067 vpe_api_main_t *am = &vpe_api_main;
7068 unix_shared_memory_queue_t *q;
7069 ip4_main_t *im = &ip4_main;
7070 fib_table_t *fib_table;
7071 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
7075 fib_route_path_encode_t *api_rpaths;
7078 q = vl_api_client_index_to_input_queue (mp->client_index);
7083 pool_foreach (fib_table, im->fibs,
7085 for (i = 0; i < ARRAY_LEN (fib_table->v4.fib_entry_by_dst_address); i++)
7087 hash_foreach(key, lfei, fib_table->v4.fib_entry_by_dst_address[i],
7089 vec_add1(lfeis, lfei);
7094 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
7096 vec_foreach(lfeip, lfeis)
7098 fib_entry_get_prefix(*lfeip, &pfx);
7099 fib_index = fib_entry_get_fib_index(*lfeip);
7100 fib_table = fib_table_get(fib_index, pfx.fp_proto);
7102 fib_entry_encode(*lfeip, &api_rpaths);
7103 send_ip_fib_details (am, q,
7104 fib_table->ft_table_id,
7108 vec_free(api_rpaths);
7115 vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
7117 clib_warning ("BUG");
7121 vl_api_ip6_fib_details_t_endian (vl_api_ip6_fib_details_t * mp)
7123 clib_warning ("BUG");
7127 vl_api_ip6_fib_details_t_print (vl_api_ip6_fib_details_t * mp)
7129 clib_warning ("BUG");
7133 send_ip6_fib_details (vpe_api_main_t * am,
7134 unix_shared_memory_queue_t * q,
7135 u32 table_id, fib_prefix_t *pfx,
7136 fib_route_path_encode_t *api_rpaths, u32 context)
7138 vl_api_ip6_fib_details_t *mp;
7139 fib_route_path_encode_t *api_rpath;
7140 vl_api_fib_path_t *fp;
7143 path_count = vec_len(api_rpaths);
7144 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
7147 memset (mp, 0, sizeof (*mp));
7148 mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS);
7149 mp->context = context;
7151 mp->table_id = htonl (table_id);
7152 mp->address_length = pfx->fp_len;
7153 memcpy(mp->address, &pfx->fp_addr.ip6, sizeof(pfx->fp_addr.ip6));
7155 mp->count = htonl (path_count);
7157 vec_foreach(api_rpath, api_rpaths)
7159 memset (fp, 0, sizeof (*fp));
7160 switch (api_rpath->dpo.dpoi_type)
7163 fp->is_local = true;
7169 switch (api_rpath->dpo.dpoi_index)
7171 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_NONE:
7174 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_UNREACH:
7175 fp->is_unreach = true;
7177 case IP_NULL_DPO_ACTION_NUM+IP_NULL_ACTION_SEND_ICMP_PROHIBIT:
7178 fp->is_prohibit = true;
7187 fp->weight = htonl(api_rpath->rpath.frp_weight);
7188 fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index);
7189 copy_fib_next_hop (api_rpath, fp);
7193 vl_msg_api_send_shmem (q, (u8 *) & mp);
7196 typedef struct apt_ip6_fib_show_ctx_t_ {
7198 fib_node_index_t *entries;
7199 } api_ip6_fib_show_ctx_t;
7202 api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp,
7205 api_ip6_fib_show_ctx_t *ctx = arg;
7207 if ((kvp->key[2] >> 32) == ctx->fib_index)
7209 vec_add1(ctx->entries, kvp->value);
7214 api_ip6_fib_table_get_all (unix_shared_memory_queue_t *q,
7215 vl_api_ip6_fib_dump_t *mp,
7216 fib_table_t *fib_table)
7218 vpe_api_main_t *am = &vpe_api_main;
7219 ip6_main_t *im6 = &ip6_main;
7220 ip6_fib_t *fib = &fib_table->v6;
7221 fib_node_index_t *fib_entry_index;
7222 api_ip6_fib_show_ctx_t ctx = {
7223 .fib_index = fib->index,
7226 fib_route_path_encode_t *api_rpaths;
7229 BV(clib_bihash_foreach_key_value_pair)
7230 ((BVT(clib_bihash) *) &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
7231 api_ip6_fib_table_put_entries,
7234 vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort);
7236 vec_foreach(fib_entry_index, ctx.entries)
7238 fib_entry_get_prefix(*fib_entry_index, &pfx);
7240 fib_entry_encode(*fib_entry_index, &api_rpaths);
7241 send_ip6_fib_details (am, q,
7242 fib_table->ft_table_id,
7246 vec_free(api_rpaths);
7249 vec_free(ctx.entries);
7253 vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp)
7255 unix_shared_memory_queue_t *q;
7256 ip6_main_t *im6 = &ip6_main;
7257 fib_table_t *fib_table;
7259 q = vl_api_client_index_to_input_queue (mp->client_index);
7264 pool_foreach (fib_table, im6->fibs,
7266 api_ip6_fib_table_get_all(q, mp, fib_table);
7271 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7273 unix_shared_memory_queue_t *q;
7275 q = vl_api_client_index_to_input_queue (mp->client_index);
7279 vnet_classify_main_t *cm = &vnet_classify_main;
7280 vnet_classify_table_t *t;
7285 pool_foreach (t, cm->tables,
7287 vec_add1 (table_ids, ntohl(t - cm->tables));
7290 count = vec_len (table_ids);
7292 vl_api_classify_table_ids_reply_t *rmp;
7293 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7294 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7295 rmp->context = mp->context;
7296 rmp->count = ntohl (count);
7297 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7300 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7302 vec_free (table_ids);
7306 vl_api_classify_table_by_interface_t_handler
7307 (vl_api_classify_table_by_interface_t * mp)
7309 vl_api_classify_table_by_interface_reply_t *rmp;
7312 u32 sw_if_index = ntohl (mp->sw_if_index);
7315 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7318 VALIDATE_SW_IF_INDEX (mp);
7320 input_acl_main_t *am = &input_acl_main;
7325 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7327 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7328 if (vec_len (vec_tbl))
7330 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7332 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7336 acl[type] = vec_elt (vec_tbl, if_idx);
7341 BAD_SW_IF_INDEX_LABEL;
7344 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7346 rmp->sw_if_index = ntohl(sw_if_index);
7347 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7348 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7349 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7356 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7358 unix_shared_memory_queue_t *q;
7360 q = vl_api_client_index_to_input_queue (mp->client_index);
7364 vl_api_classify_table_info_reply_t *rmp = 0;
7366 vnet_classify_main_t *cm = &vnet_classify_main;
7367 u32 table_id = ntohl (mp->table_id);
7368 vnet_classify_table_t *t;
7371 pool_foreach (t, cm->tables,
7373 if (table_id == t - cm->tables)
7375 rmp = vl_msg_api_alloc_as_if_client
7376 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7377 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7378 rmp->context = mp->context;
7379 rmp->table_id = ntohl(table_id);
7380 rmp->nbuckets = ntohl(t->nbuckets);
7381 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7382 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7383 rmp->active_sessions = ntohl(t->active_elements);
7384 rmp->next_table_index = ntohl(t->next_table_index);
7385 rmp->miss_next_index = ntohl(t->miss_next_index);
7386 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7387 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7396 rmp = vl_msg_api_alloc (sizeof (*rmp));
7397 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7398 rmp->context = mp->context;
7399 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7402 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7406 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7409 clib_warning ("BUG");
7413 send_classify_session_details (unix_shared_memory_queue_t * q,
7416 vnet_classify_entry_t * e, u32 context)
7418 vl_api_classify_session_details_t *rmp;
7420 rmp = vl_msg_api_alloc (sizeof (*rmp));
7421 memset (rmp, 0, sizeof (*rmp));
7422 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7423 rmp->context = context;
7424 rmp->table_id = ntohl (table_id);
7425 rmp->hit_next_index = ntohl (e->next_index);
7426 rmp->advance = ntohl (e->advance);
7427 rmp->opaque_index = ntohl (e->opaque_index);
7428 rmp->match_length = ntohl (match_length);
7429 clib_memcpy (rmp->match, e->key, match_length);
7431 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7435 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7437 vnet_classify_main_t *cm = &vnet_classify_main;
7438 unix_shared_memory_queue_t *q;
7440 u32 table_id = ntohl (mp->table_id);
7441 vnet_classify_table_t *t;
7443 q = vl_api_client_index_to_input_queue (mp->client_index);
7448 pool_foreach (t, cm->tables,
7450 if (table_id == t - cm->tables)
7452 vnet_classify_bucket_t * b;
7453 vnet_classify_entry_t * v, * save_v;
7456 for (i = 0; i < t->nbuckets; i++)
7458 b = &t->buckets [i];
7462 save_v = vnet_classify_get_entry (t, b->offset);
7463 for (j = 0; j < (1<<b->log2_pages); j++)
7465 for (k = 0; k < t->entries_per_page; k++)
7467 v = vnet_classify_entry_at_index
7468 (t, save_v, j*t->entries_per_page + k);
7469 if (vnet_classify_entry_is_free (v))
7472 send_classify_session_details
7473 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7485 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7487 vlib_main_t *vm = vlib_get_main ();
7488 flow_report_main_t *frm = &flow_report_main;
7489 vl_api_set_ipfix_exporter_reply_t *rmp;
7490 ip4_address_t collector, src;
7491 u16 collector_port = UDP_DST_PORT_ipfix;
7493 u32 template_interval;
7499 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7500 collector_port = ntohs (mp->collector_port);
7501 if (collector_port == (u16) ~ 0)
7502 collector_port = UDP_DST_PORT_ipfix;
7503 memcpy (src.data, mp->src_address, sizeof (src.data));
7504 fib_id = ntohl (mp->vrf_id);
7506 ip4_main_t *im = &ip4_main;
7513 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7516 rv = VNET_API_ERROR_NO_SUCH_FIB;
7522 path_mtu = ntohl (mp->path_mtu);
7524 path_mtu = 512; // RFC 7011 section 10.3.3.
7525 template_interval = ntohl (mp->template_interval);
7526 if (template_interval == ~0)
7527 template_interval = 20;
7528 udp_checksum = mp->udp_checksum;
7530 if (collector.as_u32 == 0)
7532 rv = VNET_API_ERROR_INVALID_VALUE;
7536 if (src.as_u32 == 0)
7538 rv = VNET_API_ERROR_INVALID_VALUE;
7542 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7544 rv = VNET_API_ERROR_INVALID_VALUE;
7550 rv = VNET_API_ERROR_INVALID_VALUE;
7554 /* Reset report streams if we are reconfiguring IP addresses */
7555 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7556 frm->src_address.as_u32 != src.as_u32 ||
7557 frm->collector_port != collector_port)
7558 vnet_flow_reports_reset (frm);
7560 frm->ipfix_collector.as_u32 = collector.as_u32;
7561 frm->collector_port = collector_port;
7562 frm->src_address.as_u32 = src.as_u32;
7563 frm->fib_index = fib_index;
7564 frm->path_mtu = path_mtu;
7565 frm->template_interval = template_interval;
7566 frm->udp_checksum = udp_checksum;
7568 /* Turn on the flow reporting process */
7569 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7572 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
7576 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
7578 flow_report_main_t *frm = &flow_report_main;
7579 unix_shared_memory_queue_t *q;
7580 vl_api_ipfix_exporter_details_t *rmp;
7581 ip4_main_t *im = &ip4_main;
7584 q = vl_api_client_index_to_input_queue (mp->client_index);
7588 rmp = vl_msg_api_alloc (sizeof (*rmp));
7589 memset (rmp, 0, sizeof (*rmp));
7590 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
7591 rmp->context = mp->context;
7592 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7593 sizeof (frm->ipfix_collector.data));
7594 rmp->collector_port = htons (frm->collector_port);
7595 memcpy (rmp->src_address, frm->src_address.data,
7596 sizeof (frm->src_address.data));
7597 if (frm->fib_index == ~0)
7600 vrf_id = im->fibs[frm->fib_index].ft_table_id;
7601 rmp->vrf_id = htonl (vrf_id);
7602 rmp->path_mtu = htonl (frm->path_mtu);
7603 rmp->template_interval = htonl (frm->template_interval);
7604 rmp->udp_checksum = (frm->udp_checksum != 0);
7606 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7610 vl_api_set_ipfix_classify_stream_t_handler
7611 (vl_api_set_ipfix_classify_stream_t * mp)
7613 vl_api_set_ipfix_classify_stream_reply_t *rmp;
7614 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7615 flow_report_main_t *frm = &flow_report_main;
7617 u32 src_port = UDP_DST_PORT_ipfix;
7620 domain_id = ntohl (mp->domain_id);
7621 src_port = ntohs (mp->src_port);
7623 if (fcm->src_port != 0 &&
7624 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
7626 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
7627 domain_id, (u16) src_port);
7631 fcm->domain_id = domain_id;
7632 fcm->src_port = (u16) src_port;
7634 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7638 vl_api_ipfix_classify_stream_dump_t_handler
7639 (vl_api_ipfix_classify_stream_dump_t * mp)
7641 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7642 unix_shared_memory_queue_t *q;
7643 vl_api_ipfix_classify_stream_details_t *rmp;
7645 q = vl_api_client_index_to_input_queue (mp->client_index);
7649 rmp = vl_msg_api_alloc (sizeof (*rmp));
7650 memset (rmp, 0, sizeof (*rmp));
7651 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
7652 rmp->context = mp->context;
7653 rmp->domain_id = htonl (fcm->domain_id);
7654 rmp->src_port = htons (fcm->src_port);
7656 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7660 vl_api_ipfix_classify_table_add_del_t_handler
7661 (vl_api_ipfix_classify_table_add_del_t * mp)
7663 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
7664 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7665 flow_report_main_t *frm = &flow_report_main;
7666 vnet_flow_report_add_del_args_t args;
7667 ipfix_classify_table_t *table;
7669 u32 classify_table_index;
7671 u8 transport_protocol;
7674 classify_table_index = ntohl (mp->table_id);
7675 ip_version = mp->ip_version;
7676 transport_protocol = mp->transport_protocol;
7677 is_add = mp->is_add;
7679 if (fcm->src_port == 0)
7681 /* call set_ipfix_classify_stream first */
7682 rv = VNET_API_ERROR_UNSPECIFIED;
7686 memset (&args, 0, sizeof (args));
7690 for (i = 0; i < vec_len (fcm->tables); i++)
7691 if (ipfix_classify_table_index_valid (i))
7692 if (fcm->tables[i].classify_table_index == classify_table_index)
7694 table = &fcm->tables[i];
7702 rv = VNET_API_ERROR_VALUE_EXIST;
7705 table = ipfix_classify_add_table ();
7706 table->classify_table_index = classify_table_index;
7712 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
7717 table->ip_version = ip_version;
7718 table->transport_protocol = transport_protocol;
7720 args.opaque.as_uword = table - fcm->tables;
7721 args.rewrite_callback = ipfix_classify_template_rewrite;
7722 args.flow_data_callback = ipfix_classify_send_flows;
7723 args.is_add = is_add;
7724 args.domain_id = fcm->domain_id;
7725 args.src_port = fcm->src_port;
7727 rv = vnet_flow_report_add_del (frm, &args);
7729 /* If deleting, or add failed */
7730 if (is_add == 0 || (rv && is_add))
7731 ipfix_classify_delete_table (table - fcm->tables);
7734 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7738 send_ipfix_classify_table_details (u32 table_index,
7739 unix_shared_memory_queue_t * q,
7742 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7743 vl_api_ipfix_classify_table_details_t *mp;
7745 ipfix_classify_table_t *table = &fcm->tables[table_index];
7747 mp = vl_msg_api_alloc (sizeof (*mp));
7748 memset (mp, 0, sizeof (*mp));
7749 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
7750 mp->context = context;
7751 mp->table_id = htonl (table->classify_table_index);
7752 mp->ip_version = table->ip_version;
7753 mp->transport_protocol = table->transport_protocol;
7755 vl_msg_api_send_shmem (q, (u8 *) & mp);
7759 vl_api_ipfix_classify_table_dump_t_handler
7760 (vl_api_ipfix_classify_table_dump_t * mp)
7762 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7763 unix_shared_memory_queue_t *q;
7766 q = vl_api_client_index_to_input_queue (mp->client_index);
7770 for (i = 0; i < vec_len (fcm->tables); i++)
7771 if (ipfix_classify_table_index_valid (i))
7772 send_ipfix_classify_table_details (i, q, mp->context);
7776 vl_api_sw_interface_span_enable_disable_t_handler
7777 (vl_api_sw_interface_span_enable_disable_t * mp)
7779 vl_api_sw_interface_span_enable_disable_reply_t *rmp;
7782 vlib_main_t *vm = vlib_get_main ();
7784 rv = span_add_delete_entry (vm, ntohl (mp->sw_if_index_from),
7785 ntohl (mp->sw_if_index_to), mp->enable);
7787 REPLY_MACRO (VL_API_SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY);
7791 vl_api_sw_interface_span_dump_t_handler (vl_api_sw_interface_span_dump_t * mp)
7794 unix_shared_memory_queue_t *q;
7795 vl_api_sw_interface_span_details_t *rmp;
7796 span_main_t *sm = &span_main;
7797 u32 src_sw_if_index = 0, *dst_sw_if_index;
7799 q = vl_api_client_index_to_input_queue (mp->client_index);
7803 vec_foreach (dst_sw_if_index, sm->dst_by_src_sw_if_index)
7805 if (*dst_sw_if_index > 0)
7807 rmp = vl_msg_api_alloc (sizeof (*rmp));
7808 memset (rmp, 0, sizeof (*rmp));
7809 rmp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SPAN_DETAILS);
7810 rmp->context = mp->context;
7812 rmp->sw_if_index_from = htonl (src_sw_if_index);
7813 rmp->sw_if_index_to = htonl (*dst_sw_if_index);
7815 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7822 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
7824 vl_api_pg_create_interface_reply_t *rmp;
7827 pg_main_t *pg = &pg_main;
7828 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
7829 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
7832 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7834 rmp->sw_if_index = ntohl(pi->sw_if_index);
7840 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
7842 vl_api_pg_capture_reply_t *rmp;
7845 vnet_main_t *vnm = vnet_get_main ();
7846 vnet_interface_main_t *im = &vnm->interface_main;
7847 vnet_hw_interface_t *hi = 0;
7849 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
7850 u32 hw_if_index = ~0;
7851 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
7854 vec_free (intf_name);
7856 if (hw_if_index != ~0)
7858 pg_capture_args_t _a, *a = &_a;
7860 u32 len = ntohl (mp->pcap_name_length);
7861 u8 *pcap_file_name = vec_new (u8, len);
7862 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
7864 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7865 a->hw_if_index = hw_if_index;
7866 a->dev_instance = hi->dev_instance;
7867 a->is_enabled = mp->is_enabled;
7868 a->pcap_file_name = pcap_file_name;
7869 a->count = ntohl (mp->count);
7871 clib_error_t *e = pg_capture (a);
7874 clib_error_report (e);
7875 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7878 vec_free (pcap_file_name);
7880 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
7884 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
7886 vl_api_pg_enable_disable_reply_t *rmp;
7889 pg_main_t *pg = &pg_main;
7890 u32 stream_index = ~0;
7892 int is_enable = mp->is_enabled != 0;
7893 u32 len = ntohl (mp->stream_name_length) - 1;
7897 u8 *stream_name = vec_new (u8, len);
7898 clib_memcpy (stream_name, mp->stream_name, len);
7899 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
7902 vec_free (stream_name);
7905 pg_enable_disable (stream_index, is_enable);
7907 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
7911 vl_api_ip_source_and_port_range_check_add_del_t_handler
7912 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
7914 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
7917 u8 is_ipv6 = mp->is_ipv6;
7918 u8 is_add = mp->is_add;
7919 u8 mask_length = mp->mask_length;
7920 ip4_address_t ip4_addr;
7921 ip6_address_t ip6_addr;
7923 u16 *high_ports = 0;
7925 u16 tmp_low, tmp_high;
7929 // Validate port range
7930 num_ranges = mp->number_of_ranges;
7931 if (num_ranges > 32)
7932 { // This is size of array in VPE.API
7933 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
7937 vec_reset_length (low_ports);
7938 vec_reset_length (high_ports);
7940 for (i = 0; i < num_ranges; i++)
7942 tmp_low = mp->low_ports[i];
7943 tmp_high = mp->high_ports[i];
7944 // If tmp_low <= tmp_high then only need to check tmp_low = 0
7945 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
7946 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
7948 rv = VNET_API_ERROR_INVALID_VALUE;
7951 vec_add1 (low_ports, tmp_low);
7952 vec_add1 (high_ports, tmp_high + 1);
7955 // Validate mask_length
7956 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
7958 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
7962 vrf_id = ntohl (mp->vrf_id);
7966 rv = VNET_API_ERROR_INVALID_VALUE;
7973 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
7974 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
7978 high_ports, is_add);
7982 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
7983 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
7987 high_ports, is_add);
7991 vec_free (low_ports);
7992 vec_free (high_ports);
7993 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
7997 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
7998 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8000 vlib_main_t *vm = vlib_get_main ();
8001 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8002 ip4_main_t *im = &ip4_main;
8005 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8006 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8010 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8011 ntohl (mp->tcp_out_vrf_id);
8012 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8013 ntohl (mp->udp_out_vrf_id);
8014 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8015 ntohl (mp->tcp_in_vrf_id);
8016 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8017 ntohl (mp->udp_in_vrf_id);
8020 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8022 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8024 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8028 rv = VNET_API_ERROR_INVALID_VALUE;
8032 fib_index[i] = p[0];
8037 sw_if_index = ntohl (mp->sw_if_index);
8039 VALIDATE_SW_IF_INDEX (mp);
8042 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8045 BAD_SW_IF_INDEX_LABEL;
8048 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8052 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8055 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8057 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8058 u32 sw_if_index = ~0;
8060 /* Check src & dst are different */
8061 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8063 rv = VNET_API_ERROR_SAME_SRC_DST;
8067 memset (a, 0, sizeof (*a));
8069 /* ip addresses sent in network byte order */
8070 clib_memcpy (&(a->src), mp->src_address, 4);
8071 clib_memcpy (&(a->dst), mp->dst_address, 4);
8072 a->is_add = mp->is_add;
8073 a->lsa = ntohl (mp->local_sa_id);
8074 a->rsa = ntohl (mp->remote_sa_id);
8076 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8080 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8082 rmp->sw_if_index = ntohl (sw_if_index);
8087 static void send_ipsec_gre_tunnel_details
8088 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8090 vl_api_ipsec_gre_tunnel_details_t *rmp;
8092 rmp = vl_msg_api_alloc (sizeof (*rmp));
8093 memset (rmp, 0, sizeof (*rmp));
8094 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8095 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8096 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8097 rmp->sw_if_index = htonl (t->sw_if_index);
8098 rmp->local_sa_id = htonl (t->local_sa_id);
8099 rmp->remote_sa_id = htonl (t->remote_sa_id);
8100 rmp->context = context;
8102 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8105 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8106 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8108 unix_shared_memory_queue_t *q;
8109 ipsec_gre_main_t *igm = &ipsec_gre_main;
8110 ipsec_gre_tunnel_t *t;
8113 q = vl_api_client_index_to_input_queue (mp->client_index);
8119 sw_if_index = ntohl (mp->sw_if_index);
8121 if (~0 == sw_if_index)
8124 pool_foreach (t, igm->tunnels,
8126 send_ipsec_gre_tunnel_details(t, q, mp->context);
8132 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8133 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8137 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8138 send_ipsec_gre_tunnel_details (t, q, mp->context);
8143 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8145 vl_api_delete_subif_reply_t *rmp;
8148 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8150 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8154 vl_api_l2_interface_pbb_tag_rewrite_t_handler
8155 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
8157 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
8158 vnet_main_t *vnm = vnet_get_main ();
8159 vlib_main_t *vm = vlib_get_main ();
8163 VALIDATE_SW_IF_INDEX (mp);
8165 vtr_op = ntohl (mp->vtr_op);
8169 case L2_VTR_DISABLED:
8172 case L2_VTR_TRANSLATE_2_1:
8176 rv = VNET_API_ERROR_INVALID_VALUE;
8177 goto bad_sw_if_index;
8180 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
8181 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
8182 ntohl (mp->i_sid), ntohs (mp->outer_tag));
8184 BAD_SW_IF_INDEX_LABEL;
8186 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
8190 vl_api_punt_t_handler (vl_api_punt_t * mp)
8192 vl_api_punt_reply_t *rmp;
8193 vlib_main_t *vm = vlib_get_main ();
8195 clib_error_t *error;
8197 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8198 ntohs (mp->l4_port), mp->is_add);
8202 clib_error_report (error);
8205 REPLY_MACRO (VL_API_PUNT_REPLY);
8209 vl_api_flow_classify_set_interface_t_handler
8210 (vl_api_flow_classify_set_interface_t * mp)
8212 vlib_main_t *vm = vlib_get_main ();
8213 vl_api_flow_classify_set_interface_reply_t *rmp;
8215 u32 sw_if_index, ip4_table_index, ip6_table_index;
8217 ip4_table_index = ntohl (mp->ip4_table_index);
8218 ip6_table_index = ntohl (mp->ip6_table_index);
8219 sw_if_index = ntohl (mp->sw_if_index);
8221 VALIDATE_SW_IF_INDEX (mp);
8223 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
8224 ip6_table_index, mp->is_add);
8226 BAD_SW_IF_INDEX_LABEL;
8228 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
8232 send_flow_classify_details (u32 sw_if_index,
8234 unix_shared_memory_queue_t * q, u32 context)
8236 vl_api_flow_classify_details_t *mp;
8238 mp = vl_msg_api_alloc (sizeof (*mp));
8239 memset (mp, 0, sizeof (*mp));
8240 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
8241 mp->context = context;
8242 mp->sw_if_index = htonl (sw_if_index);
8243 mp->table_index = htonl (table_index);
8245 vl_msg_api_send_shmem (q, (u8 *) & mp);
8249 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8251 unix_shared_memory_queue_t *q;
8252 flow_classify_main_t *pcm = &flow_classify_main;
8256 q = vl_api_client_index_to_input_queue (mp->client_index);
8260 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8262 if (vec_len (vec_tbl))
8264 for (i = 0; i < vec_len (vec_tbl); i++)
8266 if (vec_elt (vec_tbl, i) == ~0)
8269 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8276 send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
8279 vl_api_ipsec_spd_details_t *mp;
8281 mp = vl_msg_api_alloc (sizeof (*mp));
8282 memset (mp, 0, sizeof (*mp));
8283 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
8284 mp->context = context;
8286 mp->spd_id = htonl (p->id);
8287 mp->priority = htonl (p->priority);
8288 mp->is_outbound = p->is_outbound;
8289 mp->is_ipv6 = p->is_ipv6;
8292 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
8293 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
8294 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
8295 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
8299 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
8300 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
8301 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
8302 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
8304 mp->local_start_port = htons (p->lport.start);
8305 mp->local_stop_port = htons (p->lport.stop);
8306 mp->remote_start_port = htons (p->rport.start);
8307 mp->remote_stop_port = htons (p->rport.stop);
8308 mp->protocol = p->protocol;
8309 mp->policy = p->policy;
8310 mp->sa_id = htonl (p->sa_id);
8311 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
8312 mp->packets = clib_host_to_net_u64 (p->counter.packets);
8314 vl_msg_api_send_shmem (q, (u8 *) & mp);
8318 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
8320 unix_shared_memory_queue_t *q;
8321 ipsec_main_t *im = &ipsec_main;
8322 ipsec_policy_t *policy;
8327 q = vl_api_client_index_to_input_queue (mp->client_index);
8331 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
8336 spd = pool_elt_at_index (im->spds, spd_index);
8339 pool_foreach (policy, spd->policies,
8341 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
8342 send_ipsec_spd_details (policy, q,
8347 clib_warning ("unimplemented");
8352 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
8354 vl_api_feature_enable_disable_reply_t *rmp;
8356 u8 *arc_name, *feature_name;
8358 VALIDATE_SW_IF_INDEX (mp);
8360 arc_name = format (0, "%s%c", mp->arc_name, 0);
8361 feature_name = format (0, "%s%c", mp->feature_name, 0);
8363 vnet_feature_registration_t *reg;
8365 vnet_get_feature_reg ((const char *) arc_name,
8366 (const char *) feature_name);
8368 rv = VNET_API_ERROR_INVALID_VALUE;
8372 clib_error_t *error = 0;
8374 sw_if_index = ntohl (mp->sw_if_index);
8375 if (reg->enable_disable_cb)
8376 error = reg->enable_disable_cb (sw_if_index, mp->enable);
8378 vnet_feature_enable_disable ((const char *) arc_name,
8379 (const char *) feature_name,
8380 sw_if_index, mp->enable, 0, 0);
8383 clib_error_report (error);
8384 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
8388 vec_free (feature_name);
8389 vec_free (arc_name);
8391 BAD_SW_IF_INDEX_LABEL;
8393 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
8396 #define BOUNCE_HANDLER(nn) \
8397 static void vl_api_##nn##_t_handler ( \
8398 vl_api_##nn##_t *mp) \
8400 vpe_client_registration_t *reg; \
8401 vpe_api_main_t * vam = &vpe_api_main; \
8402 unix_shared_memory_queue_t * q; \
8404 /* One registration only... */ \
8405 pool_foreach(reg, vam->nn##_registrations, \
8407 q = vl_api_client_index_to_input_queue (reg->client_index); \
8410 * If the queue is stuffed, turf the msg and complain \
8411 * It's unlikely that the intended recipient is \
8412 * alive; avoid deadlock at all costs. \
8414 if (q->cursize == q->maxsize) { \
8415 clib_warning ("ERROR: receiver queue full, drop msg"); \
8416 vl_msg_api_free (mp); \
8419 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8423 vl_msg_api_free (mp); \
8426 static void setup_message_id_table (api_main_t * am);
8430 * Add vpe's API message handlers to the table.
8431 * vlib has alread mapped shared memory and
8432 * added the client registration handlers.
8433 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8435 static clib_error_t *
8436 vpe_api_hookup (vlib_main_t * vm)
8438 api_main_t *am = &api_main;
8441 vl_msg_api_set_handlers(VL_API_##N, #n, \
8442 vl_api_##n##_t_handler, \
8444 vl_api_##n##_t_endian, \
8445 vl_api_##n##_t_print, \
8446 sizeof(vl_api_##n##_t), 1);
8447 foreach_vpe_api_msg;
8451 * Manually register the sr tunnel add del msg, so we trace
8452 * enough bytes to capture a typical segment list
8454 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8455 "sr_tunnel_add_del",
8456 vl_api_sr_tunnel_add_del_t_handler,
8458 vl_api_sr_tunnel_add_del_t_endian,
8459 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8463 * Manually register the sr policy add del msg, so we trace
8464 * enough bytes to capture a typical tunnel name list
8466 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8467 "sr_policy_add_del",
8468 vl_api_sr_policy_add_del_t_handler,
8470 vl_api_sr_policy_add_del_t_endian,
8471 vl_api_sr_policy_add_del_t_print, 256, 1);
8474 * Trace space for 8 MPLS encap labels, classifier mask+match
8476 am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32);
8477 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8478 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8479 += 5 * sizeof (u32x4);
8480 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8483 * Thread-safe API messages
8485 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8486 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8489 * Set up the (msg_name, crc, message-id) table
8491 setup_message_id_table (am);
8496 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8498 static clib_error_t *
8499 vpe_api_init (vlib_main_t * vm)
8501 vpe_api_main_t *am = &vpe_api_main;
8504 am->vnet_main = vnet_get_main ();
8505 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8506 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8507 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8508 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8509 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8510 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8513 vl_set_memory_region_name ("/vpe-api");
8514 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8519 VLIB_INIT_FUNCTION (vpe_api_init);
8522 static clib_error_t *
8523 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8526 u64 baseva, size, pvt_heap_size;
8528 const int max_buf_size = 4096;
8530 struct passwd _pw, *pw;
8531 struct group _grp, *grp;
8533 buf = vec_new (char, 128);
8534 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8536 if (unformat (input, "prefix %s", &chroot_path))
8538 vec_add1 (chroot_path, 0);
8539 vl_set_memory_root_path ((char *) chroot_path);
8541 else if (unformat (input, "uid %d", &uid))
8542 vl_set_memory_uid (uid);
8543 else if (unformat (input, "gid %d", &gid))
8544 vl_set_memory_gid (gid);
8545 else if (unformat (input, "baseva %llx", &baseva))
8546 vl_set_global_memory_baseva (baseva);
8547 else if (unformat (input, "global-size %lldM", &size))
8548 vl_set_global_memory_size (size * (1ULL << 20));
8549 else if (unformat (input, "global-size %lldG", &size))
8550 vl_set_global_memory_size (size * (1ULL << 30));
8551 else if (unformat (input, "global-size %lld", &size))
8552 vl_set_global_memory_size (size);
8553 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8554 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8555 else if (unformat (input, "global-pvt-heap-size size %lld",
8557 vl_set_global_pvt_heap_size (pvt_heap_size);
8558 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8559 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8560 else if (unformat (input, "api-pvt-heap-size size %lld",
8562 vl_set_api_pvt_heap_size (pvt_heap_size);
8563 else if (unformat (input, "api-size %lldM", &size))
8564 vl_set_api_memory_size (size * (1ULL << 20));
8565 else if (unformat (input, "api-size %lldG", &size))
8566 vl_set_api_memory_size (size * (1ULL << 30));
8567 else if (unformat (input, "api-size %lld", &size))
8568 vl_set_api_memory_size (size);
8569 else if (unformat (input, "uid %s", &s))
8571 /* lookup the username */
8574 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8575 && (vec_len (buf) <= max_buf_size))
8577 vec_resize (buf, vec_len (buf) * 2);
8581 e = clib_error_return_code (0, rv,
8582 CLIB_ERROR_ERRNO_VALID |
8584 "cannot fetch username %s", s);
8592 clib_error_return_fatal (0, "username %s does not exist", s);
8598 vl_set_memory_uid (pw->pw_uid);
8600 else if (unformat (input, "gid %s", &s))
8602 /* lookup the group name */
8605 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8606 && (vec_len (buf) <= max_buf_size))
8608 vec_resize (buf, vec_len (buf) * 2);
8612 e = clib_error_return_code (0, rv,
8613 CLIB_ERROR_ERRNO_VALID |
8615 "cannot fetch group %s", s);
8622 e = clib_error_return_fatal (0, "group %s does not exist", s);
8629 vl_set_memory_gid (grp->gr_gid);
8632 return clib_error_return (0, "unknown input `%U'",
8633 format_unformat_error, input);
8638 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8641 get_unformat_vnet_sw_interface (void)
8643 return (void *) &unformat_vnet_sw_interface;
8647 format_arp_event (u8 * s, va_list * args)
8649 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8651 s = format (s, "pid %d: ", event->pid);
8653 s = format (s, "bd mac/ip4 binding events");
8655 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8660 format_nd_event (u8 * s, va_list * args)
8662 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8664 s = format (s, "pid %d: ", event->pid);
8666 s = format (s, "bd mac/ip6 binding events");
8668 s = format (s, "resolution for %U", format_ip6_address, event->address);
8672 static clib_error_t *
8673 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8674 unformat_input_t * input, vlib_cli_command_t * cmd)
8676 vpe_api_main_t *am = &vpe_api_main;
8677 vl_api_ip4_arp_event_t *arp_event;
8678 vl_api_ip6_nd_event_t *nd_event;
8680 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8682 vlib_cli_output (vm, "No active arp or nd event registrations");
8687 pool_foreach (arp_event, am->arp_events,
8689 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8692 pool_foreach (nd_event, am->nd_events,
8694 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8702 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8703 .path = "show arp-nd-event registrations",
8704 .function = show_ip_arp_nd_events_fn,
8705 .short_help = "Show ip4 arp and ip6 nd event registrations",
8709 #define vl_msg_name_crc_list
8710 #include <vpp-api/vpe_all_api_h.h>
8711 #undef vl_msg_name_crc_list
8714 setup_message_id_table (api_main_t * am)
8716 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
8717 foreach_vl_msg_name_crc_memclnt;
8718 foreach_vl_msg_name_crc_vpe;
8724 * fd.io coding-style-patch-verification: ON
8727 * eval: (c-set-style "gnu")