2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010-2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
48 #include <vnet/api_errno.h>
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/l2tp/l2tp.h>
53 #include <vnet/ip/ip.h>
54 #include <vnet/ip/ip6.h>
55 #include <vnet/ip/ip6_neighbor.h>
56 #include <vnet/mpls/mpls.h>
57 #include <vnet/mpls/mpls_tunnel.h>
58 #include <vnet/dhcp/proxy.h>
59 #include <vnet/dhcp/client.h>
61 #include <vnet/sr/sr.h>
63 #include <vnet/dhcpv6/proxy.h>
64 #include <vlib/vlib.h>
65 #include <vlib/unix/unix.h>
66 #include <vlibapi/api.h>
67 #include <vlibmemory/api.h>
68 #include <vnet/classify/vnet_classify.h>
69 #include <vnet/classify/input_acl.h>
70 #include <vnet/classify/policer_classify.h>
71 #include <vnet/classify/flow_classify.h>
72 #include <vnet/l2/l2_classify.h>
73 #include <vnet/vxlan/vxlan.h>
74 #include <vnet/gre/gre.h>
75 #include <vnet/l2/l2_vtr.h>
76 #include <vnet/vxlan-gpe/vxlan_gpe.h>
77 #include <vnet/lisp-gpe/lisp_gpe.h>
78 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
79 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
80 #include <vnet/lisp-cp/control.h>
81 #include <vnet/map/map.h>
82 #include <vnet/cop/cop.h>
83 #include <vnet/ip/ip6_hop_by_hop.h>
84 #include <vnet/ip/ip_source_and_port_range_check.h>
85 #include <vnet/devices/af_packet/af_packet.h>
86 #include <vnet/policer/policer.h>
87 #include <vnet/devices/netmap/netmap.h>
88 #include <vnet/flow/flow_report.h>
89 #include <vnet/ipsec-gre/ipsec_gre.h>
90 #include <vnet/flow/flow_report_classify.h>
91 #include <vnet/ip/punt.h>
92 #include <vnet/feature/feature.h>
95 #undef __included_bihash_template_h__
96 #include <vnet/l2/l2_fib.h>
99 #include <vnet/devices/dpdk/dpdk.h>
103 #include <vnet/ipsec/ipsec.h>
104 #include <vnet/ipsec/ikev2.h>
106 #include <vnet/devices/virtio/vhost-user.h>
108 #include <stats/stats.h>
111 #include <vnet/ethernet/ethernet.h>
112 #include <vnet/ethernet/arp_packet.h>
113 #include <vnet/interface.h>
115 #include <vnet/l2/l2_fib.h>
116 #include <vnet/l2/l2_bd.h>
117 #include <vpp-api/vpe_msg_enum.h>
118 #include <vnet/span/span.h>
120 #include <vnet/fib/ip6_fib.h>
121 #include <vnet/fib/ip4_fib.h>
122 #include <vnet/fib/fib_api.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 _(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \
149 _(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \
150 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
151 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
152 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
153 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
154 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
155 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
156 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
157 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
158 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
159 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
160 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
161 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
162 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
163 _(L2FIB_ADD_DEL, l2fib_add_del) \
164 _(L2_FLAGS, l2_flags) \
165 _(BRIDGE_FLAGS, bridge_flags) \
166 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
167 _(CREATE_SUBIF, create_subif) \
168 _(MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del) \
169 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
170 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
171 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
172 _(RESET_FIB, reset_fib) \
173 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
174 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
175 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
176 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
177 _(CREATE_LOOPBACK, create_loopback) \
178 _(CONTROL_PING, control_ping) \
179 _(CLI_REQUEST, cli_request) \
180 _(CLI_INBAND, cli_inband) \
181 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
182 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
183 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
184 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
185 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
186 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
187 _(GET_NODE_INDEX, get_node_index) \
188 _(ADD_NODE_NEXT, add_node_next) \
189 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
190 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
191 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
192 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
193 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
194 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
195 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
196 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
197 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
198 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
199 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
200 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
201 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
202 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
203 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
204 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
205 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
206 _(SHOW_VERSION, show_version) \
207 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
208 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
209 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
210 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
211 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
212 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
213 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
214 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
215 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
216 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
217 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
218 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
219 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
220 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
221 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
222 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
223 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
224 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
225 _(DELETE_LOOPBACK, delete_loopback) \
226 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
227 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
228 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
229 _(GET_NODE_GRAPH, get_node_graph) \
230 _(IOAM_ENABLE, ioam_enable) \
231 _(IOAM_DISABLE, ioam_disable) \
232 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
233 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
234 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
235 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
236 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
237 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
238 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
239 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
240 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
241 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
242 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
243 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
244 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
245 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
246 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
247 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
248 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
249 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
250 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
251 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
252 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
253 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
254 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
255 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
256 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
257 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
258 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
259 _(SHOW_LISP_STATUS, show_lisp_status) \
260 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
261 lisp_add_del_map_request_itr_rlocs) \
262 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
263 _(SHOW_LISP_PITR, show_lisp_pitr) \
264 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
265 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
266 _(AF_PACKET_CREATE, af_packet_create) \
267 _(AF_PACKET_DELETE, af_packet_delete) \
268 _(POLICER_ADD_DEL, policer_add_del) \
269 _(POLICER_DUMP, policer_dump) \
270 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
271 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
272 _(NETMAP_CREATE, netmap_create) \
273 _(NETMAP_DELETE, netmap_delete) \
274 _(MPLS_TUNNEL_DUMP, mpls_tunnel_dump) \
275 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
276 _(MPLS_FIB_DUMP, mpls_fib_dump) \
277 _(MPLS_FIB_DETAILS, mpls_fib_details) \
278 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
279 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
280 _(CLASSIFY_TABLE_INFO,classify_table_info) \
281 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
282 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
283 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
284 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
285 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
286 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
287 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
288 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
289 _(GET_NEXT_INDEX, get_next_index) \
290 _(PG_CREATE_INTERFACE, pg_create_interface) \
291 _(PG_CAPTURE, pg_capture) \
292 _(PG_ENABLE_DISABLE, pg_enable_disable) \
293 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
294 ip_source_and_port_range_check_add_del) \
295 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
296 ip_source_and_port_range_check_interface_add_del) \
297 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
298 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
299 _(DELETE_SUBIF, delete_subif) \
300 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
302 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
303 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
304 _(IPSEC_SPD_DUMP, ipsec_spd_dump) \
305 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
308 #define QUOTE(x) QUOTE_(x)
312 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
313 RESOLVE_IP6_ADD_DEL_ROUTE,
316 static vlib_node_registration_t vpe_resolver_process_node;
317 vpe_api_main_t vpe_api_main;
319 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
320 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
322 /* Clean up all registrations belonging to the indicated client */
324 vl_api_memclnt_delete_callback (u32 client_index)
326 vpe_api_main_t *vam = &vpe_api_main;
327 vpe_client_registration_t *rp;
329 int stats_memclnt_delete_callback (u32 client_index);
331 stats_memclnt_delete_callback (client_index);
334 p = hash_get (vam->a##_registration_hash, client_index); \
336 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
337 pool_put (vam->a##_registrations, rp); \
338 hash_unset (vam->a##_registration_hash, client_index); \
340 foreach_registration_hash;
345 pub_sub_handler (oam_events, OAM_EVENTS);
347 #define RESOLUTION_EVENT 1
348 #define RESOLUTION_PENDING_EVENT 2
349 #define IP4_ARP_EVENT 3
350 #define IP6_ND_EVENT 4
352 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
354 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
357 handle_ip4_arp_event (u32 pool_index)
359 vpe_api_main_t *vam = &vpe_api_main;
360 vnet_main_t *vnm = vam->vnet_main;
361 vlib_main_t *vm = vam->vlib_main;
362 vl_api_ip4_arp_event_t *event;
363 vl_api_ip4_arp_event_t *mp;
364 unix_shared_memory_queue_t *q;
366 /* Client can cancel, die, etc. */
367 if (pool_is_free_index (vam->arp_events, pool_index))
370 event = pool_elt_at_index (vam->arp_events, pool_index);
372 q = vl_api_client_index_to_input_queue (event->client_index);
375 (void) vnet_add_del_ip4_arp_change_event
376 (vnm, arp_change_delete_callback,
377 event->pid, &event->address,
378 vpe_resolver_process_node.index, IP4_ARP_EVENT,
379 ~0 /* pool index, notused */ , 0 /* is_add */ );
383 if (q->cursize < q->maxsize)
385 mp = vl_msg_api_alloc (sizeof (*mp));
386 clib_memcpy (mp, event, sizeof (*mp));
387 vl_msg_api_send_shmem (q, (u8 *) & mp);
391 static f64 last_time;
393 * Throttle syslog msgs.
394 * It's pretty tempting to just revoke the registration...
396 if (vlib_time_now (vm) > last_time + 10.0)
398 clib_warning ("arp event for %U to pid %d: queue stuffed!",
399 format_ip4_address, &event->address, event->pid);
400 last_time = vlib_time_now (vm);
406 handle_ip6_nd_event (u32 pool_index)
408 vpe_api_main_t *vam = &vpe_api_main;
409 vnet_main_t *vnm = vam->vnet_main;
410 vlib_main_t *vm = vam->vlib_main;
411 vl_api_ip6_nd_event_t *event;
412 vl_api_ip6_nd_event_t *mp;
413 unix_shared_memory_queue_t *q;
415 /* Client can cancel, die, etc. */
416 if (pool_is_free_index (vam->nd_events, pool_index))
419 event = pool_elt_at_index (vam->nd_events, pool_index);
421 q = vl_api_client_index_to_input_queue (event->client_index);
424 (void) vnet_add_del_ip6_nd_change_event
425 (vnm, nd_change_delete_callback,
426 event->pid, &event->address,
427 vpe_resolver_process_node.index, IP6_ND_EVENT,
428 ~0 /* pool index, notused */ , 0 /* is_add */ );
432 if (q->cursize < q->maxsize)
434 mp = vl_msg_api_alloc (sizeof (*mp));
435 clib_memcpy (mp, event, sizeof (*mp));
436 vl_msg_api_send_shmem (q, (u8 *) & mp);
440 static f64 last_time;
442 * Throttle syslog msgs.
443 * It's pretty tempting to just revoke the registration...
445 if (vlib_time_now (vm) > last_time + 10.0)
447 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
448 format_ip6_address, &event->address, event->pid);
449 last_time = vlib_time_now (vm);
455 resolver_process (vlib_main_t * vm,
456 vlib_node_runtime_t * rt, vlib_frame_t * f)
459 uword *event_data = 0;
465 vlib_process_wait_for_event_or_clock (vm, timeout);
467 event_type = vlib_process_get_events (vm, &event_data);
471 case RESOLUTION_PENDING_EVENT:
475 case RESOLUTION_EVENT:
476 clib_warning ("resolver: BOGUS TYPE");
480 for (i = 0; i < vec_len (event_data); i++)
481 handle_ip4_arp_event (event_data[i]);
485 for (i = 0; i < vec_len (event_data); i++)
486 handle_ip6_nd_event (event_data[i]);
489 case ~0: /* timeout */
493 vec_reset_length (event_data);
495 return 0; /* or not */
499 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
500 .function = resolver_process,
501 .type = VLIB_NODE_TYPE_PROCESS,
502 .name = "vpe-route-resolver-process",
507 mpls_route_add_del_t_handler (vnet_main_t * vnm,
508 vl_api_mpls_route_add_del_t * mp)
510 u32 fib_index, next_hop_fib_index;
511 mpls_label_t *label_stack = NULL;
512 int rv, ii, n_labels;;
516 .fp_proto = FIB_PROTOCOL_MPLS,
517 .fp_eos = mp->mr_eos,
518 .fp_label = ntohl (mp->mr_label),
522 if (mp->mr_next_hop_proto_is_ip4)
524 pfx.fp_payload_proto = DPO_PROTO_IP4;
528 pfx.fp_payload_proto = DPO_PROTO_IP6;
533 pfx.fp_payload_proto = DPO_PROTO_MPLS;
536 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
538 mp->mr_next_hop_sw_if_index,
539 dpo_proto_to_fib (pfx.fp_payload_proto),
540 mp->mr_next_hop_table_id,
541 mp->mr_create_table_if_needed,
542 &fib_index, &next_hop_fib_index);
548 memset (&nh, 0, sizeof (nh));
550 if (mp->mr_next_hop_proto_is_ip4)
551 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
553 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
555 n_labels = mp->mr_next_hop_n_out_labels;
558 else if (1 == n_labels)
559 vec_add1 (label_stack, ntohl (mp->mr_next_hop_out_label_stack[0]));
562 vec_validate (label_stack, n_labels - 1);
563 for (ii = 0; ii < n_labels; ii++)
564 label_stack[ii] = ntohl (mp->mr_next_hop_out_label_stack[ii]);
567 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
568 0, // mp->is_unreach,
569 0, // mp->is_prohibit,
572 mp->mr_classify_table_index,
573 mp->mr_is_resolve_host,
574 mp->mr_is_resolve_attached,
576 mp->mr_next_hop_proto_is_ip4,
577 &nh, ntohl (mp->mr_next_hop_sw_if_index),
579 mp->mr_next_hop_weight,
580 ntohl (mp->mr_next_hop_via_label),
585 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
587 vl_api_mpls_route_add_del_reply_t *rmp;
591 vnm = vnet_get_main ();
594 rv = mpls_route_add_del_t_handler (vnm, mp);
596 rv = (rv == 0) ? vnm->api_errno : rv;
598 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
602 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
603 vl_api_mpls_ip_bind_unbind_t * mp)
605 u32 mpls_fib_index, ip_fib_index;
608 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
610 if (~0 == mpls_fib_index)
612 if (mp->mb_create_table_if_needed)
615 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
616 ntohl (mp->mb_mpls_table_id));
619 return VNET_API_ERROR_NO_SUCH_FIB;
622 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
625 ntohl (mp->mb_ip_table_id));
626 if (~0 == ip_fib_index)
627 return VNET_API_ERROR_NO_SUCH_FIB;
630 .fp_len = mp->mb_address_length,
635 pfx.fp_proto = FIB_PROTOCOL_IP4;
636 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
637 sizeof (pfx.fp_addr.ip4));
641 pfx.fp_proto = FIB_PROTOCOL_IP6;
642 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
643 sizeof (pfx.fp_addr.ip6));
647 fib_table_entry_local_label_add (ip_fib_index, &pfx,
648 ntohl (mp->mb_label));
650 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
651 ntohl (mp->mb_label));
657 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
659 vl_api_mpls_route_add_del_reply_t *rmp;
663 vnm = vnet_get_main ();
666 rv = mpls_ip_bind_unbind_handler (vnm, mp);
668 rv = (rv == 0) ? vnm->api_errno : rv;
670 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
674 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
676 vl_api_sw_interface_set_vpath_reply_t *rmp;
678 u32 sw_if_index = ntohl (mp->sw_if_index);
680 VALIDATE_SW_IF_INDEX (mp);
682 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
683 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
684 sw_if_index, mp->enable, 0, 0);
685 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
686 sw_if_index, mp->enable, 0, 0);
687 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
688 sw_if_index, mp->enable, 0, 0);
689 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
690 sw_if_index, mp->enable, 0, 0);
692 BAD_SW_IF_INDEX_LABEL;
694 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
698 vl_api_sw_interface_set_vxlan_bypass_t_handler
699 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
701 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
703 u32 sw_if_index = ntohl (mp->sw_if_index);
705 VALIDATE_SW_IF_INDEX (mp);
709 /* not yet implemented */
712 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
713 sw_if_index, mp->enable, 0, 0);
715 BAD_SW_IF_INDEX_LABEL;
717 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
721 vl_api_sw_interface_set_l2_xconnect_t_handler
722 (vl_api_sw_interface_set_l2_xconnect_t * mp)
724 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
726 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
727 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
728 vlib_main_t *vm = vlib_get_main ();
729 vnet_main_t *vnm = vnet_get_main ();
731 VALIDATE_RX_SW_IF_INDEX (mp);
735 VALIDATE_TX_SW_IF_INDEX (mp);
736 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
737 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
741 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
744 BAD_RX_SW_IF_INDEX_LABEL;
745 BAD_TX_SW_IF_INDEX_LABEL;
747 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
751 vl_api_sw_interface_set_l2_bridge_t_handler
752 (vl_api_sw_interface_set_l2_bridge_t * mp)
754 bd_main_t *bdm = &bd_main;
755 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
757 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
758 u32 bd_id = ntohl (mp->bd_id);
762 vlib_main_t *vm = vlib_get_main ();
763 vnet_main_t *vnm = vnet_get_main ();
765 VALIDATE_RX_SW_IF_INDEX (mp);
767 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
771 //VALIDATE_TX_SW_IF_INDEX(mp);
772 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
773 rx_sw_if_index, bd_index, bvi, shg, 0);
777 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
780 BAD_RX_SW_IF_INDEX_LABEL;
782 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
786 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
787 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
789 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
793 dpdk_main_t *dm = &dpdk_main;
796 u32 sw_if_index = ntohl (mp->sw_if_index);
797 u32 subport = ntohl (mp->subport);
798 u32 pipe = ntohl (mp->pipe);
799 u32 profile = ntohl (mp->profile);
800 vnet_hw_interface_t *hw;
802 VALIDATE_SW_IF_INDEX (mp);
804 /* hw_if & dpdk device */
805 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
807 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
809 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
811 BAD_SW_IF_INDEX_LABEL;
813 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
814 rv = VNET_API_ERROR_UNIMPLEMENTED;
817 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
821 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
822 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
824 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
828 dpdk_main_t *dm = &dpdk_main;
830 struct rte_sched_subport_params p;
832 u32 sw_if_index = ntohl (mp->sw_if_index);
833 u32 subport = ntohl (mp->subport);
834 p.tb_rate = ntohl (mp->tb_rate);
835 p.tb_size = ntohl (mp->tb_size);
836 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
837 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
838 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
839 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
840 p.tc_period = ntohl (mp->tc_period);
842 vnet_hw_interface_t *hw;
844 VALIDATE_SW_IF_INDEX (mp);
846 /* hw_if & dpdk device */
847 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
849 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
851 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
853 BAD_SW_IF_INDEX_LABEL;
856 ("setting HQoS subport parameters without DPDK not implemented");
857 rv = VNET_API_ERROR_UNIMPLEMENTED;
860 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
864 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
865 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
867 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
871 dpdk_main_t *dm = &dpdk_main;
872 vlib_thread_main_t *tm = vlib_get_thread_main ();
875 u32 sw_if_index = ntohl (mp->sw_if_index);
876 u32 entry = ntohl (mp->entry);
877 u32 tc = ntohl (mp->tc);
878 u32 queue = ntohl (mp->queue);
881 vnet_hw_interface_t *hw;
883 VALIDATE_SW_IF_INDEX (mp);
885 /* hw_if & dpdk device */
886 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
888 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
890 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
892 clib_warning ("invalid traffic class !!");
893 rv = VNET_API_ERROR_INVALID_VALUE;
896 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
898 clib_warning ("invalid queue !!");
899 rv = VNET_API_ERROR_INVALID_VALUE;
903 /* Detect the set of worker threads */
904 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
908 clib_warning ("worker thread registration AWOL !!");
909 rv = VNET_API_ERROR_INVALID_VALUE_2;
913 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
914 int worker_thread_first = tr->first_index;
915 int worker_thread_count = tr->count;
917 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
918 for (i = 0; i < worker_thread_count; i++)
919 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
921 BAD_SW_IF_INDEX_LABEL;
924 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
925 rv = VNET_API_ERROR_UNIMPLEMENTED;
928 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
932 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
934 vlib_main_t *vm = vlib_get_main ();
935 bd_main_t *bdm = &bd_main;
936 vl_api_bridge_domain_add_del_reply_t *rmp;
938 u32 enable_flags = 0, disable_flags = 0;
939 u32 bd_id = ntohl (mp->bd_id);
944 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
947 enable_flags |= L2_FLOOD;
949 disable_flags |= L2_FLOOD;
952 enable_flags |= L2_UU_FLOOD;
954 disable_flags |= L2_UU_FLOOD;
957 enable_flags |= L2_FWD;
959 disable_flags |= L2_FWD;
962 enable_flags |= L2_ARP_TERM;
964 disable_flags |= L2_ARP_TERM;
967 enable_flags |= L2_LEARN;
969 disable_flags |= L2_LEARN;
972 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
975 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
979 rv = bd_delete_bd_index (bdm, bd_id);
981 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
985 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
987 clib_warning ("BUG");
991 vl_api_bridge_domain_sw_if_details_t_handler
992 (vl_api_bridge_domain_sw_if_details_t * mp)
994 clib_warning ("BUG");
998 send_bridge_domain_details (unix_shared_memory_queue_t * q,
999 l2_bridge_domain_t * bd_config,
1000 u32 n_sw_ifs, u32 context)
1002 vl_api_bridge_domain_details_t *mp;
1004 mp = vl_msg_api_alloc (sizeof (*mp));
1005 memset (mp, 0, sizeof (*mp));
1006 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1007 mp->bd_id = ntohl (bd_config->bd_id);
1008 mp->flood = bd_feature_flood (bd_config);
1009 mp->uu_flood = bd_feature_uu_flood (bd_config);
1010 mp->forward = bd_feature_forward (bd_config);
1011 mp->learn = bd_feature_learn (bd_config);
1012 mp->arp_term = bd_feature_arp_term (bd_config);
1013 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1014 mp->n_sw_ifs = ntohl (n_sw_ifs);
1015 mp->context = context;
1017 vl_msg_api_send_shmem (q, (u8 *) & mp);
1021 send_bd_sw_if_details (l2input_main_t * l2im,
1022 unix_shared_memory_queue_t * q,
1023 l2_flood_member_t * member, u32 bd_id, u32 context)
1025 vl_api_bridge_domain_sw_if_details_t *mp;
1026 l2_input_config_t *input_cfg;
1028 mp = vl_msg_api_alloc (sizeof (*mp));
1029 memset (mp, 0, sizeof (*mp));
1030 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1031 mp->bd_id = ntohl (bd_id);
1032 mp->sw_if_index = ntohl (member->sw_if_index);
1033 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1034 mp->shg = input_cfg->shg;
1035 mp->context = context;
1037 vl_msg_api_send_shmem (q, (u8 *) & mp);
1041 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1043 bd_main_t *bdm = &bd_main;
1044 l2input_main_t *l2im = &l2input_main;
1045 unix_shared_memory_queue_t *q;
1046 l2_bridge_domain_t *bd_config;
1047 u32 bd_id, bd_index;
1050 q = vl_api_client_index_to_input_queue (mp->client_index);
1055 bd_id = ntohl (mp->bd_id);
1057 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1058 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1059 for (; bd_index < end; bd_index++)
1061 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1062 /* skip dummy bd_id 0 */
1063 if (bd_config && (bd_config->bd_id > 0))
1066 l2_flood_member_t *m;
1068 n_sw_ifs = vec_len (bd_config->members);
1069 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1071 vec_foreach (m, bd_config->members)
1073 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1080 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1082 bd_main_t *bdm = &bd_main;
1083 l2input_main_t *l2im = &l2input_main;
1084 vl_api_l2fib_add_del_reply_t *rmp;
1087 u32 sw_if_index = ntohl (mp->sw_if_index);
1088 u32 bd_id = ntohl (mp->bd_id);
1097 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1100 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1101 goto bad_sw_if_index;
1107 filter_mac = mp->filter_mac ? 1 : 0;
1108 if (filter_mac == 0)
1110 VALIDATE_SW_IF_INDEX (mp);
1111 if (vec_len (l2im->configs) <= sw_if_index)
1113 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1114 goto bad_sw_if_index;
1118 l2_input_config_t *config;
1119 config = vec_elt_at_index (l2im->configs, sw_if_index);
1120 if (config->bridge == 0)
1122 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1123 goto bad_sw_if_index;
1127 static_mac = mp->static_mac ? 1 : 0;
1128 bvi_mac = mp->bvi_mac ? 1 : 0;
1129 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1134 l2fib_del_entry (mac, bd_index);
1137 BAD_SW_IF_INDEX_LABEL;
1139 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1143 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1145 vl_api_l2_flags_reply_t *rmp;
1147 u32 sw_if_index = ntohl (mp->sw_if_index);
1148 u32 flags = ntohl (mp->feature_bitmap);
1151 VALIDATE_SW_IF_INDEX (mp);
1154 if (flags & L2INPUT_FEAT_ ## a) \
1155 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1156 foreach_l2input_feat;
1159 BAD_SW_IF_INDEX_LABEL;
1162 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1164 rmp->resulting_feature_bitmap = ntohl(rbm);
1170 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1172 vlib_main_t *vm = vlib_get_main ();
1173 bd_main_t *bdm = &bd_main;
1174 vl_api_bridge_flags_reply_t *rmp;
1176 u32 bd_id = ntohl (mp->bd_id);
1178 u32 flags = ntohl (mp->feature_bitmap);
1181 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1184 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1190 bd_set_flags (vm, bd_index, flags, mp->is_set);
1194 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1196 rmp->resulting_feature_bitmap = ntohl(flags);
1202 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1204 bd_main_t *bdm = &bd_main;
1205 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1207 u32 bd_id = ntohl (mp->bd_id);
1211 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1214 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1219 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1220 mp->mac_address, mp->is_ipv6, mp->is_add))
1221 rv = VNET_API_ERROR_UNSPECIFIED;
1224 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1228 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1230 vl_api_create_vlan_subif_reply_t *rmp;
1231 vnet_main_t *vnm = vnet_get_main ();
1232 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1233 vnet_hw_interface_t *hi;
1236 vnet_sw_interface_t template;
1238 vnet_interface_main_t *im = &vnm->interface_main;
1239 u64 sup_and_sub_key;
1241 unix_shared_memory_queue_t *q;
1242 clib_error_t *error;
1244 VALIDATE_SW_IF_INDEX (mp);
1246 hw_if_index = ntohl (mp->sw_if_index);
1247 hi = vnet_get_hw_interface (vnm, hw_if_index);
1249 id = ntohl (mp->vlan_id);
1250 if (id == 0 || id > 4095)
1252 rv = VNET_API_ERROR_INVALID_VLAN;
1256 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1258 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1261 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1265 kp = clib_mem_alloc (sizeof (*kp));
1266 *kp = sup_and_sub_key;
1268 memset (&template, 0, sizeof (template));
1269 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1270 template.sup_sw_if_index = hi->sw_if_index;
1271 template.sub.id = id;
1272 template.sub.eth.raw_flags = 0;
1273 template.sub.eth.flags.one_tag = 1;
1274 template.sub.eth.outer_vlan_id = id;
1275 template.sub.eth.flags.exact_match = 1;
1277 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1280 clib_error_report (error);
1281 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1284 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1285 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1287 BAD_SW_IF_INDEX_LABEL;
1290 q = vl_api_client_index_to_input_queue (mp->client_index);
1294 rmp = vl_msg_api_alloc (sizeof (*rmp));
1295 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1296 rmp->context = mp->context;
1297 rmp->retval = ntohl (rv);
1298 rmp->sw_if_index = ntohl (sw_if_index);
1299 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1303 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1305 vl_api_create_subif_reply_t *rmp;
1306 vnet_main_t *vnm = vnet_get_main ();
1307 u32 sw_if_index = ~0;
1310 vnet_sw_interface_t *si;
1311 vnet_hw_interface_t *hi;
1312 vnet_sw_interface_t template;
1314 vnet_interface_main_t *im = &vnm->interface_main;
1315 u64 sup_and_sub_key;
1317 clib_error_t *error;
1319 VALIDATE_SW_IF_INDEX (mp);
1321 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1322 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1324 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1326 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1330 sw_if_index = si->sw_if_index;
1331 sub_id = ntohl (mp->sub_id);
1333 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1335 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1339 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1340 sw_if_index, sub_id);
1341 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1345 kp = clib_mem_alloc (sizeof (*kp));
1346 *kp = sup_and_sub_key;
1348 memset (&template, 0, sizeof (template));
1349 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1350 template.sup_sw_if_index = sw_if_index;
1351 template.sub.id = sub_id;
1352 template.sub.eth.flags.no_tags = mp->no_tags;
1353 template.sub.eth.flags.one_tag = mp->one_tag;
1354 template.sub.eth.flags.two_tags = mp->two_tags;
1355 template.sub.eth.flags.dot1ad = mp->dot1ad;
1356 template.sub.eth.flags.exact_match = mp->exact_match;
1357 template.sub.eth.flags.default_sub = mp->default_sub;
1358 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1359 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1360 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1361 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1363 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1366 clib_error_report (error);
1367 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1371 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1372 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1374 BAD_SW_IF_INDEX_LABEL;
1379 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1381 rmp->sw_if_index = ntohl(sw_if_index);
1387 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
1389 vl_api_mpls_tunnel_add_del_reply_t *rmp;
1391 stats_main_t *sm = &stats_main;
1392 u32 tunnel_sw_if_index;
1395 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1399 fib_route_path_t rpath, *rpaths = NULL;
1400 mpls_label_t *label_stack = NULL;
1402 memset (&rpath, 0, sizeof (rpath));
1404 if (mp->mt_next_hop_proto_is_ip4)
1406 rpath.frp_proto = FIB_PROTOCOL_IP4;
1407 clib_memcpy (&rpath.frp_addr.ip4,
1408 mp->mt_next_hop, sizeof (rpath.frp_addr.ip4));
1412 rpath.frp_proto = FIB_PROTOCOL_IP6;
1413 clib_memcpy (&rpath.frp_addr.ip6,
1414 mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
1416 rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
1418 for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
1419 vec_add1 (label_stack, ntohl (mp->mt_next_hop_out_label_stack[ii]));
1421 vec_add1 (rpaths, rpath);
1423 vnet_mpls_tunnel_add (rpaths, label_stack,
1424 mp->mt_l2_only, &tunnel_sw_if_index);
1426 vec_free (label_stack);
1430 tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
1431 vnet_mpls_tunnel_del (tunnel_sw_if_index);
1437 REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
1439 rmp->sw_if_index = ntohl(tunnel_sw_if_index);
1445 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
1447 vl_api_proxy_arp_add_del_reply_t *rmp;
1450 ip4_main_t *im = &ip4_main;
1451 stats_main_t *sm = &stats_main;
1452 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
1453 ip4_address_t * hi_addr,
1454 u32 fib_index, int is_del);
1457 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
1459 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1463 rv = VNET_API_ERROR_NO_SUCH_FIB;
1469 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
1470 (ip4_address_t *) mp->hi_address,
1471 fib_index, mp->is_add == 0);
1475 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
1479 vl_api_proxy_arp_intfc_enable_disable_t_handler
1480 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
1483 vnet_main_t *vnm = vnet_get_main ();
1484 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
1485 vnet_sw_interface_t *si;
1488 VALIDATE_SW_IF_INDEX (mp);
1490 sw_if_index = ntohl (mp->sw_if_index);
1492 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1494 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1498 si = vnet_get_sw_interface (vnm, sw_if_index);
1502 if (mp->enable_disable)
1503 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1505 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1507 BAD_SW_IF_INDEX_LABEL;
1510 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
1514 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
1517 vpe_main_t *rm = &vpe_main;
1518 ip4_main_t *im4 = &ip4_main;
1519 ip6_main_t *im6 = &ip6_main;
1520 ip_lookup_main_t *lm;
1526 u32 adj_index, sw_if_index;
1527 vl_api_is_address_reachable_t *rmp;
1528 ip_adjacency_t *adj;
1529 unix_shared_memory_queue_t *q;
1531 q = vl_api_client_index_to_input_queue (mp->client_index);
1534 increment_missing_api_client_counter (rm->vlib_main);
1538 rmp = vl_msg_api_alloc (sizeof (*rmp));
1539 clib_memcpy (rmp, mp, sizeof (*rmp));
1541 sw_if_index = mp->next_hop_sw_if_index;
1542 clib_memcpy (&addr, mp->address, sizeof (addr));
1545 lm = &im6->lookup_main;
1546 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
1550 lm = &im4->lookup_main;
1552 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
1554 if (adj_index == ~0)
1559 adj = ip_get_adjacency (lm, adj_index);
1561 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
1562 && adj->rewrite_header.sw_if_index == sw_if_index)
1568 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
1569 && adj->rewrite_header.sw_if_index == sw_if_index)
1572 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
1574 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
1576 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
1585 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1590 vl_api_sw_interface_set_mpls_enable_t_handler
1591 (vl_api_sw_interface_set_mpls_enable_t * mp)
1593 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
1596 VALIDATE_SW_IF_INDEX (mp);
1598 mpls_sw_interface_enable_disable (&mpls_main,
1599 ntohl (mp->sw_if_index), mp->enable);
1601 BAD_SW_IF_INDEX_LABEL;
1602 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
1606 * WARNING: replicated pending api refactor completion
1609 send_sw_interface_flags_deleted (vpe_api_main_t * am,
1610 unix_shared_memory_queue_t * q,
1613 vl_api_sw_interface_set_flags_t *mp;
1615 mp = vl_msg_api_alloc (sizeof (*mp));
1616 memset (mp, 0, sizeof (*mp));
1617 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
1618 mp->sw_if_index = ntohl (sw_if_index);
1620 mp->admin_up_down = 0;
1621 mp->link_up_down = 0;
1623 vl_msg_api_send_shmem (q, (u8 *) & mp);
1627 send_oam_event (oam_target_t * t)
1629 vpe_api_main_t *vam = &vpe_api_main;
1630 unix_shared_memory_queue_t *q;
1631 vpe_client_registration_t *reg;
1632 vl_api_oam_event_t *mp;
1635 pool_foreach(reg, vam->oam_events_registrations,
1637 q = vl_api_client_index_to_input_queue (reg->client_index);
1640 mp = vl_msg_api_alloc (sizeof (*mp));
1641 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
1642 clib_memcpy (mp->dst_address, &t->dst_address,
1643 sizeof (mp->dst_address));
1644 mp->state = t->state;
1645 vl_msg_api_send_shmem (q, (u8 *)&mp);
1652 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
1654 vl_api_oam_add_del_reply_t *rmp;
1657 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
1658 (ip4_address_t *) mp->dst_address,
1659 ntohl (mp->vrf_id), (int) (mp->is_add));
1661 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
1665 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
1667 stats_main_t *sm = &stats_main;
1668 vnet_interface_main_t *im = sm->interface_main;
1669 vl_api_vnet_summary_stats_reply_t *rmp;
1670 vlib_combined_counter_main_t *cm;
1673 u64 total_pkts[VLIB_N_RX_TX];
1674 u64 total_bytes[VLIB_N_RX_TX];
1676 unix_shared_memory_queue_t *q =
1677 vl_api_client_index_to_input_queue (mp->client_index);
1682 rmp = vl_msg_api_alloc (sizeof (*rmp));
1683 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
1684 rmp->context = mp->context;
1687 memset (total_pkts, 0, sizeof (total_pkts));
1688 memset (total_bytes, 0, sizeof (total_bytes));
1690 vnet_interface_counter_lock (im);
1692 vec_foreach (cm, im->combined_sw_if_counters)
1694 which = cm - im->combined_sw_if_counters;
1696 for (i = 0; i < vec_len (cm->maxi); i++)
1698 vlib_get_combined_counter (cm, i, &v);
1699 total_pkts[which] += v.packets;
1700 total_bytes[which] += v.bytes;
1703 vnet_interface_counter_unlock (im);
1705 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
1706 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
1707 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
1708 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
1710 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
1712 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1716 typedef CLIB_PACKED (struct {
1717 ip4_address_t address;
1718 u32 address_length: 6;
1724 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1726 vnet_main_t *vnm = vnet_get_main ();
1727 vnet_interface_main_t *im = &vnm->interface_main;
1728 ip4_main_t *im4 = &ip4_main;
1729 static u32 *sw_if_indices_to_shut;
1730 stats_main_t *sm = &stats_main;
1731 fib_table_t *fib_table;
1735 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1736 u32 target_fib_id = ntohl (mp->vrf_id);
1738 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
1741 pool_foreach (fib_table, im4->fibs,
1743 fib = &fib_table->v4;
1744 vnet_sw_interface_t * si;
1746 if (fib->table_id != target_fib_id)
1749 /* remove any mpls encap/decap labels */
1750 mpls_fib_reset_labels (fib->table_id);
1752 /* remove any proxy arps in this fib */
1753 vnet_proxy_arp_fib_reset (fib->table_id);
1755 /* Set the flow hash for this fib to the default */
1756 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
1758 vec_reset_length (sw_if_indices_to_shut);
1760 /* Shut down interfaces in this FIB / clean out intfc routes */
1761 pool_foreach (si, im->sw_interfaces,
1763 u32 sw_if_index = si->sw_if_index;
1765 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
1766 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
1768 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1771 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1772 sw_if_index = sw_if_indices_to_shut[i];
1773 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1775 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1776 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1777 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1780 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
1781 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
1785 })); /* pool_foreach (fib) */
1793 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1795 vnet_main_t *vnm = vnet_get_main ();
1796 vnet_interface_main_t *im = &vnm->interface_main;
1797 ip6_main_t *im6 = &ip6_main;
1798 stats_main_t *sm = &stats_main;
1799 static u32 *sw_if_indices_to_shut;
1800 fib_table_t *fib_table;
1804 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1805 u32 target_fib_id = ntohl (mp->vrf_id);
1807 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
1810 pool_foreach (fib_table, im6->fibs,
1812 vnet_sw_interface_t * si;
1813 fib = &(fib_table->v6);
1815 if (fib->table_id != target_fib_id)
1818 vec_reset_length (sw_if_indices_to_shut);
1820 /* Shut down interfaces in this FIB / clean out intfc routes */
1821 pool_foreach (si, im->sw_interfaces,
1823 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1825 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1828 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1829 sw_if_index = sw_if_indices_to_shut[i];
1830 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1832 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1833 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1834 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1837 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1838 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
1842 })); /* pool_foreach (fib) */
1850 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1853 vl_api_reset_fib_reply_t *rmp;
1856 rv = ip6_reset_fib_t_handler (mp);
1858 rv = ip4_reset_fib_t_handler (mp);
1860 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1865 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1867 vl_api_dhcp_proxy_config_reply_t *rmp;
1870 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
1871 (ip4_address_t *) (&mp->dhcp_src_address),
1872 (u32) ntohl (mp->vrf_id),
1873 (int) mp->insert_circuit_id,
1874 (int) (mp->is_add == 0));
1876 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1881 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1883 vl_api_dhcp_proxy_config_reply_t *rmp;
1886 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
1887 (ip6_address_t *) (&mp->dhcp_src_address),
1888 (u32) ntohl (mp->vrf_id),
1889 (int) mp->insert_circuit_id,
1890 (int) (mp->is_add == 0));
1892 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1896 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1898 vl_api_dhcp_proxy_config_reply_t *rmp;
1901 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
1902 (ip4_address_t *) (&mp->dhcp_src_address),
1903 (u32) ntohl (mp->rx_vrf_id),
1904 (u32) ntohl (mp->server_vrf_id),
1905 (int) mp->insert_circuit_id,
1906 (int) (mp->is_add == 0));
1908 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1913 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1915 vl_api_dhcp_proxy_config_reply_t *rmp;
1918 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
1919 (ip6_address_t *) (&mp->dhcp_src_address),
1920 (u32) ntohl (mp->rx_vrf_id),
1921 (u32) ntohl (mp->server_vrf_id),
1922 (int) mp->insert_circuit_id,
1923 (int) (mp->is_add == 0));
1925 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1930 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
1932 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
1935 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
1938 (int) mp->is_add == 0);
1940 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
1942 ntohl (mp->fib_id), (int) mp->is_add == 0);
1944 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
1948 static void vl_api_dhcp_proxy_config_t_handler
1949 (vl_api_dhcp_proxy_config_t * mp)
1951 if (mp->is_ipv6 == 0)
1952 dhcpv4_proxy_config (mp);
1954 dhcpv6_proxy_config (mp);
1957 static void vl_api_dhcp_proxy_config_2_t_handler
1958 (vl_api_dhcp_proxy_config_2_t * mp)
1960 if (mp->is_ipv6 == 0)
1961 dhcpv4_proxy_config_2 (mp);
1963 dhcpv6_proxy_config_2 (mp);
1967 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
1968 u8 is_ipv6, u8 * host_address, u8 * router_address,
1971 unix_shared_memory_queue_t *q;
1972 vl_api_dhcp_compl_event_t *mp;
1974 q = vl_api_client_index_to_input_queue (client_index);
1978 mp = vl_msg_api_alloc (sizeof (*mp));
1979 mp->client_index = client_index;
1981 mp->is_ipv6 = is_ipv6;
1982 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
1983 mp->hostname[vec_len (hostname) + 1] = '\n';
1984 clib_memcpy (&mp->host_address[0], host_address, 16);
1985 clib_memcpy (&mp->router_address[0], router_address, 16);
1987 if (NULL != host_mac)
1988 clib_memcpy (&mp->host_mac[0], host_mac, 6);
1990 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
1992 vl_msg_api_send_shmem (q, (u8 *) & mp);
1995 static void vl_api_dhcp_client_config_t_handler
1996 (vl_api_dhcp_client_config_t * mp)
1998 vlib_main_t *vm = vlib_get_main ();
1999 vl_api_dhcp_client_config_reply_t *rmp;
2002 VALIDATE_SW_IF_INDEX (mp);
2004 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
2005 mp->hostname, mp->is_add, mp->client_index,
2006 mp->want_dhcp_event ? dhcp_compl_event_callback :
2009 BAD_SW_IF_INDEX_LABEL;
2011 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
2015 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
2017 vl_api_create_loopback_reply_t *rmp;
2021 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
2024 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
2026 rmp->sw_if_index = ntohl (sw_if_index);
2032 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
2034 vl_api_delete_loopback_reply_t *rmp;
2038 sw_if_index = ntohl (mp->sw_if_index);
2039 rv = vnet_delete_loopback_interface (sw_if_index);
2041 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
2045 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
2047 vl_api_control_ping_reply_t *rmp;
2051 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
2053 rmp->vpe_pid = ntohl (getpid());
2059 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2061 u8 **shmem_vecp = (u8 **) arg;
2064 api_main_t *am = &api_main;
2067 shmem_vec = *shmem_vecp;
2069 offset = vec_len (shmem_vec);
2071 pthread_mutex_lock (&am->vlib_rp->mutex);
2072 oldheap = svm_push_data_heap (am->vlib_rp);
2074 vec_validate (shmem_vec, offset + buffer_bytes - 1);
2076 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
2078 svm_pop_heap (oldheap);
2079 pthread_mutex_unlock (&am->vlib_rp->mutex);
2081 *shmem_vecp = shmem_vec;
2086 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
2088 vl_api_cli_reply_t *rp;
2089 unix_shared_memory_queue_t *q;
2090 vlib_main_t *vm = vlib_get_main ();
2091 api_main_t *am = &api_main;
2092 unformat_input_t input;
2096 q = vl_api_client_index_to_input_queue (mp->client_index);
2100 rp = vl_msg_api_alloc (sizeof (*rp));
2101 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
2102 rp->context = mp->context;
2104 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
2106 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
2108 pthread_mutex_lock (&am->vlib_rp->mutex);
2109 oldheap = svm_push_data_heap (am->vlib_rp);
2111 vec_add1 (shmem_vec, 0);
2113 svm_pop_heap (oldheap);
2114 pthread_mutex_unlock (&am->vlib_rp->mutex);
2116 rp->reply_in_shmem = (uword) shmem_vec;
2118 vl_msg_api_send_shmem (q, (u8 *) & rp);
2122 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2124 u8 **mem_vecp = (u8 **) arg;
2125 u8 *mem_vec = *mem_vecp;
2126 u32 offset = vec_len (mem_vec);
2128 vec_validate (mem_vec, offset + buffer_bytes - 1);
2129 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
2130 *mem_vecp = mem_vec;
2134 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
2136 vl_api_cli_inband_reply_t *rmp;
2138 unix_shared_memory_queue_t *q;
2139 vlib_main_t *vm = vlib_get_main ();
2140 unformat_input_t input;
2143 q = vl_api_client_index_to_input_queue (mp->client_index);
2147 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
2148 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
2150 u32 len = vec_len (out_vec);
2152 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
2154 rmp->length = htonl (len);
2155 clib_memcpy (rmp->reply, out_vec, len);
2162 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2165 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2166 vnet_main_t *vnm = vnet_get_main ();
2167 clib_error_t *error;
2172 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2174 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2178 clib_error_report (error);
2179 rv = VNET_API_ERROR_UNSPECIFIED;
2183 rv = vnm->api_errno;
2186 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2189 static void vl_api_sr_tunnel_add_del_t_handler
2190 (vl_api_sr_tunnel_add_del_t * mp)
2193 clib_warning ("unimplemented");
2195 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
2197 vl_api_sr_tunnel_add_del_reply_t *rmp;
2198 ip6_address_t *segments = 0, *seg;
2199 ip6_address_t *tags = 0, *tag;
2200 ip6_address_t *this_address;
2203 if (mp->n_segments == 0)
2209 memset (a, 0, sizeof (*a));
2210 a->src_address = (ip6_address_t *) & mp->src_address;
2211 a->dst_address = (ip6_address_t *) & mp->dst_address;
2212 a->dst_mask_width = mp->dst_mask_width;
2213 a->flags_net_byte_order = mp->flags_net_byte_order;
2214 a->is_del = (mp->is_add == 0);
2215 a->rx_table_id = ntohl (mp->outer_vrf_id);
2216 a->tx_table_id = ntohl (mp->inner_vrf_id);
2218 a->name = format (0, "%s", mp->name);
2219 if (!(vec_len (a->name)))
2222 a->policy_name = format (0, "%s", mp->policy_name);
2223 if (!(vec_len (a->policy_name)))
2226 /* Yank segments and tags out of the API message */
2227 this_address = (ip6_address_t *) mp->segs_and_tags;
2228 for (i = 0; i < mp->n_segments; i++)
2230 vec_add2 (segments, seg, 1);
2231 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
2234 for (i = 0; i < mp->n_tags; i++)
2236 vec_add2 (tags, tag, 1);
2237 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
2241 a->segments = segments;
2244 rv = ip6_sr_add_del_tunnel (a);
2248 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
2252 static void vl_api_sr_policy_add_del_t_handler
2253 (vl_api_sr_policy_add_del_t * mp)
2256 clib_warning ("unimplemented");
2258 ip6_sr_add_del_policy_args_t _a, *a = &_a;
2260 vl_api_sr_policy_add_del_reply_t *rmp;
2263 memset (a, 0, sizeof (*a));
2264 a->is_del = (mp->is_add == 0);
2266 a->name = format (0, "%s", mp->name);
2267 if (!(vec_len (a->name)))
2269 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2273 if (!(mp->tunnel_names[0]))
2275 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2279 // start deserializing tunnel_names
2280 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
2281 u8 *deser_tun_names = mp->tunnel_names;
2282 deser_tun_names += 1; //moving along
2285 int tun_name_len = 0;
2287 for (i = 0; i < num_tunnels; i++)
2289 tun_name_len = *deser_tun_names;
2290 deser_tun_names += 1;
2291 vec_resize (tun_name, tun_name_len);
2292 memcpy (tun_name, deser_tun_names, tun_name_len);
2293 vec_add1 (a->tunnel_names, tun_name);
2294 deser_tun_names += tun_name_len;
2298 rv = ip6_sr_add_del_policy (a);
2302 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
2306 static void vl_api_sr_multicast_map_add_del_t_handler
2307 (vl_api_sr_multicast_map_add_del_t * mp)
2310 clib_warning ("unimplemented");
2312 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
2314 vl_api_sr_multicast_map_add_del_reply_t *rmp;
2316 memset (a, 0, sizeof (*a));
2317 a->is_del = (mp->is_add == 0);
2319 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
2320 a->policy_name = format (0, "%s", mp->policy_name);
2322 if (a->multicast_address == 0)
2328 if (!(a->policy_name))
2334 #if DPDK > 0 /* Cannot call replicate without DPDK */
2335 rv = ip6_sr_add_del_multicastmap (a);
2337 clib_warning ("multicast replication without DPDK not implemented");
2338 rv = VNET_API_ERROR_UNIMPLEMENTED;
2343 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
2347 #define foreach_classify_add_del_table_field \
2352 _(match_n_vectors) \
2353 _(next_table_index) \
2354 _(miss_next_index) \
2355 _(current_data_flag) \
2356 _(current_data_offset)
2358 static void vl_api_classify_add_del_table_t_handler
2359 (vl_api_classify_add_del_table_t * mp)
2361 vl_api_classify_add_del_table_reply_t *rmp;
2362 vnet_classify_main_t *cm = &vnet_classify_main;
2363 vnet_classify_table_t *t;
2367 foreach_classify_add_del_table_field;
2370 #define _(a) a = ntohl(mp->a);
2371 foreach_classify_add_del_table_field;
2374 /* The underlying API fails silently, on purpose, so check here */
2375 if (mp->is_add == 0) /* delete */
2377 if (pool_is_free_index (cm->tables, table_index))
2379 rv = VNET_API_ERROR_NO_SUCH_TABLE;
2383 else /* add or update */
2385 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
2389 rv = vnet_classify_add_del_table
2390 (cm, mp->mask, nbuckets, memory_size,
2391 skip_n_vectors, match_n_vectors,
2392 next_table_index, miss_next_index, &table_index,
2393 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
2397 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
2399 if (rv == 0 && mp->is_add)
2401 t = pool_elt_at_index (cm->tables, table_index);
2402 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
2403 rmp->match_n_vectors = ntohl(t->match_n_vectors);
2404 rmp->new_table_index = ntohl(table_index);
2408 rmp->skip_n_vectors = ~0;
2409 rmp->match_n_vectors = ~0;
2410 rmp->new_table_index = ~0;
2416 static void vl_api_classify_add_del_session_t_handler
2417 (vl_api_classify_add_del_session_t * mp)
2419 vnet_classify_main_t *cm = &vnet_classify_main;
2420 vl_api_classify_add_del_session_reply_t *rmp;
2422 u32 table_index, hit_next_index, opaque_index, metadata;
2426 table_index = ntohl (mp->table_index);
2427 hit_next_index = ntohl (mp->hit_next_index);
2428 opaque_index = ntohl (mp->opaque_index);
2429 advance = ntohl (mp->advance);
2430 action = mp->action;
2431 metadata = ntohl (mp->metadata);
2433 rv = vnet_classify_add_del_session
2434 (cm, table_index, mp->match, hit_next_index, opaque_index,
2435 advance, action, metadata, mp->is_add);
2437 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
2440 static void vl_api_classify_set_interface_ip_table_t_handler
2441 (vl_api_classify_set_interface_ip_table_t * mp)
2443 vlib_main_t *vm = vlib_get_main ();
2444 vl_api_classify_set_interface_ip_table_reply_t *rmp;
2446 u32 table_index, sw_if_index;
2448 table_index = ntohl (mp->table_index);
2449 sw_if_index = ntohl (mp->sw_if_index);
2451 VALIDATE_SW_IF_INDEX (mp);
2454 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
2456 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
2458 BAD_SW_IF_INDEX_LABEL;
2460 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
2463 static void vl_api_classify_set_interface_l2_tables_t_handler
2464 (vl_api_classify_set_interface_l2_tables_t * mp)
2466 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
2468 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
2471 ip4_table_index = ntohl (mp->ip4_table_index);
2472 ip6_table_index = ntohl (mp->ip6_table_index);
2473 other_table_index = ntohl (mp->other_table_index);
2474 sw_if_index = ntohl (mp->sw_if_index);
2476 VALIDATE_SW_IF_INDEX (mp);
2479 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
2483 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
2489 if (ip4_table_index != ~0 || ip6_table_index != ~0
2490 || other_table_index != ~0)
2496 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
2498 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
2501 BAD_SW_IF_INDEX_LABEL;
2503 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
2507 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
2510 vl_api_l2_fib_clear_table_reply_t *rmp;
2512 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
2513 * that is not currently implemented. When that TODO is fixed
2514 * this call should be changed to pass 1 instead of 0.
2516 l2fib_clear_table (0);
2518 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
2521 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
2522 u32 sw_if_index, u32 enable);
2525 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
2529 vl_api_l2_interface_efp_filter_reply_t *rmp;
2530 vnet_main_t *vnm = vnet_get_main ();
2532 // enable/disable the feature
2533 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
2534 rv = vnm->api_errno;
2536 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
2540 vl_api_l2_interface_vlan_tag_rewrite_t_handler
2541 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
2544 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
2545 vnet_main_t *vnm = vnet_get_main ();
2546 vlib_main_t *vm = vlib_get_main ();
2549 VALIDATE_SW_IF_INDEX (mp);
2551 vtr_op = ntohl (mp->vtr_op);
2553 /* The L2 code is unsuspicious */
2556 case L2_VTR_DISABLED:
2561 case L2_VTR_TRANSLATE_1_1:
2562 case L2_VTR_TRANSLATE_1_2:
2563 case L2_VTR_TRANSLATE_2_1:
2564 case L2_VTR_TRANSLATE_2_2:
2568 rv = VNET_API_ERROR_INVALID_VALUE;
2569 goto bad_sw_if_index;
2572 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
2573 ntohl (mp->push_dot1q), ntohl (mp->tag1),
2576 BAD_SW_IF_INDEX_LABEL;
2578 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
2582 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
2585 vl_api_create_vhost_user_if_reply_t *rmp;
2586 u32 sw_if_index = (u32) ~ 0;
2587 vnet_main_t *vnm = vnet_get_main ();
2588 vlib_main_t *vm = vlib_get_main ();
2590 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
2591 mp->is_server, &sw_if_index, (u64) ~ 0,
2592 mp->renumber, ntohl (mp->custom_dev_instance),
2593 (mp->use_custom_mac) ? mp->mac_address : NULL);
2595 /* Remember an interface tag for the new interface */
2598 /* If a tag was supplied... */
2601 /* Make sure it's a proper C-string */
2602 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
2603 u8 *tag = format (0, "%s%c", mp->tag, 0);
2604 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
2609 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
2611 rmp->sw_if_index = ntohl (sw_if_index);
2617 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
2620 vl_api_modify_vhost_user_if_reply_t *rmp;
2621 u32 sw_if_index = ntohl (mp->sw_if_index);
2623 vnet_main_t *vnm = vnet_get_main ();
2624 vlib_main_t *vm = vlib_get_main ();
2626 rv = vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
2627 mp->is_server, sw_if_index, (u64) ~ 0,
2628 mp->renumber, ntohl (mp->custom_dev_instance));
2630 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
2634 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
2637 vl_api_delete_vhost_user_if_reply_t *rmp;
2638 vpe_api_main_t *vam = &vpe_api_main;
2639 u32 sw_if_index = ntohl (mp->sw_if_index);
2641 vnet_main_t *vnm = vnet_get_main ();
2642 vlib_main_t *vm = vlib_get_main ();
2644 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
2646 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
2649 unix_shared_memory_queue_t *q =
2650 vl_api_client_index_to_input_queue (mp->client_index);
2654 vnet_clear_sw_interface_tag (vnm, sw_if_index);
2655 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2660 vl_api_sw_interface_vhost_user_details_t_handler
2661 (vl_api_sw_interface_vhost_user_details_t * mp)
2663 clib_warning ("BUG");
2667 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
2668 unix_shared_memory_queue_t * q,
2669 vhost_user_intf_details_t * vui,
2672 vl_api_sw_interface_vhost_user_details_t *mp;
2674 mp = vl_msg_api_alloc (sizeof (*mp));
2675 memset (mp, 0, sizeof (*mp));
2676 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
2677 mp->sw_if_index = ntohl (vui->sw_if_index);
2678 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
2679 mp->features = clib_net_to_host_u64 (vui->features);
2680 mp->is_server = vui->is_server;
2681 mp->num_regions = ntohl (vui->num_regions);
2682 mp->sock_errno = ntohl (vui->sock_errno);
2683 mp->context = context;
2685 strncpy ((char *) mp->sock_filename,
2686 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
2687 strncpy ((char *) mp->interface_name,
2688 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
2690 vl_msg_api_send_shmem (q, (u8 *) & mp);
2694 vl_api_sw_interface_vhost_user_dump_t_handler
2695 (vl_api_sw_interface_vhost_user_dump_t * mp)
2698 vpe_api_main_t *am = &vpe_api_main;
2699 vnet_main_t *vnm = vnet_get_main ();
2700 vlib_main_t *vm = vlib_get_main ();
2701 vhost_user_intf_details_t *ifaces = NULL;
2702 vhost_user_intf_details_t *vuid = NULL;
2703 unix_shared_memory_queue_t *q;
2705 q = vl_api_client_index_to_input_queue (mp->client_index);
2709 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
2713 vec_foreach (vuid, ifaces)
2715 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
2721 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
2722 unix_shared_memory_queue_t * q,
2724 l2t_main_t * lm, u32 context)
2726 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
2728 vnet_sw_interface_t *si = NULL;
2730 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
2732 if_name = format (if_name, "%U",
2733 format_vnet_sw_interface_name, lm->vnet_main, si);
2735 mp = vl_msg_api_alloc (sizeof (*mp));
2736 memset (mp, 0, sizeof (*mp));
2737 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
2738 strncpy ((char *) mp->interface_name,
2739 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
2740 mp->sw_if_index = ntohl (si->sw_if_index);
2741 mp->local_session_id = s->local_session_id;
2742 mp->remote_session_id = s->remote_session_id;
2743 mp->local_cookie[0] = s->local_cookie[0];
2744 mp->local_cookie[1] = s->local_cookie[1];
2745 mp->remote_cookie = s->remote_cookie;
2746 clib_memcpy (mp->client_address, &s->client_address,
2747 sizeof (s->client_address));
2748 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
2749 mp->l2_sublayer_present = s->l2_sublayer_present;
2750 mp->context = context;
2752 vl_msg_api_send_shmem (q, (u8 *) & mp);
2757 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
2760 vpe_api_main_t *am = &vpe_api_main;
2761 l2t_main_t *lm = &l2t_main;
2762 unix_shared_memory_queue_t *q;
2763 l2t_session_t *session;
2765 q = vl_api_client_index_to_input_queue (mp->client_index);
2770 pool_foreach (session, lm->sessions,
2772 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
2778 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
2780 clib_warning ("BUG");
2784 send_l2fib_table_entry (vpe_api_main_t * am,
2785 unix_shared_memory_queue_t * q,
2786 l2fib_entry_key_t * l2fe_key,
2787 l2fib_entry_result_t * l2fe_res, u32 context)
2789 vl_api_l2_fib_table_entry_t *mp;
2791 mp = vl_msg_api_alloc (sizeof (*mp));
2792 memset (mp, 0, sizeof (*mp));
2793 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
2796 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
2798 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
2799 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
2800 mp->static_mac = l2fe_res->fields.static_mac;
2801 mp->filter_mac = l2fe_res->fields.filter;
2802 mp->bvi_mac = l2fe_res->fields.bvi;
2803 mp->context = context;
2805 vl_msg_api_send_shmem (q, (u8 *) & mp);
2809 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
2811 vpe_api_main_t *am = &vpe_api_main;
2812 bd_main_t *bdm = &bd_main;
2813 l2fib_entry_key_t *l2fe_key = NULL;
2814 l2fib_entry_result_t *l2fe_res = NULL;
2815 u32 ni, bd_id = ntohl (mp->bd_id);
2817 unix_shared_memory_queue_t *q;
2820 q = vl_api_client_index_to_input_queue (mp->client_index);
2824 /* see l2fib_table_dump: ~0 means "any" */
2829 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2836 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
2838 vec_foreach_index (ni, l2fe_key)
2840 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
2841 vec_elt_at_index (l2fe_res, ni), mp->context);
2843 vec_free (l2fe_key);
2844 vec_free (l2fe_res);
2848 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
2850 vl_api_show_version_reply_t *rmp;
2852 char *vpe_api_get_build_directory (void);
2853 char *vpe_api_get_version (void);
2854 char *vpe_api_get_build_date (void);
2856 unix_shared_memory_queue_t *q =
2857 vl_api_client_index_to_input_queue (mp->client_index);
2863 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
2865 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
2866 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
2867 ARRAY_LEN(rmp->build_directory)-1);
2868 strncpy ((char *) rmp->version, vpe_api_get_version(),
2869 ARRAY_LEN(rmp->version)-1);
2870 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
2871 ARRAY_LEN(rmp->build_date)-1);
2877 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
2879 vlib_main_t *vm = vlib_get_main ();
2880 vl_api_get_node_index_reply_t *rmp;
2883 u32 node_index = ~0;
2885 n = vlib_get_node_by_name (vm, mp->node_name);
2888 rv = VNET_API_ERROR_NO_SUCH_NODE;
2890 node_index = n->index;
2893 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
2895 rmp->node_index = ntohl(node_index);
2901 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
2903 vlib_main_t *vm = vlib_get_main ();
2904 vl_api_get_next_index_reply_t *rmp;
2905 vlib_node_t *node, *next_node;
2907 u32 next_node_index = ~0, next_index = ~0;
2910 node = vlib_get_node_by_name (vm, mp->node_name);
2914 rv = VNET_API_ERROR_NO_SUCH_NODE;
2918 next_node = vlib_get_node_by_name (vm, mp->next_name);
2922 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2926 next_node_index = next_node->index;
2928 p = hash_get (node->next_slot_by_node, next_node_index);
2932 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2940 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
2942 rmp->next_index = ntohl(next_index);
2948 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
2950 vlib_main_t *vm = vlib_get_main ();
2951 vl_api_add_node_next_reply_t *rmp;
2952 vlib_node_t *n, *next;
2954 u32 next_index = ~0;
2956 n = vlib_get_node_by_name (vm, mp->node_name);
2960 rv = VNET_API_ERROR_NO_SUCH_NODE;
2964 next = vlib_get_node_by_name (vm, mp->next_name);
2967 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2969 next_index = vlib_node_add_next (vm, n->index, next->index);
2973 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
2975 rmp->next_index = ntohl(next_index);
2980 static void vl_api_l2tpv3_create_tunnel_t_handler
2981 (vl_api_l2tpv3_create_tunnel_t * mp)
2983 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
2984 l2t_main_t *lm = &l2t_main;
2985 u32 sw_if_index = (u32) ~ 0;
2988 if (mp->is_ipv6 != 1)
2990 rv = VNET_API_ERROR_UNIMPLEMENTED;
2994 u32 encap_fib_index;
2996 if (mp->encap_vrf_id != ~0)
2999 ip6_main_t *im = &ip6_main;
3002 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
3004 rv = VNET_API_ERROR_NO_SUCH_FIB;
3007 encap_fib_index = p[0];
3011 encap_fib_index = ~0;
3014 rv = create_l2tpv3_ipv6_tunnel (lm,
3015 (ip6_address_t *) mp->client_address,
3016 (ip6_address_t *) mp->our_address,
3017 ntohl (mp->local_session_id),
3018 ntohl (mp->remote_session_id),
3019 clib_net_to_host_u64 (mp->local_cookie),
3020 clib_net_to_host_u64 (mp->remote_cookie),
3021 mp->l2_sublayer_present,
3022 encap_fib_index, &sw_if_index);
3026 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
3028 rmp->sw_if_index = ntohl (sw_if_index);
3033 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
3034 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
3036 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
3037 l2t_main_t *lm = &l2t_main;
3040 VALIDATE_SW_IF_INDEX (mp);
3042 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
3043 clib_net_to_host_u64 (mp->new_local_cookie),
3044 clib_net_to_host_u64
3045 (mp->new_remote_cookie));
3047 BAD_SW_IF_INDEX_LABEL;
3049 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
3052 static void vl_api_l2tpv3_interface_enable_disable_t_handler
3053 (vl_api_l2tpv3_interface_enable_disable_t * mp)
3056 vnet_main_t *vnm = vnet_get_main ();
3057 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
3059 VALIDATE_SW_IF_INDEX (mp);
3061 rv = l2tpv3_interface_enable_disable
3062 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
3064 BAD_SW_IF_INDEX_LABEL;
3066 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
3069 static void vl_api_l2tpv3_set_lookup_key_t_handler
3070 (vl_api_l2tpv3_set_lookup_key_t * mp)
3073 l2t_main_t *lm = &l2t_main;
3074 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
3076 if (mp->key > L2T_LOOKUP_SESSION_ID)
3078 rv = VNET_API_ERROR_INVALID_VALUE;
3082 lm->lookup_type = mp->key;
3085 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
3088 static void vl_api_vxlan_add_del_tunnel_t_handler
3089 (vl_api_vxlan_add_del_tunnel_t * mp)
3091 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
3093 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
3094 u32 encap_fib_index;
3096 ip4_main_t *im = &ip4_main;
3097 u32 sw_if_index = ~0;
3099 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
3102 rv = VNET_API_ERROR_NO_SUCH_FIB;
3105 encap_fib_index = p[0];
3106 memset (a, 0, sizeof (*a));
3108 a->is_add = mp->is_add;
3109 a->is_ip6 = mp->is_ipv6;
3111 /* ip addresses sent in network byte order */
3112 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
3113 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
3115 /* Check src & dst are different */
3116 if (ip46_address_cmp (&a->dst, &a->src) == 0)
3118 rv = VNET_API_ERROR_SAME_SRC_DST;
3121 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
3122 a->encap_fib_index = encap_fib_index;
3123 a->decap_next_index = ntohl (mp->decap_next_index);
3124 a->vni = ntohl (mp->vni);
3125 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
3129 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
3131 rmp->sw_if_index = ntohl (sw_if_index);
3136 static void send_vxlan_tunnel_details
3137 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
3139 vl_api_vxlan_tunnel_details_t *rmp;
3140 ip4_main_t *im4 = &ip4_main;
3141 ip6_main_t *im6 = &ip6_main;
3142 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
3144 rmp = vl_msg_api_alloc (sizeof (*rmp));
3145 memset (rmp, 0, sizeof (*rmp));
3146 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
3149 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
3150 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
3151 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
3155 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
3156 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
3157 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
3159 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
3160 rmp->vni = htonl (t->vni);
3161 rmp->decap_next_index = htonl (t->decap_next_index);
3162 rmp->sw_if_index = htonl (t->sw_if_index);
3163 rmp->is_ipv6 = is_ipv6;
3164 rmp->context = context;
3166 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3169 static void vl_api_vxlan_tunnel_dump_t_handler
3170 (vl_api_vxlan_tunnel_dump_t * mp)
3172 unix_shared_memory_queue_t *q;
3173 vxlan_main_t *vxm = &vxlan_main;
3177 q = vl_api_client_index_to_input_queue (mp->client_index);
3183 sw_if_index = ntohl (mp->sw_if_index);
3185 if (~0 == sw_if_index)
3188 pool_foreach (t, vxm->tunnels,
3190 send_vxlan_tunnel_details(t, q, mp->context);
3196 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
3197 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
3201 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
3202 send_vxlan_tunnel_details (t, q, mp->context);
3206 static void vl_api_gre_add_del_tunnel_t_handler
3207 (vl_api_gre_add_del_tunnel_t * mp)
3209 vl_api_gre_add_del_tunnel_reply_t *rmp;
3211 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
3214 ip4_main_t *im = &ip4_main;
3215 u32 sw_if_index = ~0;
3217 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
3220 rv = VNET_API_ERROR_NO_SUCH_FIB;
3223 outer_fib_id = p[0];
3225 /* Check src & dst are different */
3226 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
3227 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
3229 rv = VNET_API_ERROR_SAME_SRC_DST;
3232 memset (a, 0, sizeof (*a));
3234 a->is_add = mp->is_add;
3237 /* ip addresses sent in network byte order */
3238 clib_memcpy (&(a->src), mp->src_address, 4);
3239 clib_memcpy (&(a->dst), mp->dst_address, 4);
3241 a->outer_fib_id = outer_fib_id;
3242 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
3246 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
3248 rmp->sw_if_index = ntohl (sw_if_index);
3253 static void send_gre_tunnel_details
3254 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
3256 vl_api_gre_tunnel_details_t *rmp;
3257 ip4_main_t *im = &ip4_main;
3259 rmp = vl_msg_api_alloc (sizeof (*rmp));
3260 memset (rmp, 0, sizeof (*rmp));
3261 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
3262 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
3263 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
3264 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
3265 rmp->teb = (GRE_TUNNEL_TYPE_TEB == t->type);
3266 rmp->sw_if_index = htonl (t->sw_if_index);
3267 rmp->context = context;
3269 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3273 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
3275 unix_shared_memory_queue_t *q;
3276 gre_main_t *gm = &gre_main;
3280 q = vl_api_client_index_to_input_queue (mp->client_index);
3286 sw_if_index = ntohl (mp->sw_if_index);
3288 if (~0 == sw_if_index)
3291 pool_foreach (t, gm->tunnels,
3293 send_gre_tunnel_details(t, q, mp->context);
3299 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
3300 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
3304 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
3305 send_gre_tunnel_details (t, q, mp->context);
3310 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
3312 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
3314 vl_api_l2_patch_add_del_reply_t *rmp;
3315 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
3319 VALIDATE_RX_SW_IF_INDEX (mp);
3320 VALIDATE_TX_SW_IF_INDEX (mp);
3322 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
3323 ntohl (mp->tx_sw_if_index),
3324 (int) (mp->is_add != 0));
3326 BAD_RX_SW_IF_INDEX_LABEL;
3327 BAD_TX_SW_IF_INDEX_LABEL;
3329 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
3333 vl_api_vxlan_gpe_add_del_tunnel_t_handler
3334 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
3336 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
3338 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
3339 u32 encap_fib_index, decap_fib_index;
3342 ip4_main_t *im = &ip4_main;
3343 u32 sw_if_index = ~0;
3346 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
3349 rv = VNET_API_ERROR_NO_SUCH_FIB;
3352 encap_fib_index = p[0];
3354 protocol = mp->protocol;
3356 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
3357 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
3359 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
3362 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
3365 decap_fib_index = p[0];
3369 decap_fib_index = ntohl (mp->decap_vrf_id);
3372 /* Check src & dst are different */
3373 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
3374 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
3376 rv = VNET_API_ERROR_SAME_SRC_DST;
3379 memset (a, 0, sizeof (*a));
3381 a->is_add = mp->is_add;
3382 a->is_ip6 = mp->is_ipv6;
3383 /* ip addresses sent in network byte order */
3386 clib_memcpy (&(a->local.ip6), mp->local, 16);
3387 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
3391 clib_memcpy (&(a->local.ip4), mp->local, 4);
3392 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
3394 a->encap_fib_index = encap_fib_index;
3395 a->decap_fib_index = decap_fib_index;
3396 a->protocol = protocol;
3397 a->vni = ntohl (mp->vni);
3398 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
3402 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
3404 rmp->sw_if_index = ntohl (sw_if_index);
3409 static void send_vxlan_gpe_tunnel_details
3410 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
3412 vl_api_vxlan_gpe_tunnel_details_t *rmp;
3413 ip4_main_t *im4 = &ip4_main;
3414 ip6_main_t *im6 = &ip6_main;
3415 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
3417 rmp = vl_msg_api_alloc (sizeof (*rmp));
3418 memset (rmp, 0, sizeof (*rmp));
3419 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
3422 memcpy (rmp->local, &(t->local.ip6), 16);
3423 memcpy (rmp->remote, &(t->remote.ip6), 16);
3424 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
3425 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
3429 memcpy (rmp->local, &(t->local.ip4), 4);
3430 memcpy (rmp->remote, &(t->remote.ip4), 4);
3431 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
3432 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
3434 rmp->vni = htonl (t->vni);
3435 rmp->protocol = t->protocol;
3436 rmp->sw_if_index = htonl (t->sw_if_index);
3437 rmp->is_ipv6 = is_ipv6;
3438 rmp->context = context;
3440 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3443 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
3444 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
3446 unix_shared_memory_queue_t *q;
3447 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
3448 vxlan_gpe_tunnel_t *t;
3451 q = vl_api_client_index_to_input_queue (mp->client_index);
3457 sw_if_index = ntohl (mp->sw_if_index);
3459 if (~0 == sw_if_index)
3462 pool_foreach (t, vgm->tunnels,
3464 send_vxlan_gpe_tunnel_details(t, q, mp->context);
3470 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
3471 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
3475 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
3476 send_vxlan_gpe_tunnel_details (t, q, mp->context);
3480 /** Used for transferring locators via VPP API */
3482 typedef CLIB_PACKED (struct {
3483 u32 sw_if_index; /**< locator sw_if_index */
3484 u8 priority; /**< locator priority */
3485 u8 weight; /**< locator weight */
3490 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
3493 vl_api_lisp_add_del_locator_set_reply_t *rmp;
3495 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
3497 ls_locator_t *ls_loc;
3498 u32 ls_index = ~0, locator_num;
3499 u8 *locator_name = NULL;
3502 memset (a, 0, sizeof (a[0]));
3504 locator_name = format (0, "%s", mp->locator_set_name);
3506 a->name = locator_name;
3507 a->is_add = mp->is_add;
3509 locator_num = clib_net_to_host_u32 (mp->locator_num);
3511 memset (&locator, 0, sizeof (locator));
3512 for (i = 0; i < locator_num; i++)
3514 ls_loc = &((ls_locator_t *) mp->locators)[i];
3515 VALIDATE_SW_IF_INDEX (ls_loc);
3517 locator.sw_if_index = htonl (ls_loc->sw_if_index);
3518 locator.priority = ls_loc->priority;
3519 locator.weight = ls_loc->weight;
3521 vec_add1 (a->locators, locator);
3524 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
3526 BAD_SW_IF_INDEX_LABEL;
3528 vec_free (locator_name);
3529 vec_free (a->locators);
3532 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
3534 rmp->ls_index = clib_host_to_net_u32 (ls_index);
3540 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
3542 vl_api_lisp_add_del_locator_reply_t *rmp;
3544 locator_t locator, *locators = NULL;
3545 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
3547 u8 *locator_name = NULL;
3549 memset (&locator, 0, sizeof (locator));
3550 memset (a, 0, sizeof (a[0]));
3552 locator.sw_if_index = ntohl (mp->sw_if_index);
3553 locator.priority = mp->priority;
3554 locator.weight = mp->weight;
3556 vec_add1 (locators, locator);
3558 locator_name = format (0, "%s", mp->locator_set_name);
3560 a->name = locator_name;
3561 a->locators = locators;
3562 a->is_add = mp->is_add;
3565 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
3567 vec_free (locators);
3568 vec_free (locator_name);
3570 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
3574 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
3580 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3581 gid_address_ip_set (dst, src, IP4);
3582 gid_address_ippref_len (dst) = len;
3583 ip_prefix_normalize (&gid_address_ippref (dst));
3586 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3587 gid_address_ip_set (dst, src, IP6);
3588 gid_address_ippref_len (dst) = len;
3589 ip_prefix_normalize (&gid_address_ippref (dst));
3591 case 2: /* l2 mac */
3592 gid_address_type (dst) = GID_ADDR_MAC;
3593 clib_memcpy (&gid_address_mac (dst), src, 6);
3597 return VNET_API_ERROR_INVALID_VALUE;
3600 gid_address_vni (dst) = vni;
3606 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
3608 vl_api_lisp_add_del_local_eid_reply_t *rmp;
3609 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3611 gid_address_t _eid, *eid = &_eid;
3613 u32 locator_set_index = ~0, map_index = ~0;
3614 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
3615 u8 *name = NULL, *key = NULL;
3616 memset (a, 0, sizeof (a[0]));
3617 memset (eid, 0, sizeof (eid[0]));
3619 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3620 mp->eid_type, mp->eid, mp->prefix_len);
3624 name = format (0, "%s", mp->locator_set_name);
3625 p = hash_get_mem (lcm->locator_set_index_by_name, name);
3628 rv = VNET_API_ERROR_INVALID_VALUE;
3631 locator_set_index = p[0];
3634 key = format (0, "%s", mp->key);
3636 /* XXX treat batch configuration */
3637 a->is_add = mp->is_add;
3638 gid_address_copy (&a->eid, eid);
3639 a->locator_set_index = locator_set_index;
3642 a->key_id = clib_net_to_host_u16 (mp->key_id);
3644 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
3649 gid_address_free (&a->eid);
3651 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
3655 vl_api_lisp_eid_table_add_del_map_t_handler
3656 (vl_api_lisp_eid_table_add_del_map_t * mp)
3658 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
3660 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
3661 clib_net_to_host_u32 (mp->dp_table),
3662 mp->is_l2, mp->is_add);
3663 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
3665 /** Used for transferring locators via VPP API */
3667 typedef CLIB_PACKED (struct {
3668 u8 is_ip4; /**< is locator an IPv4 address */
3669 u8 priority; /**< locator priority */
3670 u8 weight; /**< locator weight */
3671 u8 addr[16]; /**< IPv4/IPv6 address */
3675 static locator_pair_t *
3676 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
3679 locator_pair_t *pairs = 0, pair;
3682 for (i = 0; i < rloc_num; i++)
3685 r = &((rloc_t *) lcl_locs)[i];
3686 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
3687 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
3689 /* remote locators */
3690 r = &((rloc_t *) rmt_locs)[i];
3691 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
3692 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
3694 pair.priority = r->priority;
3695 pair.weight = r->weight;
3697 vec_add1 (pairs, pair);
3703 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
3706 locator_t *locs = 0, loc;
3709 for (i = 0; i < rloc_num; i++)
3711 /* remote locators */
3712 r = &((rloc_t *) rmt_locs)[i];
3713 memset (&loc, 0, sizeof (loc));
3714 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
3716 loc.priority = r->priority;
3717 loc.weight = r->weight;
3719 vec_add1 (locs, loc);
3725 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
3726 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
3728 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
3729 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
3730 locator_pair_t *pairs = 0;
3733 memset (a, 0, sizeof (a[0]));
3735 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
3736 mp->rmt_eid, mp->rmt_len);
3737 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
3738 mp->lcl_eid, mp->lcl_len);
3740 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
3742 if (rv || 0 == pairs)
3745 a->is_add = mp->is_add;
3746 a->locator_pairs = pairs;
3747 a->dp_table = mp->dp_table;
3749 a->action = mp->action;
3751 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
3754 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
3758 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
3761 vl_api_lisp_add_del_map_server_reply_t *rmp;
3765 memset (&addr, 0, sizeof (addr));
3767 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
3768 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
3770 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
3774 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
3777 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
3779 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
3781 memset (a, 0, sizeof (a[0]));
3783 a->is_add = mp->is_add;
3784 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
3786 rv = vnet_lisp_add_del_map_resolver (a);
3788 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
3792 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
3795 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
3797 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
3799 a->is_en = mp->is_en;
3800 vnet_lisp_gpe_enable_disable (a);
3802 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
3806 vl_api_lisp_map_register_enable_disable_t_handler
3807 (vl_api_lisp_map_register_enable_disable_t * mp)
3809 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
3812 vnet_lisp_map_register_enable_disable (mp->is_enabled);
3813 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3817 vl_api_lisp_rloc_probe_enable_disable_t_handler
3818 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
3820 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
3823 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
3824 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3828 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
3830 vl_api_lisp_enable_disable_reply_t *rmp;
3833 vnet_lisp_enable_disable (mp->is_en);
3834 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3838 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
3840 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
3848 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
3852 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
3859 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
3863 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
3866 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
3870 vl_api_show_lisp_map_request_mode_t_handler
3871 (vl_api_show_lisp_map_request_mode_t * mp)
3874 vl_api_show_lisp_map_request_mode_reply_t *rmp;
3877 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
3879 rmp->mode = vnet_lisp_get_map_request_mode ();
3885 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
3887 vl_api_lisp_map_request_mode_reply_t *rmp;
3890 rv = vnet_lisp_set_map_request_mode (mp->mode);
3892 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
3896 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
3899 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
3903 ls_name = format (0, "%s", mp->ls_name);
3904 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
3907 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
3911 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
3912 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
3914 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
3916 u8 *locator_set_name = NULL;
3917 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
3919 locator_set_name = format (0, "%s", mp->locator_set_name);
3921 a->is_add = mp->is_add;
3922 a->locator_set_name = locator_set_name;
3924 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
3926 vec_free (locator_set_name);
3928 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
3932 vl_api_lisp_add_del_remote_mapping_t_handler
3933 (vl_api_lisp_add_del_remote_mapping_t * mp)
3935 locator_t *rlocs = 0;
3936 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
3938 gid_address_t _eid, *eid = &_eid;
3939 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
3941 memset (eid, 0, sizeof (eid[0]));
3943 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3944 mp->eid_type, mp->eid, mp->eid_len);
3948 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
3952 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
3953 gid_address_copy (&a->reid, eid);
3955 rv = vnet_lisp_add_del_adjacency (a);
3962 /* NOTE: for now this works as a static remote mapping, i.e.,
3963 * not authoritative and ttl infinite. */
3964 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
3965 mp->is_add, 1 /* is_static */ , 0);
3968 vnet_lisp_clear_all_remote_adjacencies ();
3973 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
3977 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
3979 vl_api_lisp_add_del_adjacency_reply_t *rmp;
3980 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
3983 memset (a, 0, sizeof (a[0]));
3985 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
3986 mp->eid_type, mp->leid, mp->leid_len);
3987 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
3988 mp->eid_type, mp->reid, mp->reid_len);
3993 a->is_add = mp->is_add;
3994 rv = vnet_lisp_add_del_adjacency (a);
3997 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
4001 send_lisp_locator_details (lisp_cp_main_t * lcm,
4003 unix_shared_memory_queue_t * q, u32 context)
4005 vl_api_lisp_locator_details_t *rmp;
4007 rmp = vl_msg_api_alloc (sizeof (*rmp));
4008 memset (rmp, 0, sizeof (*rmp));
4009 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
4010 rmp->context = context;
4012 rmp->local = loc->local;
4015 rmp->sw_if_index = ntohl (loc->sw_if_index);
4019 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
4020 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
4022 rmp->priority = loc->priority;
4023 rmp->weight = loc->weight;
4025 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4029 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
4032 unix_shared_memory_queue_t *q = 0;
4033 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4034 locator_set_t *lsit = 0;
4036 u32 ls_index = ~0, *locit = 0;
4039 q = vl_api_client_index_to_input_queue (mp->client_index);
4045 if (mp->is_index_set)
4046 ls_index = htonl (mp->ls_index);
4049 /* make sure we get a proper C-string */
4050 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
4051 ls_name = format (0, "%s", mp->ls_name);
4052 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
4058 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
4061 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
4063 vec_foreach (locit, lsit->locator_indices)
4065 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4066 send_lisp_locator_details (lcm, loc, q, mp->context);
4073 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
4074 locator_set_t * lsit,
4075 unix_shared_memory_queue_t * q,
4076 u32 context, u32 ls_index)
4078 vl_api_lisp_locator_set_details_t *rmp;
4081 rmp = vl_msg_api_alloc (sizeof (*rmp));
4082 memset (rmp, 0, sizeof (*rmp));
4083 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
4084 rmp->context = context;
4086 rmp->ls_index = htonl (ls_index);
4089 ASSERT (lsit->name != NULL);
4090 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
4091 vec_len (lsit->name));
4095 str = format (0, "<remote-%d>", ls_index);
4096 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
4100 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4104 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
4106 unix_shared_memory_queue_t *q = NULL;
4107 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4108 locator_set_t *lsit = NULL;
4111 q = vl_api_client_index_to_input_queue (mp->client_index);
4117 filter = mp->filter;
4119 pool_foreach (lsit, lcm->locator_set_pool,
4121 if (filter && !((1 == filter && lsit->local) ||
4122 (2 == filter && !lsit->local)))
4126 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
4127 lsit - lcm->locator_set_pool);
4133 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
4135 ASSERT (prefix_length);
4136 ip_prefix_t *ippref = &fid_addr_ippref (src);
4138 switch (fid_addr_type (src))
4140 case FID_ADDR_IP_PREF:
4141 if (ip_prefix_version (ippref) == IP4)
4142 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
4144 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
4145 prefix_length[0] = ip_prefix_len (ippref);
4149 prefix_length[0] = 0;
4150 clib_memcpy (dst, fid_addr_mac (src), 6);
4154 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
4160 fid_type_to_api_type (fid_address_t * fid)
4162 ip_prefix_t *ippref;
4164 switch (fid_addr_type (fid))
4166 case FID_ADDR_IP_PREF:
4167 ippref = &fid_addr_ippref (fid);
4168 if (ip_prefix_version (ippref) == IP4)
4170 else if (ip_prefix_version (ippref) == IP6)
4183 send_lisp_eid_table_details (mapping_t * mapit,
4184 unix_shared_memory_queue_t * q,
4185 u32 context, u8 filter)
4188 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4189 locator_set_t *ls = 0;
4190 vl_api_lisp_eid_table_details_t *rmp = NULL;
4191 gid_address_t *gid = NULL;
4193 ip_prefix_t *ip_prefix = NULL;
4197 case 0: /* all mappings */
4200 case 1: /* local only */
4204 case 2: /* remote only */
4209 clib_warning ("Filter error, unknown filter: %d", filter);
4214 ip_prefix = &gid_address_ippref (gid);
4215 mac = gid_address_mac (gid);
4217 rmp = vl_msg_api_alloc (sizeof (*rmp));
4218 memset (rmp, 0, sizeof (*rmp));
4219 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
4221 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
4222 if (vec_len (ls->locator_indices) == 0)
4223 rmp->locator_set_index = ~0;
4225 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
4227 rmp->is_local = mapit->local;
4228 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
4229 rmp->action = mapit->action;
4230 rmp->authoritative = mapit->authoritative;
4232 switch (gid_address_type (gid))
4234 case GID_ADDR_SRC_DST:
4235 rmp->is_src_dst = 1;
4236 fid = &gid_address_sd_src (gid);
4237 rmp->eid_type = fid_type_to_api_type (fid);
4238 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
4239 &rmp->seid_prefix_len);
4240 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
4241 &rmp->eid_prefix_len);
4243 case GID_ADDR_IP_PREFIX:
4244 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
4245 if (ip_prefix_version (ip_prefix) == IP4)
4247 rmp->eid_type = 0; /* ipv4 type */
4248 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
4249 sizeof (ip_prefix_v4 (ip_prefix)));
4253 rmp->eid_type = 1; /* ipv6 type */
4254 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
4255 sizeof (ip_prefix_v6 (ip_prefix)));
4259 rmp->eid_type = 2; /* l2 mac type */
4260 clib_memcpy (rmp->eid, mac, 6);
4265 rmp->context = context;
4266 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
4267 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
4268 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
4269 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4273 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
4276 unix_shared_memory_queue_t *q = NULL;
4277 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4278 mapping_t *mapit = NULL;
4279 gid_address_t _eid, *eid = &_eid;
4281 q = vl_api_client_index_to_input_queue (mp->client_index);
4289 memset (eid, 0, sizeof (*eid));
4291 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4292 mp->eid_type, mp->eid, mp->prefix_length);
4294 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
4295 if ((u32) ~ 0 == mi)
4298 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
4299 send_lisp_eid_table_details (mapit, q, mp->context,
4300 0 /* ignore filter */ );
4305 pool_foreach (mapit, lcm->mapping_pool,
4307 send_lisp_eid_table_details(mapit, q, mp->context,
4315 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
4316 unix_shared_memory_queue_t * q, u32 context)
4318 vl_api_lisp_gpe_tunnel_details_t *rmp;
4319 lisp_gpe_main_t *lgm = &lisp_gpe_main;
4321 rmp = vl_msg_api_alloc (sizeof (*rmp));
4322 memset (rmp, 0, sizeof (*rmp));
4323 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
4325 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
4327 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
4328 ip_address_copy_addr (rmp->source_ip,
4329 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
4330 ip_address_copy_addr (rmp->destination_ip,
4331 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
4333 rmp->encap_fib_id = htonl (0);
4334 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
4335 rmp->iid = htonl (lfe->key->vni);
4336 rmp->context = context;
4338 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4342 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
4344 unix_shared_memory_queue_t *q = NULL;
4345 lisp_gpe_main_t *lgm = &lisp_gpe_main;
4346 lisp_gpe_fwd_entry_t *lfe = NULL;
4348 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
4353 q = vl_api_client_index_to_input_queue (mp->client_index);
4360 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
4362 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
4368 send_lisp_map_server_details (ip_address_t * ip,
4369 unix_shared_memory_queue_t * q, u32 context)
4371 vl_api_lisp_map_server_details_t *rmp = NULL;
4373 rmp = vl_msg_api_alloc (sizeof (*rmp));
4374 memset (rmp, 0, sizeof (*rmp));
4375 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
4377 switch (ip_addr_version (ip))
4381 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
4382 sizeof (ip_addr_v4 (ip)));
4387 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
4388 sizeof (ip_addr_v6 (ip)));
4394 rmp->context = context;
4396 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4400 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
4402 unix_shared_memory_queue_t *q = NULL;
4403 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4406 q = vl_api_client_index_to_input_queue (mp->client_index);
4412 vec_foreach (mr, lcm->map_servers)
4414 send_lisp_map_server_details (&mr->address, q, mp->context);
4419 send_lisp_map_resolver_details (ip_address_t * ip,
4420 unix_shared_memory_queue_t * q, u32 context)
4422 vl_api_lisp_map_resolver_details_t *rmp = NULL;
4424 rmp = vl_msg_api_alloc (sizeof (*rmp));
4425 memset (rmp, 0, sizeof (*rmp));
4426 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
4428 switch (ip_addr_version (ip))
4432 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
4433 sizeof (ip_addr_v4 (ip)));
4438 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
4439 sizeof (ip_addr_v6 (ip)));
4445 rmp->context = context;
4447 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4451 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
4453 unix_shared_memory_queue_t *q = NULL;
4454 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4457 q = vl_api_client_index_to_input_queue (mp->client_index);
4463 vec_foreach (mr, lcm->map_resolvers)
4465 send_lisp_map_resolver_details (&mr->address, q, mp->context);
4470 send_eid_table_map_pair (hash_pair_t * p,
4471 unix_shared_memory_queue_t * q, u32 context)
4473 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
4475 rmp = vl_msg_api_alloc (sizeof (*rmp));
4476 memset (rmp, 0, sizeof (*rmp));
4477 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
4479 rmp->vni = clib_host_to_net_u32 (p->key);
4480 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
4481 rmp->context = context;
4482 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4486 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
4489 unix_shared_memory_queue_t *q = NULL;
4490 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4492 uword *vni_table = 0;
4494 q = vl_api_client_index_to_input_queue (mp->client_index);
4502 vni_table = lcm->bd_id_by_vni;
4506 vni_table = lcm->table_id_by_vni;
4510 hash_foreach_pair (p, vni_table,
4512 send_eid_table_map_pair (p, q, mp->context);
4518 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
4520 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
4522 rmp = vl_msg_api_alloc (sizeof (*rmp));
4523 memset (rmp, 0, sizeof (*rmp));
4524 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
4525 rmp->context = context;
4526 rmp->vni = clib_host_to_net_u32 (vni);
4527 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4531 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
4533 lisp_adjacency_t *adj;
4534 vl_api_lisp_adjacency_t a;
4535 u32 i, n = vec_len (adjs);
4537 for (i = 0; i < n; i++)
4539 adj = vec_elt_at_index (adjs, i);
4540 memset (&a, 0, sizeof (a));
4542 switch (gid_address_type (&adj->reid))
4544 case GID_ADDR_IP_PREFIX:
4545 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
4546 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
4547 if (gid_address_ip_version (&adj->reid) == IP4)
4549 a.eid_type = 0; /* ipv4 type */
4550 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
4551 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
4555 a.eid_type = 1; /* ipv6 type */
4556 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
4557 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
4561 a.eid_type = 2; /* l2 mac type */
4562 mac_copy (a.reid, gid_address_mac (&adj->reid));
4563 mac_copy (a.leid, gid_address_mac (&adj->leid));
4573 vl_api_show_lisp_rloc_probe_state_t_handler
4574 (vl_api_show_lisp_rloc_probe_state_t * mp)
4576 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
4580 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
4582 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
4588 vl_api_show_lisp_map_register_state_t_handler
4589 (vl_api_show_lisp_map_register_state_t * mp)
4591 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
4595 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
4597 rmp->is_enabled = vnet_lisp_map_register_state_get ();
4603 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
4605 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
4606 lisp_adjacency_t *adjs = 0;
4608 vl_api_lisp_adjacency_t a;
4610 u32 vni = clib_net_to_host_u32 (mp->vni);
4612 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
4613 size = vec_len (adjs) * sizeof (a);
4616 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
4618 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
4619 lisp_adjacency_copy (rmp->adjacencies, adjs);
4627 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
4632 unix_shared_memory_queue_t *q = 0;
4633 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4635 q = vl_api_client_index_to_input_queue (mp->client_index);
4642 hash_foreach_pair (p, lcm->table_id_by_vni,
4644 hash_set (vnis, p->key, 0);
4647 hash_foreach_pair (p, lcm->bd_id_by_vni,
4649 hash_set (vnis, p->key, 0);
4652 hash_foreach_pair (p, vnis,
4654 send_eid_table_vni (p->key, q, mp->context);
4662 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
4664 unix_shared_memory_queue_t *q = NULL;
4665 vl_api_show_lisp_status_reply_t *rmp = NULL;
4668 q = vl_api_client_index_to_input_queue (mp->client_index);
4675 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
4677 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
4678 rmp->feature_status = vnet_lisp_enable_disable_status ();
4684 vl_api_lisp_get_map_request_itr_rlocs_t_handler
4685 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
4687 unix_shared_memory_queue_t *q = NULL;
4688 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
4689 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4690 locator_set_t *loc_set = 0;
4694 q = vl_api_client_index_to_input_queue (mp->client_index);
4700 if (~0 == lcm->mreq_itr_rlocs)
4702 tmp_str = format (0, " ");
4707 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
4708 tmp_str = format (0, "%s", loc_set->name);
4712 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
4714 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
4715 ARRAY_LEN(rmp->locator_set_name) - 1);
4723 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
4725 unix_shared_memory_queue_t *q = NULL;
4726 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
4727 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4729 locator_set_t *ls = 0;
4733 q = vl_api_client_index_to_input_queue (mp->client_index);
4739 if (!lcm->lisp_pitr)
4741 tmp_str = format (0, "N/A");
4745 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
4746 if (~0 != m->locator_set_index)
4749 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
4750 tmp_str = format (0, "%s", ls->name);
4754 tmp_str = format (0, "N/A");
4757 vec_add1 (tmp_str, 0);
4760 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
4762 rmp->status = lcm->lisp_pitr;
4763 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
4764 ARRAY_LEN(rmp->locator_set_name) - 1);
4770 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
4773 vl_api_interface_name_renumber_reply_t *rmp;
4776 VALIDATE_SW_IF_INDEX (mp);
4778 rv = vnet_interface_name_renumber
4779 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
4781 BAD_SW_IF_INDEX_LABEL;
4783 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4787 arp_change_data_callback (u32 pool_index, u8 * new_mac,
4788 u32 sw_if_index, u32 address)
4790 vpe_api_main_t *am = &vpe_api_main;
4791 vlib_main_t *vm = am->vlib_main;
4792 vl_api_ip4_arp_event_t *event;
4793 static f64 arp_event_last_time;
4794 f64 now = vlib_time_now (vm);
4796 if (pool_is_free_index (am->arp_events, pool_index))
4799 event = pool_elt_at_index (am->arp_events, pool_index);
4801 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
4803 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
4807 if (sw_if_index == event->sw_if_index &&
4809 /* for BD case, also check IP address with 10 sec timeout */
4810 (address == event->address &&
4811 (now - arp_event_last_time) < 10.0)))
4816 arp_event_last_time = now;
4817 event->sw_if_index = sw_if_index;
4819 event->address = address;
4824 nd_change_data_callback (u32 pool_index, u8 * new_mac,
4825 u32 sw_if_index, ip6_address_t * address)
4827 vpe_api_main_t *am = &vpe_api_main;
4828 vlib_main_t *vm = am->vlib_main;
4829 vl_api_ip6_nd_event_t *event;
4830 static f64 nd_event_last_time;
4831 f64 now = vlib_time_now (vm);
4833 if (pool_is_free_index (am->nd_events, pool_index))
4836 event = pool_elt_at_index (am->nd_events, pool_index);
4839 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
4841 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
4845 if (sw_if_index == event->sw_if_index &&
4847 /* for BD case, also check IP address with 10 sec timeout */
4848 (ip6_address_is_equal (address,
4849 (ip6_address_t *) event->address) &&
4850 (now - nd_event_last_time) < 10.0)))
4855 nd_event_last_time = now;
4856 event->sw_if_index = sw_if_index;
4858 clib_memcpy (event->address, address, sizeof (event->address));
4863 arp_change_delete_callback (u32 pool_index, u8 * notused)
4865 vpe_api_main_t *am = &vpe_api_main;
4867 if (pool_is_free_index (am->arp_events, pool_index))
4870 pool_put_index (am->arp_events, pool_index);
4875 nd_change_delete_callback (u32 pool_index, u8 * notused)
4877 vpe_api_main_t *am = &vpe_api_main;
4879 if (pool_is_free_index (am->nd_events, pool_index))
4882 pool_put_index (am->nd_events, pool_index);
4887 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
4889 vpe_api_main_t *am = &vpe_api_main;
4890 vnet_main_t *vnm = vnet_get_main ();
4891 vl_api_want_ip4_arp_events_reply_t *rmp;
4892 vl_api_ip4_arp_event_t *event;
4895 if (mp->enable_disable)
4897 pool_get (am->arp_events, event);
4898 memset (event, 0, sizeof (*event));
4900 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
4901 event->client_index = mp->client_index;
4902 event->context = mp->context;
4903 event->address = mp->address;
4904 event->pid = mp->pid;
4905 if (mp->address == 0)
4908 rv = vnet_add_del_ip4_arp_change_event
4909 (vnm, arp_change_data_callback,
4910 mp->pid, &mp->address /* addr, in net byte order */ ,
4911 vpe_resolver_process_node.index,
4912 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
4916 rv = vnet_add_del_ip4_arp_change_event
4917 (vnm, arp_change_delete_callback,
4918 mp->pid, &mp->address /* addr, in net byte order */ ,
4919 vpe_resolver_process_node.index,
4920 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
4922 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4926 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
4928 vpe_api_main_t *am = &vpe_api_main;
4929 vnet_main_t *vnm = vnet_get_main ();
4930 vl_api_want_ip6_nd_events_reply_t *rmp;
4931 vl_api_ip6_nd_event_t *event;
4934 if (mp->enable_disable)
4936 pool_get (am->nd_events, event);
4937 memset (event, 0, sizeof (*event));
4939 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
4940 event->client_index = mp->client_index;
4941 event->context = mp->context;
4942 clib_memcpy (event->address, mp->address, 16);
4943 event->pid = mp->pid;
4944 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
4947 rv = vnet_add_del_ip6_nd_change_event
4948 (vnm, nd_change_data_callback,
4949 mp->pid, mp->address /* addr, in net byte order */ ,
4950 vpe_resolver_process_node.index,
4951 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
4955 rv = vnet_add_del_ip6_nd_change_event
4956 (vnm, nd_change_delete_callback,
4957 mp->pid, mp->address /* addr, in net byte order */ ,
4958 vpe_resolver_process_node.index,
4959 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
4961 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
4964 static void vl_api_input_acl_set_interface_t_handler
4965 (vl_api_input_acl_set_interface_t * mp)
4967 vlib_main_t *vm = vlib_get_main ();
4968 vl_api_input_acl_set_interface_reply_t *rmp;
4970 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4972 ip4_table_index = ntohl (mp->ip4_table_index);
4973 ip6_table_index = ntohl (mp->ip6_table_index);
4974 l2_table_index = ntohl (mp->l2_table_index);
4975 sw_if_index = ntohl (mp->sw_if_index);
4977 VALIDATE_SW_IF_INDEX (mp);
4979 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4980 ip6_table_index, l2_table_index, mp->is_add);
4982 BAD_SW_IF_INDEX_LABEL;
4984 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4987 static void vl_api_ipsec_spd_add_del_t_handler
4988 (vl_api_ipsec_spd_add_del_t * mp)
4991 clib_warning ("unimplemented");
4994 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
4995 vl_api_ipsec_spd_add_del_reply_t *rmp;
4999 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
5001 rv = VNET_API_ERROR_UNIMPLEMENTED;
5004 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5008 static void vl_api_ipsec_interface_add_del_spd_t_handler
5009 (vl_api_ipsec_interface_add_del_spd_t * mp)
5011 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5012 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
5014 u32 sw_if_index __attribute__ ((unused));
5015 u32 spd_id __attribute__ ((unused));
5017 sw_if_index = ntohl (mp->sw_if_index);
5018 spd_id = ntohl (mp->spd_id);
5020 VALIDATE_SW_IF_INDEX (mp);
5023 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
5025 rv = VNET_API_ERROR_UNIMPLEMENTED;
5028 BAD_SW_IF_INDEX_LABEL;
5030 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5033 static void vl_api_ipsec_spd_add_del_entry_t_handler
5034 (vl_api_ipsec_spd_add_del_entry_t * mp)
5036 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5037 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
5043 memset (&p, 0, sizeof (p));
5045 p.id = ntohl (mp->spd_id);
5046 p.priority = ntohl (mp->priority);
5047 p.is_outbound = mp->is_outbound;
5048 p.is_ipv6 = mp->is_ipv6;
5050 if (mp->is_ipv6 || mp->is_ip_any)
5052 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
5053 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
5054 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
5055 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
5059 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5060 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5061 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
5062 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5064 p.protocol = mp->protocol;
5065 p.rport.start = ntohs (mp->remote_port_start);
5066 p.rport.stop = ntohs (mp->remote_port_stop);
5067 p.lport.start = ntohs (mp->local_port_start);
5068 p.lport.stop = ntohs (mp->local_port_stop);
5069 /* policy action resolve unsupported */
5070 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
5072 clib_warning ("unsupported action: 'resolve'");
5073 rv = VNET_API_ERROR_UNIMPLEMENTED;
5076 p.policy = mp->policy;
5077 p.sa_id = ntohl (mp->sa_id);
5079 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5086 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5089 rv = VNET_API_ERROR_UNIMPLEMENTED;
5094 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5097 static void vl_api_ipsec_sad_add_del_entry_t_handler
5098 (vl_api_ipsec_sad_add_del_entry_t * mp)
5100 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5101 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
5106 memset (&sa, 0, sizeof (sa));
5108 sa.id = ntohl (mp->sad_id);
5109 sa.spi = ntohl (mp->spi);
5110 /* security protocol AH unsupported */
5111 if (mp->protocol == IPSEC_PROTOCOL_AH)
5113 clib_warning ("unsupported security protocol 'AH'");
5114 rv = VNET_API_ERROR_UNIMPLEMENTED;
5117 sa.protocol = mp->protocol;
5118 /* check for unsupported crypto-alg */
5119 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5120 mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
5122 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5123 mp->crypto_algorithm);
5124 rv = VNET_API_ERROR_UNIMPLEMENTED;
5127 sa.crypto_alg = mp->crypto_algorithm;
5128 sa.crypto_key_len = mp->crypto_key_length;
5129 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
5130 /* check for unsupported integ-alg */
5132 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_NONE ||
5134 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5136 mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
5138 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5139 mp->integrity_algorithm);
5140 rv = VNET_API_ERROR_UNIMPLEMENTED;
5145 /*Special cases, aes-gcm-128 encryption */
5146 if (mp->crypto_algorithm == IPSEC_CRYPTO_ALG_AES_GCM_128)
5148 if (mp->integrity_algorithm != IPSEC_INTEG_ALG_NONE
5149 && mp->integrity_algorithm != IPSEC_INTEG_ALG_AES_GCM_128)
5152 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
5153 rv = VNET_API_ERROR_UNIMPLEMENTED;
5156 else /*set integ-alg internally to aes-gcm-128 */
5157 mp->integrity_algorithm = IPSEC_INTEG_ALG_AES_GCM_128;
5159 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_AES_GCM_128)
5161 clib_warning ("unsupported integ-alg: aes-gcm-128");
5162 rv = VNET_API_ERROR_UNIMPLEMENTED;
5165 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_NONE)
5167 clib_warning ("unsupported integ-alg: none");
5168 rv = VNET_API_ERROR_UNIMPLEMENTED;
5173 sa.integ_alg = mp->integrity_algorithm;
5174 sa.integ_key_len = mp->integrity_key_length;
5175 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
5176 sa.use_esn = mp->use_extended_sequence_number;
5177 sa.is_tunnel = mp->is_tunnel;
5178 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5179 if (sa.is_tunnel_ip6)
5181 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5182 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5186 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
5187 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
5190 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
5192 rv = VNET_API_ERROR_UNIMPLEMENTED;
5197 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5201 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
5203 vl_api_ikev2_profile_add_del_reply_t *rmp;
5207 vlib_main_t *vm = vlib_get_main ();
5208 clib_error_t *error;
5209 u8 *tmp = format (0, "%s", mp->name);
5210 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
5213 rv = VNET_API_ERROR_UNSPECIFIED;
5215 rv = VNET_API_ERROR_UNIMPLEMENTED;
5218 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5222 vl_api_ikev2_profile_set_auth_t_handler
5223 (vl_api_ikev2_profile_set_auth_t * mp)
5225 vl_api_ikev2_profile_set_auth_reply_t *rmp;
5229 vlib_main_t *vm = vlib_get_main ();
5230 clib_error_t *error;
5231 u8 *tmp = format (0, "%s", mp->name);
5232 u8 *data = vec_new (u8, mp->data_len);
5233 clib_memcpy (data, mp->data, mp->data_len);
5234 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
5238 rv = VNET_API_ERROR_UNSPECIFIED;
5240 rv = VNET_API_ERROR_UNIMPLEMENTED;
5243 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5247 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
5249 vl_api_ikev2_profile_add_del_reply_t *rmp;
5253 vlib_main_t *vm = vlib_get_main ();
5254 clib_error_t *error;
5255 u8 *tmp = format (0, "%s", mp->name);
5256 u8 *data = vec_new (u8, mp->data_len);
5257 clib_memcpy (data, mp->data, mp->data_len);
5258 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
5262 rv = VNET_API_ERROR_UNSPECIFIED;
5264 rv = VNET_API_ERROR_UNIMPLEMENTED;
5267 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5271 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
5273 vl_api_ikev2_profile_set_ts_reply_t *rmp;
5277 vlib_main_t *vm = vlib_get_main ();
5278 clib_error_t *error;
5279 u8 *tmp = format (0, "%s", mp->name);
5280 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
5281 mp->end_port, (ip4_address_t) mp->start_addr,
5282 (ip4_address_t) mp->end_addr, mp->is_local);
5285 rv = VNET_API_ERROR_UNSPECIFIED;
5287 rv = VNET_API_ERROR_UNIMPLEMENTED;
5290 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5294 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
5296 vl_api_ikev2_profile_set_ts_reply_t *rmp;
5300 vlib_main_t *vm = vlib_get_main ();
5301 clib_error_t *error;
5303 error = ikev2_set_local_key (vm, mp->key_file);
5305 rv = VNET_API_ERROR_UNSPECIFIED;
5307 rv = VNET_API_ERROR_UNIMPLEMENTED;
5310 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5314 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
5316 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5317 vl_api_ipsec_sa_set_key_reply_t *rmp;
5321 sa.id = ntohl (mp->sa_id);
5322 sa.crypto_key_len = mp->crypto_key_length;
5323 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
5324 sa.integ_key_len = mp->integrity_key_length;
5325 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
5327 rv = ipsec_set_sa_key (vm, &sa);
5329 rv = VNET_API_ERROR_UNIMPLEMENTED;
5332 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
5335 static void vl_api_cop_interface_enable_disable_t_handler
5336 (vl_api_cop_interface_enable_disable_t * mp)
5338 vl_api_cop_interface_enable_disable_reply_t *rmp;
5340 u32 sw_if_index = ntohl (mp->sw_if_index);
5343 VALIDATE_SW_IF_INDEX (mp);
5345 enable_disable = (int) mp->enable_disable;
5347 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5349 BAD_SW_IF_INDEX_LABEL;
5351 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5354 static void vl_api_cop_whitelist_enable_disable_t_handler
5355 (vl_api_cop_whitelist_enable_disable_t * mp)
5357 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
5358 cop_whitelist_enable_disable_args_t _a, *a = &_a;
5359 u32 sw_if_index = ntohl (mp->sw_if_index);
5362 VALIDATE_SW_IF_INDEX (mp);
5364 a->sw_if_index = sw_if_index;
5367 a->default_cop = mp->default_cop;
5368 a->fib_id = ntohl (mp->fib_id);
5370 rv = cop_whitelist_enable_disable (a);
5372 BAD_SW_IF_INDEX_LABEL;
5374 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5378 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
5382 api_main_t *am = &api_main;
5383 vlib_main_t *vm = vlib_get_main ();
5385 vl_api_get_node_graph_reply_t *rmp;
5387 pthread_mutex_lock (&am->vlib_rp->mutex);
5388 oldheap = svm_push_data_heap (am->vlib_rp);
5391 * Keep the number of memcpy ops to a minimum (e.g. 1).
5393 vec_validate (vector, 16384);
5394 vec_reset_length (vector);
5397 vector = vlib_node_serialize (&vm->node_main, vector,
5398 (u32) ~ 0 /* all threads */ ,
5399 1 /* include nexts */ ,
5400 1 /* include stats */ );
5402 svm_pop_heap (oldheap);
5403 pthread_mutex_unlock (&am->vlib_rp->mutex);
5406 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5408 rmp->reply_in_shmem = (uword) vector;
5414 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
5417 vl_api_ioam_enable_reply_t *rmp;
5418 clib_error_t *error;
5420 /* Ignoring the profile id as currently a single profile
5422 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
5423 mp->seqno, mp->analyse);
5426 clib_error_report (error);
5427 rv = clib_error_get_code (error);
5430 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
5434 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
5437 vl_api_ioam_disable_reply_t *rmp;
5438 clib_error_t *error;
5440 error = clear_ioam_rewrite_fn ();
5443 clib_error_report (error);
5444 rv = clib_error_get_code (error);
5447 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
5451 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
5453 vlib_main_t *vm = vlib_get_main ();
5454 vl_api_af_packet_create_reply_t *rmp;
5456 u8 *host_if_name = NULL;
5459 host_if_name = format (0, "%s", mp->host_if_name);
5460 vec_add1 (host_if_name, 0);
5462 rv = af_packet_create_if (vm, host_if_name,
5463 mp->use_random_hw_addr ? 0 : mp->hw_addr,
5466 vec_free (host_if_name);
5469 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
5471 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
5477 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
5479 vlib_main_t *vm = vlib_get_main ();
5480 vl_api_af_packet_delete_reply_t *rmp;
5482 u8 *host_if_name = NULL;
5484 host_if_name = format (0, "%s", mp->host_if_name);
5485 vec_add1 (host_if_name, 0);
5487 rv = af_packet_delete_if (vm, host_if_name);
5489 vec_free (host_if_name);
5491 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
5495 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
5497 vlib_main_t *vm = vlib_get_main ();
5498 vl_api_policer_add_del_reply_t *rmp;
5501 sse2_qos_pol_cfg_params_st cfg;
5502 clib_error_t *error;
5505 name = format (0, "%s", mp->name);
5507 memset (&cfg, 0, sizeof (cfg));
5509 cfg.rnd_type = mp->round_type;
5510 cfg.rate_type = mp->rate_type;
5511 cfg.rb.kbps.cir_kbps = mp->cir;
5512 cfg.rb.kbps.eir_kbps = mp->eir;
5513 cfg.rb.kbps.cb_bytes = mp->cb;
5514 cfg.rb.kbps.eb_bytes = mp->eb;
5515 cfg.conform_action.action_type = mp->conform_action_type;
5516 cfg.conform_action.dscp = mp->conform_dscp;
5517 cfg.exceed_action.action_type = mp->exceed_action_type;
5518 cfg.exceed_action.dscp = mp->exceed_dscp;
5519 cfg.violate_action.action_type = mp->violate_action_type;
5520 cfg.violate_action.dscp = mp->violate_dscp;
5521 cfg.color_aware = mp->color_aware;
5523 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
5526 rv = VNET_API_ERROR_UNSPECIFIED;
5529 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
5531 if (rv == 0 && mp->is_add)
5532 rmp->policer_index = ntohl(policer_index);
5534 rmp->policer_index = ~0;
5540 send_policer_details (u8 * name,
5541 sse2_qos_pol_cfg_params_st * config,
5542 policer_read_response_type_st * templ,
5543 unix_shared_memory_queue_t * q, u32 context)
5545 vl_api_policer_details_t *mp;
5547 mp = vl_msg_api_alloc (sizeof (*mp));
5548 memset (mp, 0, sizeof (*mp));
5549 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
5550 mp->context = context;
5551 mp->cir = htonl (config->rb.kbps.cir_kbps);
5552 mp->eir = htonl (config->rb.kbps.eir_kbps);
5553 mp->cb = htonl (config->rb.kbps.cb_bytes);
5554 mp->eb = htonl (config->rb.kbps.eb_bytes);
5555 mp->rate_type = config->rate_type;
5556 mp->round_type = config->rnd_type;
5557 mp->type = config->rfc;
5558 mp->conform_action_type = config->conform_action.action_type;
5559 mp->conform_dscp = config->conform_action.dscp;
5560 mp->exceed_action_type = config->exceed_action.action_type;
5561 mp->exceed_dscp = config->exceed_action.dscp;
5562 mp->violate_action_type = config->violate_action.action_type;
5563 mp->violate_dscp = config->violate_action.dscp;
5564 mp->single_rate = templ->single_rate ? 1 : 0;
5565 mp->color_aware = templ->color_aware ? 1 : 0;
5566 mp->scale = htonl (templ->scale);
5567 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
5568 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
5569 mp->current_limit = htonl (templ->current_limit);
5570 mp->current_bucket = htonl (templ->current_bucket);
5571 mp->extended_limit = htonl (templ->extended_limit);
5572 mp->extended_bucket = htonl (templ->extended_bucket);
5573 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
5575 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
5577 vl_msg_api_send_shmem (q, (u8 *) & mp);
5581 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
5583 unix_shared_memory_queue_t *q;
5584 vnet_policer_main_t *pm = &vnet_policer_main;
5590 sse2_qos_pol_cfg_params_st *config;
5591 policer_read_response_type_st *templ;
5593 q = vl_api_client_index_to_input_queue (mp->client_index);
5597 if (mp->match_name_valid)
5599 match_name = format (0, "%s%c", mp->match_name, 0);
5602 if (mp->match_name_valid)
5604 p = hash_get_mem (pm->policer_config_by_name, match_name);
5608 config = pool_elt_at_index (pm->configs, pool_index);
5609 templ = pool_elt_at_index (pm->policer_templates, pool_index);
5610 send_policer_details (match_name, config, templ, q, mp->context);
5616 hash_foreach_pair (hp, pm->policer_config_by_name,
5618 name = (u8 *) hp->key;
5619 pool_index = hp->value[0];
5620 config = pool_elt_at_index (pm->configs, pool_index);
5621 templ = pool_elt_at_index (pm->policer_templates, pool_index);
5622 send_policer_details(name, config, templ, q, mp->context);
5629 vl_api_policer_classify_set_interface_t_handler
5630 (vl_api_policer_classify_set_interface_t * mp)
5632 vlib_main_t *vm = vlib_get_main ();
5633 vl_api_policer_classify_set_interface_reply_t *rmp;
5635 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5637 ip4_table_index = ntohl (mp->ip4_table_index);
5638 ip6_table_index = ntohl (mp->ip6_table_index);
5639 l2_table_index = ntohl (mp->l2_table_index);
5640 sw_if_index = ntohl (mp->sw_if_index);
5642 VALIDATE_SW_IF_INDEX (mp);
5644 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
5645 ip6_table_index, l2_table_index,
5648 BAD_SW_IF_INDEX_LABEL;
5650 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
5654 send_policer_classify_details (u32 sw_if_index,
5656 unix_shared_memory_queue_t * q, u32 context)
5658 vl_api_policer_classify_details_t *mp;
5660 mp = vl_msg_api_alloc (sizeof (*mp));
5661 memset (mp, 0, sizeof (*mp));
5662 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
5663 mp->context = context;
5664 mp->sw_if_index = htonl (sw_if_index);
5665 mp->table_index = htonl (table_index);
5667 vl_msg_api_send_shmem (q, (u8 *) & mp);
5671 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
5673 unix_shared_memory_queue_t *q;
5674 policer_classify_main_t *pcm = &policer_classify_main;
5678 q = vl_api_client_index_to_input_queue (mp->client_index);
5682 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
5684 if (vec_len (vec_tbl))
5686 for (i = 0; i < vec_len (vec_tbl); i++)
5688 if (vec_elt (vec_tbl, i) == ~0)
5691 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
5698 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
5700 vlib_main_t *vm = vlib_get_main ();
5701 vl_api_netmap_create_reply_t *rmp;
5705 if_name = format (0, "%s", mp->netmap_if_name);
5706 vec_add1 (if_name, 0);
5709 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
5710 mp->is_pipe, mp->is_master, 0);
5714 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
5718 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
5720 vlib_main_t *vm = vlib_get_main ();
5721 vl_api_netmap_delete_reply_t *rmp;
5725 if_name = format (0, "%s", mp->netmap_if_name);
5726 vec_add1 (if_name, 0);
5728 rv = netmap_delete_if (vm, if_name);
5732 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
5736 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_fib_details_t * mp)
5738 clib_warning ("BUG");
5741 typedef struct mpls_tunnel_send_walk_ctx_t_
5743 unix_shared_memory_queue_t *q;
5746 } mpls_tunnel_send_walk_ctx_t;
5749 send_mpls_tunnel_entry (u32 mti, void *arg)
5751 mpls_tunnel_send_walk_ctx_t *ctx;
5752 vl_api_mpls_tunnel_details_t *mp;
5753 const mpls_tunnel_t *mt;
5758 if (~0 != ctx->index && mti != ctx->index)
5761 mt = mpls_tunnel_get (mti);
5762 nlabels = vec_len (mt->mt_label_stack);
5764 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
5765 memset (mp, 0, sizeof (*mp));
5766 mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
5767 mp->context = ctx->context;
5769 mp->tunnel_index = ntohl (mti);
5770 memcpy (mp->mt_next_hop_out_labels,
5771 mt->mt_label_stack, nlabels * sizeof (u32));
5775 vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
5779 vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
5781 unix_shared_memory_queue_t *q;
5783 q = vl_api_client_index_to_input_queue (mp->client_index);
5787 mpls_tunnel_send_walk_ctx_t ctx = {
5789 .index = ntohl (mp->tunnel_index),
5790 .context = mp->context,
5792 mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
5796 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
5798 clib_warning ("BUG");
5802 vl_api_mpls_fib_details_t_endian (vl_api_mpls_fib_details_t * mp)
5804 clib_warning ("BUG");
5808 vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp)
5810 clib_warning ("BUG");
5814 send_mpls_fib_details (vpe_api_main_t * am,
5815 unix_shared_memory_queue_t * q,
5816 u32 table_id, u32 label, u32 eos,
5817 fib_route_path_encode_t * api_rpaths, u32 context)
5819 vl_api_mpls_fib_details_t *mp;
5820 fib_route_path_encode_t *api_rpath;
5821 vl_api_fib_path2_t *fp;
5824 path_count = vec_len (api_rpaths);
5825 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
5828 memset (mp, 0, sizeof (*mp));
5829 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
5830 mp->context = context;
5832 mp->table_id = htonl (table_id);
5834 mp->label = htonl (label);
5836 mp->count = htonl (path_count);
5838 vec_foreach (api_rpath, api_rpaths)
5840 memset (fp, 0, sizeof (*fp));
5841 fp->weight = htonl (api_rpath->rpath.frp_weight);
5842 fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
5843 copy_fib_next_hop (api_rpath, fp);
5847 vl_msg_api_send_shmem (q, (u8 *) & mp);
5851 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
5853 vpe_api_main_t *am = &vpe_api_main;
5854 unix_shared_memory_queue_t *q;
5855 mpls_main_t *mm = &mpls_main;
5856 fib_table_t *fib_table;
5857 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
5861 fib_route_path_encode_t *api_rpaths;
5863 q = vl_api_client_index_to_input_queue (mp->client_index);
5868 pool_foreach (fib_table, mm->fibs,
5870 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
5872 vec_add1(lfeis, lfei);
5875 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
5877 vec_foreach(lfeip, lfeis)
5879 fib_entry_get_prefix(*lfeip, &pfx);
5880 fib_index = fib_entry_get_fib_index(*lfeip);
5881 fib_table = fib_table_get(fib_index, pfx.fp_proto);
5883 fib_entry_encode(*lfeip, &api_rpaths);
5884 send_mpls_fib_details (am, q,
5885 fib_table->ft_table_id,
5890 vec_free(api_rpaths);
5897 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
5899 unix_shared_memory_queue_t *q;
5901 q = vl_api_client_index_to_input_queue (mp->client_index);
5905 vnet_classify_main_t *cm = &vnet_classify_main;
5906 vnet_classify_table_t *t;
5911 pool_foreach (t, cm->tables,
5913 vec_add1 (table_ids, ntohl(t - cm->tables));
5916 count = vec_len (table_ids);
5918 vl_api_classify_table_ids_reply_t *rmp;
5919 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
5920 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
5921 rmp->context = mp->context;
5922 rmp->count = ntohl (count);
5923 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
5926 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5928 vec_free (table_ids);
5932 vl_api_classify_table_by_interface_t_handler
5933 (vl_api_classify_table_by_interface_t * mp)
5935 vl_api_classify_table_by_interface_reply_t *rmp;
5938 u32 sw_if_index = ntohl (mp->sw_if_index);
5941 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
5944 VALIDATE_SW_IF_INDEX (mp);
5946 input_acl_main_t *am = &input_acl_main;
5951 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
5953 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
5954 if (vec_len (vec_tbl))
5956 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
5958 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
5962 acl[type] = vec_elt (vec_tbl, if_idx);
5967 BAD_SW_IF_INDEX_LABEL;
5970 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
5972 rmp->sw_if_index = ntohl(sw_if_index);
5973 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
5974 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
5975 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
5982 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
5984 unix_shared_memory_queue_t *q;
5986 q = vl_api_client_index_to_input_queue (mp->client_index);
5990 vl_api_classify_table_info_reply_t *rmp = 0;
5992 vnet_classify_main_t *cm = &vnet_classify_main;
5993 u32 table_id = ntohl (mp->table_id);
5994 vnet_classify_table_t *t;
5997 pool_foreach (t, cm->tables,
5999 if (table_id == t - cm->tables)
6001 rmp = vl_msg_api_alloc_as_if_client
6002 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
6003 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
6004 rmp->context = mp->context;
6005 rmp->table_id = ntohl(table_id);
6006 rmp->nbuckets = ntohl(t->nbuckets);
6007 rmp->match_n_vectors = ntohl(t->match_n_vectors);
6008 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
6009 rmp->active_sessions = ntohl(t->active_elements);
6010 rmp->next_table_index = ntohl(t->next_table_index);
6011 rmp->miss_next_index = ntohl(t->miss_next_index);
6012 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
6013 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
6022 rmp = vl_msg_api_alloc (sizeof (*rmp));
6023 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
6024 rmp->context = mp->context;
6025 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
6028 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6032 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
6035 clib_warning ("BUG");
6039 send_classify_session_details (unix_shared_memory_queue_t * q,
6042 vnet_classify_entry_t * e, u32 context)
6044 vl_api_classify_session_details_t *rmp;
6046 rmp = vl_msg_api_alloc (sizeof (*rmp));
6047 memset (rmp, 0, sizeof (*rmp));
6048 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
6049 rmp->context = context;
6050 rmp->table_id = ntohl (table_id);
6051 rmp->hit_next_index = ntohl (e->next_index);
6052 rmp->advance = ntohl (e->advance);
6053 rmp->opaque_index = ntohl (e->opaque_index);
6054 rmp->match_length = ntohl (match_length);
6055 clib_memcpy (rmp->match, e->key, match_length);
6057 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6061 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
6063 vnet_classify_main_t *cm = &vnet_classify_main;
6064 unix_shared_memory_queue_t *q;
6066 u32 table_id = ntohl (mp->table_id);
6067 vnet_classify_table_t *t;
6069 q = vl_api_client_index_to_input_queue (mp->client_index);
6074 pool_foreach (t, cm->tables,
6076 if (table_id == t - cm->tables)
6078 vnet_classify_bucket_t * b;
6079 vnet_classify_entry_t * v, * save_v;
6082 for (i = 0; i < t->nbuckets; i++)
6084 b = &t->buckets [i];
6088 save_v = vnet_classify_get_entry (t, b->offset);
6089 for (j = 0; j < (1<<b->log2_pages); j++)
6091 for (k = 0; k < t->entries_per_page; k++)
6093 v = vnet_classify_entry_at_index
6094 (t, save_v, j*t->entries_per_page + k);
6095 if (vnet_classify_entry_is_free (v))
6098 send_classify_session_details
6099 (q, table_id, t->match_n_vectors * sizeof (u32x4),
6111 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
6113 vlib_main_t *vm = vlib_get_main ();
6114 flow_report_main_t *frm = &flow_report_main;
6115 vl_api_set_ipfix_exporter_reply_t *rmp;
6116 ip4_address_t collector, src;
6117 u16 collector_port = UDP_DST_PORT_ipfix;
6119 u32 template_interval;
6125 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
6126 collector_port = ntohs (mp->collector_port);
6127 if (collector_port == (u16) ~ 0)
6128 collector_port = UDP_DST_PORT_ipfix;
6129 memcpy (src.data, mp->src_address, sizeof (src.data));
6130 fib_id = ntohl (mp->vrf_id);
6132 ip4_main_t *im = &ip4_main;
6139 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
6142 rv = VNET_API_ERROR_NO_SUCH_FIB;
6148 path_mtu = ntohl (mp->path_mtu);
6150 path_mtu = 512; // RFC 7011 section 10.3.3.
6151 template_interval = ntohl (mp->template_interval);
6152 if (template_interval == ~0)
6153 template_interval = 20;
6154 udp_checksum = mp->udp_checksum;
6156 if (collector.as_u32 == 0)
6158 rv = VNET_API_ERROR_INVALID_VALUE;
6162 if (src.as_u32 == 0)
6164 rv = VNET_API_ERROR_INVALID_VALUE;
6168 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
6170 rv = VNET_API_ERROR_INVALID_VALUE;
6176 rv = VNET_API_ERROR_INVALID_VALUE;
6180 /* Reset report streams if we are reconfiguring IP addresses */
6181 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
6182 frm->src_address.as_u32 != src.as_u32 ||
6183 frm->collector_port != collector_port)
6184 vnet_flow_reports_reset (frm);
6186 frm->ipfix_collector.as_u32 = collector.as_u32;
6187 frm->collector_port = collector_port;
6188 frm->src_address.as_u32 = src.as_u32;
6189 frm->fib_index = fib_index;
6190 frm->path_mtu = path_mtu;
6191 frm->template_interval = template_interval;
6192 frm->udp_checksum = udp_checksum;
6194 /* Turn on the flow reporting process */
6195 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
6198 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
6202 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
6204 flow_report_main_t *frm = &flow_report_main;
6205 unix_shared_memory_queue_t *q;
6206 vl_api_ipfix_exporter_details_t *rmp;
6207 ip4_main_t *im = &ip4_main;
6210 q = vl_api_client_index_to_input_queue (mp->client_index);
6214 rmp = vl_msg_api_alloc (sizeof (*rmp));
6215 memset (rmp, 0, sizeof (*rmp));
6216 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
6217 rmp->context = mp->context;
6218 memcpy (rmp->collector_address, frm->ipfix_collector.data,
6219 sizeof (frm->ipfix_collector.data));
6220 rmp->collector_port = htons (frm->collector_port);
6221 memcpy (rmp->src_address, frm->src_address.data,
6222 sizeof (frm->src_address.data));
6223 if (frm->fib_index == ~0)
6226 vrf_id = im->fibs[frm->fib_index].ft_table_id;
6227 rmp->vrf_id = htonl (vrf_id);
6228 rmp->path_mtu = htonl (frm->path_mtu);
6229 rmp->template_interval = htonl (frm->template_interval);
6230 rmp->udp_checksum = (frm->udp_checksum != 0);
6232 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6236 vl_api_set_ipfix_classify_stream_t_handler
6237 (vl_api_set_ipfix_classify_stream_t * mp)
6239 vl_api_set_ipfix_classify_stream_reply_t *rmp;
6240 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6241 flow_report_main_t *frm = &flow_report_main;
6243 u32 src_port = UDP_DST_PORT_ipfix;
6246 domain_id = ntohl (mp->domain_id);
6247 src_port = ntohs (mp->src_port);
6249 if (fcm->src_port != 0 &&
6250 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
6252 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
6253 domain_id, (u16) src_port);
6257 fcm->domain_id = domain_id;
6258 fcm->src_port = (u16) src_port;
6260 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
6264 vl_api_ipfix_classify_stream_dump_t_handler
6265 (vl_api_ipfix_classify_stream_dump_t * mp)
6267 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6268 unix_shared_memory_queue_t *q;
6269 vl_api_ipfix_classify_stream_details_t *rmp;
6271 q = vl_api_client_index_to_input_queue (mp->client_index);
6275 rmp = vl_msg_api_alloc (sizeof (*rmp));
6276 memset (rmp, 0, sizeof (*rmp));
6277 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
6278 rmp->context = mp->context;
6279 rmp->domain_id = htonl (fcm->domain_id);
6280 rmp->src_port = htons (fcm->src_port);
6282 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6286 vl_api_ipfix_classify_table_add_del_t_handler
6287 (vl_api_ipfix_classify_table_add_del_t * mp)
6289 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
6290 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6291 flow_report_main_t *frm = &flow_report_main;
6292 vnet_flow_report_add_del_args_t args;
6293 ipfix_classify_table_t *table;
6295 u32 classify_table_index;
6297 u8 transport_protocol;
6300 classify_table_index = ntohl (mp->table_id);
6301 ip_version = mp->ip_version;
6302 transport_protocol = mp->transport_protocol;
6303 is_add = mp->is_add;
6305 if (fcm->src_port == 0)
6307 /* call set_ipfix_classify_stream first */
6308 rv = VNET_API_ERROR_UNSPECIFIED;
6312 memset (&args, 0, sizeof (args));
6316 for (i = 0; i < vec_len (fcm->tables); i++)
6317 if (ipfix_classify_table_index_valid (i))
6318 if (fcm->tables[i].classify_table_index == classify_table_index)
6320 table = &fcm->tables[i];
6328 rv = VNET_API_ERROR_VALUE_EXIST;
6331 table = ipfix_classify_add_table ();
6332 table->classify_table_index = classify_table_index;
6338 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
6343 table->ip_version = ip_version;
6344 table->transport_protocol = transport_protocol;
6346 args.opaque.as_uword = table - fcm->tables;
6347 args.rewrite_callback = ipfix_classify_template_rewrite;
6348 args.flow_data_callback = ipfix_classify_send_flows;
6349 args.is_add = is_add;
6350 args.domain_id = fcm->domain_id;
6351 args.src_port = fcm->src_port;
6353 rv = vnet_flow_report_add_del (frm, &args);
6355 /* If deleting, or add failed */
6356 if (is_add == 0 || (rv && is_add))
6357 ipfix_classify_delete_table (table - fcm->tables);
6360 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
6364 send_ipfix_classify_table_details (u32 table_index,
6365 unix_shared_memory_queue_t * q,
6368 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6369 vl_api_ipfix_classify_table_details_t *mp;
6371 ipfix_classify_table_t *table = &fcm->tables[table_index];
6373 mp = vl_msg_api_alloc (sizeof (*mp));
6374 memset (mp, 0, sizeof (*mp));
6375 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
6376 mp->context = context;
6377 mp->table_id = htonl (table->classify_table_index);
6378 mp->ip_version = table->ip_version;
6379 mp->transport_protocol = table->transport_protocol;
6381 vl_msg_api_send_shmem (q, (u8 *) & mp);
6385 vl_api_ipfix_classify_table_dump_t_handler
6386 (vl_api_ipfix_classify_table_dump_t * mp)
6388 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6389 unix_shared_memory_queue_t *q;
6392 q = vl_api_client_index_to_input_queue (mp->client_index);
6396 for (i = 0; i < vec_len (fcm->tables); i++)
6397 if (ipfix_classify_table_index_valid (i))
6398 send_ipfix_classify_table_details (i, q, mp->context);
6402 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
6404 vl_api_pg_create_interface_reply_t *rmp;
6407 pg_main_t *pg = &pg_main;
6408 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
6409 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
6412 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
6414 rmp->sw_if_index = ntohl(pi->sw_if_index);
6420 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
6422 vl_api_pg_capture_reply_t *rmp;
6425 vnet_main_t *vnm = vnet_get_main ();
6426 vnet_interface_main_t *im = &vnm->interface_main;
6427 vnet_hw_interface_t *hi = 0;
6429 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
6430 u32 hw_if_index = ~0;
6431 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
6434 vec_free (intf_name);
6436 if (hw_if_index != ~0)
6438 pg_capture_args_t _a, *a = &_a;
6440 u32 len = ntohl (mp->pcap_name_length);
6441 u8 *pcap_file_name = vec_new (u8, len);
6442 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
6444 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
6445 a->hw_if_index = hw_if_index;
6446 a->dev_instance = hi->dev_instance;
6447 a->is_enabled = mp->is_enabled;
6448 a->pcap_file_name = pcap_file_name;
6449 a->count = ntohl (mp->count);
6451 clib_error_t *e = pg_capture (a);
6454 clib_error_report (e);
6455 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
6458 vec_free (pcap_file_name);
6460 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
6464 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
6466 vl_api_pg_enable_disable_reply_t *rmp;
6469 pg_main_t *pg = &pg_main;
6470 u32 stream_index = ~0;
6472 int is_enable = mp->is_enabled != 0;
6473 u32 len = ntohl (mp->stream_name_length) - 1;
6477 u8 *stream_name = vec_new (u8, len);
6478 clib_memcpy (stream_name, mp->stream_name, len);
6479 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
6482 vec_free (stream_name);
6485 pg_enable_disable (stream_index, is_enable);
6487 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
6491 vl_api_ip_source_and_port_range_check_add_del_t_handler
6492 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
6494 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
6497 u8 is_ipv6 = mp->is_ipv6;
6498 u8 is_add = mp->is_add;
6499 u8 mask_length = mp->mask_length;
6500 ip4_address_t ip4_addr;
6501 ip6_address_t ip6_addr;
6503 u16 *high_ports = 0;
6505 u16 tmp_low, tmp_high;
6509 // Validate port range
6510 num_ranges = mp->number_of_ranges;
6511 if (num_ranges > 32)
6512 { // This is size of array in VPE.API
6513 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
6517 vec_reset_length (low_ports);
6518 vec_reset_length (high_ports);
6520 for (i = 0; i < num_ranges; i++)
6522 tmp_low = mp->low_ports[i];
6523 tmp_high = mp->high_ports[i];
6524 // If tmp_low <= tmp_high then only need to check tmp_low = 0
6525 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
6526 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
6528 rv = VNET_API_ERROR_INVALID_VALUE;
6531 vec_add1 (low_ports, tmp_low);
6532 vec_add1 (high_ports, tmp_high + 1);
6535 // Validate mask_length
6536 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
6538 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
6542 vrf_id = ntohl (mp->vrf_id);
6546 rv = VNET_API_ERROR_INVALID_VALUE;
6553 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
6554 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
6558 high_ports, is_add);
6562 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
6563 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
6567 high_ports, is_add);
6571 vec_free (low_ports);
6572 vec_free (high_ports);
6573 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
6577 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
6578 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
6580 vlib_main_t *vm = vlib_get_main ();
6581 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
6582 ip4_main_t *im = &ip4_main;
6585 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
6586 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
6590 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
6591 ntohl (mp->tcp_out_vrf_id);
6592 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
6593 ntohl (mp->udp_out_vrf_id);
6594 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
6595 ntohl (mp->tcp_in_vrf_id);
6596 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
6597 ntohl (mp->udp_in_vrf_id);
6600 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
6602 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
6604 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
6608 rv = VNET_API_ERROR_INVALID_VALUE;
6612 fib_index[i] = p[0];
6617 sw_if_index = ntohl (mp->sw_if_index);
6619 VALIDATE_SW_IF_INDEX (mp);
6622 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
6625 BAD_SW_IF_INDEX_LABEL;
6628 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
6632 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
6635 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
6637 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
6638 u32 sw_if_index = ~0;
6640 /* Check src & dst are different */
6641 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
6643 rv = VNET_API_ERROR_SAME_SRC_DST;
6647 memset (a, 0, sizeof (*a));
6649 /* ip addresses sent in network byte order */
6650 clib_memcpy (&(a->src), mp->src_address, 4);
6651 clib_memcpy (&(a->dst), mp->dst_address, 4);
6652 a->is_add = mp->is_add;
6653 a->lsa = ntohl (mp->local_sa_id);
6654 a->rsa = ntohl (mp->remote_sa_id);
6656 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
6660 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
6662 rmp->sw_if_index = ntohl (sw_if_index);
6667 static void send_ipsec_gre_tunnel_details
6668 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
6670 vl_api_ipsec_gre_tunnel_details_t *rmp;
6672 rmp = vl_msg_api_alloc (sizeof (*rmp));
6673 memset (rmp, 0, sizeof (*rmp));
6674 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
6675 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
6676 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
6677 rmp->sw_if_index = htonl (t->sw_if_index);
6678 rmp->local_sa_id = htonl (t->local_sa_id);
6679 rmp->remote_sa_id = htonl (t->remote_sa_id);
6680 rmp->context = context;
6682 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6685 static void vl_api_ipsec_gre_tunnel_dump_t_handler
6686 (vl_api_ipsec_gre_tunnel_dump_t * mp)
6688 unix_shared_memory_queue_t *q;
6689 ipsec_gre_main_t *igm = &ipsec_gre_main;
6690 ipsec_gre_tunnel_t *t;
6693 q = vl_api_client_index_to_input_queue (mp->client_index);
6699 sw_if_index = ntohl (mp->sw_if_index);
6701 if (~0 == sw_if_index)
6704 pool_foreach (t, igm->tunnels,
6706 send_ipsec_gre_tunnel_details(t, q, mp->context);
6712 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
6713 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
6717 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
6718 send_ipsec_gre_tunnel_details (t, q, mp->context);
6723 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
6725 vl_api_delete_subif_reply_t *rmp;
6728 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
6730 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
6734 vl_api_l2_interface_pbb_tag_rewrite_t_handler
6735 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
6737 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
6738 vnet_main_t *vnm = vnet_get_main ();
6739 vlib_main_t *vm = vlib_get_main ();
6743 VALIDATE_SW_IF_INDEX (mp);
6745 vtr_op = ntohl (mp->vtr_op);
6749 case L2_VTR_DISABLED:
6752 case L2_VTR_TRANSLATE_2_1:
6756 rv = VNET_API_ERROR_INVALID_VALUE;
6757 goto bad_sw_if_index;
6760 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
6761 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
6762 ntohl (mp->i_sid), ntohs (mp->outer_tag));
6764 BAD_SW_IF_INDEX_LABEL;
6766 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
6770 vl_api_punt_t_handler (vl_api_punt_t * mp)
6772 vl_api_punt_reply_t *rmp;
6773 vlib_main_t *vm = vlib_get_main ();
6775 clib_error_t *error;
6777 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
6778 ntohs (mp->l4_port), mp->is_add);
6782 clib_error_report (error);
6785 REPLY_MACRO (VL_API_PUNT_REPLY);
6789 vl_api_flow_classify_set_interface_t_handler
6790 (vl_api_flow_classify_set_interface_t * mp)
6792 vlib_main_t *vm = vlib_get_main ();
6793 vl_api_flow_classify_set_interface_reply_t *rmp;
6795 u32 sw_if_index, ip4_table_index, ip6_table_index;
6797 ip4_table_index = ntohl (mp->ip4_table_index);
6798 ip6_table_index = ntohl (mp->ip6_table_index);
6799 sw_if_index = ntohl (mp->sw_if_index);
6801 VALIDATE_SW_IF_INDEX (mp);
6803 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
6804 ip6_table_index, mp->is_add);
6806 BAD_SW_IF_INDEX_LABEL;
6808 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
6812 send_flow_classify_details (u32 sw_if_index,
6814 unix_shared_memory_queue_t * q, u32 context)
6816 vl_api_flow_classify_details_t *mp;
6818 mp = vl_msg_api_alloc (sizeof (*mp));
6819 memset (mp, 0, sizeof (*mp));
6820 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
6821 mp->context = context;
6822 mp->sw_if_index = htonl (sw_if_index);
6823 mp->table_index = htonl (table_index);
6825 vl_msg_api_send_shmem (q, (u8 *) & mp);
6829 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
6831 unix_shared_memory_queue_t *q;
6832 flow_classify_main_t *pcm = &flow_classify_main;
6836 q = vl_api_client_index_to_input_queue (mp->client_index);
6840 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6842 if (vec_len (vec_tbl))
6844 for (i = 0; i < vec_len (vec_tbl); i++)
6846 if (vec_elt (vec_tbl, i) == ~0)
6849 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
6856 send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
6859 vl_api_ipsec_spd_details_t *mp;
6861 mp = vl_msg_api_alloc (sizeof (*mp));
6862 memset (mp, 0, sizeof (*mp));
6863 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
6864 mp->context = context;
6866 mp->spd_id = htonl (p->id);
6867 mp->priority = htonl (p->priority);
6868 mp->is_outbound = p->is_outbound;
6869 mp->is_ipv6 = p->is_ipv6;
6872 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
6873 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
6874 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
6875 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
6879 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
6880 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
6881 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
6882 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
6884 mp->local_start_port = htons (p->lport.start);
6885 mp->local_stop_port = htons (p->lport.stop);
6886 mp->remote_start_port = htons (p->rport.start);
6887 mp->remote_stop_port = htons (p->rport.stop);
6888 mp->protocol = p->protocol;
6889 mp->policy = p->policy;
6890 mp->sa_id = htonl (p->sa_id);
6891 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
6892 mp->packets = clib_host_to_net_u64 (p->counter.packets);
6894 vl_msg_api_send_shmem (q, (u8 *) & mp);
6898 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
6900 unix_shared_memory_queue_t *q;
6901 ipsec_main_t *im = &ipsec_main;
6902 ipsec_policy_t *policy;
6907 q = vl_api_client_index_to_input_queue (mp->client_index);
6911 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
6916 spd = pool_elt_at_index (im->spds, spd_index);
6919 pool_foreach (policy, spd->policies,
6921 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
6922 send_ipsec_spd_details (policy, q,
6927 clib_warning ("unimplemented");
6932 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
6934 vl_api_feature_enable_disable_reply_t *rmp;
6936 u8 *arc_name, *feature_name;
6938 VALIDATE_SW_IF_INDEX (mp);
6940 arc_name = format (0, "%s%c", mp->arc_name, 0);
6941 feature_name = format (0, "%s%c", mp->feature_name, 0);
6943 vnet_feature_registration_t *reg;
6945 vnet_get_feature_reg ((const char *) arc_name,
6946 (const char *) feature_name);
6948 rv = VNET_API_ERROR_INVALID_VALUE;
6952 clib_error_t *error = 0;
6954 sw_if_index = ntohl (mp->sw_if_index);
6955 if (reg->enable_disable_cb)
6956 error = reg->enable_disable_cb (sw_if_index, mp->enable);
6958 vnet_feature_enable_disable ((const char *) arc_name,
6959 (const char *) feature_name,
6960 sw_if_index, mp->enable, 0, 0);
6963 clib_error_report (error);
6964 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
6968 vec_free (feature_name);
6969 vec_free (arc_name);
6971 BAD_SW_IF_INDEX_LABEL;
6973 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
6976 #define BOUNCE_HANDLER(nn) \
6977 static void vl_api_##nn##_t_handler ( \
6978 vl_api_##nn##_t *mp) \
6980 vpe_client_registration_t *reg; \
6981 vpe_api_main_t * vam = &vpe_api_main; \
6982 unix_shared_memory_queue_t * q; \
6984 /* One registration only... */ \
6985 pool_foreach(reg, vam->nn##_registrations, \
6987 q = vl_api_client_index_to_input_queue (reg->client_index); \
6990 * If the queue is stuffed, turf the msg and complain \
6991 * It's unlikely that the intended recipient is \
6992 * alive; avoid deadlock at all costs. \
6994 if (q->cursize == q->maxsize) { \
6995 clib_warning ("ERROR: receiver queue full, drop msg"); \
6996 vl_msg_api_free (mp); \
6999 vl_msg_api_send_shmem (q, (u8 *)&mp); \
7003 vl_msg_api_free (mp); \
7006 static void setup_message_id_table (api_main_t * am);
7010 * Add vpe's API message handlers to the table.
7011 * vlib has alread mapped shared memory and
7012 * added the client registration handlers.
7013 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
7015 static clib_error_t *
7016 vpe_api_hookup (vlib_main_t * vm)
7018 api_main_t *am = &api_main;
7021 vl_msg_api_set_handlers(VL_API_##N, #n, \
7022 vl_api_##n##_t_handler, \
7024 vl_api_##n##_t_endian, \
7025 vl_api_##n##_t_print, \
7026 sizeof(vl_api_##n##_t), 1);
7027 foreach_vpe_api_msg;
7031 * Manually register the sr tunnel add del msg, so we trace
7032 * enough bytes to capture a typical segment list
7034 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
7035 "sr_tunnel_add_del",
7036 vl_api_sr_tunnel_add_del_t_handler,
7038 vl_api_sr_tunnel_add_del_t_endian,
7039 vl_api_sr_tunnel_add_del_t_print, 256, 1);
7043 * Manually register the sr policy add del msg, so we trace
7044 * enough bytes to capture a typical tunnel name list
7046 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
7047 "sr_policy_add_del",
7048 vl_api_sr_policy_add_del_t_handler,
7050 vl_api_sr_policy_add_del_t_endian,
7051 vl_api_sr_policy_add_del_t_print, 256, 1);
7054 * Trace space for 8 MPLS encap labels, classifier mask+match
7056 am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32);
7057 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
7058 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
7059 += 5 * sizeof (u32x4);
7060 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
7063 * Thread-safe API messages
7065 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
7066 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
7069 * Set up the (msg_name, crc, message-id) table
7071 setup_message_id_table (am);
7076 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
7078 static clib_error_t *
7079 vpe_api_init (vlib_main_t * vm)
7081 vpe_api_main_t *am = &vpe_api_main;
7084 am->vnet_main = vnet_get_main ();
7085 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
7086 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7087 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7088 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7089 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7090 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
7093 vl_set_memory_region_name ("/vpe-api");
7094 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
7099 VLIB_INIT_FUNCTION (vpe_api_init);
7102 static clib_error_t *
7103 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
7106 u64 baseva, size, pvt_heap_size;
7108 const int max_buf_size = 4096;
7110 struct passwd _pw, *pw;
7111 struct group _grp, *grp;
7113 buf = vec_new (char, 128);
7114 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7116 if (unformat (input, "prefix %s", &chroot_path))
7118 vec_add1 (chroot_path, 0);
7119 vl_set_memory_root_path ((char *) chroot_path);
7121 else if (unformat (input, "uid %d", &uid))
7122 vl_set_memory_uid (uid);
7123 else if (unformat (input, "gid %d", &gid))
7124 vl_set_memory_gid (gid);
7125 else if (unformat (input, "baseva %llx", &baseva))
7126 vl_set_global_memory_baseva (baseva);
7127 else if (unformat (input, "global-size %lldM", &size))
7128 vl_set_global_memory_size (size * (1ULL << 20));
7129 else if (unformat (input, "global-size %lldG", &size))
7130 vl_set_global_memory_size (size * (1ULL << 30));
7131 else if (unformat (input, "global-size %lld", &size))
7132 vl_set_global_memory_size (size);
7133 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
7134 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
7135 else if (unformat (input, "global-pvt-heap-size size %lld",
7137 vl_set_global_pvt_heap_size (pvt_heap_size);
7138 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
7139 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
7140 else if (unformat (input, "api-pvt-heap-size size %lld",
7142 vl_set_api_pvt_heap_size (pvt_heap_size);
7143 else if (unformat (input, "api-size %lldM", &size))
7144 vl_set_api_memory_size (size * (1ULL << 20));
7145 else if (unformat (input, "api-size %lldG", &size))
7146 vl_set_api_memory_size (size * (1ULL << 30));
7147 else if (unformat (input, "api-size %lld", &size))
7148 vl_set_api_memory_size (size);
7149 else if (unformat (input, "uid %s", &s))
7151 /* lookup the username */
7154 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
7155 && (vec_len (buf) <= max_buf_size))
7157 vec_resize (buf, vec_len (buf) * 2);
7161 e = clib_error_return_code (0, rv,
7162 CLIB_ERROR_ERRNO_VALID |
7164 "cannot fetch username %s", s);
7172 clib_error_return_fatal (0, "username %s does not exist", s);
7178 vl_set_memory_uid (pw->pw_uid);
7180 else if (unformat (input, "gid %s", &s))
7182 /* lookup the group name */
7185 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
7186 && (vec_len (buf) <= max_buf_size))
7188 vec_resize (buf, vec_len (buf) * 2);
7192 e = clib_error_return_code (0, rv,
7193 CLIB_ERROR_ERRNO_VALID |
7195 "cannot fetch group %s", s);
7202 e = clib_error_return_fatal (0, "group %s does not exist", s);
7209 vl_set_memory_gid (grp->gr_gid);
7212 return clib_error_return (0, "unknown input `%U'",
7213 format_unformat_error, input);
7218 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
7221 get_unformat_vnet_sw_interface (void)
7223 return (void *) &unformat_vnet_sw_interface;
7227 format_arp_event (u8 * s, va_list * args)
7229 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
7231 s = format (s, "pid %d: ", event->pid);
7233 s = format (s, "bd mac/ip4 binding events");
7235 s = format (s, "resolution for %U", format_ip4_address, &event->address);
7240 format_nd_event (u8 * s, va_list * args)
7242 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
7244 s = format (s, "pid %d: ", event->pid);
7246 s = format (s, "bd mac/ip6 binding events");
7248 s = format (s, "resolution for %U", format_ip6_address, event->address);
7252 static clib_error_t *
7253 show_ip_arp_nd_events_fn (vlib_main_t * vm,
7254 unformat_input_t * input, vlib_cli_command_t * cmd)
7256 vpe_api_main_t *am = &vpe_api_main;
7257 vl_api_ip4_arp_event_t *arp_event;
7258 vl_api_ip6_nd_event_t *nd_event;
7260 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
7262 vlib_cli_output (vm, "No active arp or nd event registrations");
7267 pool_foreach (arp_event, am->arp_events,
7269 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
7272 pool_foreach (nd_event, am->nd_events,
7274 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
7282 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
7283 .path = "show arp-nd-event registrations",
7284 .function = show_ip_arp_nd_events_fn,
7285 .short_help = "Show ip4 arp and ip6 nd event registrations",
7289 #define vl_msg_name_crc_list
7290 #include <vpp-api/vpe_all_api_h.h>
7291 #undef vl_msg_name_crc_list
7294 setup_message_id_table (api_main_t * am)
7296 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
7297 foreach_vl_msg_name_crc_memclnt;
7298 foreach_vl_msg_name_crc_vpe;
7304 * fd.io coding-style-patch-verification: ON
7307 * eval: (c-set-style "gnu")