summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMohammed Hawari <mohammed@hawari.fr>2021-02-05 15:40:00 +0100
committerNeale Ranns <neale@graphiant.com>2021-03-14 14:37:01 +0000
commit45723b8d305c7c6d034e16fcbf1904fd72dd6bb2 (patch)
treebb010ccd464efcfb90ccfabddded7b63b8223e6a /src
parent4e3f7b2869925b0812a58d04c4bf6371e6773630 (diff)
ip: extend punt CLI for exception packets
Change-Id: I20e48a5ac8068eccb8d998346d35227c4802bb68 Signed-off-by: Mohammed Hawari <mohammed@hawari.fr> Type: feature
Diffstat (limited to 'src')
-rw-r--r--src/plugins/unittest/punt_test.c13
-rw-r--r--src/vlib/punt.c65
-rw-r--r--src/vlib/punt.h25
-rw-r--r--src/vnet/ip/punt.c43
-rw-r--r--src/vnet/ip/punt.h42
-rw-r--r--src/vnet/ipsec/ipsec_punt.c10
-rw-r--r--src/vnet/ipsec/ipsec_punt.h10
-rw-r--r--src/vnet/vxlan-gbp/vxlan_gbp.c17
8 files changed, 183 insertions, 42 deletions
diff --git a/src/plugins/unittest/punt_test.c b/src/plugins/unittest/punt_test.c
index 431624fbea0..0c4622283e0 100644
--- a/src/plugins/unittest/punt_test.c
+++ b/src/plugins/unittest/punt_test.c
@@ -18,6 +18,7 @@
#include <vnet/ethernet/ethernet.h>
#include <vnet/adj/adj.h>
#include <vnet/ip/ip.h>
+#include <vnet/ip/punt.h>
typedef enum punt_next_t_
{
@@ -316,12 +317,12 @@ punt_test (vlib_main_t * vm,
*/
punt_hdl = vlib_punt_client_register ("test");
- rc =
- vlib_punt_reason_alloc (punt_hdl, "reason-v4",
- NULL, NULL, &punt_reason_v4);
- rc |=
- vlib_punt_reason_alloc (punt_hdl, "reason-v6",
- NULL, NULL, &punt_reason_v6);
+ rc = vlib_punt_reason_alloc (
+ punt_hdl, "reason-v4", NULL, NULL, &punt_reason_v4,
+ VNET_PUNT_REASON_F_IP4_PACKET, format_vnet_punt_reason_flags);
+ rc |= vlib_punt_reason_alloc (
+ punt_hdl, "reason-v6", NULL, NULL, &punt_reason_v6,
+ VNET_PUNT_REASON_F_IP6_PACKET, format_vnet_punt_reason_flags);
ASSERT (!rc);
vnet_feature_enable_disable ("ip4-unicast",
diff --git a/src/vlib/punt.c b/src/vlib/punt.c
index 04e3b5a3956..4a5e42db203 100644
--- a/src/vlib/punt.c
+++ b/src/vlib/punt.c
@@ -63,6 +63,16 @@ typedef struct punt_reason_data_t_
* Data to pass to the callback
*/
void *pd_data;
+
+ /**
+ * Flags associated to the reason
+ */
+ u32 flags;
+
+ /**
+ * Formatting function for flags;
+ */
+ format_function_t *flags_format;
} punt_reason_data_t;
/**
@@ -148,8 +158,13 @@ u8 *
format_vlib_punt_reason (u8 * s, va_list * args)
{
vlib_punt_reason_t pr = va_arg (*args, int);
-
- return (format (s, "[%d] %v", pr, punt_reason_data[pr].pd_name));
+ format_function_t *flags_format = punt_reason_data[pr].flags_format;
+ u32 flags = punt_reason_data[pr].flags;
+ if (flags_format)
+ return (format (s, "[%d] %v flags: %U", pr, punt_reason_data[pr].pd_name,
+ flags_format, flags));
+ else
+ return (format (s, "[%d] %v", pr, punt_reason_data[pr].pd_name));
}
vlib_punt_hdl_t
@@ -400,11 +415,17 @@ vlib_punt_reason_validate (vlib_punt_reason_t reason)
return (-1);
}
+u32
+vlib_punt_reason_get_flags (vlib_punt_reason_t pr)
+{
+ return pr < punt_reason_last ? punt_reason_data[pr].flags : 0;
+}
+
int
-vlib_punt_reason_alloc (vlib_punt_hdl_t client,
- const char *reason_name,
- punt_interested_listener_t fn,
- void *data, vlib_punt_reason_t * reason)
+vlib_punt_reason_alloc (vlib_punt_hdl_t client, const char *reason_name,
+ punt_interested_listener_t fn, void *data,
+ vlib_punt_reason_t *reason, u32 flags,
+ format_function_t *flags_format)
{
vlib_punt_reason_t new;
@@ -417,6 +438,8 @@ vlib_punt_reason_alloc (vlib_punt_hdl_t client,
punt_reason_data[new].pd_reason = new;
punt_reason_data[new].pd_fn = fn;
punt_reason_data[new].pd_data = data;
+ punt_reason_data[new].flags = flags;
+ punt_reason_data[new].flags_format = flags_format;
vec_add1 (punt_reason_data[new].pd_owners, client);
vlib_validate_combined_counter (&punt_counters, new);
@@ -451,6 +474,29 @@ unformat_punt_client (unformat_input_t * input, va_list * args)
punt_client_db, result);
}
+/* Parse punt reason */
+uword
+unformat_punt_reason (unformat_input_t *input, va_list *args)
+{
+ u32 *result = va_arg (*args, u32 *);
+ u8 *s = 0;
+ u8 found = 0;
+ for (int i = 0; i < punt_reason_last - 1; i++)
+ {
+ punt_reason_data_t *pd = vec_elt_at_index (punt_reason_data, 1 + i);
+ vec_reset_length (s);
+ s = format (0, "%v%c", pd->pd_name, 0);
+ if (unformat (input, (const char *) s))
+ {
+ *result = pd->pd_reason;
+ found = 1;
+ break;
+ }
+ }
+ vec_free (s);
+ return found;
+}
+
u8 *
format_punt_reg (u8 * s, va_list * args)
{
@@ -472,8 +518,11 @@ format_punt_reason_data (u8 * s, va_list * args)
punt_reason_data_t *pd = va_arg (*args, punt_reason_data_t *);
punt_client_t *pc;
u32 *pci;
-
- s = format (s, "[%d] %v from:[", pd->pd_reason, pd->pd_name);
+ if (pd->flags_format)
+ s = format (s, "[%d] %v flags: %U from:[", pd->pd_reason, pd->pd_name,
+ pd->flags_format, pd->flags);
+ else
+ s = format (s, "[%d] %v from:[", pd->pd_reason, pd->pd_name);
vec_foreach (pci, pd->pd_owners)
{
pc = pool_elt_at_index (punt_client_pool, *pci);
diff --git a/src/vlib/punt.h b/src/vlib/punt.h
index d93b5eac599..ce949421dad 100644
--- a/src/vlib/punt.h
+++ b/src/vlib/punt.h
@@ -31,8 +31,8 @@ typedef enum vlib_punt_reason_t_
/**
* Walk each punt reason
*/
-typedef int (*punt_reason_walk_cb_t) (vlib_punt_reason_t id,
- const u8 * name, void *ctx);
+typedef int (*punt_reason_walk_cb_t) (vlib_punt_reason_t id, const u8 *name,
+ void *ctx);
extern void punt_reason_walk (punt_reason_walk_cb_t cb, void *cxt);
@@ -42,6 +42,11 @@ extern void punt_reason_walk (punt_reason_walk_cb_t cb, void *cxt);
extern u8 *format_vlib_punt_reason (u8 * s, va_list * args);
/**
+ * @brief Unformat a punt reason
+ */
+extern uword unformat_punt_reason (unformat_input_t *input, va_list *args);
+
+/**
* Typedef for a client handle
*/
typedef int vlib_punt_hdl_t;
@@ -61,14 +66,18 @@ typedef void (*punt_interested_listener_t) (vlib_enable_or_disable_t i,
/**
* Allocate a new punt reason
- * @param fn - A callback to invoke when an entity becomes [un]interested
- * in the punt code.
- * @param data - To be passed in the callback function.
+ * @param fn - A callback to invoke when an entity becomes
+ * [un]interested in the punt code.
+ * @param data - To be passed in the callback function.
+ * @param flags - flags associated with the punt reason
+ * @param flags_format - formatting function to display those flags (may be
+ * NULL)
*/
extern int vlib_punt_reason_alloc (vlib_punt_hdl_t client,
const char *reason_name,
- punt_interested_listener_t fn,
- void *data, vlib_punt_reason_t * reason);
+ punt_interested_listener_t fn, void *data,
+ vlib_punt_reason_t *reason, u32 flags,
+ format_function_t *flags_format);
/**
* Validate that a punt reason is assigned
@@ -87,6 +96,8 @@ extern int vlib_punt_register (vlib_punt_hdl_t client,
extern int vlib_punt_unregister (vlib_punt_hdl_t client,
vlib_punt_reason_t pr, const char *node);
+extern u32 vlib_punt_reason_get_flags (vlib_punt_reason_t pr);
+
/**
* FOR USE IN THE DP ONLY
*
diff --git a/src/vnet/ip/punt.c b/src/vnet/ip/punt.c
index 7cdb5fcc084..6fb8dd58776 100644
--- a/src/vnet/ip/punt.c
+++ b/src/vnet/ip/punt.c
@@ -405,6 +405,32 @@ punt_l4_add_del (vlib_main_t * vm,
}
}
+/**
+ * @brief Request exception traffic punt.
+ *
+ * @param reason Punting reason
+ *
+ * @returns 0 on success, non-zero value otherwise
+ */
+static clib_error_t *
+punt_exception_add_del (vlib_punt_reason_t reason, bool is_add)
+{
+ punt_main_t *pm = &punt_main;
+ int rv = 0;
+ vnet_punt_reason_flag_t flag = vlib_punt_reason_get_flags (reason);
+ const char *node_name =
+ vnet_punt_reason_flag_is_IP6_PACKET (flag) ? "ip6-punt" : "ip4-punt";
+ if (is_add)
+ rv = vlib_punt_register (pm->hdl, reason, node_name);
+ else
+ rv = vlib_punt_unregister (pm->hdl, reason, node_name);
+ if (!rv)
+ return 0;
+ else
+ return clib_error_return (0, is_add ? "Existing punting registration..." :
+ "Punting registration not found...");
+}
+
clib_error_t *
vnet_punt_add_del (vlib_main_t * vm, const punt_reg_t * pr, bool is_add)
{
@@ -414,6 +440,7 @@ vnet_punt_add_del (vlib_main_t * vm, const punt_reg_t * pr, bool is_add)
return (punt_l4_add_del (vm, pr->punt.l4.af, pr->punt.l4.protocol,
pr->punt.l4.port, is_add));
case PUNT_TYPE_EXCEPTION:
+ return punt_exception_add_del (pr->punt.exception.reason, is_add);
case PUNT_TYPE_IP_PROTO:
break;
}
@@ -449,6 +476,9 @@ punt_cli (vlib_main_t * vm,
{
if (unformat (input, "del"))
is_add = false;
+ else if (unformat (input, "reason %U", unformat_punt_reason,
+ &pr.punt.exception.reason))
+ pr.type = PUNT_TYPE_EXCEPTION;
else if (unformat (input, "ipv4"))
pr.punt.l4.af = AF_IP4;
else if (unformat (input, "ipv6"))
@@ -809,6 +839,19 @@ ip_punt_init (vlib_main_t * vm)
return (error);
}
+u8 *
+format_vnet_punt_reason_flags (u8 *s, va_list *args)
+{
+ vnet_punt_reason_flag_t flag = va_arg (*args, int);
+#define _(pos, len, value, name, str) \
+ if (vnet_punt_reason_flag_is_##name (flag)) \
+ s = format (s, "%s ", str);
+
+ foreach_vnet_punt_reason_flag
+#undef _
+ return (s);
+}
+
VLIB_INIT_FUNCTION (ip_punt_init);
static clib_error_t *
diff --git a/src/vnet/ip/punt.h b/src/vnet/ip/punt.h
index 33124846ba6..858ea531ef7 100644
--- a/src/vnet/ip/punt.h
+++ b/src/vnet/ip/punt.h
@@ -24,17 +24,49 @@
#include <stdbool.h>
#include <vnet/ip/ip.h>
+/* Punting reason flags bitfield
+ * (position, length, value, name, string)
+ */
+#define foreach_vnet_punt_reason_flag \
+ _ (0, 1, 0, IP4_PACKET, "ip4-packet") \
+ _ (0, 1, 1, IP6_PACKET, "ip6-packet")
+
+typedef enum vnet_punt_reason_flag_t_
+{
+#define _(pos, len, value, name, str) \
+ VNET_PUNT_REASON_F_##name = ((value) << (pos)),
+ foreach_vnet_punt_reason_flag
+#undef _
+} __clib_packed vnet_punt_reason_flag_t;
+
+enum vnet_punt_reason_flag_mask_t_
+{
+#define _(pos, len, value, name, str) \
+ VNET_PUNT_REASON_F_MASK_##name = (((1 << (len)) - 1) << (pos)),
+ foreach_vnet_punt_reason_flag
+#undef _
+};
+
+/* predicates associated with vlib_punt_reason_flag_t*/
+#define _(pos, len, value, name, str) \
+ static_always_inline int vnet_punt_reason_flag_is_##name ( \
+ vnet_punt_reason_flag_t f) \
+ { \
+ return (f & VNET_PUNT_REASON_F_MASK_##name) == VNET_PUNT_REASON_F_##name; \
+ }
+foreach_vnet_punt_reason_flag
+#undef _
+
#define foreach_punt_type \
_(L4, "l4") \
_(EXCEPTION, "exception") \
_(IP_PROTO, "ip-proto")
-typedef enum punt_type_t_
-{
+ typedef enum punt_type_t_ {
#define _(v, s) PUNT_TYPE_##v,
- foreach_punt_type
+ foreach_punt_type
#undef _
-} punt_type_t;
+ } punt_type_t;
typedef struct punt_l4_t_
{
@@ -138,6 +170,8 @@ typedef walk_rc_t (*punt_client_walk_cb_t) (const punt_client_t * pc,
extern void punt_client_walk (punt_type_t pt,
punt_client_walk_cb_t cb, void *ctx);
+extern u8 *format_vnet_punt_reason_flags (u8 *s, va_list *args);
+
/*
* inlines for the data-plane
*/
diff --git a/src/vnet/ipsec/ipsec_punt.c b/src/vnet/ipsec/ipsec_punt.c
index a08231ab299..8a276546a56 100644
--- a/src/vnet/ipsec/ipsec_punt.c
+++ b/src/vnet/ipsec/ipsec_punt.c
@@ -18,6 +18,7 @@
#include <vnet/ipsec/ipsec.h>
#include <vnet/ipsec/ipsec_punt.h>
#include <vnet/ipsec/ipsec_tun.h>
+#include <vnet/ip/punt.h>
static vlib_punt_hdl_t punt_hdl;
@@ -48,10 +49,11 @@ ipsec_punt_init (vlib_main_t * vm)
punt_hdl = vlib_punt_client_register ("ipsec");
-#define _(s,v) vlib_punt_reason_alloc (punt_hdl, v, \
- ipsec_punt_interested_listener, \
- NULL, \
- &ipsec_punt_reason[IPSEC_PUNT_##s]);
+#define _(s, v, f) \
+ vlib_punt_reason_alloc (punt_hdl, v, ipsec_punt_interested_listener, NULL, \
+ &ipsec_punt_reason[IPSEC_PUNT_##s], \
+ VNET_PUNT_REASON_F_##f, \
+ format_vnet_punt_reason_flags);
foreach_ipsec_punt_reason
#undef _
return (error);
diff --git a/src/vnet/ipsec/ipsec_punt.h b/src/vnet/ipsec/ipsec_punt.h
index f95e1da9133..afed908bffb 100644
--- a/src/vnet/ipsec/ipsec_punt.h
+++ b/src/vnet/ipsec/ipsec_punt.h
@@ -17,14 +17,14 @@
#include <vlib/vlib.h>
-#define foreach_ipsec_punt_reason \
- _(IP4_SPI_UDP_0, "ipsec4-spi-o-udp-0") \
- _(IP4_NO_SUCH_TUNNEL, "ipsec4-no-such-tunnel") \
- _(IP6_NO_SUCH_TUNNEL, "ipsec6-no-such-tunnel")
+#define foreach_ipsec_punt_reason \
+ _ (IP4_SPI_UDP_0, "ipsec4-spi-o-udp-0", IP4_PACKET) \
+ _ (IP4_NO_SUCH_TUNNEL, "ipsec4-no-such-tunnel", IP4_PACKET) \
+ _ (IP6_NO_SUCH_TUNNEL, "ipsec6-no-such-tunnel", IP6_PACKET)
typedef enum ipsec_punt_reason_t_
{
-#define _(s,v) IPSEC_PUNT_##s,
+#define _(s, v, f) IPSEC_PUNT_##s,
foreach_ipsec_punt_reason
#undef _
IPSEC_PUNT_N_REASONS,
diff --git a/src/vnet/vxlan-gbp/vxlan_gbp.c b/src/vnet/vxlan-gbp/vxlan_gbp.c
index d1267cffc13..37cfd728121 100644
--- a/src/vnet/vxlan-gbp/vxlan_gbp.c
+++ b/src/vnet/vxlan-gbp/vxlan_gbp.c
@@ -14,6 +14,7 @@
*/
#include <vnet/vxlan-gbp/vxlan_gbp.h>
#include <vnet/ip/format.h>
+#include <vnet/ip/punt.h>
#include <vnet/fib/fib_entry.h>
#include <vnet/fib/fib_table.h>
#include <vnet/fib/fib_entry_track.h>
@@ -1163,14 +1164,14 @@ vxlan_gbp_init (vlib_main_t * vm)
punt_hdl = vlib_punt_client_register ("vxlan-gbp");
- vlib_punt_reason_alloc (punt_hdl,
- "VXLAN-GBP-no-such-v4-tunnel",
- NULL, NULL,
- &vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4]);
- vlib_punt_reason_alloc (punt_hdl,
- "VXLAN-GBP-no-such-v6-tunnel",
- NULL, NULL,
- &vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6]);
+ vlib_punt_reason_alloc (punt_hdl, "VXLAN-GBP-no-such-v4-tunnel", NULL, NULL,
+ &vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4],
+ VNET_PUNT_REASON_F_IP4_PACKET,
+ format_vnet_punt_reason_flags);
+ vlib_punt_reason_alloc (punt_hdl, "VXLAN-GBP-no-such-v6-tunnel", NULL, NULL,
+ &vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6],
+ VNET_PUNT_REASON_F_IP6_PACKET,
+ format_vnet_punt_reason_flags);
return (0);
}