- if (a->multicast_address == 0)
- {
- rv = -1;
- goto out;
- }
-
- if (!(a->policy_name))
- {
- rv = -2;
- goto out;
- }
-
-#if DPDK > 0 /* Cannot call replicate without DPDK */
- rv = ip6_sr_add_del_multicastmap (a);
-#else
- clib_warning ("multicast replication without DPDK not implemented");
- rv = VNET_API_ERROR_UNIMPLEMENTED;
-#endif /* DPDK */
-
-out:
-
- REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
-#endif
-}
-
-#define foreach_classify_add_del_table_field \
-_(table_index) \
-_(nbuckets) \
-_(memory_size) \
-_(skip_n_vectors) \
-_(match_n_vectors) \
-_(next_table_index) \
-_(miss_next_index) \
-_(current_data_flag) \
-_(current_data_offset)
-
-static void vl_api_classify_add_del_table_t_handler
- (vl_api_classify_add_del_table_t * mp)
-{
- vl_api_classify_add_del_table_reply_t *rmp;
- vnet_classify_main_t *cm = &vnet_classify_main;
- vnet_classify_table_t *t;
- int rv;
-
-#define _(a) u32 a;
- foreach_classify_add_del_table_field;
-#undef _
-
-#define _(a) a = ntohl(mp->a);
- foreach_classify_add_del_table_field;
-#undef _
-
- /* The underlying API fails silently, on purpose, so check here */
- if (mp->is_add == 0) /* delete */
- {
- if (pool_is_free_index (cm->tables, table_index))
- {
- rv = VNET_API_ERROR_NO_SUCH_TABLE;
- goto out;
- }
- }
- else /* add or update */
- {
- if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
- table_index = ~0;
- }
-
- rv = vnet_classify_add_del_table
- (cm, mp->mask, nbuckets, memory_size,
- skip_n_vectors, match_n_vectors,
- next_table_index, miss_next_index, &table_index,
- current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
-
-out:
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
- ({
- if (rv == 0 && mp->is_add)
- {
- t = pool_elt_at_index (cm->tables, table_index);
- rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
- rmp->match_n_vectors = ntohl(t->match_n_vectors);
- rmp->new_table_index = ntohl(table_index);
- }
- else
- {
- rmp->skip_n_vectors = ~0;
- rmp->match_n_vectors = ~0;
- rmp->new_table_index = ~0;
- }
- }));
- /* *INDENT-ON* */
-}
-
-static void vl_api_classify_add_del_session_t_handler
- (vl_api_classify_add_del_session_t * mp)
-{
- vnet_classify_main_t *cm = &vnet_classify_main;
- vl_api_classify_add_del_session_reply_t *rmp;
- int rv;
- u32 table_index, hit_next_index, opaque_index, metadata;
- i32 advance;
- u8 action;
-
- table_index = ntohl (mp->table_index);
- hit_next_index = ntohl (mp->hit_next_index);
- opaque_index = ntohl (mp->opaque_index);
- advance = ntohl (mp->advance);
- action = mp->action;
- metadata = ntohl (mp->metadata);
-
- rv = vnet_classify_add_del_session
- (cm, table_index, mp->match, hit_next_index, opaque_index,
- advance, action, metadata, mp->is_add);
-
- REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_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);
-}
-
-static void
-vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
-{
- int rv = 0;
- vl_api_l2_fib_clear_table_reply_t *rmp;
-
- /* DAW-FIXME: This API should only clear non-static l2fib entries, but
- * that is not currently implemented. When that TODO is fixed
- * this call should be changed to pass 1 instead of 0.
- */
- l2fib_clear_table (0);
-
- REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_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_l2_interface_vlan_tag_rewrite_t_handler
- (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
-{
- int rv = 0;
- vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
- vnet_main_t *vnm = vnet_get_main ();
- vlib_main_t *vm = vlib_get_main ();
- u32 vtr_op;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- vtr_op = ntohl (mp->vtr_op);
-
- /* The L2 code is unsuspicious */
- switch (vtr_op)
- {
- case L2_VTR_DISABLED:
- case L2_VTR_PUSH_1:
- case L2_VTR_PUSH_2:
- case L2_VTR_POP_1:
- case L2_VTR_POP_2:
- case L2_VTR_TRANSLATE_1_1:
- case L2_VTR_TRANSLATE_1_2:
- case L2_VTR_TRANSLATE_2_1:
- case L2_VTR_TRANSLATE_2_2:
- break;
-
- default:
- rv = VNET_API_ERROR_INVALID_VALUE;
- goto bad_sw_if_index;
- }
-
- rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
- ntohl (mp->push_dot1q), ntohl (mp->tag1),
- ntohl (mp->tag2));
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
-}
-
-static void
-vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
-{
- clib_warning ("BUG");
-}
-
-static void
-send_l2fib_table_entry (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q,
- l2fib_entry_key_t * l2fe_key,
- l2fib_entry_result_t * l2fe_res, u32 context)
-{
- vl_api_l2_fib_table_entry_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
-
- mp->bd_id =
- ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
-
- mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
- mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
- mp->static_mac = l2fe_res->fields.static_mac;
- mp->filter_mac = l2fe_res->fields.filter;
- mp->bvi_mac = l2fe_res->fields.bvi;
- mp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
-vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
-{
- vpe_api_main_t *am = &vpe_api_main;
- bd_main_t *bdm = &bd_main;
- l2fib_entry_key_t *l2fe_key = NULL;
- l2fib_entry_result_t *l2fe_res = NULL;
- u32 ni, bd_id = ntohl (mp->bd_id);
- u32 bd_index;
- unix_shared_memory_queue_t *q;
- uword *p;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- return;
-
- /* see l2fib_table_dump: ~0 means "any" */
- if (bd_id == ~0)
- bd_index = ~0;
- else
- {
- p = hash_get (bdm->bd_index_by_bd_id, bd_id);
- if (p == 0)
- return;
-
- bd_index = p[0];
- }
-
- l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
-
- vec_foreach_index (ni, l2fe_key)
- {
- send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
- vec_elt_at_index (l2fe_res, ni), mp->context);
- }
- vec_free (l2fe_key);
- vec_free (l2fe_res);
-}
-
-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);
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
-}
-
-static void
-vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
-{
- int rv = 0;
- u8 *vector = 0;
- api_main_t *am = &api_main;
- vlib_main_t *vm = vlib_get_main ();
- void *oldheap;
- vl_api_get_node_graph_reply_t *rmp;
-
- pthread_mutex_lock (&am->vlib_rp->mutex);
- oldheap = svm_push_data_heap (am->vlib_rp);
-
- /*
- * Keep the number of memcpy ops to a minimum (e.g. 1).
- */
- vec_validate (vector, 16384);
- vec_reset_length (vector);
-
- /* $$$$ FIXME */
- vector = vlib_node_serialize (&vm->node_main, vector,
- (u32) ~ 0 /* all threads */ ,
- 1 /* include nexts */ ,
- 1 /* include stats */ );
-
- svm_pop_heap (oldheap);
- pthread_mutex_unlock (&am->vlib_rp->mutex);
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
- ({
- rmp->reply_in_shmem = (uword) vector;
- }));
- /* *INDENT-ON* */
-}
-
-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_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
-{
- vlib_main_t *vm = vlib_get_main ();
- vl_api_policer_add_del_reply_t *rmp;
- int rv = 0;
- u8 *name = NULL;
- sse2_qos_pol_cfg_params_st cfg;
- clib_error_t *error;
- u32 policer_index;
-
- name = format (0, "%s", mp->name);
-
- memset (&cfg, 0, sizeof (cfg));
- cfg.rfc = mp->type;
- cfg.rnd_type = mp->round_type;
- cfg.rate_type = mp->rate_type;
- cfg.rb.kbps.cir_kbps = mp->cir;
- cfg.rb.kbps.eir_kbps = mp->eir;
- cfg.rb.kbps.cb_bytes = mp->cb;
- cfg.rb.kbps.eb_bytes = mp->eb;
- cfg.conform_action.action_type = mp->conform_action_type;
- cfg.conform_action.dscp = mp->conform_dscp;
- cfg.exceed_action.action_type = mp->exceed_action_type;
- cfg.exceed_action.dscp = mp->exceed_dscp;
- cfg.violate_action.action_type = mp->violate_action_type;
- cfg.violate_action.dscp = mp->violate_dscp;
- cfg.color_aware = mp->color_aware;
-
- error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
-
- if (error)
- rv = VNET_API_ERROR_UNSPECIFIED;
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
- ({
- if (rv == 0 && mp->is_add)
- rmp->policer_index = ntohl(policer_index);
- else
- rmp->policer_index = ~0;
- }));
- /* *INDENT-ON* */
-}
-
-static void
-send_policer_details (u8 * name,
- sse2_qos_pol_cfg_params_st * config,
- policer_read_response_type_st * templ,
- unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_policer_details_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
- mp->context = context;
- mp->cir = htonl (config->rb.kbps.cir_kbps);
- mp->eir = htonl (config->rb.kbps.eir_kbps);
- mp->cb = htonl (config->rb.kbps.cb_bytes);
- mp->eb = htonl (config->rb.kbps.eb_bytes);
- mp->rate_type = config->rate_type;
- mp->round_type = config->rnd_type;
- mp->type = config->rfc;
- mp->conform_action_type = config->conform_action.action_type;
- mp->conform_dscp = config->conform_action.dscp;
- mp->exceed_action_type = config->exceed_action.action_type;
- mp->exceed_dscp = config->exceed_action.dscp;
- mp->violate_action_type = config->violate_action.action_type;
- mp->violate_dscp = config->violate_action.dscp;
- mp->single_rate = templ->single_rate ? 1 : 0;
- mp->color_aware = templ->color_aware ? 1 : 0;
- mp->scale = htonl (templ->scale);
- mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
- mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
- mp->current_limit = htonl (templ->current_limit);
- mp->current_bucket = htonl (templ->current_bucket);
- mp->extended_limit = htonl (templ->extended_limit);
- mp->extended_bucket = htonl (templ->extended_bucket);
- mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
-
- strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
-vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
-{
- unix_shared_memory_queue_t *q;
- vnet_policer_main_t *pm = &vnet_policer_main;
- hash_pair_t *hp;
- uword *p;
- u32 pool_index;
- u8 *match_name = 0;
- u8 *name;
- sse2_qos_pol_cfg_params_st *config;
- policer_read_response_type_st *templ;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- return;
-
- if (mp->match_name_valid)
- {
- match_name = format (0, "%s%c", mp->match_name, 0);
- }
-
- if (mp->match_name_valid)
- {
- p = hash_get_mem (pm->policer_config_by_name, match_name);
- if (p)
- {
- pool_index = p[0];
- config = pool_elt_at_index (pm->configs, pool_index);
- templ = pool_elt_at_index (pm->policer_templates, pool_index);
- send_policer_details (match_name, config, templ, q, mp->context);
- }
- }
- else