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 */ );
977 bd_set_mac_age (vm, mp->mac_age, mp->mac_age);
980 rv = bd_delete_bd_index (bdm, bd_id);
982 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
986 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
988 clib_warning ("BUG");
992 vl_api_bridge_domain_sw_if_details_t_handler
993 (vl_api_bridge_domain_sw_if_details_t * mp)
995 clib_warning ("BUG");
999 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1000 l2_bridge_domain_t * bd_config,
1001 u32 n_sw_ifs, u32 context)
1003 vl_api_bridge_domain_details_t *mp;
1005 mp = vl_msg_api_alloc (sizeof (*mp));
1006 memset (mp, 0, sizeof (*mp));
1007 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1008 mp->bd_id = ntohl (bd_config->bd_id);
1009 mp->flood = bd_feature_flood (bd_config);
1010 mp->uu_flood = bd_feature_uu_flood (bd_config);
1011 mp->forward = bd_feature_forward (bd_config);
1012 mp->learn = bd_feature_learn (bd_config);
1013 mp->arp_term = bd_feature_arp_term (bd_config);
1014 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1015 mp->mac_age = bd_config->mac_age;
1016 mp->n_sw_ifs = ntohl (n_sw_ifs);
1017 mp->context = context;
1019 vl_msg_api_send_shmem (q, (u8 *) & mp);
1023 send_bd_sw_if_details (l2input_main_t * l2im,
1024 unix_shared_memory_queue_t * q,
1025 l2_flood_member_t * member, u32 bd_id, u32 context)
1027 vl_api_bridge_domain_sw_if_details_t *mp;
1028 l2_input_config_t *input_cfg;
1030 mp = vl_msg_api_alloc (sizeof (*mp));
1031 memset (mp, 0, sizeof (*mp));
1032 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1033 mp->bd_id = ntohl (bd_id);
1034 mp->sw_if_index = ntohl (member->sw_if_index);
1035 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1036 mp->shg = input_cfg->shg;
1037 mp->context = context;
1039 vl_msg_api_send_shmem (q, (u8 *) & mp);
1043 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1045 bd_main_t *bdm = &bd_main;
1046 l2input_main_t *l2im = &l2input_main;
1047 unix_shared_memory_queue_t *q;
1048 l2_bridge_domain_t *bd_config;
1049 u32 bd_id, bd_index;
1052 q = vl_api_client_index_to_input_queue (mp->client_index);
1057 bd_id = ntohl (mp->bd_id);
1059 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1060 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1061 for (; bd_index < end; bd_index++)
1063 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1064 /* skip dummy bd_id 0 */
1065 if (bd_config && (bd_config->bd_id > 0))
1068 l2_flood_member_t *m;
1070 n_sw_ifs = vec_len (bd_config->members);
1071 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1073 vec_foreach (m, bd_config->members)
1075 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1082 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1084 bd_main_t *bdm = &bd_main;
1085 l2input_main_t *l2im = &l2input_main;
1086 vl_api_l2fib_add_del_reply_t *rmp;
1089 u32 sw_if_index = ntohl (mp->sw_if_index);
1090 u32 bd_id = ntohl (mp->bd_id);
1099 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1102 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1103 goto bad_sw_if_index;
1109 filter_mac = mp->filter_mac ? 1 : 0;
1110 if (filter_mac == 0)
1112 VALIDATE_SW_IF_INDEX (mp);
1113 if (vec_len (l2im->configs) <= sw_if_index)
1115 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1116 goto bad_sw_if_index;
1120 l2_input_config_t *config;
1121 config = vec_elt_at_index (l2im->configs, sw_if_index);
1122 if (config->bridge == 0)
1124 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1125 goto bad_sw_if_index;
1129 static_mac = mp->static_mac ? 1 : 0;
1130 bvi_mac = mp->bvi_mac ? 1 : 0;
1131 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1136 l2fib_del_entry (mac, bd_index);
1139 BAD_SW_IF_INDEX_LABEL;
1141 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1145 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1147 vl_api_l2_flags_reply_t *rmp;
1149 u32 sw_if_index = ntohl (mp->sw_if_index);
1150 u32 flags = ntohl (mp->feature_bitmap);
1153 VALIDATE_SW_IF_INDEX (mp);
1156 if (flags & L2INPUT_FEAT_ ## a) \
1157 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1158 foreach_l2input_feat;
1161 BAD_SW_IF_INDEX_LABEL;
1164 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1166 rmp->resulting_feature_bitmap = ntohl(rbm);
1172 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1174 vlib_main_t *vm = vlib_get_main ();
1175 bd_main_t *bdm = &bd_main;
1176 vl_api_bridge_flags_reply_t *rmp;
1178 u32 bd_id = ntohl (mp->bd_id);
1180 u32 flags = ntohl (mp->feature_bitmap);
1183 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1186 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1192 bd_set_flags (vm, bd_index, flags, mp->is_set);
1196 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1198 rmp->resulting_feature_bitmap = ntohl(flags);
1204 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1206 bd_main_t *bdm = &bd_main;
1207 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1209 u32 bd_id = ntohl (mp->bd_id);
1213 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1216 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1221 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1222 mp->mac_address, mp->is_ipv6, mp->is_add))
1223 rv = VNET_API_ERROR_UNSPECIFIED;
1226 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1230 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1232 vl_api_create_vlan_subif_reply_t *rmp;
1233 vnet_main_t *vnm = vnet_get_main ();
1234 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1235 vnet_hw_interface_t *hi;
1238 vnet_sw_interface_t template;
1240 vnet_interface_main_t *im = &vnm->interface_main;
1241 u64 sup_and_sub_key;
1243 unix_shared_memory_queue_t *q;
1244 clib_error_t *error;
1246 VALIDATE_SW_IF_INDEX (mp);
1248 hw_if_index = ntohl (mp->sw_if_index);
1249 hi = vnet_get_hw_interface (vnm, hw_if_index);
1251 id = ntohl (mp->vlan_id);
1252 if (id == 0 || id > 4095)
1254 rv = VNET_API_ERROR_INVALID_VLAN;
1258 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1260 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1263 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1267 kp = clib_mem_alloc (sizeof (*kp));
1268 *kp = sup_and_sub_key;
1270 memset (&template, 0, sizeof (template));
1271 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1272 template.sup_sw_if_index = hi->sw_if_index;
1273 template.sub.id = id;
1274 template.sub.eth.raw_flags = 0;
1275 template.sub.eth.flags.one_tag = 1;
1276 template.sub.eth.outer_vlan_id = id;
1277 template.sub.eth.flags.exact_match = 1;
1279 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1282 clib_error_report (error);
1283 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1286 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1287 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1289 BAD_SW_IF_INDEX_LABEL;
1292 q = vl_api_client_index_to_input_queue (mp->client_index);
1296 rmp = vl_msg_api_alloc (sizeof (*rmp));
1297 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1298 rmp->context = mp->context;
1299 rmp->retval = ntohl (rv);
1300 rmp->sw_if_index = ntohl (sw_if_index);
1301 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1305 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1307 vl_api_create_subif_reply_t *rmp;
1308 vnet_main_t *vnm = vnet_get_main ();
1309 u32 sw_if_index = ~0;
1312 vnet_sw_interface_t *si;
1313 vnet_hw_interface_t *hi;
1314 vnet_sw_interface_t template;
1316 vnet_interface_main_t *im = &vnm->interface_main;
1317 u64 sup_and_sub_key;
1319 clib_error_t *error;
1321 VALIDATE_SW_IF_INDEX (mp);
1323 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1324 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1326 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1328 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1332 sw_if_index = si->sw_if_index;
1333 sub_id = ntohl (mp->sub_id);
1335 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1337 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1341 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1342 sw_if_index, sub_id);
1343 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1347 kp = clib_mem_alloc (sizeof (*kp));
1348 *kp = sup_and_sub_key;
1350 memset (&template, 0, sizeof (template));
1351 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1352 template.sup_sw_if_index = sw_if_index;
1353 template.sub.id = sub_id;
1354 template.sub.eth.flags.no_tags = mp->no_tags;
1355 template.sub.eth.flags.one_tag = mp->one_tag;
1356 template.sub.eth.flags.two_tags = mp->two_tags;
1357 template.sub.eth.flags.dot1ad = mp->dot1ad;
1358 template.sub.eth.flags.exact_match = mp->exact_match;
1359 template.sub.eth.flags.default_sub = mp->default_sub;
1360 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1361 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1362 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1363 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1365 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1368 clib_error_report (error);
1369 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1373 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1374 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1376 BAD_SW_IF_INDEX_LABEL;
1381 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1383 rmp->sw_if_index = ntohl(sw_if_index);
1389 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
1391 vl_api_mpls_tunnel_add_del_reply_t *rmp;
1393 stats_main_t *sm = &stats_main;
1394 u32 tunnel_sw_if_index;
1397 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1401 fib_route_path_t rpath, *rpaths = NULL;
1402 mpls_label_t *label_stack = NULL;
1404 memset (&rpath, 0, sizeof (rpath));
1406 if (mp->mt_next_hop_proto_is_ip4)
1408 rpath.frp_proto = FIB_PROTOCOL_IP4;
1409 clib_memcpy (&rpath.frp_addr.ip4,
1410 mp->mt_next_hop, sizeof (rpath.frp_addr.ip4));
1414 rpath.frp_proto = FIB_PROTOCOL_IP6;
1415 clib_memcpy (&rpath.frp_addr.ip6,
1416 mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
1418 rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
1420 for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
1421 vec_add1 (label_stack, ntohl (mp->mt_next_hop_out_label_stack[ii]));
1423 vec_add1 (rpaths, rpath);
1425 vnet_mpls_tunnel_add (rpaths, label_stack,
1426 mp->mt_l2_only, &tunnel_sw_if_index);
1428 vec_free (label_stack);
1432 tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
1433 vnet_mpls_tunnel_del (tunnel_sw_if_index);
1439 REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
1441 rmp->sw_if_index = ntohl(tunnel_sw_if_index);
1447 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
1449 vl_api_proxy_arp_add_del_reply_t *rmp;
1452 ip4_main_t *im = &ip4_main;
1453 stats_main_t *sm = &stats_main;
1454 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
1455 ip4_address_t * hi_addr,
1456 u32 fib_index, int is_del);
1459 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
1461 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1465 rv = VNET_API_ERROR_NO_SUCH_FIB;
1471 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
1472 (ip4_address_t *) mp->hi_address,
1473 fib_index, mp->is_add == 0);
1477 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
1481 vl_api_proxy_arp_intfc_enable_disable_t_handler
1482 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
1485 vnet_main_t *vnm = vnet_get_main ();
1486 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
1487 vnet_sw_interface_t *si;
1490 VALIDATE_SW_IF_INDEX (mp);
1492 sw_if_index = ntohl (mp->sw_if_index);
1494 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1496 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1500 si = vnet_get_sw_interface (vnm, sw_if_index);
1504 if (mp->enable_disable)
1505 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1507 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
1509 BAD_SW_IF_INDEX_LABEL;
1512 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
1516 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
1519 vpe_main_t *rm = &vpe_main;
1520 ip4_main_t *im4 = &ip4_main;
1521 ip6_main_t *im6 = &ip6_main;
1522 ip_lookup_main_t *lm;
1528 u32 adj_index, sw_if_index;
1529 vl_api_is_address_reachable_t *rmp;
1530 ip_adjacency_t *adj;
1531 unix_shared_memory_queue_t *q;
1533 q = vl_api_client_index_to_input_queue (mp->client_index);
1536 increment_missing_api_client_counter (rm->vlib_main);
1540 rmp = vl_msg_api_alloc (sizeof (*rmp));
1541 clib_memcpy (rmp, mp, sizeof (*rmp));
1543 sw_if_index = mp->next_hop_sw_if_index;
1544 clib_memcpy (&addr, mp->address, sizeof (addr));
1547 lm = &im6->lookup_main;
1548 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
1552 lm = &im4->lookup_main;
1554 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
1556 if (adj_index == ~0)
1561 adj = ip_get_adjacency (lm, adj_index);
1563 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
1564 && adj->rewrite_header.sw_if_index == sw_if_index)
1570 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
1571 && adj->rewrite_header.sw_if_index == sw_if_index)
1574 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
1576 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
1578 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
1587 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1592 vl_api_sw_interface_set_mpls_enable_t_handler
1593 (vl_api_sw_interface_set_mpls_enable_t * mp)
1595 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
1598 VALIDATE_SW_IF_INDEX (mp);
1600 mpls_sw_interface_enable_disable (&mpls_main,
1601 ntohl (mp->sw_if_index), mp->enable);
1603 BAD_SW_IF_INDEX_LABEL;
1604 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
1608 * WARNING: replicated pending api refactor completion
1611 send_sw_interface_flags_deleted (vpe_api_main_t * am,
1612 unix_shared_memory_queue_t * q,
1615 vl_api_sw_interface_set_flags_t *mp;
1617 mp = vl_msg_api_alloc (sizeof (*mp));
1618 memset (mp, 0, sizeof (*mp));
1619 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
1620 mp->sw_if_index = ntohl (sw_if_index);
1622 mp->admin_up_down = 0;
1623 mp->link_up_down = 0;
1625 vl_msg_api_send_shmem (q, (u8 *) & mp);
1629 send_oam_event (oam_target_t * t)
1631 vpe_api_main_t *vam = &vpe_api_main;
1632 unix_shared_memory_queue_t *q;
1633 vpe_client_registration_t *reg;
1634 vl_api_oam_event_t *mp;
1637 pool_foreach(reg, vam->oam_events_registrations,
1639 q = vl_api_client_index_to_input_queue (reg->client_index);
1642 mp = vl_msg_api_alloc (sizeof (*mp));
1643 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
1644 clib_memcpy (mp->dst_address, &t->dst_address,
1645 sizeof (mp->dst_address));
1646 mp->state = t->state;
1647 vl_msg_api_send_shmem (q, (u8 *)&mp);
1654 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
1656 vl_api_oam_add_del_reply_t *rmp;
1659 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
1660 (ip4_address_t *) mp->dst_address,
1661 ntohl (mp->vrf_id), (int) (mp->is_add));
1663 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
1667 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
1669 stats_main_t *sm = &stats_main;
1670 vnet_interface_main_t *im = sm->interface_main;
1671 vl_api_vnet_summary_stats_reply_t *rmp;
1672 vlib_combined_counter_main_t *cm;
1675 u64 total_pkts[VLIB_N_RX_TX];
1676 u64 total_bytes[VLIB_N_RX_TX];
1678 unix_shared_memory_queue_t *q =
1679 vl_api_client_index_to_input_queue (mp->client_index);
1684 rmp = vl_msg_api_alloc (sizeof (*rmp));
1685 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
1686 rmp->context = mp->context;
1689 memset (total_pkts, 0, sizeof (total_pkts));
1690 memset (total_bytes, 0, sizeof (total_bytes));
1692 vnet_interface_counter_lock (im);
1694 vec_foreach (cm, im->combined_sw_if_counters)
1696 which = cm - im->combined_sw_if_counters;
1698 for (i = 0; i < vec_len (cm->maxi); i++)
1700 vlib_get_combined_counter (cm, i, &v);
1701 total_pkts[which] += v.packets;
1702 total_bytes[which] += v.bytes;
1705 vnet_interface_counter_unlock (im);
1707 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
1708 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
1709 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
1710 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
1712 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
1714 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1718 typedef CLIB_PACKED (struct {
1719 ip4_address_t address;
1720 u32 address_length: 6;
1726 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1728 vnet_main_t *vnm = vnet_get_main ();
1729 vnet_interface_main_t *im = &vnm->interface_main;
1730 ip4_main_t *im4 = &ip4_main;
1731 static u32 *sw_if_indices_to_shut;
1732 stats_main_t *sm = &stats_main;
1733 fib_table_t *fib_table;
1737 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1738 u32 target_fib_id = ntohl (mp->vrf_id);
1740 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
1743 pool_foreach (fib_table, im4->fibs,
1745 fib = &fib_table->v4;
1746 vnet_sw_interface_t * si;
1748 if (fib->table_id != target_fib_id)
1751 /* remove any mpls encap/decap labels */
1752 mpls_fib_reset_labels (fib->table_id);
1754 /* remove any proxy arps in this fib */
1755 vnet_proxy_arp_fib_reset (fib->table_id);
1757 /* Set the flow hash for this fib to the default */
1758 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
1760 vec_reset_length (sw_if_indices_to_shut);
1762 /* Shut down interfaces in this FIB / clean out intfc routes */
1763 pool_foreach (si, im->sw_interfaces,
1765 u32 sw_if_index = si->sw_if_index;
1767 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
1768 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
1770 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1773 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1774 sw_if_index = sw_if_indices_to_shut[i];
1775 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1777 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1778 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1779 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1782 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
1783 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
1787 })); /* pool_foreach (fib) */
1795 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1797 vnet_main_t *vnm = vnet_get_main ();
1798 vnet_interface_main_t *im = &vnm->interface_main;
1799 ip6_main_t *im6 = &ip6_main;
1800 stats_main_t *sm = &stats_main;
1801 static u32 *sw_if_indices_to_shut;
1802 fib_table_t *fib_table;
1806 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1807 u32 target_fib_id = ntohl (mp->vrf_id);
1809 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
1812 pool_foreach (fib_table, im6->fibs,
1814 vnet_sw_interface_t * si;
1815 fib = &(fib_table->v6);
1817 if (fib->table_id != target_fib_id)
1820 vec_reset_length (sw_if_indices_to_shut);
1822 /* Shut down interfaces in this FIB / clean out intfc routes */
1823 pool_foreach (si, im->sw_interfaces,
1825 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1827 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1830 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1831 sw_if_index = sw_if_indices_to_shut[i];
1832 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1834 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1835 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1836 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1839 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1840 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
1844 })); /* pool_foreach (fib) */
1852 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1855 vl_api_reset_fib_reply_t *rmp;
1858 rv = ip6_reset_fib_t_handler (mp);
1860 rv = ip4_reset_fib_t_handler (mp);
1862 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1867 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1869 vl_api_dhcp_proxy_config_reply_t *rmp;
1872 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
1873 (ip4_address_t *) (&mp->dhcp_src_address),
1874 (u32) ntohl (mp->vrf_id),
1875 (int) mp->insert_circuit_id,
1876 (int) (mp->is_add == 0));
1878 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1883 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1885 vl_api_dhcp_proxy_config_reply_t *rmp;
1888 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
1889 (ip6_address_t *) (&mp->dhcp_src_address),
1890 (u32) ntohl (mp->vrf_id),
1891 (int) mp->insert_circuit_id,
1892 (int) (mp->is_add == 0));
1894 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1898 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1900 vl_api_dhcp_proxy_config_reply_t *rmp;
1903 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
1904 (ip4_address_t *) (&mp->dhcp_src_address),
1905 (u32) ntohl (mp->rx_vrf_id),
1906 (u32) ntohl (mp->server_vrf_id),
1907 (int) mp->insert_circuit_id,
1908 (int) (mp->is_add == 0));
1910 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1915 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1917 vl_api_dhcp_proxy_config_reply_t *rmp;
1920 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
1921 (ip6_address_t *) (&mp->dhcp_src_address),
1922 (u32) ntohl (mp->rx_vrf_id),
1923 (u32) ntohl (mp->server_vrf_id),
1924 (int) mp->insert_circuit_id,
1925 (int) (mp->is_add == 0));
1927 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1932 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
1934 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
1937 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
1940 (int) mp->is_add == 0);
1942 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
1944 ntohl (mp->fib_id), (int) mp->is_add == 0);
1946 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
1950 static void vl_api_dhcp_proxy_config_t_handler
1951 (vl_api_dhcp_proxy_config_t * mp)
1953 if (mp->is_ipv6 == 0)
1954 dhcpv4_proxy_config (mp);
1956 dhcpv6_proxy_config (mp);
1959 static void vl_api_dhcp_proxy_config_2_t_handler
1960 (vl_api_dhcp_proxy_config_2_t * mp)
1962 if (mp->is_ipv6 == 0)
1963 dhcpv4_proxy_config_2 (mp);
1965 dhcpv6_proxy_config_2 (mp);
1969 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
1970 u8 is_ipv6, u8 * host_address, u8 * router_address,
1973 unix_shared_memory_queue_t *q;
1974 vl_api_dhcp_compl_event_t *mp;
1976 q = vl_api_client_index_to_input_queue (client_index);
1980 mp = vl_msg_api_alloc (sizeof (*mp));
1981 mp->client_index = client_index;
1983 mp->is_ipv6 = is_ipv6;
1984 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
1985 mp->hostname[vec_len (hostname) + 1] = '\n';
1986 clib_memcpy (&mp->host_address[0], host_address, 16);
1987 clib_memcpy (&mp->router_address[0], router_address, 16);
1989 if (NULL != host_mac)
1990 clib_memcpy (&mp->host_mac[0], host_mac, 6);
1992 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
1994 vl_msg_api_send_shmem (q, (u8 *) & mp);
1997 static void vl_api_dhcp_client_config_t_handler
1998 (vl_api_dhcp_client_config_t * mp)
2000 vlib_main_t *vm = vlib_get_main ();
2001 vl_api_dhcp_client_config_reply_t *rmp;
2004 VALIDATE_SW_IF_INDEX (mp);
2006 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
2007 mp->hostname, mp->is_add, mp->client_index,
2008 mp->want_dhcp_event ? dhcp_compl_event_callback :
2011 BAD_SW_IF_INDEX_LABEL;
2013 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
2017 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
2019 vl_api_create_loopback_reply_t *rmp;
2023 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
2026 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
2028 rmp->sw_if_index = ntohl (sw_if_index);
2034 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
2036 vl_api_delete_loopback_reply_t *rmp;
2040 sw_if_index = ntohl (mp->sw_if_index);
2041 rv = vnet_delete_loopback_interface (sw_if_index);
2043 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
2047 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
2049 vl_api_control_ping_reply_t *rmp;
2053 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
2055 rmp->vpe_pid = ntohl (getpid());
2061 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2063 u8 **shmem_vecp = (u8 **) arg;
2066 api_main_t *am = &api_main;
2069 shmem_vec = *shmem_vecp;
2071 offset = vec_len (shmem_vec);
2073 pthread_mutex_lock (&am->vlib_rp->mutex);
2074 oldheap = svm_push_data_heap (am->vlib_rp);
2076 vec_validate (shmem_vec, offset + buffer_bytes - 1);
2078 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
2080 svm_pop_heap (oldheap);
2081 pthread_mutex_unlock (&am->vlib_rp->mutex);
2083 *shmem_vecp = shmem_vec;
2088 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
2090 vl_api_cli_reply_t *rp;
2091 unix_shared_memory_queue_t *q;
2092 vlib_main_t *vm = vlib_get_main ();
2093 api_main_t *am = &api_main;
2094 unformat_input_t input;
2098 q = vl_api_client_index_to_input_queue (mp->client_index);
2102 rp = vl_msg_api_alloc (sizeof (*rp));
2103 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
2104 rp->context = mp->context;
2106 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
2108 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
2110 pthread_mutex_lock (&am->vlib_rp->mutex);
2111 oldheap = svm_push_data_heap (am->vlib_rp);
2113 vec_add1 (shmem_vec, 0);
2115 svm_pop_heap (oldheap);
2116 pthread_mutex_unlock (&am->vlib_rp->mutex);
2118 rp->reply_in_shmem = (uword) shmem_vec;
2120 vl_msg_api_send_shmem (q, (u8 *) & rp);
2124 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
2126 u8 **mem_vecp = (u8 **) arg;
2127 u8 *mem_vec = *mem_vecp;
2128 u32 offset = vec_len (mem_vec);
2130 vec_validate (mem_vec, offset + buffer_bytes - 1);
2131 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
2132 *mem_vecp = mem_vec;
2136 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
2138 vl_api_cli_inband_reply_t *rmp;
2140 unix_shared_memory_queue_t *q;
2141 vlib_main_t *vm = vlib_get_main ();
2142 unformat_input_t input;
2145 q = vl_api_client_index_to_input_queue (mp->client_index);
2149 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
2150 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
2152 u32 len = vec_len (out_vec);
2154 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
2156 rmp->length = htonl (len);
2157 clib_memcpy (rmp->reply, out_vec, len);
2164 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2167 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2168 vnet_main_t *vnm = vnet_get_main ();
2169 clib_error_t *error;
2174 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2176 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2180 clib_error_report (error);
2181 rv = VNET_API_ERROR_UNSPECIFIED;
2185 rv = vnm->api_errno;
2188 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2191 static void vl_api_sr_tunnel_add_del_t_handler
2192 (vl_api_sr_tunnel_add_del_t * mp)
2195 clib_warning ("unimplemented");
2197 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
2199 vl_api_sr_tunnel_add_del_reply_t *rmp;
2200 ip6_address_t *segments = 0, *seg;
2201 ip6_address_t *tags = 0, *tag;
2202 ip6_address_t *this_address;
2205 if (mp->n_segments == 0)
2211 memset (a, 0, sizeof (*a));
2212 a->src_address = (ip6_address_t *) & mp->src_address;
2213 a->dst_address = (ip6_address_t *) & mp->dst_address;
2214 a->dst_mask_width = mp->dst_mask_width;
2215 a->flags_net_byte_order = mp->flags_net_byte_order;
2216 a->is_del = (mp->is_add == 0);
2217 a->rx_table_id = ntohl (mp->outer_vrf_id);
2218 a->tx_table_id = ntohl (mp->inner_vrf_id);
2220 a->name = format (0, "%s", mp->name);
2221 if (!(vec_len (a->name)))
2224 a->policy_name = format (0, "%s", mp->policy_name);
2225 if (!(vec_len (a->policy_name)))
2228 /* Yank segments and tags out of the API message */
2229 this_address = (ip6_address_t *) mp->segs_and_tags;
2230 for (i = 0; i < mp->n_segments; i++)
2232 vec_add2 (segments, seg, 1);
2233 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
2236 for (i = 0; i < mp->n_tags; i++)
2238 vec_add2 (tags, tag, 1);
2239 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
2243 a->segments = segments;
2246 rv = ip6_sr_add_del_tunnel (a);
2250 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
2254 static void vl_api_sr_policy_add_del_t_handler
2255 (vl_api_sr_policy_add_del_t * mp)
2258 clib_warning ("unimplemented");
2260 ip6_sr_add_del_policy_args_t _a, *a = &_a;
2262 vl_api_sr_policy_add_del_reply_t *rmp;
2265 memset (a, 0, sizeof (*a));
2266 a->is_del = (mp->is_add == 0);
2268 a->name = format (0, "%s", mp->name);
2269 if (!(vec_len (a->name)))
2271 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2275 if (!(mp->tunnel_names[0]))
2277 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2281 // start deserializing tunnel_names
2282 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
2283 u8 *deser_tun_names = mp->tunnel_names;
2284 deser_tun_names += 1; //moving along
2287 int tun_name_len = 0;
2289 for (i = 0; i < num_tunnels; i++)
2291 tun_name_len = *deser_tun_names;
2292 deser_tun_names += 1;
2293 vec_resize (tun_name, tun_name_len);
2294 memcpy (tun_name, deser_tun_names, tun_name_len);
2295 vec_add1 (a->tunnel_names, tun_name);
2296 deser_tun_names += tun_name_len;
2300 rv = ip6_sr_add_del_policy (a);
2304 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
2308 static void vl_api_sr_multicast_map_add_del_t_handler
2309 (vl_api_sr_multicast_map_add_del_t * mp)
2312 clib_warning ("unimplemented");
2314 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
2316 vl_api_sr_multicast_map_add_del_reply_t *rmp;
2318 memset (a, 0, sizeof (*a));
2319 a->is_del = (mp->is_add == 0);
2321 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
2322 a->policy_name = format (0, "%s", mp->policy_name);
2324 if (a->multicast_address == 0)
2330 if (!(a->policy_name))
2336 #if DPDK > 0 /* Cannot call replicate without DPDK */
2337 rv = ip6_sr_add_del_multicastmap (a);
2339 clib_warning ("multicast replication without DPDK not implemented");
2340 rv = VNET_API_ERROR_UNIMPLEMENTED;
2345 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
2349 #define foreach_classify_add_del_table_field \
2354 _(match_n_vectors) \
2355 _(next_table_index) \
2356 _(miss_next_index) \
2357 _(current_data_flag) \
2358 _(current_data_offset)
2360 static void vl_api_classify_add_del_table_t_handler
2361 (vl_api_classify_add_del_table_t * mp)
2363 vl_api_classify_add_del_table_reply_t *rmp;
2364 vnet_classify_main_t *cm = &vnet_classify_main;
2365 vnet_classify_table_t *t;
2369 foreach_classify_add_del_table_field;
2372 #define _(a) a = ntohl(mp->a);
2373 foreach_classify_add_del_table_field;
2376 /* The underlying API fails silently, on purpose, so check here */
2377 if (mp->is_add == 0) /* delete */
2379 if (pool_is_free_index (cm->tables, table_index))
2381 rv = VNET_API_ERROR_NO_SUCH_TABLE;
2385 else /* add or update */
2387 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
2391 rv = vnet_classify_add_del_table
2392 (cm, mp->mask, nbuckets, memory_size,
2393 skip_n_vectors, match_n_vectors,
2394 next_table_index, miss_next_index, &table_index,
2395 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
2399 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
2401 if (rv == 0 && mp->is_add)
2403 t = pool_elt_at_index (cm->tables, table_index);
2404 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
2405 rmp->match_n_vectors = ntohl(t->match_n_vectors);
2406 rmp->new_table_index = ntohl(table_index);
2410 rmp->skip_n_vectors = ~0;
2411 rmp->match_n_vectors = ~0;
2412 rmp->new_table_index = ~0;
2418 static void vl_api_classify_add_del_session_t_handler
2419 (vl_api_classify_add_del_session_t * mp)
2421 vnet_classify_main_t *cm = &vnet_classify_main;
2422 vl_api_classify_add_del_session_reply_t *rmp;
2424 u32 table_index, hit_next_index, opaque_index, metadata;
2428 table_index = ntohl (mp->table_index);
2429 hit_next_index = ntohl (mp->hit_next_index);
2430 opaque_index = ntohl (mp->opaque_index);
2431 advance = ntohl (mp->advance);
2432 action = mp->action;
2433 metadata = ntohl (mp->metadata);
2435 rv = vnet_classify_add_del_session
2436 (cm, table_index, mp->match, hit_next_index, opaque_index,
2437 advance, action, metadata, mp->is_add);
2439 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
2442 static void vl_api_classify_set_interface_ip_table_t_handler
2443 (vl_api_classify_set_interface_ip_table_t * mp)
2445 vlib_main_t *vm = vlib_get_main ();
2446 vl_api_classify_set_interface_ip_table_reply_t *rmp;
2448 u32 table_index, sw_if_index;
2450 table_index = ntohl (mp->table_index);
2451 sw_if_index = ntohl (mp->sw_if_index);
2453 VALIDATE_SW_IF_INDEX (mp);
2456 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
2458 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
2460 BAD_SW_IF_INDEX_LABEL;
2462 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
2465 static void vl_api_classify_set_interface_l2_tables_t_handler
2466 (vl_api_classify_set_interface_l2_tables_t * mp)
2468 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
2470 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
2473 ip4_table_index = ntohl (mp->ip4_table_index);
2474 ip6_table_index = ntohl (mp->ip6_table_index);
2475 other_table_index = ntohl (mp->other_table_index);
2476 sw_if_index = ntohl (mp->sw_if_index);
2478 VALIDATE_SW_IF_INDEX (mp);
2481 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
2485 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
2491 if (ip4_table_index != ~0 || ip6_table_index != ~0
2492 || other_table_index != ~0)
2498 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
2500 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
2503 BAD_SW_IF_INDEX_LABEL;
2505 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
2509 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
2512 vl_api_l2_fib_clear_table_reply_t *rmp;
2514 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
2515 * that is not currently implemented. When that TODO is fixed
2516 * this call should be changed to pass 1 instead of 0.
2518 l2fib_clear_table (0);
2520 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
2523 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
2524 u32 sw_if_index, u32 enable);
2527 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
2531 vl_api_l2_interface_efp_filter_reply_t *rmp;
2532 vnet_main_t *vnm = vnet_get_main ();
2534 // enable/disable the feature
2535 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
2536 rv = vnm->api_errno;
2538 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
2542 vl_api_l2_interface_vlan_tag_rewrite_t_handler
2543 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
2546 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
2547 vnet_main_t *vnm = vnet_get_main ();
2548 vlib_main_t *vm = vlib_get_main ();
2551 VALIDATE_SW_IF_INDEX (mp);
2553 vtr_op = ntohl (mp->vtr_op);
2555 /* The L2 code is unsuspicious */
2558 case L2_VTR_DISABLED:
2563 case L2_VTR_TRANSLATE_1_1:
2564 case L2_VTR_TRANSLATE_1_2:
2565 case L2_VTR_TRANSLATE_2_1:
2566 case L2_VTR_TRANSLATE_2_2:
2570 rv = VNET_API_ERROR_INVALID_VALUE;
2571 goto bad_sw_if_index;
2574 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
2575 ntohl (mp->push_dot1q), ntohl (mp->tag1),
2578 BAD_SW_IF_INDEX_LABEL;
2580 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
2584 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
2587 vl_api_create_vhost_user_if_reply_t *rmp;
2588 u32 sw_if_index = (u32) ~ 0;
2589 vnet_main_t *vnm = vnet_get_main ();
2590 vlib_main_t *vm = vlib_get_main ();
2592 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
2593 mp->is_server, &sw_if_index, (u64) ~ 0,
2594 mp->renumber, ntohl (mp->custom_dev_instance),
2595 (mp->use_custom_mac) ? mp->mac_address : NULL);
2597 /* Remember an interface tag for the new interface */
2600 /* If a tag was supplied... */
2603 /* Make sure it's a proper C-string */
2604 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
2605 u8 *tag = format (0, "%s%c", mp->tag, 0);
2606 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
2611 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
2613 rmp->sw_if_index = ntohl (sw_if_index);
2619 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
2622 vl_api_modify_vhost_user_if_reply_t *rmp;
2623 u32 sw_if_index = ntohl (mp->sw_if_index);
2625 vnet_main_t *vnm = vnet_get_main ();
2626 vlib_main_t *vm = vlib_get_main ();
2628 rv = vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
2629 mp->is_server, sw_if_index, (u64) ~ 0,
2630 mp->renumber, ntohl (mp->custom_dev_instance));
2632 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
2636 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
2639 vl_api_delete_vhost_user_if_reply_t *rmp;
2640 vpe_api_main_t *vam = &vpe_api_main;
2641 u32 sw_if_index = ntohl (mp->sw_if_index);
2643 vnet_main_t *vnm = vnet_get_main ();
2644 vlib_main_t *vm = vlib_get_main ();
2646 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
2648 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
2651 unix_shared_memory_queue_t *q =
2652 vl_api_client_index_to_input_queue (mp->client_index);
2656 vnet_clear_sw_interface_tag (vnm, sw_if_index);
2657 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2662 vl_api_sw_interface_vhost_user_details_t_handler
2663 (vl_api_sw_interface_vhost_user_details_t * mp)
2665 clib_warning ("BUG");
2669 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
2670 unix_shared_memory_queue_t * q,
2671 vhost_user_intf_details_t * vui,
2674 vl_api_sw_interface_vhost_user_details_t *mp;
2676 mp = vl_msg_api_alloc (sizeof (*mp));
2677 memset (mp, 0, sizeof (*mp));
2678 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
2679 mp->sw_if_index = ntohl (vui->sw_if_index);
2680 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
2681 mp->features = clib_net_to_host_u64 (vui->features);
2682 mp->is_server = vui->is_server;
2683 mp->num_regions = ntohl (vui->num_regions);
2684 mp->sock_errno = ntohl (vui->sock_errno);
2685 mp->context = context;
2687 strncpy ((char *) mp->sock_filename,
2688 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
2689 strncpy ((char *) mp->interface_name,
2690 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
2692 vl_msg_api_send_shmem (q, (u8 *) & mp);
2696 vl_api_sw_interface_vhost_user_dump_t_handler
2697 (vl_api_sw_interface_vhost_user_dump_t * mp)
2700 vpe_api_main_t *am = &vpe_api_main;
2701 vnet_main_t *vnm = vnet_get_main ();
2702 vlib_main_t *vm = vlib_get_main ();
2703 vhost_user_intf_details_t *ifaces = NULL;
2704 vhost_user_intf_details_t *vuid = NULL;
2705 unix_shared_memory_queue_t *q;
2707 q = vl_api_client_index_to_input_queue (mp->client_index);
2711 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
2715 vec_foreach (vuid, ifaces)
2717 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
2723 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
2724 unix_shared_memory_queue_t * q,
2726 l2t_main_t * lm, u32 context)
2728 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
2730 vnet_sw_interface_t *si = NULL;
2732 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
2734 if_name = format (if_name, "%U",
2735 format_vnet_sw_interface_name, lm->vnet_main, si);
2737 mp = vl_msg_api_alloc (sizeof (*mp));
2738 memset (mp, 0, sizeof (*mp));
2739 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
2740 strncpy ((char *) mp->interface_name,
2741 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
2742 mp->sw_if_index = ntohl (si->sw_if_index);
2743 mp->local_session_id = s->local_session_id;
2744 mp->remote_session_id = s->remote_session_id;
2745 mp->local_cookie[0] = s->local_cookie[0];
2746 mp->local_cookie[1] = s->local_cookie[1];
2747 mp->remote_cookie = s->remote_cookie;
2748 clib_memcpy (mp->client_address, &s->client_address,
2749 sizeof (s->client_address));
2750 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
2751 mp->l2_sublayer_present = s->l2_sublayer_present;
2752 mp->context = context;
2754 vl_msg_api_send_shmem (q, (u8 *) & mp);
2759 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
2762 vpe_api_main_t *am = &vpe_api_main;
2763 l2t_main_t *lm = &l2t_main;
2764 unix_shared_memory_queue_t *q;
2765 l2t_session_t *session;
2767 q = vl_api_client_index_to_input_queue (mp->client_index);
2772 pool_foreach (session, lm->sessions,
2774 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
2780 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
2782 clib_warning ("BUG");
2786 send_l2fib_table_entry (vpe_api_main_t * am,
2787 unix_shared_memory_queue_t * q,
2788 l2fib_entry_key_t * l2fe_key,
2789 l2fib_entry_result_t * l2fe_res, u32 context)
2791 vl_api_l2_fib_table_entry_t *mp;
2793 mp = vl_msg_api_alloc (sizeof (*mp));
2794 memset (mp, 0, sizeof (*mp));
2795 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
2798 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
2800 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
2801 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
2802 mp->static_mac = l2fe_res->fields.static_mac;
2803 mp->filter_mac = l2fe_res->fields.filter;
2804 mp->bvi_mac = l2fe_res->fields.bvi;
2805 mp->context = context;
2807 vl_msg_api_send_shmem (q, (u8 *) & mp);
2811 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
2813 vpe_api_main_t *am = &vpe_api_main;
2814 bd_main_t *bdm = &bd_main;
2815 l2fib_entry_key_t *l2fe_key = NULL;
2816 l2fib_entry_result_t *l2fe_res = NULL;
2817 u32 ni, bd_id = ntohl (mp->bd_id);
2819 unix_shared_memory_queue_t *q;
2822 q = vl_api_client_index_to_input_queue (mp->client_index);
2826 /* see l2fib_table_dump: ~0 means "any" */
2831 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2838 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
2840 vec_foreach_index (ni, l2fe_key)
2842 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
2843 vec_elt_at_index (l2fe_res, ni), mp->context);
2845 vec_free (l2fe_key);
2846 vec_free (l2fe_res);
2850 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
2852 vl_api_show_version_reply_t *rmp;
2854 char *vpe_api_get_build_directory (void);
2855 char *vpe_api_get_version (void);
2856 char *vpe_api_get_build_date (void);
2858 unix_shared_memory_queue_t *q =
2859 vl_api_client_index_to_input_queue (mp->client_index);
2865 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
2867 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
2868 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
2869 ARRAY_LEN(rmp->build_directory)-1);
2870 strncpy ((char *) rmp->version, vpe_api_get_version(),
2871 ARRAY_LEN(rmp->version)-1);
2872 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
2873 ARRAY_LEN(rmp->build_date)-1);
2879 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
2881 vlib_main_t *vm = vlib_get_main ();
2882 vl_api_get_node_index_reply_t *rmp;
2885 u32 node_index = ~0;
2887 n = vlib_get_node_by_name (vm, mp->node_name);
2890 rv = VNET_API_ERROR_NO_SUCH_NODE;
2892 node_index = n->index;
2895 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
2897 rmp->node_index = ntohl(node_index);
2903 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
2905 vlib_main_t *vm = vlib_get_main ();
2906 vl_api_get_next_index_reply_t *rmp;
2907 vlib_node_t *node, *next_node;
2909 u32 next_node_index = ~0, next_index = ~0;
2912 node = vlib_get_node_by_name (vm, mp->node_name);
2916 rv = VNET_API_ERROR_NO_SUCH_NODE;
2920 next_node = vlib_get_node_by_name (vm, mp->next_name);
2924 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2928 next_node_index = next_node->index;
2930 p = hash_get (node->next_slot_by_node, next_node_index);
2934 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2942 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
2944 rmp->next_index = ntohl(next_index);
2950 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
2952 vlib_main_t *vm = vlib_get_main ();
2953 vl_api_add_node_next_reply_t *rmp;
2954 vlib_node_t *n, *next;
2956 u32 next_index = ~0;
2958 n = vlib_get_node_by_name (vm, mp->node_name);
2962 rv = VNET_API_ERROR_NO_SUCH_NODE;
2966 next = vlib_get_node_by_name (vm, mp->next_name);
2969 rv = VNET_API_ERROR_NO_SUCH_NODE2;
2971 next_index = vlib_node_add_next (vm, n->index, next->index);
2975 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
2977 rmp->next_index = ntohl(next_index);
2982 static void vl_api_l2tpv3_create_tunnel_t_handler
2983 (vl_api_l2tpv3_create_tunnel_t * mp)
2985 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
2986 l2t_main_t *lm = &l2t_main;
2987 u32 sw_if_index = (u32) ~ 0;
2990 if (mp->is_ipv6 != 1)
2992 rv = VNET_API_ERROR_UNIMPLEMENTED;
2996 u32 encap_fib_index;
2998 if (mp->encap_vrf_id != ~0)
3001 ip6_main_t *im = &ip6_main;
3004 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
3006 rv = VNET_API_ERROR_NO_SUCH_FIB;
3009 encap_fib_index = p[0];
3013 encap_fib_index = ~0;
3016 rv = create_l2tpv3_ipv6_tunnel (lm,
3017 (ip6_address_t *) mp->client_address,
3018 (ip6_address_t *) mp->our_address,
3019 ntohl (mp->local_session_id),
3020 ntohl (mp->remote_session_id),
3021 clib_net_to_host_u64 (mp->local_cookie),
3022 clib_net_to_host_u64 (mp->remote_cookie),
3023 mp->l2_sublayer_present,
3024 encap_fib_index, &sw_if_index);
3028 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
3030 rmp->sw_if_index = ntohl (sw_if_index);
3035 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
3036 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
3038 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
3039 l2t_main_t *lm = &l2t_main;
3042 VALIDATE_SW_IF_INDEX (mp);
3044 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
3045 clib_net_to_host_u64 (mp->new_local_cookie),
3046 clib_net_to_host_u64
3047 (mp->new_remote_cookie));
3049 BAD_SW_IF_INDEX_LABEL;
3051 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
3054 static void vl_api_l2tpv3_interface_enable_disable_t_handler
3055 (vl_api_l2tpv3_interface_enable_disable_t * mp)
3058 vnet_main_t *vnm = vnet_get_main ();
3059 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
3061 VALIDATE_SW_IF_INDEX (mp);
3063 rv = l2tpv3_interface_enable_disable
3064 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
3066 BAD_SW_IF_INDEX_LABEL;
3068 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
3071 static void vl_api_l2tpv3_set_lookup_key_t_handler
3072 (vl_api_l2tpv3_set_lookup_key_t * mp)
3075 l2t_main_t *lm = &l2t_main;
3076 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
3078 if (mp->key > L2T_LOOKUP_SESSION_ID)
3080 rv = VNET_API_ERROR_INVALID_VALUE;
3084 lm->lookup_type = mp->key;
3087 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
3090 static void vl_api_vxlan_add_del_tunnel_t_handler
3091 (vl_api_vxlan_add_del_tunnel_t * mp)
3093 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
3095 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
3096 u32 encap_fib_index;
3098 ip4_main_t *im = &ip4_main;
3099 u32 sw_if_index = ~0;
3101 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
3104 rv = VNET_API_ERROR_NO_SUCH_FIB;
3107 encap_fib_index = p[0];
3108 memset (a, 0, sizeof (*a));
3110 a->is_add = mp->is_add;
3111 a->is_ip6 = mp->is_ipv6;
3113 /* ip addresses sent in network byte order */
3114 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
3115 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
3117 /* Check src & dst are different */
3118 if (ip46_address_cmp (&a->dst, &a->src) == 0)
3120 rv = VNET_API_ERROR_SAME_SRC_DST;
3123 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
3124 a->encap_fib_index = encap_fib_index;
3125 a->decap_next_index = ntohl (mp->decap_next_index);
3126 a->vni = ntohl (mp->vni);
3127 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
3131 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
3133 rmp->sw_if_index = ntohl (sw_if_index);
3138 static void send_vxlan_tunnel_details
3139 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
3141 vl_api_vxlan_tunnel_details_t *rmp;
3142 ip4_main_t *im4 = &ip4_main;
3143 ip6_main_t *im6 = &ip6_main;
3144 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
3146 rmp = vl_msg_api_alloc (sizeof (*rmp));
3147 memset (rmp, 0, sizeof (*rmp));
3148 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
3151 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
3152 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
3153 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
3157 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
3158 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
3159 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
3161 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
3162 rmp->vni = htonl (t->vni);
3163 rmp->decap_next_index = htonl (t->decap_next_index);
3164 rmp->sw_if_index = htonl (t->sw_if_index);
3165 rmp->is_ipv6 = is_ipv6;
3166 rmp->context = context;
3168 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3171 static void vl_api_vxlan_tunnel_dump_t_handler
3172 (vl_api_vxlan_tunnel_dump_t * mp)
3174 unix_shared_memory_queue_t *q;
3175 vxlan_main_t *vxm = &vxlan_main;
3179 q = vl_api_client_index_to_input_queue (mp->client_index);
3185 sw_if_index = ntohl (mp->sw_if_index);
3187 if (~0 == sw_if_index)
3190 pool_foreach (t, vxm->tunnels,
3192 send_vxlan_tunnel_details(t, q, mp->context);
3198 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
3199 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
3203 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
3204 send_vxlan_tunnel_details (t, q, mp->context);
3208 static void vl_api_gre_add_del_tunnel_t_handler
3209 (vl_api_gre_add_del_tunnel_t * mp)
3211 vl_api_gre_add_del_tunnel_reply_t *rmp;
3213 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
3216 ip4_main_t *im = &ip4_main;
3217 u32 sw_if_index = ~0;
3219 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
3222 rv = VNET_API_ERROR_NO_SUCH_FIB;
3225 outer_fib_id = p[0];
3227 /* Check src & dst are different */
3228 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
3229 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
3231 rv = VNET_API_ERROR_SAME_SRC_DST;
3234 memset (a, 0, sizeof (*a));
3236 a->is_add = mp->is_add;
3239 /* ip addresses sent in network byte order */
3240 clib_memcpy (&(a->src), mp->src_address, 4);
3241 clib_memcpy (&(a->dst), mp->dst_address, 4);
3243 a->outer_fib_id = outer_fib_id;
3244 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
3248 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
3250 rmp->sw_if_index = ntohl (sw_if_index);
3255 static void send_gre_tunnel_details
3256 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
3258 vl_api_gre_tunnel_details_t *rmp;
3259 ip4_main_t *im = &ip4_main;
3261 rmp = vl_msg_api_alloc (sizeof (*rmp));
3262 memset (rmp, 0, sizeof (*rmp));
3263 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
3264 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
3265 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
3266 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
3267 rmp->teb = (GRE_TUNNEL_TYPE_TEB == t->type);
3268 rmp->sw_if_index = htonl (t->sw_if_index);
3269 rmp->context = context;
3271 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3275 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
3277 unix_shared_memory_queue_t *q;
3278 gre_main_t *gm = &gre_main;
3282 q = vl_api_client_index_to_input_queue (mp->client_index);
3288 sw_if_index = ntohl (mp->sw_if_index);
3290 if (~0 == sw_if_index)
3293 pool_foreach (t, gm->tunnels,
3295 send_gre_tunnel_details(t, q, mp->context);
3301 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
3302 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
3306 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
3307 send_gre_tunnel_details (t, q, mp->context);
3312 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
3314 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
3316 vl_api_l2_patch_add_del_reply_t *rmp;
3317 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
3321 VALIDATE_RX_SW_IF_INDEX (mp);
3322 VALIDATE_TX_SW_IF_INDEX (mp);
3324 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
3325 ntohl (mp->tx_sw_if_index),
3326 (int) (mp->is_add != 0));
3328 BAD_RX_SW_IF_INDEX_LABEL;
3329 BAD_TX_SW_IF_INDEX_LABEL;
3331 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
3335 vl_api_vxlan_gpe_add_del_tunnel_t_handler
3336 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
3338 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
3340 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
3341 u32 encap_fib_index, decap_fib_index;
3344 ip4_main_t *im = &ip4_main;
3345 u32 sw_if_index = ~0;
3348 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
3351 rv = VNET_API_ERROR_NO_SUCH_FIB;
3354 encap_fib_index = p[0];
3356 protocol = mp->protocol;
3358 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
3359 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
3361 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
3364 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
3367 decap_fib_index = p[0];
3371 decap_fib_index = ntohl (mp->decap_vrf_id);
3374 /* Check src & dst are different */
3375 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
3376 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
3378 rv = VNET_API_ERROR_SAME_SRC_DST;
3381 memset (a, 0, sizeof (*a));
3383 a->is_add = mp->is_add;
3384 a->is_ip6 = mp->is_ipv6;
3385 /* ip addresses sent in network byte order */
3388 clib_memcpy (&(a->local.ip6), mp->local, 16);
3389 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
3393 clib_memcpy (&(a->local.ip4), mp->local, 4);
3394 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
3396 a->encap_fib_index = encap_fib_index;
3397 a->decap_fib_index = decap_fib_index;
3398 a->protocol = protocol;
3399 a->vni = ntohl (mp->vni);
3400 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
3404 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
3406 rmp->sw_if_index = ntohl (sw_if_index);
3411 static void send_vxlan_gpe_tunnel_details
3412 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
3414 vl_api_vxlan_gpe_tunnel_details_t *rmp;
3415 ip4_main_t *im4 = &ip4_main;
3416 ip6_main_t *im6 = &ip6_main;
3417 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
3419 rmp = vl_msg_api_alloc (sizeof (*rmp));
3420 memset (rmp, 0, sizeof (*rmp));
3421 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
3424 memcpy (rmp->local, &(t->local.ip6), 16);
3425 memcpy (rmp->remote, &(t->remote.ip6), 16);
3426 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
3427 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
3431 memcpy (rmp->local, &(t->local.ip4), 4);
3432 memcpy (rmp->remote, &(t->remote.ip4), 4);
3433 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
3434 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
3436 rmp->vni = htonl (t->vni);
3437 rmp->protocol = t->protocol;
3438 rmp->sw_if_index = htonl (t->sw_if_index);
3439 rmp->is_ipv6 = is_ipv6;
3440 rmp->context = context;
3442 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3445 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
3446 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
3448 unix_shared_memory_queue_t *q;
3449 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
3450 vxlan_gpe_tunnel_t *t;
3453 q = vl_api_client_index_to_input_queue (mp->client_index);
3459 sw_if_index = ntohl (mp->sw_if_index);
3461 if (~0 == sw_if_index)
3464 pool_foreach (t, vgm->tunnels,
3466 send_vxlan_gpe_tunnel_details(t, q, mp->context);
3472 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
3473 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
3477 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
3478 send_vxlan_gpe_tunnel_details (t, q, mp->context);
3482 /** Used for transferring locators via VPP API */
3484 typedef CLIB_PACKED (struct {
3485 u32 sw_if_index; /**< locator sw_if_index */
3486 u8 priority; /**< locator priority */
3487 u8 weight; /**< locator weight */
3492 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
3495 vl_api_lisp_add_del_locator_set_reply_t *rmp;
3497 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
3499 ls_locator_t *ls_loc;
3500 u32 ls_index = ~0, locator_num;
3501 u8 *locator_name = NULL;
3504 memset (a, 0, sizeof (a[0]));
3506 locator_name = format (0, "%s", mp->locator_set_name);
3508 a->name = locator_name;
3509 a->is_add = mp->is_add;
3511 locator_num = clib_net_to_host_u32 (mp->locator_num);
3513 memset (&locator, 0, sizeof (locator));
3514 for (i = 0; i < locator_num; i++)
3516 ls_loc = &((ls_locator_t *) mp->locators)[i];
3517 VALIDATE_SW_IF_INDEX (ls_loc);
3519 locator.sw_if_index = htonl (ls_loc->sw_if_index);
3520 locator.priority = ls_loc->priority;
3521 locator.weight = ls_loc->weight;
3523 vec_add1 (a->locators, locator);
3526 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
3528 BAD_SW_IF_INDEX_LABEL;
3530 vec_free (locator_name);
3531 vec_free (a->locators);
3534 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
3536 rmp->ls_index = clib_host_to_net_u32 (ls_index);
3542 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
3544 vl_api_lisp_add_del_locator_reply_t *rmp;
3546 locator_t locator, *locators = NULL;
3547 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
3549 u8 *locator_name = NULL;
3551 memset (&locator, 0, sizeof (locator));
3552 memset (a, 0, sizeof (a[0]));
3554 locator.sw_if_index = ntohl (mp->sw_if_index);
3555 locator.priority = mp->priority;
3556 locator.weight = mp->weight;
3558 vec_add1 (locators, locator);
3560 locator_name = format (0, "%s", mp->locator_set_name);
3562 a->name = locator_name;
3563 a->locators = locators;
3564 a->is_add = mp->is_add;
3567 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
3569 vec_free (locators);
3570 vec_free (locator_name);
3572 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
3576 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
3582 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3583 gid_address_ip_set (dst, src, IP4);
3584 gid_address_ippref_len (dst) = len;
3585 ip_prefix_normalize (&gid_address_ippref (dst));
3588 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3589 gid_address_ip_set (dst, src, IP6);
3590 gid_address_ippref_len (dst) = len;
3591 ip_prefix_normalize (&gid_address_ippref (dst));
3593 case 2: /* l2 mac */
3594 gid_address_type (dst) = GID_ADDR_MAC;
3595 clib_memcpy (&gid_address_mac (dst), src, 6);
3599 return VNET_API_ERROR_INVALID_VALUE;
3602 gid_address_vni (dst) = vni;
3608 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
3610 vl_api_lisp_add_del_local_eid_reply_t *rmp;
3611 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3613 gid_address_t _eid, *eid = &_eid;
3615 u32 locator_set_index = ~0, map_index = ~0;
3616 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
3617 u8 *name = NULL, *key = NULL;
3618 memset (a, 0, sizeof (a[0]));
3619 memset (eid, 0, sizeof (eid[0]));
3621 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3622 mp->eid_type, mp->eid, mp->prefix_len);
3626 name = format (0, "%s", mp->locator_set_name);
3627 p = hash_get_mem (lcm->locator_set_index_by_name, name);
3630 rv = VNET_API_ERROR_INVALID_VALUE;
3633 locator_set_index = p[0];
3636 key = format (0, "%s", mp->key);
3638 /* XXX treat batch configuration */
3639 a->is_add = mp->is_add;
3640 gid_address_copy (&a->eid, eid);
3641 a->locator_set_index = locator_set_index;
3644 a->key_id = clib_net_to_host_u16 (mp->key_id);
3646 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
3651 gid_address_free (&a->eid);
3653 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
3657 vl_api_lisp_eid_table_add_del_map_t_handler
3658 (vl_api_lisp_eid_table_add_del_map_t * mp)
3660 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
3662 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
3663 clib_net_to_host_u32 (mp->dp_table),
3664 mp->is_l2, mp->is_add);
3665 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
3667 /** Used for transferring locators via VPP API */
3669 typedef CLIB_PACKED (struct {
3670 u8 is_ip4; /**< is locator an IPv4 address */
3671 u8 priority; /**< locator priority */
3672 u8 weight; /**< locator weight */
3673 u8 addr[16]; /**< IPv4/IPv6 address */
3677 static locator_pair_t *
3678 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
3681 locator_pair_t *pairs = 0, pair;
3684 for (i = 0; i < rloc_num; i++)
3687 r = &((rloc_t *) lcl_locs)[i];
3688 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
3689 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
3691 /* remote locators */
3692 r = &((rloc_t *) rmt_locs)[i];
3693 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
3694 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
3696 pair.priority = r->priority;
3697 pair.weight = r->weight;
3699 vec_add1 (pairs, pair);
3705 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
3708 locator_t *locs = 0, loc;
3711 for (i = 0; i < rloc_num; i++)
3713 /* remote locators */
3714 r = &((rloc_t *) rmt_locs)[i];
3715 memset (&loc, 0, sizeof (loc));
3716 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
3718 loc.priority = r->priority;
3719 loc.weight = r->weight;
3721 vec_add1 (locs, loc);
3727 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
3728 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
3730 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
3731 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
3732 locator_pair_t *pairs = 0;
3735 memset (a, 0, sizeof (a[0]));
3737 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
3738 mp->rmt_eid, mp->rmt_len);
3739 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
3740 mp->lcl_eid, mp->lcl_len);
3742 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
3744 if (rv || 0 == pairs)
3747 a->is_add = mp->is_add;
3748 a->locator_pairs = pairs;
3749 a->dp_table = mp->dp_table;
3751 a->action = mp->action;
3753 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
3756 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
3760 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
3763 vl_api_lisp_add_del_map_server_reply_t *rmp;
3767 memset (&addr, 0, sizeof (addr));
3769 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
3770 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
3772 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
3776 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
3779 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
3781 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
3783 memset (a, 0, sizeof (a[0]));
3785 a->is_add = mp->is_add;
3786 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
3788 rv = vnet_lisp_add_del_map_resolver (a);
3790 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
3794 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
3797 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
3799 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
3801 a->is_en = mp->is_en;
3802 vnet_lisp_gpe_enable_disable (a);
3804 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
3808 vl_api_lisp_map_register_enable_disable_t_handler
3809 (vl_api_lisp_map_register_enable_disable_t * mp)
3811 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
3814 vnet_lisp_map_register_enable_disable (mp->is_enabled);
3815 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3819 vl_api_lisp_rloc_probe_enable_disable_t_handler
3820 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
3822 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
3825 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
3826 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3830 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
3832 vl_api_lisp_enable_disable_reply_t *rmp;
3835 vnet_lisp_enable_disable (mp->is_en);
3836 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
3840 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
3842 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
3850 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
3854 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
3861 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
3865 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
3868 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
3872 vl_api_show_lisp_map_request_mode_t_handler
3873 (vl_api_show_lisp_map_request_mode_t * mp)
3876 vl_api_show_lisp_map_request_mode_reply_t *rmp;
3879 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
3881 rmp->mode = vnet_lisp_get_map_request_mode ();
3887 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
3889 vl_api_lisp_map_request_mode_reply_t *rmp;
3892 rv = vnet_lisp_set_map_request_mode (mp->mode);
3894 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
3898 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
3901 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
3905 ls_name = format (0, "%s", mp->ls_name);
3906 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
3909 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
3913 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
3914 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
3916 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
3918 u8 *locator_set_name = NULL;
3919 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
3921 locator_set_name = format (0, "%s", mp->locator_set_name);
3923 a->is_add = mp->is_add;
3924 a->locator_set_name = locator_set_name;
3926 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
3928 vec_free (locator_set_name);
3930 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
3934 vl_api_lisp_add_del_remote_mapping_t_handler
3935 (vl_api_lisp_add_del_remote_mapping_t * mp)
3937 locator_t *rlocs = 0;
3938 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
3940 gid_address_t _eid, *eid = &_eid;
3941 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
3943 memset (eid, 0, sizeof (eid[0]));
3945 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
3946 mp->eid_type, mp->eid, mp->eid_len);
3950 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
3954 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
3955 gid_address_copy (&a->reid, eid);
3957 rv = vnet_lisp_add_del_adjacency (a);
3964 /* NOTE: for now this works as a static remote mapping, i.e.,
3965 * not authoritative and ttl infinite. */
3966 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
3967 mp->is_add, 1 /* is_static */ , 0);
3970 vnet_lisp_clear_all_remote_adjacencies ();
3975 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
3979 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
3981 vl_api_lisp_add_del_adjacency_reply_t *rmp;
3982 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
3985 memset (a, 0, sizeof (a[0]));
3987 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
3988 mp->eid_type, mp->leid, mp->leid_len);
3989 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
3990 mp->eid_type, mp->reid, mp->reid_len);
3995 a->is_add = mp->is_add;
3996 rv = vnet_lisp_add_del_adjacency (a);
3999 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
4003 send_lisp_locator_details (lisp_cp_main_t * lcm,
4005 unix_shared_memory_queue_t * q, u32 context)
4007 vl_api_lisp_locator_details_t *rmp;
4009 rmp = vl_msg_api_alloc (sizeof (*rmp));
4010 memset (rmp, 0, sizeof (*rmp));
4011 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
4012 rmp->context = context;
4014 rmp->local = loc->local;
4017 rmp->sw_if_index = ntohl (loc->sw_if_index);
4021 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
4022 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
4024 rmp->priority = loc->priority;
4025 rmp->weight = loc->weight;
4027 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4031 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
4034 unix_shared_memory_queue_t *q = 0;
4035 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4036 locator_set_t *lsit = 0;
4038 u32 ls_index = ~0, *locit = 0;
4041 q = vl_api_client_index_to_input_queue (mp->client_index);
4047 if (mp->is_index_set)
4048 ls_index = htonl (mp->ls_index);
4051 /* make sure we get a proper C-string */
4052 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
4053 ls_name = format (0, "%s", mp->ls_name);
4054 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
4060 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
4063 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
4065 vec_foreach (locit, lsit->locator_indices)
4067 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4068 send_lisp_locator_details (lcm, loc, q, mp->context);
4075 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
4076 locator_set_t * lsit,
4077 unix_shared_memory_queue_t * q,
4078 u32 context, u32 ls_index)
4080 vl_api_lisp_locator_set_details_t *rmp;
4083 rmp = vl_msg_api_alloc (sizeof (*rmp));
4084 memset (rmp, 0, sizeof (*rmp));
4085 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
4086 rmp->context = context;
4088 rmp->ls_index = htonl (ls_index);
4091 ASSERT (lsit->name != NULL);
4092 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
4093 vec_len (lsit->name));
4097 str = format (0, "<remote-%d>", ls_index);
4098 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
4102 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4106 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
4108 unix_shared_memory_queue_t *q = NULL;
4109 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4110 locator_set_t *lsit = NULL;
4113 q = vl_api_client_index_to_input_queue (mp->client_index);
4119 filter = mp->filter;
4121 pool_foreach (lsit, lcm->locator_set_pool,
4123 if (filter && !((1 == filter && lsit->local) ||
4124 (2 == filter && !lsit->local)))
4128 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
4129 lsit - lcm->locator_set_pool);
4135 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
4137 ASSERT (prefix_length);
4138 ip_prefix_t *ippref = &fid_addr_ippref (src);
4140 switch (fid_addr_type (src))
4142 case FID_ADDR_IP_PREF:
4143 if (ip_prefix_version (ippref) == IP4)
4144 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
4146 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
4147 prefix_length[0] = ip_prefix_len (ippref);
4151 prefix_length[0] = 0;
4152 clib_memcpy (dst, fid_addr_mac (src), 6);
4156 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
4162 fid_type_to_api_type (fid_address_t * fid)
4164 ip_prefix_t *ippref;
4166 switch (fid_addr_type (fid))
4168 case FID_ADDR_IP_PREF:
4169 ippref = &fid_addr_ippref (fid);
4170 if (ip_prefix_version (ippref) == IP4)
4172 else if (ip_prefix_version (ippref) == IP6)
4185 send_lisp_eid_table_details (mapping_t * mapit,
4186 unix_shared_memory_queue_t * q,
4187 u32 context, u8 filter)
4190 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4191 locator_set_t *ls = 0;
4192 vl_api_lisp_eid_table_details_t *rmp = NULL;
4193 gid_address_t *gid = NULL;
4195 ip_prefix_t *ip_prefix = NULL;
4199 case 0: /* all mappings */
4202 case 1: /* local only */
4206 case 2: /* remote only */
4211 clib_warning ("Filter error, unknown filter: %d", filter);
4216 ip_prefix = &gid_address_ippref (gid);
4217 mac = gid_address_mac (gid);
4219 rmp = vl_msg_api_alloc (sizeof (*rmp));
4220 memset (rmp, 0, sizeof (*rmp));
4221 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
4223 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
4224 if (vec_len (ls->locator_indices) == 0)
4225 rmp->locator_set_index = ~0;
4227 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
4229 rmp->is_local = mapit->local;
4230 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
4231 rmp->action = mapit->action;
4232 rmp->authoritative = mapit->authoritative;
4234 switch (gid_address_type (gid))
4236 case GID_ADDR_SRC_DST:
4237 rmp->is_src_dst = 1;
4238 fid = &gid_address_sd_src (gid);
4239 rmp->eid_type = fid_type_to_api_type (fid);
4240 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
4241 &rmp->seid_prefix_len);
4242 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
4243 &rmp->eid_prefix_len);
4245 case GID_ADDR_IP_PREFIX:
4246 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
4247 if (ip_prefix_version (ip_prefix) == IP4)
4249 rmp->eid_type = 0; /* ipv4 type */
4250 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
4251 sizeof (ip_prefix_v4 (ip_prefix)));
4255 rmp->eid_type = 1; /* ipv6 type */
4256 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
4257 sizeof (ip_prefix_v6 (ip_prefix)));
4261 rmp->eid_type = 2; /* l2 mac type */
4262 clib_memcpy (rmp->eid, mac, 6);
4267 rmp->context = context;
4268 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
4269 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
4270 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
4271 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4275 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
4278 unix_shared_memory_queue_t *q = NULL;
4279 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4280 mapping_t *mapit = NULL;
4281 gid_address_t _eid, *eid = &_eid;
4283 q = vl_api_client_index_to_input_queue (mp->client_index);
4291 memset (eid, 0, sizeof (*eid));
4293 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
4294 mp->eid_type, mp->eid, mp->prefix_length);
4296 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
4297 if ((u32) ~ 0 == mi)
4300 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
4301 send_lisp_eid_table_details (mapit, q, mp->context,
4302 0 /* ignore filter */ );
4307 pool_foreach (mapit, lcm->mapping_pool,
4309 send_lisp_eid_table_details(mapit, q, mp->context,
4317 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
4318 unix_shared_memory_queue_t * q, u32 context)
4320 vl_api_lisp_gpe_tunnel_details_t *rmp;
4321 lisp_gpe_main_t *lgm = &lisp_gpe_main;
4323 rmp = vl_msg_api_alloc (sizeof (*rmp));
4324 memset (rmp, 0, sizeof (*rmp));
4325 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
4327 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
4329 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
4330 ip_address_copy_addr (rmp->source_ip,
4331 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
4332 ip_address_copy_addr (rmp->destination_ip,
4333 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
4335 rmp->encap_fib_id = htonl (0);
4336 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
4337 rmp->iid = htonl (lfe->key->vni);
4338 rmp->context = context;
4340 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4344 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
4346 unix_shared_memory_queue_t *q = NULL;
4347 lisp_gpe_main_t *lgm = &lisp_gpe_main;
4348 lisp_gpe_fwd_entry_t *lfe = NULL;
4350 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
4355 q = vl_api_client_index_to_input_queue (mp->client_index);
4362 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
4364 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
4370 send_lisp_map_server_details (ip_address_t * ip,
4371 unix_shared_memory_queue_t * q, u32 context)
4373 vl_api_lisp_map_server_details_t *rmp = NULL;
4375 rmp = vl_msg_api_alloc (sizeof (*rmp));
4376 memset (rmp, 0, sizeof (*rmp));
4377 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
4379 switch (ip_addr_version (ip))
4383 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
4384 sizeof (ip_addr_v4 (ip)));
4389 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
4390 sizeof (ip_addr_v6 (ip)));
4396 rmp->context = context;
4398 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4402 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
4404 unix_shared_memory_queue_t *q = NULL;
4405 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4408 q = vl_api_client_index_to_input_queue (mp->client_index);
4414 vec_foreach (mr, lcm->map_servers)
4416 send_lisp_map_server_details (&mr->address, q, mp->context);
4421 send_lisp_map_resolver_details (ip_address_t * ip,
4422 unix_shared_memory_queue_t * q, u32 context)
4424 vl_api_lisp_map_resolver_details_t *rmp = NULL;
4426 rmp = vl_msg_api_alloc (sizeof (*rmp));
4427 memset (rmp, 0, sizeof (*rmp));
4428 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
4430 switch (ip_addr_version (ip))
4434 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
4435 sizeof (ip_addr_v4 (ip)));
4440 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
4441 sizeof (ip_addr_v6 (ip)));
4447 rmp->context = context;
4449 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4453 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
4455 unix_shared_memory_queue_t *q = NULL;
4456 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4459 q = vl_api_client_index_to_input_queue (mp->client_index);
4465 vec_foreach (mr, lcm->map_resolvers)
4467 send_lisp_map_resolver_details (&mr->address, q, mp->context);
4472 send_eid_table_map_pair (hash_pair_t * p,
4473 unix_shared_memory_queue_t * q, u32 context)
4475 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
4477 rmp = vl_msg_api_alloc (sizeof (*rmp));
4478 memset (rmp, 0, sizeof (*rmp));
4479 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
4481 rmp->vni = clib_host_to_net_u32 (p->key);
4482 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
4483 rmp->context = context;
4484 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4488 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
4491 unix_shared_memory_queue_t *q = NULL;
4492 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4494 uword *vni_table = 0;
4496 q = vl_api_client_index_to_input_queue (mp->client_index);
4504 vni_table = lcm->bd_id_by_vni;
4508 vni_table = lcm->table_id_by_vni;
4512 hash_foreach_pair (p, vni_table,
4514 send_eid_table_map_pair (p, q, mp->context);
4520 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
4522 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
4524 rmp = vl_msg_api_alloc (sizeof (*rmp));
4525 memset (rmp, 0, sizeof (*rmp));
4526 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
4527 rmp->context = context;
4528 rmp->vni = clib_host_to_net_u32 (vni);
4529 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4533 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
4535 lisp_adjacency_t *adj;
4536 vl_api_lisp_adjacency_t a;
4537 u32 i, n = vec_len (adjs);
4539 for (i = 0; i < n; i++)
4541 adj = vec_elt_at_index (adjs, i);
4542 memset (&a, 0, sizeof (a));
4544 switch (gid_address_type (&adj->reid))
4546 case GID_ADDR_IP_PREFIX:
4547 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
4548 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
4549 if (gid_address_ip_version (&adj->reid) == IP4)
4551 a.eid_type = 0; /* ipv4 type */
4552 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
4553 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
4557 a.eid_type = 1; /* ipv6 type */
4558 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
4559 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
4563 a.eid_type = 2; /* l2 mac type */
4564 mac_copy (a.reid, gid_address_mac (&adj->reid));
4565 mac_copy (a.leid, gid_address_mac (&adj->leid));
4575 vl_api_show_lisp_rloc_probe_state_t_handler
4576 (vl_api_show_lisp_rloc_probe_state_t * mp)
4578 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
4582 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
4584 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
4590 vl_api_show_lisp_map_register_state_t_handler
4591 (vl_api_show_lisp_map_register_state_t * mp)
4593 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
4597 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
4599 rmp->is_enabled = vnet_lisp_map_register_state_get ();
4605 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
4607 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
4608 lisp_adjacency_t *adjs = 0;
4610 vl_api_lisp_adjacency_t a;
4612 u32 vni = clib_net_to_host_u32 (mp->vni);
4614 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
4615 size = vec_len (adjs) * sizeof (a);
4618 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
4620 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
4621 lisp_adjacency_copy (rmp->adjacencies, adjs);
4629 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
4634 unix_shared_memory_queue_t *q = 0;
4635 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4637 q = vl_api_client_index_to_input_queue (mp->client_index);
4644 hash_foreach_pair (p, lcm->table_id_by_vni,
4646 hash_set (vnis, p->key, 0);
4649 hash_foreach_pair (p, lcm->bd_id_by_vni,
4651 hash_set (vnis, p->key, 0);
4654 hash_foreach_pair (p, vnis,
4656 send_eid_table_vni (p->key, q, mp->context);
4664 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
4666 unix_shared_memory_queue_t *q = NULL;
4667 vl_api_show_lisp_status_reply_t *rmp = NULL;
4670 q = vl_api_client_index_to_input_queue (mp->client_index);
4677 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
4679 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
4680 rmp->feature_status = vnet_lisp_enable_disable_status ();
4686 vl_api_lisp_get_map_request_itr_rlocs_t_handler
4687 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
4689 unix_shared_memory_queue_t *q = NULL;
4690 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
4691 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4692 locator_set_t *loc_set = 0;
4696 q = vl_api_client_index_to_input_queue (mp->client_index);
4702 if (~0 == lcm->mreq_itr_rlocs)
4704 tmp_str = format (0, " ");
4709 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
4710 tmp_str = format (0, "%s", loc_set->name);
4714 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
4716 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
4717 ARRAY_LEN(rmp->locator_set_name) - 1);
4725 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
4727 unix_shared_memory_queue_t *q = NULL;
4728 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
4729 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4731 locator_set_t *ls = 0;
4735 q = vl_api_client_index_to_input_queue (mp->client_index);
4741 if (!lcm->lisp_pitr)
4743 tmp_str = format (0, "N/A");
4747 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
4748 if (~0 != m->locator_set_index)
4751 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
4752 tmp_str = format (0, "%s", ls->name);
4756 tmp_str = format (0, "N/A");
4759 vec_add1 (tmp_str, 0);
4762 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
4764 rmp->status = lcm->lisp_pitr;
4765 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
4766 ARRAY_LEN(rmp->locator_set_name) - 1);
4772 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
4775 vl_api_interface_name_renumber_reply_t *rmp;
4778 VALIDATE_SW_IF_INDEX (mp);
4780 rv = vnet_interface_name_renumber
4781 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
4783 BAD_SW_IF_INDEX_LABEL;
4785 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4789 arp_change_data_callback (u32 pool_index, u8 * new_mac,
4790 u32 sw_if_index, u32 address)
4792 vpe_api_main_t *am = &vpe_api_main;
4793 vlib_main_t *vm = am->vlib_main;
4794 vl_api_ip4_arp_event_t *event;
4795 static f64 arp_event_last_time;
4796 f64 now = vlib_time_now (vm);
4798 if (pool_is_free_index (am->arp_events, pool_index))
4801 event = pool_elt_at_index (am->arp_events, pool_index);
4803 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
4805 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
4809 if (sw_if_index == event->sw_if_index &&
4811 /* for BD case, also check IP address with 10 sec timeout */
4812 (address == event->address &&
4813 (now - arp_event_last_time) < 10.0)))
4818 arp_event_last_time = now;
4819 event->sw_if_index = sw_if_index;
4821 event->address = address;
4826 nd_change_data_callback (u32 pool_index, u8 * new_mac,
4827 u32 sw_if_index, ip6_address_t * address)
4829 vpe_api_main_t *am = &vpe_api_main;
4830 vlib_main_t *vm = am->vlib_main;
4831 vl_api_ip6_nd_event_t *event;
4832 static f64 nd_event_last_time;
4833 f64 now = vlib_time_now (vm);
4835 if (pool_is_free_index (am->nd_events, pool_index))
4838 event = pool_elt_at_index (am->nd_events, pool_index);
4841 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
4843 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
4847 if (sw_if_index == event->sw_if_index &&
4849 /* for BD case, also check IP address with 10 sec timeout */
4850 (ip6_address_is_equal (address,
4851 (ip6_address_t *) event->address) &&
4852 (now - nd_event_last_time) < 10.0)))
4857 nd_event_last_time = now;
4858 event->sw_if_index = sw_if_index;
4860 clib_memcpy (event->address, address, sizeof (event->address));
4865 arp_change_delete_callback (u32 pool_index, u8 * notused)
4867 vpe_api_main_t *am = &vpe_api_main;
4869 if (pool_is_free_index (am->arp_events, pool_index))
4872 pool_put_index (am->arp_events, pool_index);
4877 nd_change_delete_callback (u32 pool_index, u8 * notused)
4879 vpe_api_main_t *am = &vpe_api_main;
4881 if (pool_is_free_index (am->nd_events, pool_index))
4884 pool_put_index (am->nd_events, pool_index);
4889 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
4891 vpe_api_main_t *am = &vpe_api_main;
4892 vnet_main_t *vnm = vnet_get_main ();
4893 vl_api_want_ip4_arp_events_reply_t *rmp;
4894 vl_api_ip4_arp_event_t *event;
4897 if (mp->enable_disable)
4899 pool_get (am->arp_events, event);
4900 memset (event, 0, sizeof (*event));
4902 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
4903 event->client_index = mp->client_index;
4904 event->context = mp->context;
4905 event->address = mp->address;
4906 event->pid = mp->pid;
4907 if (mp->address == 0)
4910 rv = vnet_add_del_ip4_arp_change_event
4911 (vnm, arp_change_data_callback,
4912 mp->pid, &mp->address /* addr, in net byte order */ ,
4913 vpe_resolver_process_node.index,
4914 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
4918 rv = vnet_add_del_ip4_arp_change_event
4919 (vnm, arp_change_delete_callback,
4920 mp->pid, &mp->address /* addr, in net byte order */ ,
4921 vpe_resolver_process_node.index,
4922 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
4924 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4928 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
4930 vpe_api_main_t *am = &vpe_api_main;
4931 vnet_main_t *vnm = vnet_get_main ();
4932 vl_api_want_ip6_nd_events_reply_t *rmp;
4933 vl_api_ip6_nd_event_t *event;
4936 if (mp->enable_disable)
4938 pool_get (am->nd_events, event);
4939 memset (event, 0, sizeof (*event));
4941 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
4942 event->client_index = mp->client_index;
4943 event->context = mp->context;
4944 clib_memcpy (event->address, mp->address, 16);
4945 event->pid = mp->pid;
4946 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
4949 rv = vnet_add_del_ip6_nd_change_event
4950 (vnm, nd_change_data_callback,
4951 mp->pid, mp->address /* addr, in net byte order */ ,
4952 vpe_resolver_process_node.index,
4953 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
4957 rv = vnet_add_del_ip6_nd_change_event
4958 (vnm, nd_change_delete_callback,
4959 mp->pid, mp->address /* addr, in net byte order */ ,
4960 vpe_resolver_process_node.index,
4961 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
4963 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
4966 static void vl_api_input_acl_set_interface_t_handler
4967 (vl_api_input_acl_set_interface_t * mp)
4969 vlib_main_t *vm = vlib_get_main ();
4970 vl_api_input_acl_set_interface_reply_t *rmp;
4972 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4974 ip4_table_index = ntohl (mp->ip4_table_index);
4975 ip6_table_index = ntohl (mp->ip6_table_index);
4976 l2_table_index = ntohl (mp->l2_table_index);
4977 sw_if_index = ntohl (mp->sw_if_index);
4979 VALIDATE_SW_IF_INDEX (mp);
4981 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4982 ip6_table_index, l2_table_index, mp->is_add);
4984 BAD_SW_IF_INDEX_LABEL;
4986 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4989 static void vl_api_ipsec_spd_add_del_t_handler
4990 (vl_api_ipsec_spd_add_del_t * mp)
4993 clib_warning ("unimplemented");
4996 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
4997 vl_api_ipsec_spd_add_del_reply_t *rmp;
5001 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
5003 rv = VNET_API_ERROR_UNIMPLEMENTED;
5006 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5010 static void vl_api_ipsec_interface_add_del_spd_t_handler
5011 (vl_api_ipsec_interface_add_del_spd_t * mp)
5013 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5014 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
5016 u32 sw_if_index __attribute__ ((unused));
5017 u32 spd_id __attribute__ ((unused));
5019 sw_if_index = ntohl (mp->sw_if_index);
5020 spd_id = ntohl (mp->spd_id);
5022 VALIDATE_SW_IF_INDEX (mp);
5025 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
5027 rv = VNET_API_ERROR_UNIMPLEMENTED;
5030 BAD_SW_IF_INDEX_LABEL;
5032 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5035 static void vl_api_ipsec_spd_add_del_entry_t_handler
5036 (vl_api_ipsec_spd_add_del_entry_t * mp)
5038 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5039 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
5045 memset (&p, 0, sizeof (p));
5047 p.id = ntohl (mp->spd_id);
5048 p.priority = ntohl (mp->priority);
5049 p.is_outbound = mp->is_outbound;
5050 p.is_ipv6 = mp->is_ipv6;
5052 if (mp->is_ipv6 || mp->is_ip_any)
5054 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
5055 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
5056 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
5057 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
5061 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5062 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5063 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
5064 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5066 p.protocol = mp->protocol;
5067 p.rport.start = ntohs (mp->remote_port_start);
5068 p.rport.stop = ntohs (mp->remote_port_stop);
5069 p.lport.start = ntohs (mp->local_port_start);
5070 p.lport.stop = ntohs (mp->local_port_stop);
5071 /* policy action resolve unsupported */
5072 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
5074 clib_warning ("unsupported action: 'resolve'");
5075 rv = VNET_API_ERROR_UNIMPLEMENTED;
5078 p.policy = mp->policy;
5079 p.sa_id = ntohl (mp->sa_id);
5081 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5088 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
5091 rv = VNET_API_ERROR_UNIMPLEMENTED;
5096 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5099 static void vl_api_ipsec_sad_add_del_entry_t_handler
5100 (vl_api_ipsec_sad_add_del_entry_t * mp)
5102 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5103 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
5108 memset (&sa, 0, sizeof (sa));
5110 sa.id = ntohl (mp->sad_id);
5111 sa.spi = ntohl (mp->spi);
5112 /* security protocol AH unsupported */
5113 if (mp->protocol == IPSEC_PROTOCOL_AH)
5115 clib_warning ("unsupported security protocol 'AH'");
5116 rv = VNET_API_ERROR_UNIMPLEMENTED;
5119 sa.protocol = mp->protocol;
5120 /* check for unsupported crypto-alg */
5121 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5122 mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
5124 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5125 mp->crypto_algorithm);
5126 rv = VNET_API_ERROR_UNIMPLEMENTED;
5129 sa.crypto_alg = mp->crypto_algorithm;
5130 sa.crypto_key_len = mp->crypto_key_length;
5131 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
5132 /* check for unsupported integ-alg */
5134 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_NONE ||
5136 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5138 mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
5140 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5141 mp->integrity_algorithm);
5142 rv = VNET_API_ERROR_UNIMPLEMENTED;
5147 /*Special cases, aes-gcm-128 encryption */
5148 if (mp->crypto_algorithm == IPSEC_CRYPTO_ALG_AES_GCM_128)
5150 if (mp->integrity_algorithm != IPSEC_INTEG_ALG_NONE
5151 && mp->integrity_algorithm != IPSEC_INTEG_ALG_AES_GCM_128)
5154 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
5155 rv = VNET_API_ERROR_UNIMPLEMENTED;
5158 else /*set integ-alg internally to aes-gcm-128 */
5159 mp->integrity_algorithm = IPSEC_INTEG_ALG_AES_GCM_128;
5161 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_AES_GCM_128)
5163 clib_warning ("unsupported integ-alg: aes-gcm-128");
5164 rv = VNET_API_ERROR_UNIMPLEMENTED;
5167 else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_NONE)
5169 clib_warning ("unsupported integ-alg: none");
5170 rv = VNET_API_ERROR_UNIMPLEMENTED;
5175 sa.integ_alg = mp->integrity_algorithm;
5176 sa.integ_key_len = mp->integrity_key_length;
5177 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
5178 sa.use_esn = mp->use_extended_sequence_number;
5179 sa.is_tunnel = mp->is_tunnel;
5180 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5181 if (sa.is_tunnel_ip6)
5183 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5184 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5188 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
5189 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
5192 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
5194 rv = VNET_API_ERROR_UNIMPLEMENTED;
5199 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5203 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
5205 vl_api_ikev2_profile_add_del_reply_t *rmp;
5209 vlib_main_t *vm = vlib_get_main ();
5210 clib_error_t *error;
5211 u8 *tmp = format (0, "%s", mp->name);
5212 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
5215 rv = VNET_API_ERROR_UNSPECIFIED;
5217 rv = VNET_API_ERROR_UNIMPLEMENTED;
5220 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5224 vl_api_ikev2_profile_set_auth_t_handler
5225 (vl_api_ikev2_profile_set_auth_t * mp)
5227 vl_api_ikev2_profile_set_auth_reply_t *rmp;
5231 vlib_main_t *vm = vlib_get_main ();
5232 clib_error_t *error;
5233 u8 *tmp = format (0, "%s", mp->name);
5234 u8 *data = vec_new (u8, mp->data_len);
5235 clib_memcpy (data, mp->data, mp->data_len);
5236 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
5240 rv = VNET_API_ERROR_UNSPECIFIED;
5242 rv = VNET_API_ERROR_UNIMPLEMENTED;
5245 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5249 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
5251 vl_api_ikev2_profile_add_del_reply_t *rmp;
5255 vlib_main_t *vm = vlib_get_main ();
5256 clib_error_t *error;
5257 u8 *tmp = format (0, "%s", mp->name);
5258 u8 *data = vec_new (u8, mp->data_len);
5259 clib_memcpy (data, mp->data, mp->data_len);
5260 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
5264 rv = VNET_API_ERROR_UNSPECIFIED;
5266 rv = VNET_API_ERROR_UNIMPLEMENTED;
5269 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5273 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
5275 vl_api_ikev2_profile_set_ts_reply_t *rmp;
5279 vlib_main_t *vm = vlib_get_main ();
5280 clib_error_t *error;
5281 u8 *tmp = format (0, "%s", mp->name);
5282 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
5283 mp->end_port, (ip4_address_t) mp->start_addr,
5284 (ip4_address_t) mp->end_addr, mp->is_local);
5287 rv = VNET_API_ERROR_UNSPECIFIED;
5289 rv = VNET_API_ERROR_UNIMPLEMENTED;
5292 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5296 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
5298 vl_api_ikev2_profile_set_ts_reply_t *rmp;
5302 vlib_main_t *vm = vlib_get_main ();
5303 clib_error_t *error;
5305 error = ikev2_set_local_key (vm, mp->key_file);
5307 rv = VNET_API_ERROR_UNSPECIFIED;
5309 rv = VNET_API_ERROR_UNIMPLEMENTED;
5312 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5316 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
5318 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
5319 vl_api_ipsec_sa_set_key_reply_t *rmp;
5323 sa.id = ntohl (mp->sa_id);
5324 sa.crypto_key_len = mp->crypto_key_length;
5325 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
5326 sa.integ_key_len = mp->integrity_key_length;
5327 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
5329 rv = ipsec_set_sa_key (vm, &sa);
5331 rv = VNET_API_ERROR_UNIMPLEMENTED;
5334 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
5337 static void vl_api_cop_interface_enable_disable_t_handler
5338 (vl_api_cop_interface_enable_disable_t * mp)
5340 vl_api_cop_interface_enable_disable_reply_t *rmp;
5342 u32 sw_if_index = ntohl (mp->sw_if_index);
5345 VALIDATE_SW_IF_INDEX (mp);
5347 enable_disable = (int) mp->enable_disable;
5349 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5351 BAD_SW_IF_INDEX_LABEL;
5353 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5356 static void vl_api_cop_whitelist_enable_disable_t_handler
5357 (vl_api_cop_whitelist_enable_disable_t * mp)
5359 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
5360 cop_whitelist_enable_disable_args_t _a, *a = &_a;
5361 u32 sw_if_index = ntohl (mp->sw_if_index);
5364 VALIDATE_SW_IF_INDEX (mp);
5366 a->sw_if_index = sw_if_index;
5369 a->default_cop = mp->default_cop;
5370 a->fib_id = ntohl (mp->fib_id);
5372 rv = cop_whitelist_enable_disable (a);
5374 BAD_SW_IF_INDEX_LABEL;
5376 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5380 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
5384 api_main_t *am = &api_main;
5385 vlib_main_t *vm = vlib_get_main ();
5387 vl_api_get_node_graph_reply_t *rmp;
5389 pthread_mutex_lock (&am->vlib_rp->mutex);
5390 oldheap = svm_push_data_heap (am->vlib_rp);
5393 * Keep the number of memcpy ops to a minimum (e.g. 1).
5395 vec_validate (vector, 16384);
5396 vec_reset_length (vector);
5399 vector = vlib_node_serialize (&vm->node_main, vector,
5400 (u32) ~ 0 /* all threads */ ,
5401 1 /* include nexts */ ,
5402 1 /* include stats */ );
5404 svm_pop_heap (oldheap);
5405 pthread_mutex_unlock (&am->vlib_rp->mutex);
5408 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5410 rmp->reply_in_shmem = (uword) vector;
5416 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
5419 vl_api_ioam_enable_reply_t *rmp;
5420 clib_error_t *error;
5422 /* Ignoring the profile id as currently a single profile
5424 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
5425 mp->seqno, mp->analyse);
5428 clib_error_report (error);
5429 rv = clib_error_get_code (error);
5432 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
5436 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
5439 vl_api_ioam_disable_reply_t *rmp;
5440 clib_error_t *error;
5442 error = clear_ioam_rewrite_fn ();
5445 clib_error_report (error);
5446 rv = clib_error_get_code (error);
5449 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
5453 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
5455 vlib_main_t *vm = vlib_get_main ();
5456 vl_api_af_packet_create_reply_t *rmp;
5458 u8 *host_if_name = NULL;
5461 host_if_name = format (0, "%s", mp->host_if_name);
5462 vec_add1 (host_if_name, 0);
5464 rv = af_packet_create_if (vm, host_if_name,
5465 mp->use_random_hw_addr ? 0 : mp->hw_addr,
5468 vec_free (host_if_name);
5471 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
5473 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
5479 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
5481 vlib_main_t *vm = vlib_get_main ();
5482 vl_api_af_packet_delete_reply_t *rmp;
5484 u8 *host_if_name = NULL;
5486 host_if_name = format (0, "%s", mp->host_if_name);
5487 vec_add1 (host_if_name, 0);
5489 rv = af_packet_delete_if (vm, host_if_name);
5491 vec_free (host_if_name);
5493 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
5497 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
5499 vlib_main_t *vm = vlib_get_main ();
5500 vl_api_policer_add_del_reply_t *rmp;
5503 sse2_qos_pol_cfg_params_st cfg;
5504 clib_error_t *error;
5507 name = format (0, "%s", mp->name);
5509 memset (&cfg, 0, sizeof (cfg));
5511 cfg.rnd_type = mp->round_type;
5512 cfg.rate_type = mp->rate_type;
5513 cfg.rb.kbps.cir_kbps = mp->cir;
5514 cfg.rb.kbps.eir_kbps = mp->eir;
5515 cfg.rb.kbps.cb_bytes = mp->cb;
5516 cfg.rb.kbps.eb_bytes = mp->eb;
5517 cfg.conform_action.action_type = mp->conform_action_type;
5518 cfg.conform_action.dscp = mp->conform_dscp;
5519 cfg.exceed_action.action_type = mp->exceed_action_type;
5520 cfg.exceed_action.dscp = mp->exceed_dscp;
5521 cfg.violate_action.action_type = mp->violate_action_type;
5522 cfg.violate_action.dscp = mp->violate_dscp;
5523 cfg.color_aware = mp->color_aware;
5525 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
5528 rv = VNET_API_ERROR_UNSPECIFIED;
5531 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
5533 if (rv == 0 && mp->is_add)
5534 rmp->policer_index = ntohl(policer_index);
5536 rmp->policer_index = ~0;
5542 send_policer_details (u8 * name,
5543 sse2_qos_pol_cfg_params_st * config,
5544 policer_read_response_type_st * templ,
5545 unix_shared_memory_queue_t * q, u32 context)
5547 vl_api_policer_details_t *mp;
5549 mp = vl_msg_api_alloc (sizeof (*mp));
5550 memset (mp, 0, sizeof (*mp));
5551 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
5552 mp->context = context;
5553 mp->cir = htonl (config->rb.kbps.cir_kbps);
5554 mp->eir = htonl (config->rb.kbps.eir_kbps);
5555 mp->cb = htonl (config->rb.kbps.cb_bytes);
5556 mp->eb = htonl (config->rb.kbps.eb_bytes);
5557 mp->rate_type = config->rate_type;
5558 mp->round_type = config->rnd_type;
5559 mp->type = config->rfc;
5560 mp->conform_action_type = config->conform_action.action_type;
5561 mp->conform_dscp = config->conform_action.dscp;
5562 mp->exceed_action_type = config->exceed_action.action_type;
5563 mp->exceed_dscp = config->exceed_action.dscp;
5564 mp->violate_action_type = config->violate_action.action_type;
5565 mp->violate_dscp = config->violate_action.dscp;
5566 mp->single_rate = templ->single_rate ? 1 : 0;
5567 mp->color_aware = templ->color_aware ? 1 : 0;
5568 mp->scale = htonl (templ->scale);
5569 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
5570 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
5571 mp->current_limit = htonl (templ->current_limit);
5572 mp->current_bucket = htonl (templ->current_bucket);
5573 mp->extended_limit = htonl (templ->extended_limit);
5574 mp->extended_bucket = htonl (templ->extended_bucket);
5575 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
5577 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
5579 vl_msg_api_send_shmem (q, (u8 *) & mp);
5583 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
5585 unix_shared_memory_queue_t *q;
5586 vnet_policer_main_t *pm = &vnet_policer_main;
5592 sse2_qos_pol_cfg_params_st *config;
5593 policer_read_response_type_st *templ;
5595 q = vl_api_client_index_to_input_queue (mp->client_index);
5599 if (mp->match_name_valid)
5601 match_name = format (0, "%s%c", mp->match_name, 0);
5604 if (mp->match_name_valid)
5606 p = hash_get_mem (pm->policer_config_by_name, match_name);
5610 config = pool_elt_at_index (pm->configs, pool_index);
5611 templ = pool_elt_at_index (pm->policer_templates, pool_index);
5612 send_policer_details (match_name, config, templ, q, mp->context);
5618 hash_foreach_pair (hp, pm->policer_config_by_name,
5620 name = (u8 *) hp->key;
5621 pool_index = hp->value[0];
5622 config = pool_elt_at_index (pm->configs, pool_index);
5623 templ = pool_elt_at_index (pm->policer_templates, pool_index);
5624 send_policer_details(name, config, templ, q, mp->context);
5631 vl_api_policer_classify_set_interface_t_handler
5632 (vl_api_policer_classify_set_interface_t * mp)
5634 vlib_main_t *vm = vlib_get_main ();
5635 vl_api_policer_classify_set_interface_reply_t *rmp;
5637 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5639 ip4_table_index = ntohl (mp->ip4_table_index);
5640 ip6_table_index = ntohl (mp->ip6_table_index);
5641 l2_table_index = ntohl (mp->l2_table_index);
5642 sw_if_index = ntohl (mp->sw_if_index);
5644 VALIDATE_SW_IF_INDEX (mp);
5646 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
5647 ip6_table_index, l2_table_index,
5650 BAD_SW_IF_INDEX_LABEL;
5652 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
5656 send_policer_classify_details (u32 sw_if_index,
5658 unix_shared_memory_queue_t * q, u32 context)
5660 vl_api_policer_classify_details_t *mp;
5662 mp = vl_msg_api_alloc (sizeof (*mp));
5663 memset (mp, 0, sizeof (*mp));
5664 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
5665 mp->context = context;
5666 mp->sw_if_index = htonl (sw_if_index);
5667 mp->table_index = htonl (table_index);
5669 vl_msg_api_send_shmem (q, (u8 *) & mp);
5673 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
5675 unix_shared_memory_queue_t *q;
5676 policer_classify_main_t *pcm = &policer_classify_main;
5680 q = vl_api_client_index_to_input_queue (mp->client_index);
5684 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
5686 if (vec_len (vec_tbl))
5688 for (i = 0; i < vec_len (vec_tbl); i++)
5690 if (vec_elt (vec_tbl, i) == ~0)
5693 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
5700 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
5702 vlib_main_t *vm = vlib_get_main ();
5703 vl_api_netmap_create_reply_t *rmp;
5707 if_name = format (0, "%s", mp->netmap_if_name);
5708 vec_add1 (if_name, 0);
5711 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
5712 mp->is_pipe, mp->is_master, 0);
5716 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
5720 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
5722 vlib_main_t *vm = vlib_get_main ();
5723 vl_api_netmap_delete_reply_t *rmp;
5727 if_name = format (0, "%s", mp->netmap_if_name);
5728 vec_add1 (if_name, 0);
5730 rv = netmap_delete_if (vm, if_name);
5734 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
5738 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_fib_details_t * mp)
5740 clib_warning ("BUG");
5743 typedef struct mpls_tunnel_send_walk_ctx_t_
5745 unix_shared_memory_queue_t *q;
5748 } mpls_tunnel_send_walk_ctx_t;
5751 send_mpls_tunnel_entry (u32 mti, void *arg)
5753 mpls_tunnel_send_walk_ctx_t *ctx;
5754 vl_api_mpls_tunnel_details_t *mp;
5755 const mpls_tunnel_t *mt;
5760 if (~0 != ctx->index && mti != ctx->index)
5763 mt = mpls_tunnel_get (mti);
5764 nlabels = vec_len (mt->mt_label_stack);
5766 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
5767 memset (mp, 0, sizeof (*mp));
5768 mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
5769 mp->context = ctx->context;
5771 mp->tunnel_index = ntohl (mti);
5772 memcpy (mp->mt_next_hop_out_labels,
5773 mt->mt_label_stack, nlabels * sizeof (u32));
5777 vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
5781 vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
5783 unix_shared_memory_queue_t *q;
5785 q = vl_api_client_index_to_input_queue (mp->client_index);
5789 mpls_tunnel_send_walk_ctx_t ctx = {
5791 .index = ntohl (mp->tunnel_index),
5792 .context = mp->context,
5794 mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
5798 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
5800 clib_warning ("BUG");
5804 vl_api_mpls_fib_details_t_endian (vl_api_mpls_fib_details_t * mp)
5806 clib_warning ("BUG");
5810 vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp)
5812 clib_warning ("BUG");
5816 send_mpls_fib_details (vpe_api_main_t * am,
5817 unix_shared_memory_queue_t * q,
5818 u32 table_id, u32 label, u32 eos,
5819 fib_route_path_encode_t * api_rpaths, u32 context)
5821 vl_api_mpls_fib_details_t *mp;
5822 fib_route_path_encode_t *api_rpath;
5823 vl_api_fib_path2_t *fp;
5826 path_count = vec_len (api_rpaths);
5827 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
5830 memset (mp, 0, sizeof (*mp));
5831 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
5832 mp->context = context;
5834 mp->table_id = htonl (table_id);
5836 mp->label = htonl (label);
5838 mp->count = htonl (path_count);
5840 vec_foreach (api_rpath, api_rpaths)
5842 memset (fp, 0, sizeof (*fp));
5843 fp->weight = htonl (api_rpath->rpath.frp_weight);
5844 fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
5845 copy_fib_next_hop (api_rpath, fp);
5849 vl_msg_api_send_shmem (q, (u8 *) & mp);
5853 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
5855 vpe_api_main_t *am = &vpe_api_main;
5856 unix_shared_memory_queue_t *q;
5857 mpls_main_t *mm = &mpls_main;
5858 fib_table_t *fib_table;
5859 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
5863 fib_route_path_encode_t *api_rpaths;
5865 q = vl_api_client_index_to_input_queue (mp->client_index);
5870 pool_foreach (fib_table, mm->fibs,
5872 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
5874 vec_add1(lfeis, lfei);
5877 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
5879 vec_foreach(lfeip, lfeis)
5881 fib_entry_get_prefix(*lfeip, &pfx);
5882 fib_index = fib_entry_get_fib_index(*lfeip);
5883 fib_table = fib_table_get(fib_index, pfx.fp_proto);
5885 fib_entry_encode(*lfeip, &api_rpaths);
5886 send_mpls_fib_details (am, q,
5887 fib_table->ft_table_id,
5892 vec_free(api_rpaths);
5899 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
5901 unix_shared_memory_queue_t *q;
5903 q = vl_api_client_index_to_input_queue (mp->client_index);
5907 vnet_classify_main_t *cm = &vnet_classify_main;
5908 vnet_classify_table_t *t;
5913 pool_foreach (t, cm->tables,
5915 vec_add1 (table_ids, ntohl(t - cm->tables));
5918 count = vec_len (table_ids);
5920 vl_api_classify_table_ids_reply_t *rmp;
5921 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
5922 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
5923 rmp->context = mp->context;
5924 rmp->count = ntohl (count);
5925 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
5928 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5930 vec_free (table_ids);
5934 vl_api_classify_table_by_interface_t_handler
5935 (vl_api_classify_table_by_interface_t * mp)
5937 vl_api_classify_table_by_interface_reply_t *rmp;
5940 u32 sw_if_index = ntohl (mp->sw_if_index);
5943 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
5946 VALIDATE_SW_IF_INDEX (mp);
5948 input_acl_main_t *am = &input_acl_main;
5953 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
5955 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
5956 if (vec_len (vec_tbl))
5958 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
5960 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
5964 acl[type] = vec_elt (vec_tbl, if_idx);
5969 BAD_SW_IF_INDEX_LABEL;
5972 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
5974 rmp->sw_if_index = ntohl(sw_if_index);
5975 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
5976 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
5977 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
5984 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
5986 unix_shared_memory_queue_t *q;
5988 q = vl_api_client_index_to_input_queue (mp->client_index);
5992 vl_api_classify_table_info_reply_t *rmp = 0;
5994 vnet_classify_main_t *cm = &vnet_classify_main;
5995 u32 table_id = ntohl (mp->table_id);
5996 vnet_classify_table_t *t;
5999 pool_foreach (t, cm->tables,
6001 if (table_id == t - cm->tables)
6003 rmp = vl_msg_api_alloc_as_if_client
6004 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
6005 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
6006 rmp->context = mp->context;
6007 rmp->table_id = ntohl(table_id);
6008 rmp->nbuckets = ntohl(t->nbuckets);
6009 rmp->match_n_vectors = ntohl(t->match_n_vectors);
6010 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
6011 rmp->active_sessions = ntohl(t->active_elements);
6012 rmp->next_table_index = ntohl(t->next_table_index);
6013 rmp->miss_next_index = ntohl(t->miss_next_index);
6014 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
6015 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
6024 rmp = vl_msg_api_alloc (sizeof (*rmp));
6025 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
6026 rmp->context = mp->context;
6027 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
6030 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6034 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
6037 clib_warning ("BUG");
6041 send_classify_session_details (unix_shared_memory_queue_t * q,
6044 vnet_classify_entry_t * e, u32 context)
6046 vl_api_classify_session_details_t *rmp;
6048 rmp = vl_msg_api_alloc (sizeof (*rmp));
6049 memset (rmp, 0, sizeof (*rmp));
6050 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
6051 rmp->context = context;
6052 rmp->table_id = ntohl (table_id);
6053 rmp->hit_next_index = ntohl (e->next_index);
6054 rmp->advance = ntohl (e->advance);
6055 rmp->opaque_index = ntohl (e->opaque_index);
6056 rmp->match_length = ntohl (match_length);
6057 clib_memcpy (rmp->match, e->key, match_length);
6059 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6063 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
6065 vnet_classify_main_t *cm = &vnet_classify_main;
6066 unix_shared_memory_queue_t *q;
6068 u32 table_id = ntohl (mp->table_id);
6069 vnet_classify_table_t *t;
6071 q = vl_api_client_index_to_input_queue (mp->client_index);
6076 pool_foreach (t, cm->tables,
6078 if (table_id == t - cm->tables)
6080 vnet_classify_bucket_t * b;
6081 vnet_classify_entry_t * v, * save_v;
6084 for (i = 0; i < t->nbuckets; i++)
6086 b = &t->buckets [i];
6090 save_v = vnet_classify_get_entry (t, b->offset);
6091 for (j = 0; j < (1<<b->log2_pages); j++)
6093 for (k = 0; k < t->entries_per_page; k++)
6095 v = vnet_classify_entry_at_index
6096 (t, save_v, j*t->entries_per_page + k);
6097 if (vnet_classify_entry_is_free (v))
6100 send_classify_session_details
6101 (q, table_id, t->match_n_vectors * sizeof (u32x4),
6113 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
6115 vlib_main_t *vm = vlib_get_main ();
6116 flow_report_main_t *frm = &flow_report_main;
6117 vl_api_set_ipfix_exporter_reply_t *rmp;
6118 ip4_address_t collector, src;
6119 u16 collector_port = UDP_DST_PORT_ipfix;
6121 u32 template_interval;
6127 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
6128 collector_port = ntohs (mp->collector_port);
6129 if (collector_port == (u16) ~ 0)
6130 collector_port = UDP_DST_PORT_ipfix;
6131 memcpy (src.data, mp->src_address, sizeof (src.data));
6132 fib_id = ntohl (mp->vrf_id);
6134 ip4_main_t *im = &ip4_main;
6141 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
6144 rv = VNET_API_ERROR_NO_SUCH_FIB;
6150 path_mtu = ntohl (mp->path_mtu);
6152 path_mtu = 512; // RFC 7011 section 10.3.3.
6153 template_interval = ntohl (mp->template_interval);
6154 if (template_interval == ~0)
6155 template_interval = 20;
6156 udp_checksum = mp->udp_checksum;
6158 if (collector.as_u32 == 0)
6160 rv = VNET_API_ERROR_INVALID_VALUE;
6164 if (src.as_u32 == 0)
6166 rv = VNET_API_ERROR_INVALID_VALUE;
6170 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
6172 rv = VNET_API_ERROR_INVALID_VALUE;
6178 rv = VNET_API_ERROR_INVALID_VALUE;
6182 /* Reset report streams if we are reconfiguring IP addresses */
6183 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
6184 frm->src_address.as_u32 != src.as_u32 ||
6185 frm->collector_port != collector_port)
6186 vnet_flow_reports_reset (frm);
6188 frm->ipfix_collector.as_u32 = collector.as_u32;
6189 frm->collector_port = collector_port;
6190 frm->src_address.as_u32 = src.as_u32;
6191 frm->fib_index = fib_index;
6192 frm->path_mtu = path_mtu;
6193 frm->template_interval = template_interval;
6194 frm->udp_checksum = udp_checksum;
6196 /* Turn on the flow reporting process */
6197 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
6200 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
6204 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
6206 flow_report_main_t *frm = &flow_report_main;
6207 unix_shared_memory_queue_t *q;
6208 vl_api_ipfix_exporter_details_t *rmp;
6209 ip4_main_t *im = &ip4_main;
6212 q = vl_api_client_index_to_input_queue (mp->client_index);
6216 rmp = vl_msg_api_alloc (sizeof (*rmp));
6217 memset (rmp, 0, sizeof (*rmp));
6218 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
6219 rmp->context = mp->context;
6220 memcpy (rmp->collector_address, frm->ipfix_collector.data,
6221 sizeof (frm->ipfix_collector.data));
6222 rmp->collector_port = htons (frm->collector_port);
6223 memcpy (rmp->src_address, frm->src_address.data,
6224 sizeof (frm->src_address.data));
6225 if (frm->fib_index == ~0)
6228 vrf_id = im->fibs[frm->fib_index].ft_table_id;
6229 rmp->vrf_id = htonl (vrf_id);
6230 rmp->path_mtu = htonl (frm->path_mtu);
6231 rmp->template_interval = htonl (frm->template_interval);
6232 rmp->udp_checksum = (frm->udp_checksum != 0);
6234 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6238 vl_api_set_ipfix_classify_stream_t_handler
6239 (vl_api_set_ipfix_classify_stream_t * mp)
6241 vl_api_set_ipfix_classify_stream_reply_t *rmp;
6242 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6243 flow_report_main_t *frm = &flow_report_main;
6245 u32 src_port = UDP_DST_PORT_ipfix;
6248 domain_id = ntohl (mp->domain_id);
6249 src_port = ntohs (mp->src_port);
6251 if (fcm->src_port != 0 &&
6252 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
6254 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
6255 domain_id, (u16) src_port);
6259 fcm->domain_id = domain_id;
6260 fcm->src_port = (u16) src_port;
6262 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
6266 vl_api_ipfix_classify_stream_dump_t_handler
6267 (vl_api_ipfix_classify_stream_dump_t * mp)
6269 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6270 unix_shared_memory_queue_t *q;
6271 vl_api_ipfix_classify_stream_details_t *rmp;
6273 q = vl_api_client_index_to_input_queue (mp->client_index);
6277 rmp = vl_msg_api_alloc (sizeof (*rmp));
6278 memset (rmp, 0, sizeof (*rmp));
6279 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
6280 rmp->context = mp->context;
6281 rmp->domain_id = htonl (fcm->domain_id);
6282 rmp->src_port = htons (fcm->src_port);
6284 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6288 vl_api_ipfix_classify_table_add_del_t_handler
6289 (vl_api_ipfix_classify_table_add_del_t * mp)
6291 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
6292 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6293 flow_report_main_t *frm = &flow_report_main;
6294 vnet_flow_report_add_del_args_t args;
6295 ipfix_classify_table_t *table;
6297 u32 classify_table_index;
6299 u8 transport_protocol;
6302 classify_table_index = ntohl (mp->table_id);
6303 ip_version = mp->ip_version;
6304 transport_protocol = mp->transport_protocol;
6305 is_add = mp->is_add;
6307 if (fcm->src_port == 0)
6309 /* call set_ipfix_classify_stream first */
6310 rv = VNET_API_ERROR_UNSPECIFIED;
6314 memset (&args, 0, sizeof (args));
6318 for (i = 0; i < vec_len (fcm->tables); i++)
6319 if (ipfix_classify_table_index_valid (i))
6320 if (fcm->tables[i].classify_table_index == classify_table_index)
6322 table = &fcm->tables[i];
6330 rv = VNET_API_ERROR_VALUE_EXIST;
6333 table = ipfix_classify_add_table ();
6334 table->classify_table_index = classify_table_index;
6340 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
6345 table->ip_version = ip_version;
6346 table->transport_protocol = transport_protocol;
6348 args.opaque.as_uword = table - fcm->tables;
6349 args.rewrite_callback = ipfix_classify_template_rewrite;
6350 args.flow_data_callback = ipfix_classify_send_flows;
6351 args.is_add = is_add;
6352 args.domain_id = fcm->domain_id;
6353 args.src_port = fcm->src_port;
6355 rv = vnet_flow_report_add_del (frm, &args);
6357 /* If deleting, or add failed */
6358 if (is_add == 0 || (rv && is_add))
6359 ipfix_classify_delete_table (table - fcm->tables);
6362 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
6366 send_ipfix_classify_table_details (u32 table_index,
6367 unix_shared_memory_queue_t * q,
6370 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6371 vl_api_ipfix_classify_table_details_t *mp;
6373 ipfix_classify_table_t *table = &fcm->tables[table_index];
6375 mp = vl_msg_api_alloc (sizeof (*mp));
6376 memset (mp, 0, sizeof (*mp));
6377 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
6378 mp->context = context;
6379 mp->table_id = htonl (table->classify_table_index);
6380 mp->ip_version = table->ip_version;
6381 mp->transport_protocol = table->transport_protocol;
6383 vl_msg_api_send_shmem (q, (u8 *) & mp);
6387 vl_api_ipfix_classify_table_dump_t_handler
6388 (vl_api_ipfix_classify_table_dump_t * mp)
6390 flow_report_classify_main_t *fcm = &flow_report_classify_main;
6391 unix_shared_memory_queue_t *q;
6394 q = vl_api_client_index_to_input_queue (mp->client_index);
6398 for (i = 0; i < vec_len (fcm->tables); i++)
6399 if (ipfix_classify_table_index_valid (i))
6400 send_ipfix_classify_table_details (i, q, mp->context);
6404 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
6406 vl_api_pg_create_interface_reply_t *rmp;
6409 pg_main_t *pg = &pg_main;
6410 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
6411 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
6414 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
6416 rmp->sw_if_index = ntohl(pi->sw_if_index);
6422 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
6424 vl_api_pg_capture_reply_t *rmp;
6427 vnet_main_t *vnm = vnet_get_main ();
6428 vnet_interface_main_t *im = &vnm->interface_main;
6429 vnet_hw_interface_t *hi = 0;
6431 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
6432 u32 hw_if_index = ~0;
6433 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
6436 vec_free (intf_name);
6438 if (hw_if_index != ~0)
6440 pg_capture_args_t _a, *a = &_a;
6442 u32 len = ntohl (mp->pcap_name_length);
6443 u8 *pcap_file_name = vec_new (u8, len);
6444 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
6446 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
6447 a->hw_if_index = hw_if_index;
6448 a->dev_instance = hi->dev_instance;
6449 a->is_enabled = mp->is_enabled;
6450 a->pcap_file_name = pcap_file_name;
6451 a->count = ntohl (mp->count);
6453 clib_error_t *e = pg_capture (a);
6456 clib_error_report (e);
6457 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
6460 vec_free (pcap_file_name);
6462 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
6466 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
6468 vl_api_pg_enable_disable_reply_t *rmp;
6471 pg_main_t *pg = &pg_main;
6472 u32 stream_index = ~0;
6474 int is_enable = mp->is_enabled != 0;
6475 u32 len = ntohl (mp->stream_name_length) - 1;
6479 u8 *stream_name = vec_new (u8, len);
6480 clib_memcpy (stream_name, mp->stream_name, len);
6481 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
6484 vec_free (stream_name);
6487 pg_enable_disable (stream_index, is_enable);
6489 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
6493 vl_api_ip_source_and_port_range_check_add_del_t_handler
6494 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
6496 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
6499 u8 is_ipv6 = mp->is_ipv6;
6500 u8 is_add = mp->is_add;
6501 u8 mask_length = mp->mask_length;
6502 ip4_address_t ip4_addr;
6503 ip6_address_t ip6_addr;
6505 u16 *high_ports = 0;
6507 u16 tmp_low, tmp_high;
6511 // Validate port range
6512 num_ranges = mp->number_of_ranges;
6513 if (num_ranges > 32)
6514 { // This is size of array in VPE.API
6515 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
6519 vec_reset_length (low_ports);
6520 vec_reset_length (high_ports);
6522 for (i = 0; i < num_ranges; i++)
6524 tmp_low = mp->low_ports[i];
6525 tmp_high = mp->high_ports[i];
6526 // If tmp_low <= tmp_high then only need to check tmp_low = 0
6527 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
6528 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
6530 rv = VNET_API_ERROR_INVALID_VALUE;
6533 vec_add1 (low_ports, tmp_low);
6534 vec_add1 (high_ports, tmp_high + 1);
6537 // Validate mask_length
6538 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
6540 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
6544 vrf_id = ntohl (mp->vrf_id);
6548 rv = VNET_API_ERROR_INVALID_VALUE;
6555 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
6556 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
6560 high_ports, is_add);
6564 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
6565 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
6569 high_ports, is_add);
6573 vec_free (low_ports);
6574 vec_free (high_ports);
6575 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
6579 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
6580 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
6582 vlib_main_t *vm = vlib_get_main ();
6583 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
6584 ip4_main_t *im = &ip4_main;
6587 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
6588 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
6592 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
6593 ntohl (mp->tcp_out_vrf_id);
6594 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
6595 ntohl (mp->udp_out_vrf_id);
6596 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
6597 ntohl (mp->tcp_in_vrf_id);
6598 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
6599 ntohl (mp->udp_in_vrf_id);
6602 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
6604 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
6606 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
6610 rv = VNET_API_ERROR_INVALID_VALUE;
6614 fib_index[i] = p[0];
6619 sw_if_index = ntohl (mp->sw_if_index);
6621 VALIDATE_SW_IF_INDEX (mp);
6624 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
6627 BAD_SW_IF_INDEX_LABEL;
6630 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
6634 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
6637 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
6639 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
6640 u32 sw_if_index = ~0;
6642 /* Check src & dst are different */
6643 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
6645 rv = VNET_API_ERROR_SAME_SRC_DST;
6649 memset (a, 0, sizeof (*a));
6651 /* ip addresses sent in network byte order */
6652 clib_memcpy (&(a->src), mp->src_address, 4);
6653 clib_memcpy (&(a->dst), mp->dst_address, 4);
6654 a->is_add = mp->is_add;
6655 a->lsa = ntohl (mp->local_sa_id);
6656 a->rsa = ntohl (mp->remote_sa_id);
6658 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
6662 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
6664 rmp->sw_if_index = ntohl (sw_if_index);
6669 static void send_ipsec_gre_tunnel_details
6670 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
6672 vl_api_ipsec_gre_tunnel_details_t *rmp;
6674 rmp = vl_msg_api_alloc (sizeof (*rmp));
6675 memset (rmp, 0, sizeof (*rmp));
6676 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
6677 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
6678 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
6679 rmp->sw_if_index = htonl (t->sw_if_index);
6680 rmp->local_sa_id = htonl (t->local_sa_id);
6681 rmp->remote_sa_id = htonl (t->remote_sa_id);
6682 rmp->context = context;
6684 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6687 static void vl_api_ipsec_gre_tunnel_dump_t_handler
6688 (vl_api_ipsec_gre_tunnel_dump_t * mp)
6690 unix_shared_memory_queue_t *q;
6691 ipsec_gre_main_t *igm = &ipsec_gre_main;
6692 ipsec_gre_tunnel_t *t;
6695 q = vl_api_client_index_to_input_queue (mp->client_index);
6701 sw_if_index = ntohl (mp->sw_if_index);
6703 if (~0 == sw_if_index)
6706 pool_foreach (t, igm->tunnels,
6708 send_ipsec_gre_tunnel_details(t, q, mp->context);
6714 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
6715 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
6719 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
6720 send_ipsec_gre_tunnel_details (t, q, mp->context);
6725 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
6727 vl_api_delete_subif_reply_t *rmp;
6730 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
6732 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
6736 vl_api_l2_interface_pbb_tag_rewrite_t_handler
6737 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
6739 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
6740 vnet_main_t *vnm = vnet_get_main ();
6741 vlib_main_t *vm = vlib_get_main ();
6745 VALIDATE_SW_IF_INDEX (mp);
6747 vtr_op = ntohl (mp->vtr_op);
6751 case L2_VTR_DISABLED:
6754 case L2_VTR_TRANSLATE_2_1:
6758 rv = VNET_API_ERROR_INVALID_VALUE;
6759 goto bad_sw_if_index;
6762 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
6763 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
6764 ntohl (mp->i_sid), ntohs (mp->outer_tag));
6766 BAD_SW_IF_INDEX_LABEL;
6768 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
6772 vl_api_punt_t_handler (vl_api_punt_t * mp)
6774 vl_api_punt_reply_t *rmp;
6775 vlib_main_t *vm = vlib_get_main ();
6777 clib_error_t *error;
6779 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
6780 ntohs (mp->l4_port), mp->is_add);
6784 clib_error_report (error);
6787 REPLY_MACRO (VL_API_PUNT_REPLY);
6791 vl_api_flow_classify_set_interface_t_handler
6792 (vl_api_flow_classify_set_interface_t * mp)
6794 vlib_main_t *vm = vlib_get_main ();
6795 vl_api_flow_classify_set_interface_reply_t *rmp;
6797 u32 sw_if_index, ip4_table_index, ip6_table_index;
6799 ip4_table_index = ntohl (mp->ip4_table_index);
6800 ip6_table_index = ntohl (mp->ip6_table_index);
6801 sw_if_index = ntohl (mp->sw_if_index);
6803 VALIDATE_SW_IF_INDEX (mp);
6805 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
6806 ip6_table_index, mp->is_add);
6808 BAD_SW_IF_INDEX_LABEL;
6810 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
6814 send_flow_classify_details (u32 sw_if_index,
6816 unix_shared_memory_queue_t * q, u32 context)
6818 vl_api_flow_classify_details_t *mp;
6820 mp = vl_msg_api_alloc (sizeof (*mp));
6821 memset (mp, 0, sizeof (*mp));
6822 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
6823 mp->context = context;
6824 mp->sw_if_index = htonl (sw_if_index);
6825 mp->table_index = htonl (table_index);
6827 vl_msg_api_send_shmem (q, (u8 *) & mp);
6831 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
6833 unix_shared_memory_queue_t *q;
6834 flow_classify_main_t *pcm = &flow_classify_main;
6838 q = vl_api_client_index_to_input_queue (mp->client_index);
6842 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6844 if (vec_len (vec_tbl))
6846 for (i = 0; i < vec_len (vec_tbl); i++)
6848 if (vec_elt (vec_tbl, i) == ~0)
6851 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
6858 send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
6861 vl_api_ipsec_spd_details_t *mp;
6863 mp = vl_msg_api_alloc (sizeof (*mp));
6864 memset (mp, 0, sizeof (*mp));
6865 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
6866 mp->context = context;
6868 mp->spd_id = htonl (p->id);
6869 mp->priority = htonl (p->priority);
6870 mp->is_outbound = p->is_outbound;
6871 mp->is_ipv6 = p->is_ipv6;
6874 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
6875 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
6876 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
6877 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
6881 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
6882 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
6883 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
6884 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
6886 mp->local_start_port = htons (p->lport.start);
6887 mp->local_stop_port = htons (p->lport.stop);
6888 mp->remote_start_port = htons (p->rport.start);
6889 mp->remote_stop_port = htons (p->rport.stop);
6890 mp->protocol = p->protocol;
6891 mp->policy = p->policy;
6892 mp->sa_id = htonl (p->sa_id);
6893 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
6894 mp->packets = clib_host_to_net_u64 (p->counter.packets);
6896 vl_msg_api_send_shmem (q, (u8 *) & mp);
6900 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
6902 unix_shared_memory_queue_t *q;
6903 ipsec_main_t *im = &ipsec_main;
6904 ipsec_policy_t *policy;
6909 q = vl_api_client_index_to_input_queue (mp->client_index);
6913 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
6918 spd = pool_elt_at_index (im->spds, spd_index);
6921 pool_foreach (policy, spd->policies,
6923 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
6924 send_ipsec_spd_details (policy, q,
6929 clib_warning ("unimplemented");
6934 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
6936 vl_api_feature_enable_disable_reply_t *rmp;
6938 u8 *arc_name, *feature_name;
6940 VALIDATE_SW_IF_INDEX (mp);
6942 arc_name = format (0, "%s%c", mp->arc_name, 0);
6943 feature_name = format (0, "%s%c", mp->feature_name, 0);
6945 vnet_feature_registration_t *reg;
6947 vnet_get_feature_reg ((const char *) arc_name,
6948 (const char *) feature_name);
6950 rv = VNET_API_ERROR_INVALID_VALUE;
6954 clib_error_t *error = 0;
6956 sw_if_index = ntohl (mp->sw_if_index);
6957 if (reg->enable_disable_cb)
6958 error = reg->enable_disable_cb (sw_if_index, mp->enable);
6960 vnet_feature_enable_disable ((const char *) arc_name,
6961 (const char *) feature_name,
6962 sw_if_index, mp->enable, 0, 0);
6965 clib_error_report (error);
6966 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
6970 vec_free (feature_name);
6971 vec_free (arc_name);
6973 BAD_SW_IF_INDEX_LABEL;
6975 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
6978 #define BOUNCE_HANDLER(nn) \
6979 static void vl_api_##nn##_t_handler ( \
6980 vl_api_##nn##_t *mp) \
6982 vpe_client_registration_t *reg; \
6983 vpe_api_main_t * vam = &vpe_api_main; \
6984 unix_shared_memory_queue_t * q; \
6986 /* One registration only... */ \
6987 pool_foreach(reg, vam->nn##_registrations, \
6989 q = vl_api_client_index_to_input_queue (reg->client_index); \
6992 * If the queue is stuffed, turf the msg and complain \
6993 * It's unlikely that the intended recipient is \
6994 * alive; avoid deadlock at all costs. \
6996 if (q->cursize == q->maxsize) { \
6997 clib_warning ("ERROR: receiver queue full, drop msg"); \
6998 vl_msg_api_free (mp); \
7001 vl_msg_api_send_shmem (q, (u8 *)&mp); \
7005 vl_msg_api_free (mp); \
7008 static void setup_message_id_table (api_main_t * am);
7012 * Add vpe's API message handlers to the table.
7013 * vlib has alread mapped shared memory and
7014 * added the client registration handlers.
7015 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
7017 static clib_error_t *
7018 vpe_api_hookup (vlib_main_t * vm)
7020 api_main_t *am = &api_main;
7023 vl_msg_api_set_handlers(VL_API_##N, #n, \
7024 vl_api_##n##_t_handler, \
7026 vl_api_##n##_t_endian, \
7027 vl_api_##n##_t_print, \
7028 sizeof(vl_api_##n##_t), 1);
7029 foreach_vpe_api_msg;
7033 * Manually register the sr tunnel add del msg, so we trace
7034 * enough bytes to capture a typical segment list
7036 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
7037 "sr_tunnel_add_del",
7038 vl_api_sr_tunnel_add_del_t_handler,
7040 vl_api_sr_tunnel_add_del_t_endian,
7041 vl_api_sr_tunnel_add_del_t_print, 256, 1);
7045 * Manually register the sr policy add del msg, so we trace
7046 * enough bytes to capture a typical tunnel name list
7048 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
7049 "sr_policy_add_del",
7050 vl_api_sr_policy_add_del_t_handler,
7052 vl_api_sr_policy_add_del_t_endian,
7053 vl_api_sr_policy_add_del_t_print, 256, 1);
7056 * Trace space for 8 MPLS encap labels, classifier mask+match
7058 am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32);
7059 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
7060 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
7061 += 5 * sizeof (u32x4);
7062 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
7065 * Thread-safe API messages
7067 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
7068 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
7071 * Set up the (msg_name, crc, message-id) table
7073 setup_message_id_table (am);
7078 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
7080 static clib_error_t *
7081 vpe_api_init (vlib_main_t * vm)
7083 vpe_api_main_t *am = &vpe_api_main;
7086 am->vnet_main = vnet_get_main ();
7087 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
7088 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7089 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7090 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7091 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7092 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
7095 vl_set_memory_region_name ("/vpe-api");
7096 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
7101 VLIB_INIT_FUNCTION (vpe_api_init);
7104 static clib_error_t *
7105 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
7108 u64 baseva, size, pvt_heap_size;
7110 const int max_buf_size = 4096;
7112 struct passwd _pw, *pw;
7113 struct group _grp, *grp;
7115 buf = vec_new (char, 128);
7116 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7118 if (unformat (input, "prefix %s", &chroot_path))
7120 vec_add1 (chroot_path, 0);
7121 vl_set_memory_root_path ((char *) chroot_path);
7123 else if (unformat (input, "uid %d", &uid))
7124 vl_set_memory_uid (uid);
7125 else if (unformat (input, "gid %d", &gid))
7126 vl_set_memory_gid (gid);
7127 else if (unformat (input, "baseva %llx", &baseva))
7128 vl_set_global_memory_baseva (baseva);
7129 else if (unformat (input, "global-size %lldM", &size))
7130 vl_set_global_memory_size (size * (1ULL << 20));
7131 else if (unformat (input, "global-size %lldG", &size))
7132 vl_set_global_memory_size (size * (1ULL << 30));
7133 else if (unformat (input, "global-size %lld", &size))
7134 vl_set_global_memory_size (size);
7135 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
7136 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
7137 else if (unformat (input, "global-pvt-heap-size size %lld",
7139 vl_set_global_pvt_heap_size (pvt_heap_size);
7140 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
7141 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
7142 else if (unformat (input, "api-pvt-heap-size size %lld",
7144 vl_set_api_pvt_heap_size (pvt_heap_size);
7145 else if (unformat (input, "api-size %lldM", &size))
7146 vl_set_api_memory_size (size * (1ULL << 20));
7147 else if (unformat (input, "api-size %lldG", &size))
7148 vl_set_api_memory_size (size * (1ULL << 30));
7149 else if (unformat (input, "api-size %lld", &size))
7150 vl_set_api_memory_size (size);
7151 else if (unformat (input, "uid %s", &s))
7153 /* lookup the username */
7156 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
7157 && (vec_len (buf) <= max_buf_size))
7159 vec_resize (buf, vec_len (buf) * 2);
7163 e = clib_error_return_code (0, rv,
7164 CLIB_ERROR_ERRNO_VALID |
7166 "cannot fetch username %s", s);
7174 clib_error_return_fatal (0, "username %s does not exist", s);
7180 vl_set_memory_uid (pw->pw_uid);
7182 else if (unformat (input, "gid %s", &s))
7184 /* lookup the group name */
7187 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
7188 && (vec_len (buf) <= max_buf_size))
7190 vec_resize (buf, vec_len (buf) * 2);
7194 e = clib_error_return_code (0, rv,
7195 CLIB_ERROR_ERRNO_VALID |
7197 "cannot fetch group %s", s);
7204 e = clib_error_return_fatal (0, "group %s does not exist", s);
7211 vl_set_memory_gid (grp->gr_gid);
7214 return clib_error_return (0, "unknown input `%U'",
7215 format_unformat_error, input);
7220 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
7223 get_unformat_vnet_sw_interface (void)
7225 return (void *) &unformat_vnet_sw_interface;
7229 format_arp_event (u8 * s, va_list * args)
7231 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
7233 s = format (s, "pid %d: ", event->pid);
7235 s = format (s, "bd mac/ip4 binding events");
7237 s = format (s, "resolution for %U", format_ip4_address, &event->address);
7242 format_nd_event (u8 * s, va_list * args)
7244 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
7246 s = format (s, "pid %d: ", event->pid);
7248 s = format (s, "bd mac/ip6 binding events");
7250 s = format (s, "resolution for %U", format_ip6_address, event->address);
7254 static clib_error_t *
7255 show_ip_arp_nd_events_fn (vlib_main_t * vm,
7256 unformat_input_t * input, vlib_cli_command_t * cmd)
7258 vpe_api_main_t *am = &vpe_api_main;
7259 vl_api_ip4_arp_event_t *arp_event;
7260 vl_api_ip6_nd_event_t *nd_event;
7262 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
7264 vlib_cli_output (vm, "No active arp or nd event registrations");
7269 pool_foreach (arp_event, am->arp_events,
7271 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
7274 pool_foreach (nd_event, am->nd_events,
7276 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
7284 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
7285 .path = "show arp-nd-event registrations",
7286 .function = show_ip_arp_nd_events_fn,
7287 .short_help = "Show ip4 arp and ip6 nd event registrations",
7291 #define vl_msg_name_crc_list
7292 #include <vpp-api/vpe_all_api_h.h>
7293 #undef vl_msg_name_crc_list
7296 setup_message_id_table (api_main_t * am)
7298 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
7299 foreach_vl_msg_name_crc_memclnt;
7300 foreach_vl_msg_name_crc_vpe;
7306 * fd.io coding-style-patch-verification: ON
7309 * eval: (c-set-style "gnu")