-static void
-vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
- mp)
-{
- vl_api_sw_interface_clear_stats_reply_t *rmp;
-
- vnet_main_t *vnm = vnet_get_main ();
- vnet_interface_main_t *im = &vnm->interface_main;
- vlib_simple_counter_main_t *sm;
- vlib_combined_counter_main_t *cm;
- static vnet_main_t **my_vnet_mains;
- int i, j, n_counters;
- int rv = 0;
-
- if (mp->sw_if_index != ~0)
- VALIDATE_SW_IF_INDEX (mp);
-
- vec_reset_length (my_vnet_mains);
-
- for (i = 0; i < vec_len (vnet_mains); i++)
- {
- if (vnet_mains[i])
- vec_add1 (my_vnet_mains, vnet_mains[i]);
- }
-
- if (vec_len (vnet_mains) == 0)
- vec_add1 (my_vnet_mains, vnm);
-
- n_counters = vec_len (im->combined_sw_if_counters);
-
- for (j = 0; j < n_counters; j++)
- {
- for (i = 0; i < vec_len (my_vnet_mains); i++)
- {
- im = &my_vnet_mains[i]->interface_main;
- cm = im->combined_sw_if_counters + j;
- if (mp->sw_if_index == (u32) ~ 0)
- vlib_clear_combined_counters (cm);
- else
- vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
- }
- }
-
- n_counters = vec_len (im->sw_if_counters);
-
- for (j = 0; j < n_counters; j++)
- {
- for (i = 0; i < vec_len (my_vnet_mains); i++)
- {
- im = &my_vnet_mains[i]->interface_main;
- sm = im->sw_if_counters + j;
- if (mp->sw_if_index == (u32) ~ 0)
- vlib_clear_simple_counters (sm);
- else
- vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
- }
- }
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
-}
-
-static void
-send_sw_interface_details (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q,
- vnet_sw_interface_t * swif,
- u8 * interface_name, u32 context)
-{
- vl_api_sw_interface_details_t *mp;
- vnet_hw_interface_t *hi;
-
- hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
- mp->sw_if_index = ntohl (swif->sw_if_index);
- mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
- mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
- mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
- mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
- VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
- mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
- VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
- mp->link_mtu = ntohs (hi->max_packet_bytes);
- mp->context = context;
-
- strncpy ((char *) mp->interface_name,
- (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
-
- /* Send the L2 address for ethernet physical intfcs */
- if (swif->sup_sw_if_index == swif->sw_if_index
- && hi->hw_class_index == ethernet_hw_interface_class.index)
- {
- ethernet_main_t *em = ethernet_get_main (am->vlib_main);
- ethernet_interface_t *ei;
-
- ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
- ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
- clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
- mp->l2_address_length = ntohl (sizeof (ei->address));
- }
- else if (swif->sup_sw_if_index != swif->sw_if_index)
- {
- vnet_sub_interface_t *sub = &swif->sub;
- mp->sub_id = ntohl (sub->id);
- mp->sub_dot1ad = sub->eth.flags.dot1ad;
- mp->sub_number_of_tags =
- sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
- mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
- mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
- mp->sub_exact_match = sub->eth.flags.exact_match;
- mp->sub_default = sub->eth.flags.default_sub;
- mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
- mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
-
- /* vlan tag rewrite data */
- u32 vtr_op = L2_VTR_DISABLED;
- u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
-
- if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
- &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
- {
- // error - default to disabled
- mp->vtr_op = ntohl (L2_VTR_DISABLED);
- clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
- swif->sw_if_index);
- }
- else
- {
- mp->vtr_op = ntohl (vtr_op);
- mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
- mp->vtr_tag1 = ntohl (vtr_tag1);
- mp->vtr_tag2 = ntohl (vtr_tag2);
- }
- }
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
-send_sw_interface_flags (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q,
- vnet_sw_interface_t * swif)
-{
- vl_api_sw_interface_set_flags_t *mp;
- vnet_main_t *vnm = am->vnet_main;
-
- vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
- swif->sw_if_index);
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
- mp->sw_if_index = ntohl (swif->sw_if_index);
-
- mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
- mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-