+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+
+ while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
+ ;
+}
+
+static void
+ vl_api_ip_container_proxy_add_del_t_handler
+ (vl_api_ip_container_proxy_add_del_t * mp)
+{
+ vl_api_ip_container_proxy_add_del_reply_t *rmp;
+ vnet_ip_container_proxy_args_t args;
+ int rv = 0;
+ clib_error_t *error;
+
+ clib_memset (&args, 0, sizeof (args));
+
+ ip_prefix_decode (&mp->pfx, &args.prefix);
+
+ args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
+ args.is_add = mp->is_add;
+ if ((error = vnet_ip_container_proxy_add_del (&args)))
+ {
+ rv = clib_error_get_code (error);
+ clib_error_report (error);
+ }
+
+ REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
+}
+
+typedef struct ip_container_proxy_walk_ctx_t_
+{
+ vl_api_registration_t *reg;
+ u32 context;
+} ip_container_proxy_walk_ctx_t;
+
+static int
+ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
+ void *args)
+{
+ vl_api_ip_container_proxy_details_t *mp;
+ ip_container_proxy_walk_ctx_t *ctx = args;
+
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ if (!mp)
+ return 1;
+
+ clib_memset (mp, 0, sizeof (*mp));
+ mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
+ mp->context = ctx->context;
+
+ mp->sw_if_index = ntohl (sw_if_index);
+ ip_prefix_encode (pfx, &mp->prefix);
+
+ vl_api_send_msg (ctx->reg, (u8 *) mp);
+
+ return 1;
+}
+
+static void
+vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t *
+ mp)
+{
+ vl_api_registration_t *reg;
+
+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+
+ ip_container_proxy_walk_ctx_t ctx = {
+ .context = mp->context,
+ .reg = reg,
+ };
+
+ ip_container_proxy_walk (ip_container_proxy_send_details, &ctx);
+}
+
+static void
+vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
+{
+ int rv = 0;
+ vl_api_ioam_enable_reply_t *rmp;
+ clib_error_t *error;
+
+ /* Ignoring the profile id as currently a single profile
+ * is supported */
+ error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
+ mp->seqno, mp->analyse);
+ if (error)
+ {
+ clib_error_report (error);
+ rv = clib_error_get_code (error);
+ }
+
+ REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
+}
+
+static void
+vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
+{
+ int rv = 0;
+ vl_api_ioam_disable_reply_t *rmp;
+ clib_error_t *error;
+
+ error = clear_ioam_rewrite_fn ();
+ if (error)
+ {
+ clib_error_report (error);
+ rv = clib_error_get_code (error);
+ }
+
+ REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
+}
+
+static void
+ vl_api_ip_source_and_port_range_check_add_del_t_handler
+ (vl_api_ip_source_and_port_range_check_add_del_t * mp)
+{
+ vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
+ int rv = 0;
+
+ u8 is_add = mp->is_add;
+ fib_prefix_t pfx;
+ u16 *low_ports = 0;
+ u16 *high_ports = 0;
+ u32 vrf_id;
+ u16 tmp_low, tmp_high;
+ u8 num_ranges;
+ int i;
+
+ ip_prefix_decode (&mp->prefix, &pfx);
+
+ // Validate port range
+ num_ranges = mp->number_of_ranges;
+ if (num_ranges > 32)
+ { // This is size of array in VPE.API
+ rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
+ goto reply;
+ }
+
+ vec_reset_length (low_ports);
+ vec_reset_length (high_ports);
+
+ for (i = 0; i < num_ranges; i++)
+ {
+ tmp_low = mp->low_ports[i];
+ tmp_high = mp->high_ports[i];
+ // If tmp_low <= tmp_high then only need to check tmp_low = 0
+ // If tmp_low <= tmp_high then only need to check tmp_high > 65535
+ if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto reply;
+ }
+ vec_add1 (low_ports, tmp_low);
+ vec_add1 (high_ports, tmp_high + 1);
+ }
+
+ vrf_id = ntohl (mp->vrf_id);
+
+ if (vrf_id < 1)
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto reply;
+ }
+
+
+ if (FIB_PROTOCOL_IP6 == pfx.fp_proto)
+ {
+ rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6,
+ pfx.fp_len,
+ vrf_id,
+ low_ports,
+ high_ports, is_add);
+ }
+ else
+ {
+ rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4,
+ pfx.fp_len,
+ vrf_id,
+ low_ports,
+ high_ports, is_add);
+ }
+
+reply:
+ vec_free (low_ports);
+ vec_free (high_ports);
+ REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
+}
+
+static void
+ vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
+ (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
+{
+ vlib_main_t *vm = vlib_get_main ();
+ vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
+ ip4_main_t *im = &ip4_main;
+ int rv;
+ u32 sw_if_index;
+ u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
+ u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
+ uword *p = 0;
+ int i;
+
+ vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
+ ntohl (mp->tcp_out_vrf_id);
+ vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
+ ntohl (mp->udp_out_vrf_id);
+ vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
+ ntohl (mp->tcp_in_vrf_id);
+ vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
+ ntohl (mp->udp_in_vrf_id);
+
+
+ for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
+ {
+ if (vrf_id[i] != 0 && vrf_id[i] != ~0)
+ {
+ p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
+
+ if (p == 0)
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto reply;
+ }
+
+ fib_index[i] = p[0];
+ }
+ else
+ fib_index[i] = ~0;
+ }
+ sw_if_index = ntohl (mp->sw_if_index);
+
+ VALIDATE_SW_IF_INDEX (mp);
+
+ rv =
+ set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
+ mp->is_add);
+
+ BAD_SW_IF_INDEX_LABEL;
+reply:
+
+ REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
+}
+
+typedef union
+{
+ u32 fib_index;
+} ip4_source_check_config_t;
+
+static void
+ vl_api_ip_source_check_interface_add_del_t_handler
+ (vl_api_ip_source_check_interface_add_del_t * mp)
+{
+ vl_api_ip_source_check_interface_add_del_reply_t *rmp;
+ int rv;
+ u32 sw_if_index = ntohl (mp->sw_if_index);
+ u8 is_add = mp->is_add;
+ char *feature_name =
+ mp->loose ? "ip4-source-check-via-any" : "ip4-source-check-via-rx";
+
+ ip4_source_check_config_t config;
+
+ VALIDATE_SW_IF_INDEX (mp);
+
+ config.fib_index =
+ fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index);
+ rv =
+ vnet_feature_enable_disable ("ip4-unicast", feature_name, sw_if_index,
+ is_add, &config, sizeof (config));
+ BAD_SW_IF_INDEX_LABEL;
+
+ REPLY_MACRO (VL_API_IP_SOURCE_CHECK_INTERFACE_ADD_DEL_REPLY);
+}
+
+#define IP4_ARP_EVENT 3
+#define IP6_ND_EVENT 4
+
+static vlib_node_registration_t ip_resolver_process_node;
+
+static int
+arp_change_delete_callback (u32 pool_index,
+ const mac_address_t * mac,
+ u32 sw_if_index, const ip4_address_t * address)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+
+ if (pool_is_free_index (am->arp_events, pool_index))
+ return 1;
+
+ pool_put_index (am->arp_events, pool_index);
+ return 0;
+}
+
+static void
+handle_ip4_arp_event (u32 pool_index)
+{
+ vpe_api_main_t *vam = &vpe_api_main;
+ vnet_main_t *vnm = vam->vnet_main;
+ vlib_main_t *vm = vam->vlib_main;
+ vl_api_ip4_arp_event_t *event;
+ vl_api_ip4_arp_event_t *mp;
+ vl_api_registration_t *reg;
+
+ /* Client can cancel, die, etc. */
+ if (pool_is_free_index (vam->arp_events, pool_index))
+ return;
+
+ event = pool_elt_at_index (vam->arp_events, pool_index);
+
+ reg = vl_api_client_index_to_registration (event->client_index);
+ if (!reg)
+ {
+ (void) vnet_add_del_ip4_arp_change_event
+ (vnm, arp_change_delete_callback,
+ event->pid, event->ip,
+ ip_resolver_process_node.index, IP4_ARP_EVENT,
+ ~0 /* pool index, notused */ , 0 /* is_add */ );
+ return;
+ }
+
+ if (vl_api_can_send_msg (reg))
+ {
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ clib_memcpy (mp, event, sizeof (*mp));
+ vl_api_send_msg (reg, (u8 *) mp);
+ }
+ else
+ {
+ static f64 last_time;
+ /*
+ * Throttle syslog msgs.
+ * It's pretty tempting to just revoke the registration...
+ */
+ if (vlib_time_now (vm) > last_time + 10.0)
+ {
+ clib_warning ("arp event for %U to pid %d: queue stuffed!",
+ format_ip4_address, event->ip, event->pid);
+ last_time = vlib_time_now (vm);
+ }
+ }
+}
+
+static int
+nd_change_delete_callback (u32 pool_index,
+ const mac_address_t * mac,
+ u32 sw_if_index, const ip6_address_t * addr)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+
+ if (pool_is_free_index (am->nd_events, pool_index))
+ return 1;
+
+ pool_put_index (am->nd_events, pool_index);
+ return 0;
+}
+
+static void
+handle_ip6_nd_event (u32 pool_index)
+{
+ vpe_api_main_t *vam = &vpe_api_main;
+ vnet_main_t *vnm = vam->vnet_main;
+ vlib_main_t *vm = vam->vlib_main;
+ vl_api_ip6_nd_event_t *event;
+ vl_api_ip6_nd_event_t *mp;
+ vl_api_registration_t *reg;
+
+ /* Client can cancel, die, etc. */
+ if (pool_is_free_index (vam->nd_events, pool_index))
+ return;
+
+ event = pool_elt_at_index (vam->nd_events, pool_index);
+
+ reg = vl_api_client_index_to_registration (event->client_index);
+ if (!reg)
+ {
+ (void) vnet_add_del_ip6_nd_change_event
+ (vnm, nd_change_delete_callback,
+ event->pid, event->ip,
+ ip_resolver_process_node.index, IP6_ND_EVENT,
+ ~0 /* pool index, notused */ , 0 /* is_add */ );
+ return;
+ }
+
+ if (vl_api_can_send_msg (reg))
+ {
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ clib_memcpy (mp, event, sizeof (*mp));
+ vl_api_send_msg (reg, (u8 *) mp);
+ }
+ else
+ {
+ static f64 last_time;
+ /*
+ * Throttle syslog msgs.
+ * It's pretty tempting to just revoke the registration...
+ */
+ if (vlib_time_now (vm) > last_time + 10.0)
+ {
+ clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
+ format_ip6_address, event->ip, event->pid);
+ last_time = vlib_time_now (vm);
+ }
+ }
+}
+
+static uword
+resolver_process (vlib_main_t * vm,
+ vlib_node_runtime_t * rt, vlib_frame_t * f)
+{
+ volatile f64 timeout = 100.0;
+ volatile uword *event_data = 0;
+
+ while (1)
+ {
+ vlib_process_wait_for_event_or_clock (vm, timeout);
+
+ uword event_type =
+ vlib_process_get_events (vm, (uword **) & event_data);
+
+ int i;
+ switch (event_type)
+ {
+ case IP4_ARP_EVENT:
+ for (i = 0; i < vec_len (event_data); i++)
+ handle_ip4_arp_event (event_data[i]);
+ break;
+
+ case IP6_ND_EVENT:
+ for (i = 0; i < vec_len (event_data); i++)
+ handle_ip6_nd_event (event_data[i]);
+ break;
+
+ case ~0: /* timeout */
+ break;
+ }
+
+ vec_reset_length (event_data);
+ }
+ return 0; /* or not */
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip_resolver_process_node,static) = {
+ .function = resolver_process,
+ .type = VLIB_NODE_TYPE_PROCESS,
+ .name = "ip-route-resolver-process",
+};
+/* *INDENT-ON* */
+
+static int
+nd_change_data_callback (u32 pool_index, const mac_address_t * new_mac,
+ u32 sw_if_index, const ip6_address_t * address)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+ vl_api_ip6_nd_event_t *event;
+
+ if (pool_is_free_index (am->nd_events, pool_index))
+ return 1;
+
+ event = pool_elt_at_index (am->nd_events, pool_index);
+ if (ethernet_mac_address_equal (event->mac, new_mac->bytes) &&
+ sw_if_index == ntohl (event->sw_if_index))
+ {
+ return 1;
+ }
+
+ mac_address_encode (new_mac, event->mac);
+ event->sw_if_index = htonl (sw_if_index);
+ return 0;
+}
+
+static vlib_node_registration_t wc_arp_process_node;
+
+enum
+{ WC_ARP_REPORT, WC_ND_REPORT, RA_REPORT, REPORT_MAX };
+
+static uword
+wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
+{
+ /* These cross the longjmp boundary (vlib_process_wait_for_event)
+ * and need to be volatile - to prevent them from being optimized into
+ * a register - which could change during suspension */
+
+ volatile wc_arp_report_t arp_prev = { 0 };
+ volatile wc_nd_report_t nd_prev = { 0 };
+ volatile f64 last_arp = vlib_time_now (vm);
+ volatile f64 last_nd = vlib_time_now (vm);
+
+ while (1)
+ {
+ vlib_process_wait_for_event (vm);
+ uword event_type = WC_ARP_REPORT;
+ void *event_data = vlib_process_get_event_data (vm, &event_type);
+
+ f64 now = vlib_time_now (vm);
+ int i;
+ if (event_type == WC_ARP_REPORT)
+ {
+ wc_arp_report_t *arp_events = event_data;
+ for (i = 0; i < vec_len (arp_events); i++)
+ {
+ /* discard dup event - cast away volatile */
+ if (arp_prev.ip.as_u32 == arp_events[i].ip.as_u32 &&
+ mac_address_equal ((const mac_address_t *) &arp_prev.mac,
+ &arp_events[i].mac) &&
+ arp_prev.sw_if_index == arp_events[i].sw_if_index &&
+ (now - last_arp) < 10.0)
+ {
+ continue;
+ }
+ arp_prev = arp_events[i];
+ last_arp = now;
+ vpe_client_registration_t *reg;
+ /* *INDENT-OFF* */
+ pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations,
+ ({
+ vl_api_registration_t *vl_reg;
+ vl_reg = vl_api_client_index_to_registration (reg->client_index);
+ ASSERT (vl_reg != NULL);
+ if (reg && vl_api_can_send_msg (vl_reg))
+ {
+ vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event);
+ clib_memset (event, 0, sizeof *event);
+ event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
+ event->client_index = reg->client_index;
+ event->pid = reg->client_pid;
+ event->mac_ip = 1;
+ ip4_address_encode(&arp_events[i].ip, event->ip);
+ event->sw_if_index = htonl(arp_events[i].sw_if_index);
+ mac_address_encode(&arp_events[i].mac, event->mac);
+ vl_api_send_msg (vl_reg, (u8 *) event);
+ }
+ }));
+ /* *INDENT-ON* */
+ }
+ }
+ else if (event_type == WC_ND_REPORT)
+ {
+ wc_nd_report_t *nd_events = event_data;
+ for (i = 0; i < vec_len (nd_events); i++)
+ {
+ /* discard dup event - cast away volatile */
+ if (ip6_address_is_equal ((const ip6_address_t *) &nd_prev.ip6,
+ &nd_events[i].ip6)
+ && mac_address_equal ((const mac_address_t *) &nd_prev.mac,
+ &nd_events[i].mac)
+ && nd_prev.sw_if_index == nd_events[i].sw_if_index
+ && (now - last_nd) < 10.0)
+ {
+ continue;
+ }
+ nd_prev = nd_events[i];
+ last_nd = now;
+ vpe_client_registration_t *reg;
+ /* *INDENT-OFF* */
+ pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations,
+ ({
+ vl_api_registration_t *vl_reg;
+ vl_reg = vl_api_client_index_to_registration (reg->client_index);
+ if (vl_reg && vl_api_can_send_msg (vl_reg))
+ {
+ vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event);
+ clib_memset (event, 0, sizeof *event);
+ event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT);
+ event->client_index = reg->client_index;
+ event->pid = reg->client_pid;
+ event->mac_ip = 1;
+ ip6_address_encode(&nd_events[i].ip6, event->ip);
+ event->sw_if_index = htonl(nd_events[i].sw_if_index);
+ mac_address_encode(&nd_events[i].mac, event->mac);
+ vl_api_send_msg (vl_reg, (u8 *) event);
+ }
+ }));
+ /* *INDENT-ON* */
+ }
+ }
+ else if (event_type == RA_REPORT)
+ {
+ ra_report_t *ra_events = event_data;
+ for (i = 0; i < vec_len (ra_events); i++)
+ {
+ ip6_neighbor_public_main_t *npm = &ip6_neighbor_public_main;
+ call_ip6_neighbor_callbacks (&ra_events[i],
+ npm->ra_report_functions);
+
+ vpe_client_registration_t *reg;
+ /* *INDENT-OFF* */
+ pool_foreach(reg, vpe_api_main.ip6_ra_events_registrations,
+ ({
+ vl_api_registration_t *vl_reg;
+ vl_reg =
+ vl_api_client_index_to_registration (reg->client_index);
+ if (vl_reg && vl_api_can_send_msg (vl_reg))
+ {
+ u32 event_size =
+ sizeof (vl_api_ip6_ra_event_t) +
+ vec_len (ra_events[i].prefixes) *
+ sizeof (vl_api_ip6_ra_prefix_info_t);
+ vl_api_ip6_ra_event_t *event =
+ vl_msg_api_alloc (event_size);
+ clib_memset (event, 0, event_size);
+ event->_vl_msg_id = htons (VL_API_IP6_RA_EVENT);
+ event->client_index = reg->client_index;
+ event->pid = reg->client_pid;
+
+ event->sw_if_index = clib_host_to_net_u32 (ra_events[i].sw_if_index);
+
+ ip6_address_encode (&ra_events[i].router_address,
+ event->router_addr);
+
+ event->current_hop_limit = ra_events[i].current_hop_limit;
+ event->flags = ra_events[i].flags;
+ event->router_lifetime_in_sec =
+ clib_host_to_net_u16 (ra_events
+ [i].router_lifetime_in_sec);
+ event->neighbor_reachable_time_in_msec =
+ clib_host_to_net_u32 (ra_events
+ [i].neighbor_reachable_time_in_msec);
+ event->time_in_msec_between_retransmitted_neighbor_solicitations
+ =
+ clib_host_to_net_u32 (ra_events
+ [i].time_in_msec_between_retransmitted_neighbor_solicitations);
+
+ event->n_prefixes =
+ clib_host_to_net_u32 (vec_len (ra_events[i].prefixes));
+ vl_api_ip6_ra_prefix_info_t *prefix =
+ (typeof (prefix)) event->prefixes;
+ u32 j;
+ for (j = 0; j < vec_len (ra_events[i].prefixes); j++)
+ {
+ ra_report_prefix_info_t *info =
+ &ra_events[i].prefixes[j];
+ ip_prefix_encode(&info->prefix, &prefix->prefix);
+ prefix->flags = info->flags;
+ prefix->valid_time =
+ clib_host_to_net_u32 (info->valid_time);
+ prefix->preferred_time =
+ clib_host_to_net_u32 (info->preferred_time);
+ prefix++;
+ }
+
+ vl_api_send_msg (vl_reg, (u8 *) event);
+ }
+ }));
+ /* *INDENT-ON* */
+ vec_free (ra_events[i].prefixes);
+ }
+ }
+ vlib_process_put_event_data (vm, event_data);
+ }
+
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (wc_arp_process_node,static) = {
+ .function = wc_arp_process,
+ .type = VLIB_NODE_TYPE_PROCESS,
+ .name = "wildcard-ip4-arp-publisher-process",
+};
+/* *INDENT-ON* */
+
+static int
+arp_change_data_callback (u32 pool_index,
+ const mac_address_t * mac,
+ u32 sw_if_index, const ip4_address_t * address)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+ vl_api_ip4_arp_event_t *event;
+
+ if (pool_is_free_index (am->arp_events, pool_index))
+ return 1;
+
+ event = pool_elt_at_index (am->arp_events, pool_index);
+ if (ethernet_mac_address_equal (event->mac, mac->bytes) &&
+ sw_if_index == ntohl (event->sw_if_index))
+ {
+ return 1;
+ }
+
+ mac_address_encode (mac, event->mac);
+ event->sw_if_index = htonl (sw_if_index);
+ return 0;
+}
+
+static void
+vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ vl_api_want_ip4_arp_events_reply_t *rmp;
+ ip4_address_t ip;
+ int rv = 0;
+
+ ip4_address_decode (mp->ip, &ip);
+
+ if (ip.as_u32 == 0)
+ {
+ uword *p =
+ hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index);
+ vpe_client_registration_t *rp;
+ if (p)
+ {
+ if (mp->enable_disable)
+ {
+ clib_warning ("pid %d: already enabled...", mp->pid);
+ rv = VNET_API_ERROR_INVALID_REGISTRATION;
+ goto reply;
+ }
+ else
+ {
+ rp =
+ pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
+ pool_put (am->wc_ip4_arp_events_registrations, rp);
+ hash_unset (am->wc_ip4_arp_events_registration_hash,
+ mp->client_index);
+ if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
+ wc_arp_set_publisher_node (~0, REPORT_MAX);
+ goto reply;
+ }
+ }
+ if (mp->enable_disable == 0)
+ {
+ clib_warning ("pid %d: already disabled...", mp->pid);
+ rv = VNET_API_ERROR_INVALID_REGISTRATION;
+ goto reply;
+ }
+ pool_get (am->wc_ip4_arp_events_registrations, rp);
+ rp->client_index = mp->client_index;
+ rp->client_pid = mp->pid;
+ hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index,
+ rp - am->wc_ip4_arp_events_registrations);
+ wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT);
+ goto reply;
+ }
+
+ if (mp->enable_disable)
+ {
+ vl_api_ip4_arp_event_t *event;
+ pool_get (am->arp_events, event);
+ rv = vnet_add_del_ip4_arp_change_event
+ (vnm, arp_change_data_callback,
+ mp->pid, mp->ip /* addr, in net byte order */ ,
+ ip_resolver_process_node.index,
+ IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
+
+ if (rv)
+ {
+ pool_put (am->arp_events, event);
+ goto reply;
+ }
+ clib_memset (event, 0, sizeof (*event));
+
+ /* Python API expects events to have no context */
+ event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
+ event->client_index = mp->client_index;
+ memcpy (event->ip, mp->ip, 4);
+ event->pid = mp->pid;
+ if (ip.as_u32 == 0)
+ event->mac_ip = 1;
+ }
+ else
+ {
+ rv = vnet_add_del_ip4_arp_change_event
+ (vnm, arp_change_delete_callback,
+ mp->pid, mp->ip /* addr, in net byte order */ ,
+ ip_resolver_process_node.index,
+ IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
+ }
+reply:
+ REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
+}
+
+static clib_error_t *
+want_ip4_arp_events_reaper (u32 client_index)
+{
+ vpe_client_registration_t *rp;
+ vl_api_ip4_arp_event_t *event;
+ u32 *to_delete, *event_id;
+ vpe_api_main_t *am;
+ vnet_main_t *vnm;
+ uword *p;
+
+ am = &vpe_api_main;
+ vnm = vnet_get_main ();
+ to_delete = NULL;
+
+ /* clear out all of its pending resolutions */
+ /* *INDENT-OFF* */
+ pool_foreach(event, am->arp_events,
+ ({
+ if (event->client_index == client_index)
+ {
+ vec_add1(to_delete, event - am->arp_events);
+ }
+ }));
+ /* *INDENT-ON* */
+
+ vec_foreach (event_id, to_delete)
+ {
+ event = pool_elt_at_index (am->arp_events, *event_id);
+ vnet_add_del_ip4_arp_change_event
+ (vnm, arp_change_delete_callback,
+ event->pid, event->ip,
+ ip_resolver_process_node.index, IP4_ARP_EVENT,
+ ~0 /* pool index, notused */ , 0 /* is_add */ );
+ }
+ vec_free (to_delete);
+
+ /* remove from the registration hash */
+ p = hash_get (am->wc_ip4_arp_events_registration_hash, client_index);
+
+ if (p)
+ {
+ rp = pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
+ pool_put (am->wc_ip4_arp_events_registrations, rp);
+ hash_unset (am->wc_ip4_arp_events_registration_hash, client_index);
+ if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
+ wc_arp_set_publisher_node (~0, REPORT_MAX);
+ }
+ return (NULL);
+}
+
+VL_MSG_API_REAPER_FUNCTION (want_ip4_arp_events_reaper);
+
+static void
+vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ vl_api_want_ip6_nd_events_reply_t *rmp;
+ ip6_address_t ip6;
+ int rv = 0;
+
+ ip6_address_decode (mp->ip, &ip6);
+
+ if (ip6_address_is_zero (&ip6))
+ {
+ uword *p =
+ hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index);
+ vpe_client_registration_t *rp;
+ if (p)
+ {
+ if (mp->enable_disable)
+ {
+ clib_warning ("pid %d: already enabled...", mp->pid);
+ rv = VNET_API_ERROR_INVALID_REGISTRATION;
+ goto reply;
+ }
+ else
+ {
+ rp =
+ pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
+ pool_put (am->wc_ip6_nd_events_registrations, rp);
+ hash_unset (am->wc_ip6_nd_events_registration_hash,
+ mp->client_index);
+ if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
+ wc_nd_set_publisher_node (~0, REPORT_MAX);
+ goto reply;
+ }
+ }
+ if (mp->enable_disable == 0)
+ {
+ clib_warning ("pid %d: already disabled...", mp->pid);
+ rv = VNET_API_ERROR_INVALID_REGISTRATION;
+ goto reply;
+ }
+ pool_get (am->wc_ip6_nd_events_registrations, rp);
+ rp->client_index = mp->client_index;
+ rp->client_pid = mp->pid;
+ hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index,
+ rp - am->wc_ip6_nd_events_registrations);
+ wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT);
+ goto reply;
+ }
+
+ if (mp->enable_disable)
+ {
+ vl_api_ip6_nd_event_t *event;
+ pool_get (am->nd_events, event);
+
+ rv = vnet_add_del_ip6_nd_change_event
+ (vnm, nd_change_data_callback,
+ mp->pid, &ip6,
+ ip_resolver_process_node.index,
+ IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
+
+ if (rv)
+ {
+ pool_put (am->nd_events, event);
+ goto reply;
+ }
+ clib_memset (event, 0, sizeof (*event));
+
+ event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
+ event->client_index = mp->client_index;
+ ip6_address_encode (&ip6, event->ip);
+ event->pid = mp->pid;
+ }
+ else
+ {
+ rv = vnet_add_del_ip6_nd_change_event
+ (vnm, nd_change_delete_callback,
+ mp->pid, &ip6 /* addr, in net byte order */ ,
+ ip_resolver_process_node.index,
+ IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
+ }
+reply:
+ REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
+}
+
+static clib_error_t *
+want_ip6_nd_events_reaper (u32 client_index)
+{
+
+ vpe_client_registration_t *rp;
+ vl_api_ip6_nd_event_t *event;
+ u32 *to_delete, *event_id;
+ vpe_api_main_t *am;
+ vnet_main_t *vnm;
+ uword *p;
+
+ am = &vpe_api_main;
+ vnm = vnet_get_main ();
+ to_delete = NULL;
+
+ /* clear out all of its pending resolutions */
+ /* *INDENT-OFF* */
+ pool_foreach(event, am->nd_events,
+ ({
+ if (event->client_index == client_index)
+ {
+ vec_add1(to_delete, event - am->nd_events);
+ }
+ }));
+ /* *INDENT-ON* */
+
+ vec_foreach (event_id, to_delete)
+ {
+ event = pool_elt_at_index (am->nd_events, *event_id);
+ vnet_add_del_ip6_nd_change_event
+ (vnm, nd_change_delete_callback,
+ event->pid, event->ip,
+ ip_resolver_process_node.index, IP6_ND_EVENT,
+ ~0 /* pool index, notused */ , 0 /* is_add */ );
+ }
+ vec_free (to_delete);
+
+ /* remove from the registration hash */
+ p = hash_get (am->wc_ip6_nd_events_registration_hash, client_index);
+
+ if (p)
+ {
+ rp = pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
+ pool_put (am->wc_ip6_nd_events_registrations, rp);
+ hash_unset (am->wc_ip6_nd_events_registration_hash, client_index);
+ if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
+ wc_nd_set_publisher_node (~0, REPORT_MAX);
+ }
+ return (NULL);
+}
+
+VL_MSG_API_REAPER_FUNCTION (want_ip6_nd_events_reaper);
+
+static void
+vl_api_want_ip6_ra_events_t_handler (vl_api_want_ip6_ra_events_t * mp)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+ vl_api_want_ip6_ra_events_reply_t *rmp;
+ int rv = 0;
+
+ uword *p = hash_get (am->ip6_ra_events_registration_hash, mp->client_index);
+ vpe_client_registration_t *rp;
+ if (p)
+ {
+ if (mp->enable_disable)
+ {
+ clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
+ rv = VNET_API_ERROR_INVALID_REGISTRATION;
+ goto reply;
+ }
+ else
+ {
+ rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
+ pool_put (am->ip6_ra_events_registrations, rp);
+ hash_unset (am->ip6_ra_events_registration_hash, mp->client_index);
+ goto reply;
+ }
+ }
+ if (mp->enable_disable == 0)
+ {
+ clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
+ rv = VNET_API_ERROR_INVALID_REGISTRATION;
+ goto reply;
+ }
+ pool_get (am->ip6_ra_events_registrations, rp);
+ rp->client_index = mp->client_index;
+ rp->client_pid = ntohl (mp->pid);
+ hash_set (am->ip6_ra_events_registration_hash, rp->client_index,
+ rp - am->ip6_ra_events_registrations);
+
+reply:
+ REPLY_MACRO (VL_API_WANT_IP6_RA_EVENTS_REPLY);
+}
+
+static clib_error_t *
+want_ip6_ra_events_reaper (u32 client_index)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+ vpe_client_registration_t *rp;
+ uword *p;
+
+ p = hash_get (am->ip6_ra_events_registration_hash, client_index);
+
+ if (p)
+ {
+ rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
+ pool_put (am->ip6_ra_events_registrations, rp);
+ hash_unset (am->ip6_ra_events_registration_hash, client_index);
+ }
+ return (NULL);
+}
+
+VL_MSG_API_REAPER_FUNCTION (want_ip6_ra_events_reaper);
+
+static void
+vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
+{
+ vl_api_proxy_arp_add_del_reply_t *rmp;
+ ip4_address_t lo, hi;
+ u32 fib_index;
+ int rv;
+
+ stats_dslock_with_hint (1 /* release hint */ , 6 /* tag */ );
+
+ fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->proxy.table_id));
+
+ if (~0 == fib_index)