- clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
-
- svm_pop_heap (oldheap);
- pthread_mutex_unlock (&am->vlib_rp->mutex);
-
- *shmem_vecp = shmem_vec;
-}
-
-
-static void
-vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
-{
- vl_api_cli_reply_t *rp;
- unix_shared_memory_queue_t *q;
- vlib_main_t *vm = vlib_get_main ();
- api_main_t *am = &api_main;
- unformat_input_t input;
- u8 *shmem_vec = 0;
- void *oldheap;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (!q)
- return;
-
- rp = vl_msg_api_alloc (sizeof (*rp));
- rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
- rp->context = mp->context;
-
- unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
-
- vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
-
- pthread_mutex_lock (&am->vlib_rp->mutex);
- oldheap = svm_push_data_heap (am->vlib_rp);
-
- vec_add1 (shmem_vec, 0);
-
- svm_pop_heap (oldheap);
- pthread_mutex_unlock (&am->vlib_rp->mutex);
-
- rp->reply_in_shmem = (uword) shmem_vec;
-
- vl_msg_api_send_shmem (q, (u8 *) & rp);
-}
-
-static void
-inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
-{
- u8 **mem_vecp = (u8 **) arg;
- u8 *mem_vec = *mem_vecp;
- u32 offset = vec_len (mem_vec);
-
- vec_validate (mem_vec, offset + buffer_bytes - 1);
- clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
- *mem_vecp = mem_vec;
-}
-
-static void
-vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
-{
- vl_api_cli_inband_reply_t *rmp;
- int rv = 0;
- unix_shared_memory_queue_t *q;
- vlib_main_t *vm = vlib_get_main ();
- unformat_input_t input;
- u8 *out_vec = 0;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (!q)
- return;
-
- unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
- vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
-
- u32 len = vec_len (out_vec);
- /* *INDENT-OFF* */
- REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
- ({
- rmp->length = htonl (len);
- clib_memcpy (rmp->reply, out_vec, len);
- }));
- /* *INDENT-ON* */
- vec_free (out_vec);
-}
-
-static void
-vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
-{
- int rv;
- vl_api_set_arp_neighbor_limit_reply_t *rmp;
- vnet_main_t *vnm = vnet_get_main ();
- clib_error_t *error;
-
- vnm->api_errno = 0;
-
- if (mp->is_ipv6)
- error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
- else
- error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
-
- if (error)
- {
- clib_error_report (error);
- rv = VNET_API_ERROR_UNSPECIFIED;
- }
- else
- {
- rv = vnm->api_errno;
- }
-
- REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
-}
-
-static void vl_api_classify_set_interface_ip_table_t_handler
- (vl_api_classify_set_interface_ip_table_t * mp)
-{
- vlib_main_t *vm = vlib_get_main ();
- vl_api_classify_set_interface_ip_table_reply_t *rmp;
- int rv;
- u32 table_index, sw_if_index;
-
- table_index = ntohl (mp->table_index);
- sw_if_index = ntohl (mp->sw_if_index);
-
- VALIDATE_SW_IF_INDEX (mp);
-
- if (mp->is_ipv6)
- rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
- else
- rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
-}
-
-static void vl_api_classify_set_interface_l2_tables_t_handler
- (vl_api_classify_set_interface_l2_tables_t * mp)
-{
- vl_api_classify_set_interface_l2_tables_reply_t *rmp;
- int rv;
- u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
- int enable;
-
- ip4_table_index = ntohl (mp->ip4_table_index);
- ip6_table_index = ntohl (mp->ip6_table_index);
- other_table_index = ntohl (mp->other_table_index);
- sw_if_index = ntohl (mp->sw_if_index);
-
- VALIDATE_SW_IF_INDEX (mp);
-
- if (mp->is_input)
- rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
- ip6_table_index,
- other_table_index);
- else
- rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
- ip6_table_index,
- other_table_index);
-
- if (rv == 0)
- {
- if (ip4_table_index != ~0 || ip6_table_index != ~0
- || other_table_index != ~0)
- enable = 1;
- else
- enable = 0;
-
- if (mp->is_input)
- vnet_l2_input_classify_enable_disable (sw_if_index, enable);
- else
- vnet_l2_output_classify_enable_disable (sw_if_index, enable);
- }
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
-}
-
-extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
- u32 sw_if_index, u32 enable);
-
-static void
-vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
- mp)
-{
- int rv;
- vl_api_l2_interface_efp_filter_reply_t *rmp;
- vnet_main_t *vnm = vnet_get_main ();
-
- // enable/disable the feature
- l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
- rv = vnm->api_errno;
-
- REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
-}
-
-static void
-vl_api_show_version_t_handler (vl_api_show_version_t * mp)
-{
- vl_api_show_version_reply_t *rmp;
- int rv = 0;
- char *vpe_api_get_build_directory (void);
- char *vpe_api_get_version (void);
- char *vpe_api_get_build_date (void);
-
- unix_shared_memory_queue_t *q =
- vl_api_client_index_to_input_queue (mp->client_index);
-
- if (!q)
- return;
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
- ({
- strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
- strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
- ARRAY_LEN(rmp->build_directory)-1);
- strncpy ((char *) rmp->version, vpe_api_get_version(),
- ARRAY_LEN(rmp->version)-1);
- strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
- ARRAY_LEN(rmp->build_date)-1);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
-{
- vlib_main_t *vm = vlib_get_main ();
- vl_api_get_node_index_reply_t *rmp;
- vlib_node_t *n;
- int rv = 0;
- u32 node_index = ~0;
-
- n = vlib_get_node_by_name (vm, mp->node_name);
-
- if (n == 0)
- rv = VNET_API_ERROR_NO_SUCH_NODE;
- else
- node_index = n->index;
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
- ({
- rmp->node_index = ntohl(node_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
-{
- vlib_main_t *vm = vlib_get_main ();
- vl_api_get_next_index_reply_t *rmp;
- vlib_node_t *node, *next_node;
- int rv = 0;
- u32 next_node_index = ~0, next_index = ~0;
- uword *p;
-
- node = vlib_get_node_by_name (vm, mp->node_name);
-
- if (node == 0)
- {
- rv = VNET_API_ERROR_NO_SUCH_NODE;
- goto out;
- }
-
- next_node = vlib_get_node_by_name (vm, mp->next_name);
-
- if (next_node == 0)
- {
- rv = VNET_API_ERROR_NO_SUCH_NODE2;
- goto out;
- }
- else
- next_node_index = next_node->index;
-
- p = hash_get (node->next_slot_by_node, next_node_index);
-
- if (p == 0)
- {
- rv = VNET_API_ERROR_NO_SUCH_ENTRY;
- goto out;
- }
- else
- next_index = p[0];
-
-out:
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
- ({
- rmp->next_index = ntohl(next_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
-{
- vlib_main_t *vm = vlib_get_main ();
- vl_api_add_node_next_reply_t *rmp;
- vlib_node_t *n, *next;
- int rv = 0;
- u32 next_index = ~0;
-
- n = vlib_get_node_by_name (vm, mp->node_name);
-
- if (n == 0)
- {
- rv = VNET_API_ERROR_NO_SUCH_NODE;
- goto out;
- }
-
- next = vlib_get_node_by_name (vm, mp->next_name);
-
- if (next == 0)
- rv = VNET_API_ERROR_NO_SUCH_NODE2;
- else
- next_index = vlib_node_add_next (vm, n->index, next->index);
-
-out:
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
- ({
- rmp->next_index = ntohl(next_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void vl_api_vxlan_add_del_tunnel_t_handler
- (vl_api_vxlan_add_del_tunnel_t * mp)
-{
- vl_api_vxlan_add_del_tunnel_reply_t *rmp;
- int rv = 0;
- vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
- u32 encap_fib_index;
- uword *p;
- ip4_main_t *im = &ip4_main;
- vnet_main_t *vnm = vnet_get_main ();
- u32 sw_if_index = ~0;
-
- p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
- if (!p)
- {
- rv = VNET_API_ERROR_NO_SUCH_FIB;
- goto out;
- }
- encap_fib_index = p[0];
- memset (a, 0, sizeof (*a));
-
- a->is_add = mp->is_add;
- a->is_ip6 = mp->is_ipv6;
-
- /* ip addresses sent in network byte order */
- ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
- ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
-
- /* Check src & dst are different */
- if (ip46_address_cmp (&a->dst, &a->src) == 0)
- {
- rv = VNET_API_ERROR_SAME_SRC_DST;
- goto out;
- }
- a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
- if (ip46_address_is_multicast (&a->dst) &&
- pool_is_free_index (vnm->interface_main.sw_interfaces,
- a->mcast_sw_if_index))
- {
- rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
- goto out;
- }
- a->encap_fib_index = encap_fib_index;
- a->decap_next_index = ntohl (mp->decap_next_index);
- a->vni = ntohl (mp->vni);
- rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
-
-out:
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
- ({
- rmp->sw_if_index = ntohl (sw_if_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void send_vxlan_tunnel_details
- (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_vxlan_tunnel_details_t *rmp;
- ip4_main_t *im4 = &ip4_main;
- ip6_main_t *im6 = &ip6_main;
- u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
- if (is_ipv6)
- {
- memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
- memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
- rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
- }
- else
- {
- memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
- memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
- rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
- }
- rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
- rmp->vni = htonl (t->vni);
- rmp->decap_next_index = htonl (t->decap_next_index);
- rmp->sw_if_index = htonl (t->sw_if_index);
- rmp->is_ipv6 = is_ipv6;
- rmp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void vl_api_vxlan_tunnel_dump_t_handler
- (vl_api_vxlan_tunnel_dump_t * mp)
-{
- unix_shared_memory_queue_t *q;
- vxlan_main_t *vxm = &vxlan_main;
- vxlan_tunnel_t *t;
- u32 sw_if_index;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- sw_if_index = ntohl (mp->sw_if_index);
-
- if (~0 == sw_if_index)
- {
- /* *INDENT-OFF* */
- pool_foreach (t, vxm->tunnels,
- ({
- send_vxlan_tunnel_details(t, q, mp->context);
- }));
- /* *INDENT-ON* */
- }
- else
- {
- if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
- (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
- {
- return;
- }
- t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
- send_vxlan_tunnel_details (t, q, mp->context);
- }
-}
-
-static void
-vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
-{
- extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
- int is_add);
- vl_api_l2_patch_add_del_reply_t *rmp;
- int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
- int is_add);
- int rv = 0;
-
- VALIDATE_RX_SW_IF_INDEX (mp);
- VALIDATE_TX_SW_IF_INDEX (mp);
-
- rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
- ntohl (mp->tx_sw_if_index),
- (int) (mp->is_add != 0));
-
- BAD_RX_SW_IF_INDEX_LABEL;
- BAD_TX_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
-}
-
-static void
- vl_api_vxlan_gpe_add_del_tunnel_t_handler
- (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
-{
- vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
- int rv = 0;
- vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
- u32 encap_fib_index, decap_fib_index;
- u8 protocol;
- uword *p;
- ip4_main_t *im = &ip4_main;
- u32 sw_if_index = ~0;
-
-
- p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
- if (!p)
- {
- rv = VNET_API_ERROR_NO_SUCH_FIB;
- goto out;
- }
- encap_fib_index = p[0];
-
- protocol = mp->protocol;
-
- /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
- if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
- {
- p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
- if (!p)
- {
- rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
- goto out;
- }
- decap_fib_index = p[0];
- }
- else
- {
- decap_fib_index = ntohl (mp->decap_vrf_id);
- }
-
- /* Check src & dst are different */
- if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
- (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
- {
- rv = VNET_API_ERROR_SAME_SRC_DST;
- goto out;
- }
- memset (a, 0, sizeof (*a));
-
- a->is_add = mp->is_add;
- a->is_ip6 = mp->is_ipv6;
- /* ip addresses sent in network byte order */
- if (a->is_ip6)
- {
- clib_memcpy (&(a->local.ip6), mp->local, 16);
- clib_memcpy (&(a->remote.ip6), mp->remote, 16);
- }
- else
- {
- clib_memcpy (&(a->local.ip4), mp->local, 4);
- clib_memcpy (&(a->remote.ip4), mp->remote, 4);
- }
- a->encap_fib_index = encap_fib_index;
- a->decap_fib_index = decap_fib_index;
- a->protocol = protocol;
- a->vni = ntohl (mp->vni);
- rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
-
-out:
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
- ({
- rmp->sw_if_index = ntohl (sw_if_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void send_vxlan_gpe_tunnel_details
- (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_vxlan_gpe_tunnel_details_t *rmp;
- ip4_main_t *im4 = &ip4_main;
- ip6_main_t *im6 = &ip6_main;
- u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
- if (is_ipv6)
- {
- memcpy (rmp->local, &(t->local.ip6), 16);
- memcpy (rmp->remote, &(t->remote.ip6), 16);
- rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
- rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
- }
- else
- {
- memcpy (rmp->local, &(t->local.ip4), 4);
- memcpy (rmp->remote, &(t->remote.ip4), 4);
- rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
- rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
- }
- rmp->vni = htonl (t->vni);
- rmp->protocol = t->protocol;
- rmp->sw_if_index = htonl (t->sw_if_index);
- rmp->is_ipv6 = is_ipv6;
- rmp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void vl_api_vxlan_gpe_tunnel_dump_t_handler
- (vl_api_vxlan_gpe_tunnel_dump_t * mp)
-{
- unix_shared_memory_queue_t *q;
- vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
- vxlan_gpe_tunnel_t *t;
- u32 sw_if_index;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- sw_if_index = ntohl (mp->sw_if_index);
-
- if (~0 == sw_if_index)
- {
- /* *INDENT-OFF* */
- pool_foreach (t, vgm->tunnels,
- ({
- send_vxlan_gpe_tunnel_details(t, q, mp->context);
- }));
- /* *INDENT-ON* */
- }
- else
- {
- if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
- (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
- {
- return;
- }
- t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
- send_vxlan_gpe_tunnel_details (t, q, mp->context);
- }
-}
-
-static void
-vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
- mp)
-{
- vl_api_interface_name_renumber_reply_t *rmp;
- int rv = 0;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- rv = vnet_interface_name_renumber
- (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
-}
-
-static int
-arp_change_data_callback (u32 pool_index, u8 * new_mac,
- u32 sw_if_index, u32 address)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vlib_main_t *vm = am->vlib_main;
- vl_api_ip4_arp_event_t *event;
- static f64 arp_event_last_time;
- f64 now = vlib_time_now (vm);
-
- if (pool_is_free_index (am->arp_events, pool_index))
- return 1;
-
- event = pool_elt_at_index (am->arp_events, pool_index);
- /* *INDENT-OFF* */
- if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
- {
- clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
- }
- else
- { /* same mac */
- if (sw_if_index == event->sw_if_index &&
- (!event->mac_ip ||
- /* for BD case, also check IP address with 10 sec timeout */
- (address == event->address &&
- (now - arp_event_last_time) < 10.0)))
- return 1;
- }
- /* *INDENT-ON* */
-
- arp_event_last_time = now;
- event->sw_if_index = sw_if_index;
- if (event->mac_ip)
- event->address = address;
- return 0;
-}
-
-static int
-nd_change_data_callback (u32 pool_index, u8 * new_mac,
- u32 sw_if_index, ip6_address_t * address)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vlib_main_t *vm = am->vlib_main;
- vl_api_ip6_nd_event_t *event;
- static f64 nd_event_last_time;
- f64 now = vlib_time_now (vm);
-
- if (pool_is_free_index (am->nd_events, pool_index))
- return 1;
-
- event = pool_elt_at_index (am->nd_events, pool_index);
-
- /* *INDENT-OFF* */
- if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
- {
- clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
- }
- else
- { /* same mac */
- if (sw_if_index == event->sw_if_index &&
- (!event->mac_ip ||
- /* for BD case, also check IP address with 10 sec timeout */
- (ip6_address_is_equal (address,
- (ip6_address_t *) event->address) &&
- (now - nd_event_last_time) < 10.0)))
- return 1;
- }
- /* *INDENT-ON* */
-
- nd_event_last_time = now;
- event->sw_if_index = sw_if_index;
- if (event->mac_ip)
- clib_memcpy (event->address, address, sizeof (event->address));
- return 0;
-}
-
-static int
-arp_change_delete_callback (u32 pool_index, u8 * notused)
-{
- 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 int
-nd_change_delete_callback (u32 pool_index, u8 * notused)
-{
- 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
-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;
- vl_api_ip4_arp_event_t *event;
- int rv;
-
- if (mp->enable_disable)
- {
- pool_get (am->arp_events, event);
- memset (event, 0, sizeof (*event));
-
- event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
- event->client_index = mp->client_index;
- event->context = mp->context;
- event->address = mp->address;
- event->pid = mp->pid;
- if (mp->address == 0)
- event->mac_ip = 1;
-
- rv = vnet_add_del_ip4_arp_change_event
- (vnm, arp_change_data_callback,
- mp->pid, &mp->address /* addr, in net byte order */ ,
- vpe_resolver_process_node.index,
- IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
- }
- else
- {
- rv = vnet_add_del_ip4_arp_change_event
- (vnm, arp_change_delete_callback,
- mp->pid, &mp->address /* addr, in net byte order */ ,
- vpe_resolver_process_node.index,
- IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
- }
- REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
-}
-
-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;
- vl_api_ip6_nd_event_t *event;
- int rv;
-
- if (mp->enable_disable)
- {
- pool_get (am->nd_events, event);
- memset (event, 0, sizeof (*event));
-
- event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
- event->client_index = mp->client_index;
- event->context = mp->context;
- clib_memcpy (event->address, mp->address, 16);
- event->pid = mp->pid;
- if (ip6_address_is_zero ((ip6_address_t *) mp->address))
- event->mac_ip = 1;
-
- rv = vnet_add_del_ip6_nd_change_event
- (vnm, nd_change_data_callback,
- mp->pid, mp->address /* addr, in net byte order */ ,
- vpe_resolver_process_node.index,
- IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
- }
- else
- {
- rv = vnet_add_del_ip6_nd_change_event
- (vnm, nd_change_delete_callback,
- mp->pid, mp->address /* addr, in net byte order */ ,
- vpe_resolver_process_node.index,
- IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
- }
- REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
-}
-
-static void vl_api_input_acl_set_interface_t_handler
- (vl_api_input_acl_set_interface_t * mp)
-{
- vlib_main_t *vm = vlib_get_main ();
- vl_api_input_acl_set_interface_reply_t *rmp;
- int rv;
- u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
-
- ip4_table_index = ntohl (mp->ip4_table_index);
- ip6_table_index = ntohl (mp->ip6_table_index);
- l2_table_index = ntohl (mp->l2_table_index);
- sw_if_index = ntohl (mp->sw_if_index);
-
- VALIDATE_SW_IF_INDEX (mp);
-
- rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
- ip6_table_index, l2_table_index, mp->is_add);
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
-}
-
-static void vl_api_cop_interface_enable_disable_t_handler
- (vl_api_cop_interface_enable_disable_t * mp)
-{
- vl_api_cop_interface_enable_disable_reply_t *rmp;
- int rv;
- u32 sw_if_index = ntohl (mp->sw_if_index);
- int enable_disable;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- enable_disable = (int) mp->enable_disable;
-
- rv = cop_interface_enable_disable (sw_if_index, enable_disable);
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
-}
-
-static void vl_api_cop_whitelist_enable_disable_t_handler
- (vl_api_cop_whitelist_enable_disable_t * mp)
-{
- vl_api_cop_whitelist_enable_disable_reply_t *rmp;
- cop_whitelist_enable_disable_args_t _a, *a = &_a;
- u32 sw_if_index = ntohl (mp->sw_if_index);
- int rv;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- a->sw_if_index = sw_if_index;
- a->ip4 = mp->ip4;
- a->ip6 = mp->ip6;
- a->default_cop = mp->default_cop;
- a->fib_id = ntohl (mp->fib_id);
-
- rv = cop_whitelist_enable_disable (a);