ip: Replace Sematics for Interface IP addresses
[vpp.git] / src / vnet / ip / punt.c
index 6f32150..a295277 100644 (file)
@@ -27,7 +27,6 @@
 #include <vnet/pg/pg.h>
 #include <vnet/udp/udp.h>
 #include <vnet/tcp/tcp.h>
-#include <vnet/sctp/sctp.h>
 #include <vnet/ip/punt.h>
 #include <vlib/unix/unix.h>
 
@@ -352,10 +351,10 @@ vnet_punt_socket_del (vlib_main_t * vm, const punt_reg_t * pr)
 }
 
 /**
- * @brief Request IP traffic punt to the local TCP/IP stack.
+ * @brief Request IP L4 traffic punt to the local TCP/IP stack.
  *
  * @em Note
- * - UDP, TCP and SCTP are the only protocols supported in the current implementation
+ * - UDP is the only protocol supported in the current implementation
  *
  * @param vm       vlib_main_t corresponding to the current thread
  * @param af       IP address family.
@@ -371,13 +370,11 @@ punt_l4_add_del (vlib_main_t * vm,
                 ip_address_family_t af,
                 ip_protocol_t protocol, u16 port, bool is_add)
 {
-  /* For now we only support TCP, UDP and SCTP punt */
-  if (protocol != IP_PROTOCOL_UDP &&
-      protocol != IP_PROTOCOL_TCP && protocol != IP_PROTOCOL_SCTP)
+  /* For now we only support TCP and UDP punt */
+  if (protocol != IP_PROTOCOL_UDP && protocol != IP_PROTOCOL_TCP)
     return clib_error_return (0,
-                             "only UDP (%d), TCP (%d) and SCTP (%d) protocols are supported, got %d",
-                             IP_PROTOCOL_UDP, IP_PROTOCOL_TCP,
-                             IP_PROTOCOL_SCTP, protocol);
+                             "only UDP (%d) and TCP (%d) protocols are supported, got %d",
+                             IP_PROTOCOL_UDP, IP_PROTOCOL_TCP, protocol);
 
   if (port == (u16) ~ 0)
     {
@@ -385,17 +382,14 @@ punt_l4_add_del (vlib_main_t * vm,
        udp_punt_unknown (vm, af == AF_IP4, is_add);
       else if (protocol == IP_PROTOCOL_TCP)
        tcp_punt_unknown (vm, af == AF_IP4, is_add);
-      else if (protocol == IP_PROTOCOL_SCTP)
-       sctp_punt_unknown (vm, af == AF_IP4, is_add);
 
       return 0;
     }
 
   else if (is_add)
     {
-      if (protocol == IP_PROTOCOL_TCP || protocol == IP_PROTOCOL_SCTP)
-       return clib_error_return (0,
-                                 "punt TCP/SCTP ports is not supported yet");
+      if (protocol == IP_PROTOCOL_TCP)
+       return clib_error_return (0, "punt TCP ports is not supported yet");
 
       udp_register_dst_port (vm, port, udp4_punt_node.index, af == AF_IP4);
 
@@ -403,9 +397,8 @@ punt_l4_add_del (vlib_main_t * vm,
     }
   else
     {
-      if (protocol == IP_PROTOCOL_TCP || protocol == IP_PROTOCOL_SCTP)
-       return clib_error_return (0,
-                                 "punt TCP/SCTP ports is not supported yet");
+      if (protocol == IP_PROTOCOL_TCP)
+       return clib_error_return (0, "punt TCP ports is not supported yet");
 
       udp_unregister_dst_port (vm, port, af == AF_IP4);
 
@@ -441,7 +434,7 @@ punt_cli (vlib_main_t * vm,
       .l4 = {
         .af = AF_IP4,
         .port = ~0,
-        .protocol = ~0,
+        .protocol = IP_PROTOCOL_UDP,
       },
     },
     .type = PUNT_TYPE_L4,
@@ -453,12 +446,16 @@ punt_cli (vlib_main_t * vm,
     {
       if (unformat (input, "del"))
        is_add = false;
+      else if (unformat (input, "ipv4"))
+       pr.punt.l4.af = AF_IP4;
       else if (unformat (input, "ipv6"))
        pr.punt.l4.af = AF_IP6;
       else if (unformat (input, "ip6"))
        pr.punt.l4.af = AF_IP6;
       else if (unformat (input, "%d", &port))
        pr.punt.l4.port = port;
+      else if (unformat (input, "all"))
+       pr.punt.l4.port = ~0;
       else if (unformat (input, "udp"))
        pr.punt.l4.protocol = IP_PROTOCOL_UDP;
       else if (unformat (input, "tcp"))
@@ -505,7 +502,7 @@ done:
 /* *INDENT-OFF* */
 VLIB_CLI_COMMAND (punt_command, static) = {
   .path = "set punt",
-  .short_help = "set punt [udp|tcp] [del] <all | port-num1 [port-num2 ...]>",
+  .short_help = "set punt [IPV4|ip6|ipv6] [UDP|tcp] [del] [ALL|<port-num>]",
   .function = punt_cli,
 };
 /* *INDENT-ON* */
@@ -522,7 +519,7 @@ punt_socket_register_cmd (vlib_main_t * vm,
       .l4 = {
         .af = AF_IP4,
         .port = ~0,
-        .protocol = ~0,
+        .protocol = IP_PROTOCOL_UDP,
       },
     },
     .type = PUNT_TYPE_L4,
@@ -532,7 +529,7 @@ punt_socket_register_cmd (vlib_main_t * vm,
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
       if (unformat (input, "ipv4"))
-       ;
+       pr.punt.l4.af = AF_IP4;
       else if (unformat (input, "ipv6"))
        pr.punt.l4.af = AF_IP6;
       else if (unformat (input, "udp"))
@@ -541,6 +538,8 @@ punt_socket_register_cmd (vlib_main_t * vm,
        pr.punt.l4.protocol = IP_PROTOCOL_TCP;
       else if (unformat (input, "%d", &pr.punt.l4.port))
        ;
+      else if (unformat (input, "all"))
+       pr.punt.l4.port = ~0;
       else if (unformat (input, "socket %s", &socket_name))
        ;
       else
@@ -551,7 +550,10 @@ punt_socket_register_cmd (vlib_main_t * vm,
        }
     }
 
-  error = vnet_punt_socket_add (vm, 1, &pr, (char *) socket_name);
+  if (!socket_name)
+    error = clib_error_return (0, "socket name not specified");
+  else
+    error = vnet_punt_socket_add (vm, 1, &pr, (char *) socket_name);
 
 done:
   return error;
@@ -560,14 +562,15 @@ done:
 /*?
  *
  * @cliexpar
- * @cliexcmd{punt socket register}
+ * @cliexcmd{punt socket register socket punt_l4_foo.sock}
+
  ?*/
 /* *INDENT-OFF* */
 VLIB_CLI_COMMAND (punt_socket_register_command, static) =
 {
   .path = "punt socket register",
   .function = punt_socket_register_cmd,
-  .short_help = "punt socket register [ipv4|ipv6] [udp|tcp]> <all | port-num1 [port-num2 ...]> <socket>",
+  .short_help = "punt socket register [IPV4|ipv6] [UDP|tcp] [ALL|<port-num>] socket <socket>",
   .is_mp_safe = 1,
 };
 /* *INDENT-ON* */
@@ -584,7 +587,7 @@ punt_socket_deregister_cmd (vlib_main_t * vm,
       .l4 = {
         .af = AF_IP4,
         .port = ~0,
-        .protocol = ~0,
+        .protocol = IP_PROTOCOL_UDP,
       },
     },
     .type = PUNT_TYPE_L4,
@@ -594,7 +597,7 @@ punt_socket_deregister_cmd (vlib_main_t * vm,
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
       if (unformat (input, "ipv4"))
-       ;
+       pr.punt.l4.af = AF_IP4;
       else if (unformat (input, "ipv6"))
        pr.punt.l4.af = AF_IP6;
       else if (unformat (input, "udp"))
@@ -603,6 +606,8 @@ punt_socket_deregister_cmd (vlib_main_t * vm,
        pr.punt.l4.protocol = IP_PROTOCOL_TCP;
       else if (unformat (input, "%d", &pr.punt.l4.port))
        ;
+      else if (unformat (input, "all"))
+       pr.punt.l4.port = ~0;
       else
        {
          error = clib_error_return (0, "parse error: '%U'",
@@ -626,7 +631,7 @@ VLIB_CLI_COMMAND (punt_socket_deregister_command, static) =
 {
   .path = "punt socket deregister",
   .function = punt_socket_deregister_cmd,
-  .short_help = "punt socket deregister [ipv4|ipv6] [udp|tcp]> <all | port-num1 [port-num2 ...]>",
+  .short_help = "punt socket deregister [IPV4|ipv6] [UDP|tcp] [ALL|<port-num>]",
   .is_mp_safe = 1,
 };
 /* *INDENT-ON* */
@@ -767,6 +772,7 @@ ip_punt_init (vlib_main_t * vm)
 {
   clib_error_t *error = NULL;
   punt_main_t *pm = &punt_main;
+  vlib_thread_main_t *tm = vlib_get_thread_main ();
 
   pm->is_configured = false;
   pm->interface_output_node =
@@ -777,6 +783,9 @@ ip_punt_init (vlib_main_t * vm)
 
   pm->hdl = vlib_punt_client_register ("ip-punt");
 
+  vec_validate_aligned (pm->thread_data, tm->n_vlib_mains,
+                       CLIB_CACHE_LINE_BYTES);
+
   return (error);
 }