summaryrefslogtreecommitdiffstats
path: root/src/vnet/ip/ip4_punt_drop.c
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-06-03 13:21:40 +0000
committerNeale Ranns <nranns@cisco.com>2019-06-06 12:12:58 +0000
commit922077505b43f9560550653f530cf93acc81044d (patch)
tree99bbd28d90de7b1b4db986a5586c04143a8f0c61 /src/vnet/ip/ip4_punt_drop.c
parent831f4200cab2b363f2a8ea340331343c14407b7d (diff)
IP-Punt-redirect: allow the use of a FIB path to describe how to
redirect Change-Id: I2a3ba2a3d73ea8511e3a511855b041432328f0a8 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/ip/ip4_punt_drop.c')
-rw-r--r--src/vnet/ip/ip4_punt_drop.c220
1 files changed, 34 insertions, 186 deletions
diff --git a/src/vnet/ip/ip4_punt_drop.c b/src/vnet/ip/ip4_punt_drop.c
index 85409857f38..4771e8d5b34 100644
--- a/src/vnet/ip/ip4_punt_drop.c
+++ b/src/vnet/ip/ip4_punt_drop.c
@@ -33,8 +33,6 @@ VNET_FEATURE_ARC_INIT (ip4_drop) =
/* *INDENT-ON* */
extern ip_punt_policer_t ip4_punt_policer_cfg;
-extern ip_punt_redirect_t ip4_punt_redirect_cfg;
-extern ip_punt_redirect_rx_t uninit_rx_redirect;
#ifndef CLIB_MARCH_VARIANT
u8 *
@@ -89,41 +87,6 @@ VNET_FEATURE_INIT (ip4_punt_policer_node) = {
};
/* *INDENT-ON* */
-#ifndef CLIB_MARCH_VARIANT
-u8 *
-format_ip_punt_redirect_trace (u8 * s, va_list * args)
-{
- CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
- CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- ip_punt_redirect_trace_t *t = va_arg (*args, ip_punt_redirect_trace_t *);
- vnet_main_t *vnm = vnet_get_main ();
- vnet_sw_interface_t *si;
-
- si = vnet_get_sw_interface_safe (vnm, t->redirect.tx_sw_if_index);
-
- if (NULL != si)
- s = format (s, "via %U on %U using adj:%d",
- format_ip46_address, &t->redirect.nh, IP46_TYPE_ANY,
- format_vnet_sw_interface_name, vnm, si,
- t->redirect.adj_index);
- else
- s = format (s, "via %U on %d using adj:%d",
- format_ip46_address, &t->redirect.nh, IP46_TYPE_ANY,
- t->redirect.tx_sw_if_index, t->redirect.adj_index);
-
- return s;
-}
-
-/* *INDENT-OFF* */
-ip_punt_redirect_t ip4_punt_redirect_cfg = {
- .any_rx_sw_if_index = {
- .tx_sw_if_index = ~0,
- .adj_index = ADJ_INDEX_INVALID,
- },
-};
-/* *INDENT-ON* */
-#endif /* CLIB_MARCH_VARIANT */
-
#define foreach_ip4_punt_redirect_error \
_(DROP, "ip4 punt redirect drop")
@@ -148,7 +111,7 @@ VLIB_NODE_FN (ip4_punt_redirect_node) (vlib_main_t * vm,
{
return (ip_punt_redirect (vm, node, frame,
vnet_feat_arc_ip4_punt.feature_arc_index,
- &ip4_punt_redirect_cfg));
+ FIB_PROTOCOL_IP4));
}
/* *INDENT-OFF* */
@@ -327,72 +290,34 @@ VLIB_CLI_COMMAND (ip4_punt_policer_command, static) =
/* *INDENT-ON* */
#ifndef CLIB_MARCH_VARIANT
-/*
- * an uninitalised rx-redirect strcut used to pad the vector
- */
-ip_punt_redirect_rx_t uninit_rx_redirect = {
- .tx_sw_if_index = ~0,
- .adj_index = ADJ_INDEX_INVALID,
-};
void
-ip_punt_redirect_add (ip_punt_redirect_t * cfg,
- u32 rx_sw_if_index,
- ip_punt_redirect_rx_t * redirect,
- fib_protocol_t fproto, vnet_link_t linkt)
+ip4_punt_redirect_add (u32 rx_sw_if_index,
+ u32 tx_sw_if_index, ip46_address_t * nh)
{
- ip_punt_redirect_rx_t *new;
-
- if (~0 == rx_sw_if_index)
- {
- cfg->any_rx_sw_if_index = *redirect;
- new = &cfg->any_rx_sw_if_index;
- }
- else
- {
- vec_validate_init_empty (cfg->redirect_by_rx_sw_if_index,
- rx_sw_if_index, uninit_rx_redirect);
- cfg->redirect_by_rx_sw_if_index[rx_sw_if_index] = *redirect;
- new = &cfg->redirect_by_rx_sw_if_index[rx_sw_if_index];
- }
+ /* *INDENT-OFF* */
+ fib_route_path_t *rpaths = NULL, rpath = {
+ .frp_proto = DPO_PROTO_IP4,
+ .frp_addr = *nh,
+ .frp_sw_if_index = tx_sw_if_index,
+ .frp_weight = 1,
+ .frp_fib_index = ~0,
+ };
+ /* *INDENT-ON* */
- new->adj_index = adj_nbr_add_or_lock (fproto, linkt,
- &redirect->nh,
- redirect->tx_sw_if_index);
-}
+ vec_add1 (rpaths, rpath);
-void
-ip_punt_redirect_del (ip_punt_redirect_t * cfg, u32 rx_sw_if_index)
-{
- ip_punt_redirect_rx_t *old;
+ ip4_punt_redirect_add_paths (rx_sw_if_index, rpaths);
- if (~0 == rx_sw_if_index)
- {
- old = &cfg->any_rx_sw_if_index;
- }
- else
- {
- old = &cfg->redirect_by_rx_sw_if_index[rx_sw_if_index];
- }
-
- if ((old == NULL) || (old->adj_index == ADJ_INDEX_INVALID))
- return;
-
- adj_unlock (old->adj_index);
- *old = uninit_rx_redirect;
+ vec_free (rpaths);
}
void
-ip4_punt_redirect_add (u32 rx_sw_if_index,
- u32 tx_sw_if_index, ip46_address_t * nh)
+ip4_punt_redirect_add_paths (u32 rx_sw_if_index, fib_route_path_t * rpaths)
{
- ip_punt_redirect_rx_t rx = {
- .tx_sw_if_index = tx_sw_if_index,
- .nh = *nh,
- };
-
- ip_punt_redirect_add (&ip4_punt_redirect_cfg,
- rx_sw_if_index, &rx, FIB_PROTOCOL_IP4, VNET_LINK_IP4);
+ ip_punt_redirect_add (FIB_PROTOCOL_IP4,
+ rx_sw_if_index,
+ FIB_FORW_CHAIN_TYPE_UNICAST_IP4, rpaths);
vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 1, 0, 0);
}
@@ -402,7 +327,7 @@ ip4_punt_redirect_del (u32 rx_sw_if_index)
{
vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 0, 0, 0);
- ip_punt_redirect_del (&ip4_punt_redirect_cfg, rx_sw_if_index);
+ ip_punt_redirect_del (FIB_PROTOCOL_IP4, rx_sw_if_index);
}
#endif /* CLIB_MARCH_VARIANT */
@@ -412,10 +337,9 @@ ip4_punt_redirect_cmd (vlib_main_t * vm,
vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
- ip46_address_t nh = ip46_address_initializer;
+ fib_route_path_t *rpaths = NULL, rpath;
clib_error_t *error = 0;
- u32 rx_sw_if_index = 0;
- u32 tx_sw_if_index = 0;
+ u32 rx_sw_if_index = ~0;
vnet_main_t *vnm;
u8 is_add;
@@ -436,14 +360,9 @@ ip4_punt_redirect_cmd (vlib_main_t * vm,
else if (unformat (line_input, "rx %U",
unformat_vnet_sw_interface, vnm, &rx_sw_if_index))
;
- else if (unformat (line_input, "via %U %U",
- unformat_ip4_address,
- &nh.ip4,
- unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
- ;
else if (unformat (line_input, "via %U",
- unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
- clib_memset (&nh, 0, sizeof (nh));
+ unformat_fib_route_path, &rpath))
+ vec_add1 (rpaths, rpath);
else
{
error = unformat_parse_error (line_input);
@@ -451,19 +370,20 @@ ip4_punt_redirect_cmd (vlib_main_t * vm,
}
}
+ if (~0 == rx_sw_if_index)
+ {
+ error = unformat_parse_error (line_input);
+ goto done;
+ }
+
if (is_add)
{
- if (rx_sw_if_index && tx_sw_if_index)
- {
- ip4_punt_redirect_add (rx_sw_if_index, tx_sw_if_index, &nh);
- }
+ if (vec_len (rpaths))
+ ip4_punt_redirect_add_paths (rx_sw_if_index, rpaths);
}
else
{
- if (rx_sw_if_index)
- {
- ip4_punt_redirect_del (rx_sw_if_index);
- }
+ ip4_punt_redirect_del (rx_sw_if_index);
}
done:
@@ -485,84 +405,12 @@ VLIB_CLI_COMMAND (ip4_punt_redirect_command, static) =
};
/* *INDENT-ON* */
-#ifndef CLIB_MARCH_VARIANT
-u8 *
-format_ip_punt_redirect (u8 * s, va_list * args)
-{
- ip_punt_redirect_t *cfg = va_arg (*args, ip_punt_redirect_t *);
- ip_punt_redirect_rx_t *rx;
- u32 rx_sw_if_index;
- vnet_main_t *vnm = vnet_get_main ();
-
- vec_foreach_index (rx_sw_if_index, cfg->redirect_by_rx_sw_if_index)
- {
- rx = &cfg->redirect_by_rx_sw_if_index[rx_sw_if_index];
- if (~0 != rx->tx_sw_if_index)
- {
- s = format (s, " rx %U redirect via %U %U\n",
- format_vnet_sw_interface_name, vnm,
- vnet_get_sw_interface (vnm, rx_sw_if_index),
- format_ip46_address, &rx->nh, IP46_TYPE_ANY,
- format_vnet_sw_interface_name, vnm,
- vnet_get_sw_interface (vnm, rx->tx_sw_if_index));
- }
- }
- if (~0 != cfg->any_rx_sw_if_index.tx_sw_if_index)
- {
- s = format (s, " rx all redirect via %U %U\n",
- format_ip46_address, &cfg->any_rx_sw_if_index.nh,
- IP46_TYPE_ANY, format_vnet_sw_interface_name, vnm,
- vnet_get_sw_interface (vnm,
- cfg->
- any_rx_sw_if_index.tx_sw_if_index));
- }
-
- return (s);
-}
-
-ip_punt_redirect_detail_t *
-ip4_punt_redirect_entries (u32 sw_if_index)
-{
- ip_punt_redirect_rx_t *pr;
- ip_punt_redirect_detail_t *prs = 0;
- u32 rx_sw_if_index;
-
- vec_foreach_index (rx_sw_if_index,
- ip4_punt_redirect_cfg.redirect_by_rx_sw_if_index)
- {
- if (sw_if_index == ~0 || sw_if_index == rx_sw_if_index)
- {
- pr =
- &ip4_punt_redirect_cfg.redirect_by_rx_sw_if_index[rx_sw_if_index];
- if (~0 != pr->tx_sw_if_index)
- {
- ip_punt_redirect_detail_t detail = {.rx_sw_if_index =
- rx_sw_if_index,
- .punt_redirect = *pr
- };
- vec_add1 (prs, detail);
- }
- }
- }
- if (~0 != ip4_punt_redirect_cfg.any_rx_sw_if_index.tx_sw_if_index)
- {
- pr = &ip4_punt_redirect_cfg.any_rx_sw_if_index;
- ip_punt_redirect_detail_t detail = {.rx_sw_if_index = ~0,
- .punt_redirect = *pr
- };
- vec_add1 (prs, detail);
- }
-
- return prs;
-}
-#endif /* CLIB_MARCH_VARIANT */
-
static clib_error_t *
ip4_punt_redirect_show_cmd (vlib_main_t * vm,
unformat_input_t * main_input,
vlib_cli_command_t * cmd)
{
- vlib_cli_output (vm, "%U", format_ip_punt_redirect, &ip4_punt_redirect_cfg);
+ vlib_cli_output (vm, "%U", format_ip_punt_redirect, FIB_PROTOCOL_IP4);
return (NULL);
}