*/
#include <vnet/ip/ip.h>
+#include <vnet/fib/ip4_fib.h>
+#include <vnet/dpo/load_balance.h>
typedef struct {
u8 packet_data[64];
{
ip4_main_t * im = &ip4_main;
ip_lookup_main_t * lm = &im->lookup_main;
- ip_config_main_t * cm = &lm->rx_config_mains[VNET_UNICAST];
+ ip_config_main_t * cm = &lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
u32 n_left_from, * from, * to_next;
u32 next_index;
vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip4_input_node.index);
ip4_fib_mtrie_t * mtrie0, * mtrie1;
ip4_fib_mtrie_leaf_t leaf0, leaf1;
ip4_source_check_config_t * c0, * c1;
- ip_adjacency_t * adj0, * adj1;
- u32 pi0, next0, pass0, adj_index0;
- u32 pi1, next1, pass1, adj_index1;
+ const load_balance_t * lb0, * lb1;
+ u32 pi0, next0, pass0, lb_index0;
+ u32 pi1, next1, pass1, lb_index1;
+ const ip_adjacency_t *adj0, *adj1;
+ const dpo_id_t *dpo0, *dpo1;
+ u32 ii0, ii1;
/* Prefetch next iteration. */
{
ip1 = vlib_buffer_get_current (p1);
c0 = vnet_get_config_data (&cm->config_main,
- &vnet_buffer (p0)->ip.current_config_index,
+ &p0->current_config_index,
&next0,
sizeof (c0[0]));
c1 = vnet_get_config_data (&cm->config_main,
- &vnet_buffer (p1)->ip.current_config_index,
+ &p1->current_config_index,
&next1,
sizeof (c1[0]));
- mtrie0 = &vec_elt_at_index (im->fibs, c0->fib_index)->mtrie;
- mtrie1 = &vec_elt_at_index (im->fibs, c1->fib_index)->mtrie;
+ mtrie0 = &ip4_fib_get (c0->fib_index)->mtrie;
+ mtrie1 = &ip4_fib_get (c1->fib_index)->mtrie;
leaf0 = leaf1 = IP4_FIB_MTRIE_LEAF_ROOT;
leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 3);
- adj_index0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
- adj_index1 = ip4_fib_mtrie_leaf_get_adj_index (leaf1);
+ lb_index0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
+ lb_index1 = ip4_fib_mtrie_leaf_get_adj_index (leaf1);
- ASSERT (adj_index0 == ip4_fib_lookup_with_table (im, c0->fib_index,
- &ip0->src_address,
- c0->no_default_route));
- ASSERT (adj_index1 == ip4_fib_lookup_with_table (im, c1->fib_index,
- &ip1->src_address,
- c1->no_default_route));
-
- adj0 = ip_get_adjacency (lm, adj_index0);
- adj1 = ip_get_adjacency (lm, adj_index1);
+ lb0 = load_balance_get(lb_index0);
+ lb1 = load_balance_get(lb_index1);
/* Pass multicast. */
pass0 = ip4_address_is_multicast (&ip0->src_address) || ip0->src_address.as_u32 == clib_host_to_net_u32(0xFFFFFFFF);
pass1 = ip4_address_is_multicast (&ip1->src_address) || ip1->src_address.as_u32 == clib_host_to_net_u32(0xFFFFFFFF);
- pass0 |= (adj0->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
- && (source_check_type == IP4_SOURCE_CHECK_REACHABLE_VIA_ANY
- || vnet_buffer (p0)->sw_if_index[VLIB_RX] == adj0->rewrite_header.sw_if_index));
- pass1 |= (adj1->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
- && (source_check_type == IP4_SOURCE_CHECK_REACHABLE_VIA_ANY
- || vnet_buffer (p1)->sw_if_index[VLIB_RX] == adj1->rewrite_header.sw_if_index));
+ if (PREDICT_TRUE(1 == lb0->lb_n_buckets))
+ {
+ dpo0 = load_balance_get_bucket_i(lb0, 0);
+ if (PREDICT_TRUE(dpo0->dpoi_type == DPO_ADJACENCY))
+ {
+ pass0 |= (source_check_type ==
+ IP4_SOURCE_CHECK_REACHABLE_VIA_ANY);
+ adj0 = adj_get(dpo0->dpoi_index);
+ pass0 |= (vnet_buffer (p0)->sw_if_index[VLIB_RX] ==
+ adj0->rewrite_header.sw_if_index);
+ }
+ }
+ else
+ {
+ for (ii0 = 0; ii0 < lb0->lb_n_buckets && !pass0; ii0++)
+ {
+ dpo0 = load_balance_get_bucket_i(lb0, ii0);
+ if (PREDICT_TRUE(dpo0->dpoi_type == DPO_ADJACENCY))
+ {
+ pass0 |= (source_check_type ==
+ IP4_SOURCE_CHECK_REACHABLE_VIA_ANY);
+ adj0 = adj_get(dpo0->dpoi_index);
+ pass0 |= (vnet_buffer (p0)->sw_if_index[VLIB_RX] ==
+ adj0->rewrite_header.sw_if_index);
+ }
+ }
+ }
+ if (PREDICT_TRUE(1 == lb1->lb_n_buckets))
+ {
+ dpo1 = load_balance_get_bucket_i(lb1, 0);
+ if (PREDICT_TRUE(dpo1->dpoi_type == DPO_ADJACENCY))
+ {
+ pass1 |= (source_check_type ==
+ IP4_SOURCE_CHECK_REACHABLE_VIA_ANY);
+ adj1 = adj_get(dpo1->dpoi_index);
+ pass1 |= (vnet_buffer (p1)->sw_if_index[VLIB_RX] ==
+ adj1->rewrite_header.sw_if_index);
+ }
+ }
+ else
+ {
+ for (ii1 = 0; ii1 < lb1->lb_n_buckets && !pass1; ii1++)
+ {
+ dpo1 = load_balance_get_bucket_i(lb1, ii1);
+ if (PREDICT_TRUE(dpo1->dpoi_type == DPO_ADJACENCY))
+ {
+ pass1 |= (source_check_type ==
+ IP4_SOURCE_CHECK_REACHABLE_VIA_ANY);
+ adj1 = adj_get(dpo1->dpoi_index);
+ pass1 |= (vnet_buffer (p1)->sw_if_index[VLIB_RX] ==
+ adj1->rewrite_header.sw_if_index);
+ }
+ }
+ }
next0 = (pass0 ? next0 : IP4_SOURCE_CHECK_NEXT_DROP);
next1 = (pass1 ? next1 : IP4_SOURCE_CHECK_NEXT_DROP);
ip4_fib_mtrie_leaf_t leaf0;
ip4_source_check_config_t * c0;
ip_adjacency_t * adj0;
- u32 pi0, next0, pass0, adj_index0;
+ u32 pi0, next0, pass0, lb_index0;
+ const load_balance_t * lb0;
+ const dpo_id_t *dpo0;
+ u32 ii0;
pi0 = from[0];
to_next[0] = pi0;
ip0 = vlib_buffer_get_current (p0);
c0 = vnet_get_config_data (&cm->config_main,
- &vnet_buffer (p0)->ip.current_config_index,
+ &p0->current_config_index,
&next0,
sizeof (c0[0]));
- mtrie0 = &vec_elt_at_index (im->fibs, c0->fib_index)->mtrie;
+ mtrie0 = &ip4_fib_get (c0->fib_index)->mtrie;
leaf0 = IP4_FIB_MTRIE_LEAF_ROOT;
leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
- adj_index0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
+ lb_index0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
- ASSERT (adj_index0 == ip4_fib_lookup_with_table (im, c0->fib_index,
- &ip0->src_address,
- c0->no_default_route));
- adj0 = ip_get_adjacency (lm, adj_index0);
+ lb0 = load_balance_get(lb_index0);
/* Pass multicast. */
pass0 = ip4_address_is_multicast (&ip0->src_address) || ip0->src_address.as_u32 == clib_host_to_net_u32(0xFFFFFFFF);
- pass0 |= (adj0->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
- && (source_check_type == IP4_SOURCE_CHECK_REACHABLE_VIA_ANY
- || vnet_buffer (p0)->sw_if_index[VLIB_RX] == adj0->rewrite_header.sw_if_index));
+ if (PREDICT_TRUE(1 == lb0->lb_n_buckets))
+ {
+ dpo0 = load_balance_get_bucket_i(lb0, 0);
+ if (PREDICT_TRUE(dpo0->dpoi_type == DPO_ADJACENCY))
+ {
+ pass0 |= (source_check_type ==
+ IP4_SOURCE_CHECK_REACHABLE_VIA_ANY);
+ adj0 = adj_get(dpo0->dpoi_index);
+ pass0 |= (vnet_buffer (p0)->sw_if_index[VLIB_RX] ==
+ adj0->rewrite_header.sw_if_index);
+ }
+ }
+ else
+ {
+ for (ii0 = 0; ii0 < lb0->lb_n_buckets && !pass0; ii0++)
+ {
+ dpo0 = load_balance_get_bucket_i(lb0, ii0);
+ if (PREDICT_TRUE(dpo0->dpoi_type == DPO_ADJACENCY))
+ {
+ pass0 |= (source_check_type ==
+ IP4_SOURCE_CHECK_REACHABLE_VIA_ANY);
+ adj0 = adj_get(dpo0->dpoi_index);
+ pass0 |= (vnet_buffer (p0)->sw_if_index[VLIB_RX] ==
+ adj0->rewrite_header.sw_if_index);
+ }
+ }
+ }
next0 = (pass0 ? next0 : IP4_SOURCE_CHECK_NEXT_DROP);
p0->error = error_node->errors[IP4_ERROR_UNICAST_SOURCE_CHECK_FAILS];
vnet_main_t * vnm = vnet_get_main();
ip4_main_t * im = &ip4_main;
ip_lookup_main_t * lm = &im->lookup_main;
- ip_config_main_t * rx_cm = &lm->rx_config_mains[VNET_UNICAST];
+ ip_config_main_t * rx_cm = &lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
clib_error_t * error = 0;
u32 sw_if_index, is_del, ci;
ip4_source_check_config_t config;
- ip4_rx_feature_type_t type;
+ u32 feature_index;
sw_if_index = ~0;
is_del = 0;
config.no_default_route = 0;
config.fib_index = im->fib_index_by_sw_if_index[sw_if_index];
- type = IP4_RX_FEATURE_SOURCE_CHECK_REACHABLE_VIA_RX;
+ feature_index = im->ip4_unicast_rx_feature_source_reachable_via_rx;
if (unformat (input, "del"))
is_del = 1;
: vnet_config_add_feature)
(vm, &rx_cm->config_main,
ci,
- type,
+ feature_index,
&config,
sizeof (config));
rx_cm->config_index_by_sw_if_index[sw_if_index] = ci;