quic: improve udp dgram write
[vpp.git] / src / vnet / ip / punt.c
index a3ccc43..fb0cc22 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <vnet/ip/ip.h>
 #include <vlib/vlib.h>
-#include <vnet/pg/pg.h>
 #include <vnet/udp/udp.h>
 #include <vnet/tcp/tcp.h>
 #include <vnet/ip/punt.h>
@@ -406,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)
 {
@@ -415,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;
     }
@@ -450,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"))
@@ -552,6 +581,9 @@ punt_socket_register_cmd (vlib_main_t * vm,
        pr.punt.l4.port = ~0;
       else if (unformat (input, "socket %s", &socket_name))
        ;
+      else if (unformat (input, "reason %U", unformat_punt_reason,
+                        &pr.punt.exception.reason))
+       pr.type = PUNT_TYPE_EXCEPTION;
       else
        {
          error = clib_error_return (0, "parse error: '%U'",
@@ -623,6 +655,9 @@ punt_socket_deregister_cmd (vlib_main_t * vm,
        ;
       else if (unformat (input, "all"))
        pr.punt.l4.port = ~0;
+      else if (unformat (input, "reason %U", unformat_punt_reason,
+                        &pr.punt.exception.reason))
+       pr.type = PUNT_TYPE_EXCEPTION;
       else
        {
          error = clib_error_return (0, "parse error: '%U'",
@@ -810,6 +845,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 *
@@ -870,7 +918,7 @@ punt_config (vlib_main_t * vm, unformat_input_t * input)
   clib_file_t template = { 0 };
   template.read_function = punt_socket_read_ready;
   template.file_descriptor = pm->socket_fd;
-  template.description = format (0, "%s", socket_path);
+  template.description = format (0, "punt socket %s", socket_path);
   pm->clib_file_index = clib_file_add (fm, &template);
 
   pm->is_configured = true;