Allow the provider of a midchain adjacency to pass context data that is returned in the fixup function
Change-Id: I458e6e03b03e27775df33a2fd302743126d6ac44 Signed-off-by: Neale Ranns <nranns@cisco.com>
This commit is contained in:
Neale Ranns
committed by
Florin Coras
parent
bb16d3ffec
commit
db14f5aff6
@ -146,16 +146,23 @@ pppoe_build_rewrite (vnet_main_t * vnm,
|
||||
* @brief Fixup the adj rewrite post encap. Insert the packet's length
|
||||
*/
|
||||
static void
|
||||
pppoe_fixup (vlib_main_t * vm, ip_adjacency_t * adj, vlib_buffer_t * b0)
|
||||
pppoe_fixup (vlib_main_t * vm,
|
||||
ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
|
||||
{
|
||||
const pppoe_session_t *t;
|
||||
pppoe_header_t *pppoe0;
|
||||
|
||||
/* update the rewrite string */
|
||||
pppoe0 = vlib_buffer_get_current (b0) + sizeof (ethernet_header_t);
|
||||
|
||||
pppoe0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
|
||||
- sizeof (pppoe_header_t)
|
||||
+ sizeof (pppoe0->ppp_proto)
|
||||
- sizeof (ethernet_header_t));
|
||||
/* Swap to the the packet's output interface to the encap (not the
|
||||
* session) interface */
|
||||
t = data;
|
||||
vnet_buffer (b0)->sw_if_index[VLIB_TX] = t->encap_if_index;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -170,12 +177,14 @@ pppoe_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
|
||||
ASSERT (ADJ_INDEX_INVALID != ai);
|
||||
|
||||
adj = adj_get (ai);
|
||||
session_id = pem->session_index_by_sw_if_index[sw_if_index];
|
||||
t = pool_elt_at_index (pem->sessions, session_id);
|
||||
|
||||
switch (adj->lookup_next_index)
|
||||
{
|
||||
case IP_LOOKUP_NEXT_ARP:
|
||||
case IP_LOOKUP_NEXT_GLEAN:
|
||||
adj_nbr_midchain_update_rewrite (ai, pppoe_fixup,
|
||||
adj_nbr_midchain_update_rewrite (ai, pppoe_fixup, t,
|
||||
ADJ_FLAG_NONE,
|
||||
pppoe_build_rewrite (vnm,
|
||||
sw_if_index,
|
||||
@ -187,7 +196,7 @@ pppoe_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
|
||||
* Construct a partial rewrite from the known ethernet mcast dest MAC
|
||||
* There's no MAC fixup, so the last 2 parameters are 0
|
||||
*/
|
||||
adj_mcast_midchain_update_rewrite (ai, pppoe_fixup,
|
||||
adj_mcast_midchain_update_rewrite (ai, pppoe_fixup, t,
|
||||
ADJ_FLAG_NONE,
|
||||
pppoe_build_rewrite (vnm,
|
||||
sw_if_index,
|
||||
@ -207,8 +216,6 @@ pppoe_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
|
||||
break;
|
||||
}
|
||||
|
||||
session_id = pem->session_index_by_sw_if_index[sw_if_index];
|
||||
t = pool_elt_at_index (pem->sessions, session_id);
|
||||
interface_tx_dpo_add_or_lock (vnet_link_to_dpo_proto (adj->ia_link),
|
||||
t->encap_if_index, &dpo);
|
||||
|
||||
|
@ -141,7 +141,8 @@ struct ip_adjacency_t_;
|
||||
*/
|
||||
typedef void (*adj_midchain_fixup_t) (vlib_main_t * vm,
|
||||
struct ip_adjacency_t_ * adj,
|
||||
vlib_buffer_t * b0);
|
||||
vlib_buffer_t * b0,
|
||||
const void *data);
|
||||
|
||||
/**
|
||||
* @brief Flags on an IP adjacency
|
||||
@ -242,6 +243,10 @@ typedef struct ip_adjacency_t_
|
||||
* A function to perform the post-rewrite fixup
|
||||
*/
|
||||
adj_midchain_fixup_t fixup_func;
|
||||
/**
|
||||
* Fixup data passed back to the client in the fixup function
|
||||
*/
|
||||
const void *fixup_data;
|
||||
} midchain;
|
||||
/**
|
||||
* IP_LOOKUP_NEXT_GLEAN
|
||||
|
@ -95,6 +95,7 @@ extern void adj_nbr_update_rewrite_internal(ip_adjacency_t *adj,
|
||||
u8 *rewrite);
|
||||
extern void adj_midchain_setup(adj_index_t adj_index,
|
||||
adj_midchain_fixup_t fixup,
|
||||
const void *data,
|
||||
adj_flags_t flags);
|
||||
|
||||
extern ip_adjacency_t * adj_alloc(fib_protocol_t proto);
|
||||
|
@ -110,7 +110,9 @@ adj_l2_rewrite_inline (vlib_main_t * vm,
|
||||
|
||||
if (is_midchain)
|
||||
{
|
||||
adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
|
||||
adj0->sub_type.midchain.fixup_func(
|
||||
vm, adj0, p0,
|
||||
adj0->sub_type.midchain.fixup_data);
|
||||
}
|
||||
|
||||
vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
|
||||
|
@ -139,6 +139,7 @@ adj_mcast_update_rewrite (adj_index_t adj_index,
|
||||
void
|
||||
adj_mcast_midchain_update_rewrite (adj_index_t adj_index,
|
||||
adj_midchain_fixup_t fixup,
|
||||
const void *fixup_data,
|
||||
adj_flags_t flags,
|
||||
u8 *rewrite,
|
||||
u8 offset,
|
||||
@ -160,7 +161,7 @@ adj_mcast_midchain_update_rewrite (adj_index_t adj_index,
|
||||
*/
|
||||
ASSERT(NULL != rewrite);
|
||||
|
||||
adj_midchain_setup(adj_index, fixup, flags);
|
||||
adj_midchain_setup(adj_index, fixup, fixup_data, flags);
|
||||
|
||||
/*
|
||||
* update the adj's rewrite string and build the arc
|
||||
@ -354,14 +355,13 @@ format_adj_mcast_midchain (u8* s, va_list *ap)
|
||||
{
|
||||
index_t index = va_arg(*ap, index_t);
|
||||
CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
|
||||
vnet_main_t * vnm = vnet_get_main();
|
||||
ip_adjacency_t * adj = adj_get(index);
|
||||
|
||||
s = format(s, "%U-mcast-midchain: ",
|
||||
format_fib_protocol, adj->ia_nh_proto);
|
||||
s = format (s, "%U",
|
||||
format_vnet_rewrite,
|
||||
vnm->vlib_main, &adj->rewrite_header,
|
||||
&adj->rewrite_header,
|
||||
sizeof (adj->rewrite_data), 0);
|
||||
s = format (s, "\n%Ustacked-on:\n%U%U",
|
||||
format_white_space, indent,
|
||||
|
@ -77,11 +77,22 @@ extern void adj_mcast_update_rewrite(adj_index_t adj_index,
|
||||
* @param
|
||||
* The index of the adj to update
|
||||
*
|
||||
* @param fixup
|
||||
* The function that will be invoked at paket switch time to 'fixup'
|
||||
* the rewrite applied with necessary per-packet info (i.e. length, checksums).
|
||||
* @param fixup_data
|
||||
* Context data set by the caller that is provided as an argument in the
|
||||
* fixup function.
|
||||
*
|
||||
* @param flags
|
||||
* Flags controlling the adjacency behaviour
|
||||
*
|
||||
* @param
|
||||
* The new rewrite
|
||||
*/
|
||||
extern void adj_mcast_midchain_update_rewrite(adj_index_t adj_index,
|
||||
adj_midchain_fixup_t fixup,
|
||||
const void *fixup_data,
|
||||
adj_flags_t flags,
|
||||
u8 *rewrite,
|
||||
u8 offset,
|
||||
|
@ -460,6 +460,7 @@ adj_nbr_midchain_get_feature_node (ip_adjacency_t *adj)
|
||||
void
|
||||
adj_midchain_setup (adj_index_t adj_index,
|
||||
adj_midchain_fixup_t fixup,
|
||||
const void *data,
|
||||
adj_flags_t flags)
|
||||
{
|
||||
u32 feature_index, tx_node;
|
||||
@ -471,6 +472,7 @@ adj_midchain_setup (adj_index_t adj_index,
|
||||
adj = adj_get(adj_index);
|
||||
|
||||
adj->sub_type.midchain.fixup_func = fixup;
|
||||
adj->sub_type.midchain.fixup_data = data;
|
||||
adj->ia_flags |= flags;
|
||||
|
||||
arc_index = adj_midchain_get_feature_arc_index_for_link_type (adj);
|
||||
@ -503,6 +505,7 @@ adj_midchain_setup (adj_index_t adj_index,
|
||||
void
|
||||
adj_nbr_midchain_update_rewrite (adj_index_t adj_index,
|
||||
adj_midchain_fixup_t fixup,
|
||||
const void *fixup_data,
|
||||
adj_flags_t flags,
|
||||
u8 *rewrite)
|
||||
{
|
||||
@ -522,7 +525,7 @@ adj_nbr_midchain_update_rewrite (adj_index_t adj_index,
|
||||
*/
|
||||
ASSERT(NULL != rewrite);
|
||||
|
||||
adj_midchain_setup(adj_index, fixup, flags);
|
||||
adj_midchain_setup(adj_index, fixup, fixup_data, flags);
|
||||
|
||||
/*
|
||||
* update the rewirte with the workers paused.
|
||||
|
@ -31,15 +31,22 @@
|
||||
* @param adj_index
|
||||
* The index of the neighbour adjacency.
|
||||
*
|
||||
* @param post_rewrite_node
|
||||
* The VLIB graph node that provides the post-encap fixup.
|
||||
* where 'fixup' is e.g., correcting chksum, length, etc.
|
||||
* @param fixup
|
||||
* The function that will be invoked at paket switch time to 'fixup'
|
||||
* the rewrite applied with necessary per-packet info (i.e. length, checksums).
|
||||
* @param fixup_data
|
||||
* Context data set by the caller that is provided as an argument in the
|
||||
* fixup function.
|
||||
*
|
||||
* @param flags
|
||||
* Flags controlling the adjacency behaviour
|
||||
*
|
||||
* @param rewrite
|
||||
* The rewrite.
|
||||
*/
|
||||
extern void adj_nbr_midchain_update_rewrite(adj_index_t adj_index,
|
||||
adj_midchain_fixup_t fixup,
|
||||
const void *fixup_data,
|
||||
adj_flags_t flags,
|
||||
u8 *rewrite);
|
||||
|
||||
|
@ -111,7 +111,9 @@ adj_nsh_rewrite_inline (vlib_main_t * vm,
|
||||
|
||||
if (is_midchain)
|
||||
{
|
||||
adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
|
||||
adj0->sub_type.midchain.fixup_func(
|
||||
vm, adj0, p0,
|
||||
adj0->sub_type.midchain.fixup_data);
|
||||
}
|
||||
|
||||
vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
|
||||
|
@ -261,8 +261,9 @@ gre_build_rewrite (vnet_main_t * vnm,
|
||||
|
||||
#define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40
|
||||
|
||||
void
|
||||
gre4_fixup (vlib_main_t * vm, ip_adjacency_t * adj, vlib_buffer_t * b0)
|
||||
static void
|
||||
gre4_fixup (vlib_main_t * vm,
|
||||
ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
|
||||
{
|
||||
ip4_header_t *ip0;
|
||||
|
||||
@ -274,8 +275,9 @@ gre4_fixup (vlib_main_t * vm, ip_adjacency_t * adj, vlib_buffer_t * b0)
|
||||
ip0->checksum = ip4_header_checksum (ip0);
|
||||
}
|
||||
|
||||
void
|
||||
gre6_fixup (vlib_main_t * vm, ip_adjacency_t * adj, vlib_buffer_t * b0)
|
||||
static void
|
||||
gre6_fixup (vlib_main_t * vm,
|
||||
ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
|
||||
{
|
||||
ip6_header_t *ip0;
|
||||
|
||||
@ -301,6 +303,7 @@ gre_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
|
||||
is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
|
||||
|
||||
adj_nbr_midchain_update_rewrite (ai, !is_ipv6 ? gre4_fixup : gre6_fixup,
|
||||
NULL,
|
||||
(VNET_LINK_ETHERNET ==
|
||||
adj_get_link_type (ai) ?
|
||||
ADJ_FLAG_MIDCHAIN_NO_COUNT :
|
||||
|
@ -2541,8 +2541,10 @@ ip4_rewrite_inline (vlib_main_t * vm,
|
||||
|
||||
if (is_midchain)
|
||||
{
|
||||
adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
|
||||
adj1->sub_type.midchain.fixup_func (vm, adj1, p1);
|
||||
adj0->sub_type.midchain.fixup_func
|
||||
(vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
|
||||
adj1->sub_type.midchain.fixup_func
|
||||
(vm, adj1, p1, adj0->sub_type.midchain.fixup_data);
|
||||
}
|
||||
if (is_mcast)
|
||||
{
|
||||
@ -2667,7 +2669,8 @@ ip4_rewrite_inline (vlib_main_t * vm,
|
||||
|
||||
if (is_midchain)
|
||||
{
|
||||
adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
|
||||
adj0->sub_type.midchain.fixup_func
|
||||
(vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
|
||||
}
|
||||
|
||||
if (PREDICT_FALSE
|
||||
|
@ -2229,8 +2229,10 @@ ip6_rewrite_inline (vlib_main_t * vm,
|
||||
|
||||
if (is_midchain)
|
||||
{
|
||||
adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
|
||||
adj1->sub_type.midchain.fixup_func (vm, adj1, p1);
|
||||
adj0->sub_type.midchain.fixup_func
|
||||
(vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
|
||||
adj1->sub_type.midchain.fixup_func
|
||||
(vm, adj1, p1, adj1->sub_type.midchain.fixup_data);
|
||||
}
|
||||
if (is_mcast)
|
||||
{
|
||||
@ -2340,7 +2342,8 @@ ip6_rewrite_inline (vlib_main_t * vm,
|
||||
|
||||
if (is_midchain)
|
||||
{
|
||||
adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
|
||||
adj0->sub_type.midchain.fixup_func
|
||||
(vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
|
||||
}
|
||||
if (is_mcast)
|
||||
{
|
||||
|
@ -307,7 +307,8 @@ lisp_gpe_increment_stats_counters (lisp_cp_main_t * lcm, ip_adjacency_t * adj,
|
||||
}
|
||||
|
||||
static void
|
||||
lisp_gpe_fixup (vlib_main_t * vm, ip_adjacency_t * adj, vlib_buffer_t * b)
|
||||
lisp_gpe_fixup (vlib_main_t * vm,
|
||||
ip_adjacency_t * adj, vlib_buffer_t * b, const void *data)
|
||||
{
|
||||
lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
|
||||
|
||||
@ -348,6 +349,7 @@ lisp_gpe_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
|
||||
linkt = adj_get_link_type (ai);
|
||||
adj_nbr_midchain_update_rewrite
|
||||
(ai, lisp_gpe_fixup,
|
||||
NULL,
|
||||
(VNET_LINK_ETHERNET == linkt ?
|
||||
ADJ_FLAG_MIDCHAIN_NO_COUNT :
|
||||
ADJ_FLAG_NONE),
|
||||
|
@ -185,8 +185,12 @@ mpls_output_inline (vlib_main_t * vm,
|
||||
}
|
||||
if (is_midchain)
|
||||
{
|
||||
adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
|
||||
adj1->sub_type.midchain.fixup_func(vm, adj1, p1);
|
||||
adj0->sub_type.midchain.fixup_func
|
||||
(vm, adj0, p0,
|
||||
adj0->sub_type.midchain.fixup_data);
|
||||
adj1->sub_type.midchain.fixup_func
|
||||
(vm, adj1, p1,
|
||||
adj1->sub_type.midchain.fixup_data);
|
||||
}
|
||||
|
||||
p0->error = error_node->errors[error0];
|
||||
@ -266,7 +270,9 @@ mpls_output_inline (vlib_main_t * vm,
|
||||
}
|
||||
if (is_midchain)
|
||||
{
|
||||
adj0->sub_type.midchain.fixup_func(vm, adj0, p0);
|
||||
adj0->sub_type.midchain.fixup_func
|
||||
(vm, adj0, p0,
|
||||
adj0->sub_type.midchain.fixup_data);
|
||||
}
|
||||
|
||||
p0->error = error_node->errors[error0];
|
||||
|
@ -377,7 +377,8 @@ mpls_tunnel_admin_up_down (vnet_main_t * vnm,
|
||||
static void
|
||||
mpls_tunnel_fixup (vlib_main_t *vm,
|
||||
ip_adjacency_t *adj,
|
||||
vlib_buffer_t *b0)
|
||||
vlib_buffer_t *b0,
|
||||
const void*data)
|
||||
{
|
||||
/*
|
||||
* A no-op w.r.t. the header. but reset the 'have we pushed any
|
||||
@ -403,6 +404,7 @@ mpls_tunnel_update_adj (vnet_main_t * vnm,
|
||||
case IP_LOOKUP_NEXT_ARP:
|
||||
case IP_LOOKUP_NEXT_GLEAN:
|
||||
adj_nbr_midchain_update_rewrite(ai, mpls_tunnel_fixup,
|
||||
NULL,
|
||||
ADJ_FLAG_NONE,
|
||||
mpls_tunnel_build_rewrite_i());
|
||||
break;
|
||||
@ -412,6 +414,7 @@ mpls_tunnel_update_adj (vnet_main_t * vnm,
|
||||
* There's no MAC fixup, so the last 2 parameters are 0
|
||||
*/
|
||||
adj_mcast_midchain_update_rewrite(ai, mpls_tunnel_fixup,
|
||||
NULL,
|
||||
ADJ_FLAG_NONE,
|
||||
mpls_tunnel_build_rewrite_i(),
|
||||
0, 0);
|
||||
|
Reference in New Issue
Block a user