aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/ip')
-rw-r--r--src/vnet/ip/punt.c43
-rw-r--r--src/vnet/ip/punt.h42
2 files changed, 81 insertions, 4 deletions
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
*/