int nsim_cross_connect_enable_disable (nsim_main_t * nsm, u32 sw_if_index0, u32 sw_if_index1, int enable_disable) { vnet_sw_interface_t *sw; vnet_hw_interface_t *hw; int rv = 0; if (nsm->is_configured == 0) return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE; /* Utterly wrong? */ if (pool_is_free_index (nsm->vnet_main->interface_main.sw_interfaces, sw_if_index0)) return VNET_API_ERROR_INVALID_SW_IF_INDEX; if (pool_is_free_index (nsm->vnet_main->interface_main.sw_interfaces, sw_if_index1)) return VNET_API_ERROR_INVALID_SW_IF_INDEX; /* Not a physical port? */ sw = vnet_get_sw_interface (nsm->vnet_main, sw_if_index0); if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) return VNET_API_ERROR_INVALID_SW_IF_INDEX; sw = vnet_get_sw_interface (nsm->vnet_main, sw_if_index1); if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) return VNET_API_ERROR_INVALID_SW_IF_INDEX; /* Add graph arcs for the input / wheel scraper node */ hw = vnet_get_hw_interface (nsm->vnet_main, sw_if_index0); nsm->output_next_index0 = vlib_node_add_next (nsm->vlib_main, nsim_input_node.index, hw->output_node_index); hw = vnet_get_hw_interface (nsm->vnet_main, sw_if_index1); nsm->output_next_index1 = vlib_node_add_next (nsm->vlib_main, nsim_input_node.index, hw->output_node_index); nsm->sw_if_index0 = sw_if_index0; nsm->sw_if_index1 = sw_if_index1; vnet_feature_enable_disable ("device-input", "nsim", sw_if_index0, enable_disable, 0, 0); vnet_feature_enable_disable ("device-input", "nsim", sw_if_index1, enable_disable, 0, 0); return rv; }
int sample_macswap_enable_disable (sample_main_t * sm, u32 sw_if_index, int enable_disable) { vnet_sw_interface_t * sw; int rv; u32 node_index = enable_disable ? sample_node.index : ~0; /* Utterly wrong? */ if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces, sw_if_index)) return VNET_API_ERROR_INVALID_SW_IF_INDEX; /* Not a physical port? */ sw = vnet_get_sw_interface (sm->vnet_main, sw_if_index); if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) return VNET_API_ERROR_INVALID_SW_IF_INDEX; /* * Redirect pkts from the driver to the macswap node. * Returns VNET_API_ERROR_UNIMPLEMENTED if the h/w driver * doesn't implement the API. * * Node_index = ~0 => shut off redirection */ rv = vnet_hw_interface_rx_redirect_to_node (sm->vnet_main, sw_if_index, node_index); return rv; }
int nsim_output_feature_enable_disable (nsim_main_t * nsm, u32 sw_if_index, int enable_disable) { vnet_sw_interface_t *sw; vnet_hw_interface_t *hw; int rv = 0; if (nsm->is_configured == 0) return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE; /* Utterly wrong? */ if (pool_is_free_index (nsm->vnet_main->interface_main.sw_interfaces, sw_if_index)) return VNET_API_ERROR_INVALID_SW_IF_INDEX; /* Not a physical port? */ sw = vnet_get_sw_interface (nsm->vnet_main, sw_if_index); if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) return VNET_API_ERROR_INVALID_SW_IF_INDEX; /* Add a graph arc for the input / wheel scraper node */ hw = vnet_get_hw_interface (nsm->vnet_main, sw_if_index); vec_validate_init_empty (nsm->output_next_index_by_sw_if_index, sw_if_index, ~0); /* Note: use the tx node, this pkt has already visited the output node... */ nsm->output_next_index_by_sw_if_index[sw_if_index] = vlib_node_add_next (nsm->vlib_main, nsim_input_node.index, hw->tx_node_index); vnet_feature_enable_disable ("interface-output", "nsim-output-feature", sw_if_index, enable_disable, 0, 0); return rv; }
static ct_connection_t * ct_connection_get (u32 ct_index) { if (pool_is_free_index (connections, ct_index)) return 0; return pool_elt_at_index (connections, ct_index); }
session_table_t * session_table_get (u32 table_index) { if (pool_is_free_index (lookup_tables, table_index)) return 0; return pool_elt_at_index (lookup_tables, table_index); }
/* Free up all trace buffer memory. */ always_inline void clear_trace_buffer (void) { int i; vlib_trace_main_t *tm; /* *INDENT-OFF* */ foreach_vlib_main ( ({ tm = &this_vlib_main->trace_main; tm->trace_enable = 0; for (i = 0; i < vec_len (tm->trace_buffer_pool); i++) if (! pool_is_free_index (tm->trace_buffer_pool, i)) vec_free (tm->trace_buffer_pool[i]); pool_free (tm->trace_buffer_pool); }));
/* Free up all trace buffer memory. */ always_inline void clear_trace_buffer (void) { int i; vlib_trace_main_t * tm; foreach_vlib_main ( ({ void *mainheap; tm = &this_vlib_main->trace_main; mainheap = clib_mem_set_heap (this_vlib_main->heap_base); for (i = 0; i < vec_len (tm->trace_buffer_pool); i++) if (! pool_is_free_index (tm->trace_buffer_pool, i)) vec_free (tm->trace_buffer_pool[i]); pool_free (tm->trace_buffer_pool); clib_mem_set_heap (mainheap); }));
/* SRv6 LocalSID instantiation and removal functions */ static int srv6_am_localsid_creation_fn (ip6_sr_localsid_t * localsid) { srv6_am_main_t *sm = &srv6_am_main; srv6_am_localsid_t *ls_mem = localsid->plugin_mem; adj_index_t nh_adj_index = ADJ_INDEX_INVALID; /* Step 1: Prepare xconnect adjacency for sending packets to the VNF */ /* Retrieve the adjacency corresponding to the (OIF, next_hop) */ nh_adj_index = adj_nbr_add_or_lock (FIB_PROTOCOL_IP6, VNET_LINK_IP6, &ls_mem->nh_addr, ls_mem->sw_if_index_out); if (nh_adj_index == ADJ_INDEX_INVALID) return -5; localsid->nh_adj = nh_adj_index; /* Step 2: Prepare inbound policy for packets returning from the VNF */ /* Sanitise the SW_IF_INDEX */ if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces, ls_mem->sw_if_index_in)) return -3; vnet_sw_interface_t *sw = vnet_get_sw_interface (sm->vnet_main, ls_mem->sw_if_index_in); if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) return -3; int ret = vnet_feature_enable_disable ("ip6-unicast", "srv6-am-rewrite", ls_mem->sw_if_index_in, 1, 0, 0); if (ret != 0) return -1; return 0; }