ip: extend punt CLI for exception packets
[vpp.git] / src / vnet / ip / punt.h
index a77e633..858ea53 100644 (file)
 #include <stdbool.h>
 #include <vnet/ip/ip.h>
 
-#define foreach_punt_type \
-  _(L4, "l4")             \
-  _(EXCEPTION, "exception")
+/* 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 punt_type_t_
+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_ {
 #define _(v, s) PUNT_TYPE_##v,
-  foreach_punt_type
+    foreach_punt_type
 #undef _
-} punt_type_t;
+  } punt_type_t;
 
 typedef struct punt_l4_t_
 {
@@ -42,6 +75,12 @@ typedef struct punt_l4_t_
   u16 port;
 } punt_l4_t;
 
+typedef struct punt_ip_proto_t_
+{
+  ip_address_family_t af;
+  ip_protocol_t protocol;
+} punt_ip_proto_t;
+
 typedef struct punt_exception_t_
 {
   vlib_punt_reason_t reason;
@@ -51,6 +90,7 @@ typedef struct punt_union_t_
 {
   punt_exception_t exception;
   punt_l4_t l4;
+  punt_ip_proto_t ip_proto;
 } punt_union_t;
 
 typedef struct punt_reg_t_
@@ -100,8 +140,14 @@ typedef struct punt_client_db_t_
 {
   void *clients_by_l4_port;
   u32 *clients_by_exception;
+  void *clients_by_ip_proto;
 } punt_client_db_t;
 
+typedef struct punt_thread_data_t_
+{
+  struct iovec *iovecs;
+} punt_thread_data_t;
+
 typedef struct
 {
   int socket_fd;
@@ -113,6 +159,7 @@ typedef struct
   vlib_node_t *interface_output_node;
   u32 *ready_fds;
   u32 *rx_buffers;
+  punt_thread_data_t *thread_data;
   vlib_punt_hdl_t hdl;
 } punt_main_t;
 
@@ -123,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
  */
@@ -146,6 +195,28 @@ punt_client_l4_get (ip_address_family_t af, u16 port)
   return (NULL);
 }
 
+static_always_inline u32
+punt_client_ip_proto_mk_key (ip_address_family_t af, ip_protocol_t proto)
+{
+  return (af << 16 | proto);
+}
+
+static_always_inline punt_client_t *
+punt_client_ip_proto_get (ip_address_family_t af, ip_protocol_t proto)
+{
+  punt_main_t *pm = &punt_main;
+  uword *p;
+
+  p =
+    hash_get (pm->db.clients_by_ip_proto,
+             punt_client_ip_proto_mk_key (af, proto));
+
+  if (p)
+    return (pool_elt_at_index (pm->punt_client_pool, p[0]));
+
+  return (NULL);
+}
+
 static_always_inline punt_client_t *
 punt_client_exception_get (vlib_punt_reason_t reason)
 {
@@ -167,6 +238,8 @@ extern vlib_node_registration_t udp4_punt_node;
 extern vlib_node_registration_t udp6_punt_node;
 extern vlib_node_registration_t udp4_punt_socket_node;
 extern vlib_node_registration_t udp6_punt_socket_node;
+extern vlib_node_registration_t ip4_proto_punt_socket_node;
+extern vlib_node_registration_t ip6_proto_punt_socket_node;
 extern vlib_node_registration_t punt_socket_rx_node;
 
 #endif