-pub_sub_handler (oam_events, OAM_EVENTS);
-
-#define RESOLUTION_EVENT 1
-#define RESOLUTION_PENDING_EVENT 2
-#define IP4_ARP_EVENT 3
-#define IP6_ND_EVENT 4
-
-int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
-
-int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
-
-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;
- unix_shared_memory_queue_t *q;
-
- /* 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);
-
- q = vl_api_client_index_to_input_queue (event->client_index);
- if (!q)
- {
- (void) vnet_add_del_ip4_arp_change_event
- (vnm, arp_change_delete_callback,
- event->pid, &event->address,
- vpe_resolver_process_node.index, IP4_ARP_EVENT,
- ~0 /* pool index, notused */ , 0 /* is_add */ );
- return;
- }
-
- if (q->cursize < q->maxsize)
- {
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memcpy (mp, event, sizeof (*mp));
- vl_msg_api_send_shmem (q, (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->address, event->pid);
- last_time = vlib_time_now (vm);
- }
- }
-}
-
-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;
- unix_shared_memory_queue_t *q;
-
- /* 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);
-
- q = vl_api_client_index_to_input_queue (event->client_index);
- if (!q)
- {
- (void) vnet_add_del_ip6_nd_change_event
- (vnm, nd_change_delete_callback,
- event->pid, &event->address,
- vpe_resolver_process_node.index, IP6_ND_EVENT,
- ~0 /* pool index, notused */ , 0 /* is_add */ );
- return;
- }
-
- if (q->cursize < q->maxsize)
- {
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memcpy (mp, event, sizeof (*mp));
- vl_msg_api_send_shmem (q, (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->address, 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)
-{
- uword event_type;
- uword *event_data = 0;
- f64 timeout = 100.0;
- int i;
-
- while (1)
- {
- vlib_process_wait_for_event_or_clock (vm, timeout);
-
- event_type = vlib_process_get_events (vm, &event_data);
-
- switch (event_type)
- {
- case RESOLUTION_PENDING_EVENT:
- timeout = 1.0;
- break;
-
- case RESOLUTION_EVENT:
- clib_warning ("resolver: BOGUS TYPE");
- break;
-
- 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 (vpe_resolver_process_node,static) = {
- .function = resolver_process,
- .type = VLIB_NODE_TYPE_PROCESS,
- .name = "vpe-route-resolver-process",
-};
-/* *INDENT-ON* */
-
-static void
-vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
-{
- vl_api_sw_interface_set_vpath_reply_t *rmp;
- int rv = 0;
- u32 sw_if_index = ntohl (mp->sw_if_index);
-
- VALIDATE_SW_IF_INDEX (mp);
-
- l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
- vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
- sw_if_index, mp->enable, 0, 0);
- vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
- sw_if_index, mp->enable, 0, 0);
- vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
- sw_if_index, mp->enable, 0, 0);
- vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
- sw_if_index, mp->enable, 0, 0);
-
- BAD_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
-}
-
-static void
- vl_api_sw_interface_set_l2_xconnect_t_handler
- (vl_api_sw_interface_set_l2_xconnect_t * mp)
-{
- vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
- int rv = 0;
- u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
- u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
- vlib_main_t *vm = vlib_get_main ();
- vnet_main_t *vnm = vnet_get_main ();
-
- VALIDATE_RX_SW_IF_INDEX (mp);
-
- if (mp->enable)
- {
- VALIDATE_TX_SW_IF_INDEX (mp);
- rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
- rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
- }
- else
- {
- rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
- }
-
- BAD_RX_SW_IF_INDEX_LABEL;
- BAD_TX_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
-}
-
-static void
- vl_api_sw_interface_set_l2_bridge_t_handler
- (vl_api_sw_interface_set_l2_bridge_t * mp)
-{
- bd_main_t *bdm = &bd_main;
- vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
- int rv = 0;
- u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
- u32 bd_id = ntohl (mp->bd_id);
- u32 bd_index;
- u32 bvi = mp->bvi;
- u8 shg = mp->shg;
- vlib_main_t *vm = vlib_get_main ();
- vnet_main_t *vnm = vnet_get_main ();
-
- VALIDATE_RX_SW_IF_INDEX (mp);
-
- bd_index = bd_find_or_add_bd_index (bdm, bd_id);
-
- if (mp->enable)
- {
- //VALIDATE_TX_SW_IF_INDEX(mp);
- rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
- rx_sw_if_index, bd_index, bvi, shg, 0);
- }
- else
- {
- rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
- }
-
- BAD_RX_SW_IF_INDEX_LABEL;
-
- REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
-}
-
-static void
-vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
-{
- bd_main_t *bdm = &bd_main;
- vl_api_bd_ip_mac_add_del_reply_t *rmp;
- int rv = 0;
- u32 bd_id = ntohl (mp->bd_id);
- u32 bd_index;
- uword *p;
-
- p = hash_get (bdm->bd_index_by_bd_id, bd_id);
- if (p == 0)
- {
- rv = VNET_API_ERROR_NO_SUCH_ENTRY;
- goto out;
- }
-
- bd_index = p[0];
- if (bd_add_del_ip_mac (bd_index, mp->ip_address,
- mp->mac_address, mp->is_ipv6, mp->is_add))
- rv = VNET_API_ERROR_UNSPECIFIED;
-
-out:
- REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
-}
-
-static void
-vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
-{
- vl_api_create_vlan_subif_reply_t *rmp;
- vnet_main_t *vnm = vnet_get_main ();
- u32 sw_if_index = (u32) ~ 0;
- vnet_hw_interface_t *hi;
- int rv = 0;
- u32 id;
- vnet_sw_interface_t template;
- uword *p;
- vnet_interface_main_t *im = &vnm->interface_main;
- u64 sup_and_sub_key;
- u64 *kp;
- unix_shared_memory_queue_t *q;
- clib_error_t *error;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
-
- if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
- {
- rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
- goto out;
- }
-
- id = ntohl (mp->vlan_id);
- if (id == 0 || id > 4095)
- {
- rv = VNET_API_ERROR_INVALID_VLAN;
- goto out;
- }
-
- sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
-
- p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
- if (p)
- {
- rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
- goto out;
- }
-
- kp = clib_mem_alloc (sizeof (*kp));
- *kp = sup_and_sub_key;
-
- memset (&template, 0, sizeof (template));
- template.type = VNET_SW_INTERFACE_TYPE_SUB;
- template.sup_sw_if_index = hi->sw_if_index;
- template.sub.id = id;
- template.sub.eth.raw_flags = 0;
- template.sub.eth.flags.one_tag = 1;
- template.sub.eth.outer_vlan_id = id;
- template.sub.eth.flags.exact_match = 1;
-
- error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
- if (error)
- {
- clib_error_report (error);
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto out;
- }
- hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
- hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
-
- BAD_SW_IF_INDEX_LABEL;
-
-out:
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (!q)
- return;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
- rmp->context = mp->context;
- rmp->retval = ntohl (rv);
- rmp->sw_if_index = ntohl (sw_if_index);
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void
-vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
-{
- vl_api_create_subif_reply_t *rmp;
- vnet_main_t *vnm = vnet_get_main ();
- u32 sw_if_index = ~0;
- int rv = 0;
- u32 sub_id;
- vnet_sw_interface_t *si;
- vnet_hw_interface_t *hi;
- vnet_sw_interface_t template;
- uword *p;
- vnet_interface_main_t *im = &vnm->interface_main;
- u64 sup_and_sub_key;
- u64 *kp;
- clib_error_t *error;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
- hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
-
- if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
- {
- rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
- goto out;
- }
-
- sw_if_index = si->sw_if_index;
- sub_id = ntohl (mp->sub_id);
-
- sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
-
- p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
- if (p)
- {
- if (CLIB_DEBUG > 0)
- clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
- sw_if_index, sub_id);
- rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
- goto out;
- }
-
- kp = clib_mem_alloc (sizeof (*kp));
- *kp = sup_and_sub_key;
-
- memset (&template, 0, sizeof (template));
- template.type = VNET_SW_INTERFACE_TYPE_SUB;
- template.sup_sw_if_index = sw_if_index;
- template.sub.id = sub_id;
- template.sub.eth.flags.no_tags = mp->no_tags;
- template.sub.eth.flags.one_tag = mp->one_tag;
- template.sub.eth.flags.two_tags = mp->two_tags;
- template.sub.eth.flags.dot1ad = mp->dot1ad;
- template.sub.eth.flags.exact_match = mp->exact_match;
- template.sub.eth.flags.default_sub = mp->default_sub;
- template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
- template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
- template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
- template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
-
- error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
- if (error)
- {
- clib_error_report (error);
- rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
- goto out;
- }
-
- hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
- hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
-
- BAD_SW_IF_INDEX_LABEL;
-
-out:
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
- ({
- rmp->sw_if_index = ntohl(sw_if_index);
- }));
- /* *INDENT-ON* */
-}
-
-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;
- u32 fib_index;
- int rv;
- ip4_main_t *im = &ip4_main;
- stats_main_t *sm = &stats_main;
- int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
- ip4_address_t * hi_addr,
- u32 fib_index, int is_del);
- uword *p;
-
- dslock (sm, 1 /* release hint */ , 6 /* tag */ );
-
- p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
-
- if (!p)
- {
- rv = VNET_API_ERROR_NO_SUCH_FIB;
- goto out;
- }
-
- fib_index = p[0];
-
- rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
- (ip4_address_t *) mp->hi_address,
- fib_index, mp->is_add == 0);
-
-out:
- dsunlock (sm);
- REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
-}
-
-static void
- vl_api_proxy_arp_intfc_enable_disable_t_handler
- (vl_api_proxy_arp_intfc_enable_disable_t * mp)
-{
- int rv = 0;
- vnet_main_t *vnm = vnet_get_main ();
- vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
- vnet_sw_interface_t *si;
- u32 sw_if_index;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- sw_if_index = ntohl (mp->sw_if_index);
-
- if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
- {
- rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
- goto out;
- }
-
- si = vnet_get_sw_interface (vnm, sw_if_index);
-
- ASSERT (si);
-
- if (mp->enable_disable)
- si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
- else
- si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
-
- BAD_SW_IF_INDEX_LABEL;
-
-out:
- REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
-}
-
-static void
-vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
-{
-#if 0
- vpe_main_t *rm = &vpe_main;
- ip4_main_t *im4 = &ip4_main;
- ip6_main_t *im6 = &ip6_main;
- ip_lookup_main_t *lm;
- union
- {
- ip4_address_t ip4;
- ip6_address_t ip6;
- } addr;
- u32 adj_index, sw_if_index;
- vl_api_is_address_reachable_t *rmp;
- ip_adjacency_t *adj;
- unix_shared_memory_queue_t *q;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (!q)
- {
- increment_missing_api_client_counter (rm->vlib_main);
- return;
- }
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- clib_memcpy (rmp, mp, sizeof (*rmp));
-
- sw_if_index = mp->next_hop_sw_if_index;
- clib_memcpy (&addr, mp->address, sizeof (addr));
- if (mp->is_ipv6)
- {
- lm = &im6->lookup_main;
- adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
- }
- else
- {
- lm = &im4->lookup_main;
- // FIXME NOT an ADJ
- adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
- }
- if (adj_index == ~0)
- {
- rmp->is_error = 1;
- goto send;
- }
- adj = ip_get_adjacency (lm, adj_index);
-
- if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
- && adj->rewrite_header.sw_if_index == sw_if_index)
- {
- rmp->is_known = 1;
- }
- else
- {
- if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
- && adj->rewrite_header.sw_if_index == sw_if_index)
- {
- if (mp->is_ipv6)
- ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
- else
- ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
- }
- else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
- {
- rmp->is_known = 1;
- goto send;
- }
- rmp->is_known = 0;
- }
-
-send:
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-#endif
-}
-
-static void
- vl_api_sw_interface_set_mpls_enable_t_handler
- (vl_api_sw_interface_set_mpls_enable_t * mp)
-{
- vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
- int rv = 0;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- mpls_sw_interface_enable_disable (&mpls_main,
- ntohl (mp->sw_if_index), mp->enable);
-
- BAD_SW_IF_INDEX_LABEL;
- REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
-}
-
-void
-send_oam_event (oam_target_t * t)
-{
- vpe_api_main_t *vam = &vpe_api_main;
- unix_shared_memory_queue_t *q;
- vpe_client_registration_t *reg;
- vl_api_oam_event_t *mp;
-
- /* *INDENT-OFF* */
- pool_foreach(reg, vam->oam_events_registrations,
- ({
- q = vl_api_client_index_to_input_queue (reg->client_index);
- if (q)
- {
- mp = vl_msg_api_alloc (sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
- clib_memcpy (mp->dst_address, &t->dst_address,
- sizeof (mp->dst_address));
- mp->state = t->state;
- vl_msg_api_send_shmem (q, (u8 *)&mp);
- }
- }));
- /* *INDENT-ON* */
-}
-
-static void
-vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
-{
- vl_api_oam_add_del_reply_t *rmp;
- int rv;
-
- rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
- (ip4_address_t *) mp->dst_address,
- ntohl (mp->vrf_id), (int) (mp->is_add));
-
- REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
-}
-
-static void
-vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
-{
- stats_main_t *sm = &stats_main;
- vnet_interface_main_t *im = sm->interface_main;
- vl_api_vnet_summary_stats_reply_t *rmp;
- vlib_combined_counter_main_t *cm;
- vlib_counter_t v;
- int i, which;
- u64 total_pkts[VLIB_N_RX_TX];
- u64 total_bytes[VLIB_N_RX_TX];
-
- unix_shared_memory_queue_t *q =
- vl_api_client_index_to_input_queue (mp->client_index);
-
- if (!q)
- return;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
- rmp->context = mp->context;
- rmp->retval = 0;
-
- memset (total_pkts, 0, sizeof (total_pkts));
- memset (total_bytes, 0, sizeof (total_bytes));
-
- vnet_interface_counter_lock (im);
-
- vec_foreach (cm, im->combined_sw_if_counters)
- {
- which = cm - im->combined_sw_if_counters;
-
- for (i = 0; i < vec_len (cm->maxi); i++)
- {
- vlib_get_combined_counter (cm, i, &v);
- total_pkts[which] += v.packets;
- total_bytes[which] += v.bytes;
- }
- }
- vnet_interface_counter_unlock (im);
-
- rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
- rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
- rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
- rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
- rmp->vector_rate =
- clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
-
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-/* *INDENT-OFF* */
-typedef CLIB_PACKED (struct {
- ip4_address_t address;
- u32 address_length: 6;
- u32 index:26;
-}) ip4_route_t;
-/* *INDENT-ON* */
-
-static int
-ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
-{
- vnet_main_t *vnm = vnet_get_main ();
- vnet_interface_main_t *im = &vnm->interface_main;
- ip4_main_t *im4 = &ip4_main;
- static u32 *sw_if_indices_to_shut;
- stats_main_t *sm = &stats_main;
- fib_table_t *fib_table;
- ip4_fib_t *fib;
- u32 sw_if_index;
- int i;
- int rv = VNET_API_ERROR_NO_SUCH_FIB;
- u32 target_fib_id = ntohl (mp->vrf_id);
-
- dslock (sm, 1 /* release hint */ , 8 /* tag */ );
-
- /* *INDENT-OFF* */
- pool_foreach (fib_table, im4->fibs,
- ({
- fib = &fib_table->v4;
- vnet_sw_interface_t * si;
-
- if (fib->table_id != target_fib_id)
- continue;
-
- /* remove any mpls encap/decap labels */
- mpls_fib_reset_labels (fib->table_id);
-
- /* remove any proxy arps in this fib */
- vnet_proxy_arp_fib_reset (fib->table_id);
-
- /* Set the flow hash for this fib to the default */
- vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
-
- vec_reset_length (sw_if_indices_to_shut);
-
- /* Shut down interfaces in this FIB / clean out intfc routes */
- pool_foreach (si, im->sw_interfaces,
- ({
- u32 sw_if_index = si->sw_if_index;
-
- if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
- && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
- fib->index))
- vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
- }));
-
- for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
- sw_if_index = sw_if_indices_to_shut[i];
-
- u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
- flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
- vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
- }
-
- fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
-
- rv = 0;
- break;
- })); /* pool_foreach (fib) */
- /* *INDENT-ON* */
-
- dsunlock (sm);
- return rv;
-}
-
-static int
-ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
-{
- vnet_main_t *vnm = vnet_get_main ();
- vnet_interface_main_t *im = &vnm->interface_main;
- ip6_main_t *im6 = &ip6_main;
- stats_main_t *sm = &stats_main;
- static u32 *sw_if_indices_to_shut;
- fib_table_t *fib_table;
- ip6_fib_t *fib;
- u32 sw_if_index;
- int i;
- int rv = VNET_API_ERROR_NO_SUCH_FIB;
- u32 target_fib_id = ntohl (mp->vrf_id);
-
- dslock (sm, 1 /* release hint */ , 9 /* tag */ );
-
- /* *INDENT-OFF* */
- pool_foreach (fib_table, im6->fibs,
- ({
- vnet_sw_interface_t * si;
- fib = &(fib_table->v6);
-
- if (fib->table_id != target_fib_id)
- continue;
-
- vec_reset_length (sw_if_indices_to_shut);
-
- /* Shut down interfaces in this FIB / clean out intfc routes */
- pool_foreach (si, im->sw_interfaces,
- ({
- if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
- fib->index)
- vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
- }));
-
- for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
- sw_if_index = sw_if_indices_to_shut[i];
-
- u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
- flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
- vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
- }
-
- fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
-
- rv = 0;
- break;
- })); /* pool_foreach (fib) */
- /* *INDENT-ON* */
-
- dsunlock (sm);
- return rv;
-}
-
-static void
-vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
-{
- int rv;
- vl_api_reset_fib_reply_t *rmp;
-
- if (mp->is_ipv6)
- rv = ip6_reset_fib_t_handler (mp);
- else
- rv = ip4_reset_fib_t_handler (mp);
-
- REPLY_MACRO (VL_API_RESET_FIB_REPLY);
-}
-
-static void
-vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
-{
- vl_api_create_loopback_reply_t *rmp;
- u32 sw_if_index;
- int rv;
-
- rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
- ({
- rmp->sw_if_index = ntohl (sw_if_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
-{
- vl_api_delete_loopback_reply_t *rmp;
- u32 sw_if_index;
- int rv;
-
- sw_if_index = ntohl (mp->sw_if_index);
- rv = vnet_delete_loopback_interface (sw_if_index);
-
- REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
-}