diff options
author | Neale Ranns <nranns@cisco.com> | 2018-01-29 10:43:33 -0800 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2018-01-30 08:54:29 +0000 |
commit | db14f5aff69311d13a0a90baa3567e92f3faa783 (patch) | |
tree | 2ee6edb0d8b82b840fdc90b62f782ea0b95bc8f0 | |
parent | bb16d3ffecd357907d01f2785ac78edf0292cfd3 (diff) |
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>
-rw-r--r-- | src/plugins/pppoe/pppoe.c | 17 | ||||
-rw-r--r-- | src/vnet/adj/adj.h | 7 | ||||
-rw-r--r-- | src/vnet/adj/adj_internal.h | 1 | ||||
-rw-r--r-- | src/vnet/adj/adj_l2.c | 4 | ||||
-rw-r--r-- | src/vnet/adj/adj_mcast.c | 6 | ||||
-rw-r--r-- | src/vnet/adj/adj_mcast.h | 11 | ||||
-rw-r--r-- | src/vnet/adj/adj_midchain.c | 5 | ||||
-rw-r--r-- | src/vnet/adj/adj_midchain.h | 13 | ||||
-rw-r--r-- | src/vnet/adj/adj_nsh.c | 4 | ||||
-rw-r--r-- | src/vnet/gre/gre.c | 11 | ||||
-rwxr-xr-x | src/vnet/ip/ip4_forward.c | 9 | ||||
-rw-r--r-- | src/vnet/ip/ip6_forward.c | 9 | ||||
-rw-r--r-- | src/vnet/lisp-gpe/lisp_gpe_adjacency.c | 4 | ||||
-rw-r--r-- | src/vnet/mpls/mpls_output.c | 12 | ||||
-rw-r--r-- | src/vnet/mpls/mpls_tunnel.c | 5 |
15 files changed, 88 insertions, 30 deletions
diff --git a/src/plugins/pppoe/pppoe.c b/src/plugins/pppoe/pppoe.c index fac29c781fa..dfbe2e487c9 100644 --- a/src/plugins/pppoe/pppoe.c +++ b/src/plugins/pppoe/pppoe.c @@ -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); diff --git a/src/vnet/adj/adj.h b/src/vnet/adj/adj.h index ed5eb1f1e88..fe77d1634e0 100644 --- a/src/vnet/adj/adj.h +++ b/src/vnet/adj/adj.h @@ -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 diff --git a/src/vnet/adj/adj_internal.h b/src/vnet/adj/adj_internal.h index ca41cb21d9e..e6d276e4d02 100644 --- a/src/vnet/adj/adj_internal.h +++ b/src/vnet/adj/adj_internal.h @@ -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); diff --git a/src/vnet/adj/adj_l2.c b/src/vnet/adj/adj_l2.c index 20d70dd4cd1..132ceb28168 100644 --- a/src/vnet/adj/adj_l2.c +++ b/src/vnet/adj/adj_l2.c @@ -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; diff --git a/src/vnet/adj/adj_mcast.c b/src/vnet/adj/adj_mcast.c index 00a12ad330b..efc781de989 100644 --- a/src/vnet/adj/adj_mcast.c +++ b/src/vnet/adj/adj_mcast.c @@ -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, diff --git a/src/vnet/adj/adj_mcast.h b/src/vnet/adj/adj_mcast.h index bfb0d6f6d11..55e2ec03d09 100644 --- a/src/vnet/adj/adj_mcast.h +++ b/src/vnet/adj/adj_mcast.h @@ -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, diff --git a/src/vnet/adj/adj_midchain.c b/src/vnet/adj/adj_midchain.c index 370fa4652f8..9fd3246b15a 100644 --- a/src/vnet/adj/adj_midchain.c +++ b/src/vnet/adj/adj_midchain.c @@ -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. diff --git a/src/vnet/adj/adj_midchain.h b/src/vnet/adj/adj_midchain.h index 27ca1d3398d..65892314f40 100644 --- a/src/vnet/adj/adj_midchain.h +++ b/src/vnet/adj/adj_midchain.h @@ -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); diff --git a/src/vnet/adj/adj_nsh.c b/src/vnet/adj/adj_nsh.c index 128570b02a9..76503f59309 100644 --- a/src/vnet/adj/adj_nsh.c +++ b/src/vnet/adj/adj_nsh.c @@ -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; diff --git a/src/vnet/gre/gre.c b/src/vnet/gre/gre.c index 7660bbe1d4b..c049b87b6a7 100644 --- a/src/vnet/gre/gre.c +++ b/src/vnet/gre/gre.c @@ -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 : diff --git a/src/vnet/ip/ip4_forward.c b/src/vnet/ip/ip4_forward.c index 201d391a77e..c4c54b7ab22 100755 --- a/src/vnet/ip/ip4_forward.c +++ b/src/vnet/ip/ip4_forward.c @@ -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 diff --git a/src/vnet/ip/ip6_forward.c b/src/vnet/ip/ip6_forward.c index a7e7930a69f..0a308720389 100644 --- a/src/vnet/ip/ip6_forward.c +++ b/src/vnet/ip/ip6_forward.c @@ -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) { diff --git a/src/vnet/lisp-gpe/lisp_gpe_adjacency.c b/src/vnet/lisp-gpe/lisp_gpe_adjacency.c index 7db1c9bbb72..7464af3d441 100644 --- a/src/vnet/lisp-gpe/lisp_gpe_adjacency.c +++ b/src/vnet/lisp-gpe/lisp_gpe_adjacency.c @@ -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), diff --git a/src/vnet/mpls/mpls_output.c b/src/vnet/mpls/mpls_output.c index 0dc12b8d5bd..22e6c1062c3 100644 --- a/src/vnet/mpls/mpls_output.c +++ b/src/vnet/mpls/mpls_output.c @@ -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]; diff --git a/src/vnet/mpls/mpls_tunnel.c b/src/vnet/mpls/mpls_tunnel.c index efd9e2dbc84..8ed2c409ce8 100644 --- a/src/vnet/mpls/mpls_tunnel.c +++ b/src/vnet/mpls/mpls_tunnel.c @@ -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); |