ipsec: move startup config to common file 75/33275/2
authorZachary Leaf <zachary.leaf@arm.com>
Tue, 27 Jul 2021 10:18:47 +0000 (05:18 -0500)
committerNeale Ranns <neale@graphiant.com>
Thu, 29 Jul 2021 07:30:33 +0000 (07:30 +0000)
The ipsec startup.conf config currently exists in ipsec_tun.c. This is
because currently the only ipsec{...} options are tunnel related.

This patch moves the ipsec config to a common file (ipsec.c) for future
extensibility/addition of non-tunnel related config options.

Type: refactor
Signed-off-by: Zachary Leaf <zachary.leaf@arm.com>
Change-Id: I1569dd7948334fd2cc28523ccc6791a22dea8d32

src/vnet/ipsec/ipsec.c
src/vnet/ipsec/ipsec_tun.c
src/vnet/ipsec/ipsec_tun.h

index 7471345..d154b51 100644 (file)
@@ -24,6 +24,7 @@
 #include <vnet/ipsec/ipsec.h>
 #include <vnet/ipsec/esp.h>
 #include <vnet/ipsec/ah.h>
+#include <vnet/ipsec/ipsec_tun.h>
 
 ipsec_main_t ipsec_main;
 esp_async_post_next_t esp_encrypt_async_next;
@@ -549,6 +550,56 @@ ipsec_init (vlib_main_t * vm)
 
 VLIB_INIT_FUNCTION (ipsec_init);
 
+static clib_error_t *
+ipsec_config (vlib_main_t *vm, unformat_input_t *input)
+{
+  unformat_input_t sub_input;
+
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "ip4 %U", unformat_vlib_cli_sub_input, &sub_input))
+       {
+         uword table_size = ~0;
+         u32 n_buckets = ~0;
+
+         while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT)
+           {
+             if (unformat (&sub_input, "num-buckets %u", &n_buckets))
+               ;
+             else
+               return clib_error_return (0, "unknown input `%U'",
+                                         format_unformat_error, &sub_input);
+           }
+
+         ipsec_tun_table_init (AF_IP4, table_size, n_buckets);
+       }
+      else if (unformat (input, "ip6 %U", unformat_vlib_cli_sub_input,
+                        &sub_input))
+       {
+         uword table_size = ~0;
+         u32 n_buckets = ~0;
+
+         while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT)
+           {
+             if (unformat (&sub_input, "num-buckets %u", &n_buckets))
+               ;
+             else
+               return clib_error_return (0, "unknown input `%U'",
+                                         format_unformat_error, &sub_input);
+           }
+
+         ipsec_tun_table_init (AF_IP6, table_size, n_buckets);
+       }
+      else
+       return clib_error_return (0, "unknown input `%U'",
+                                 format_unformat_error, input);
+    }
+
+  return 0;
+}
+
+VLIB_CONFIG_FUNCTION (ipsec_config, "ipsec");
+
 /*
  * fd.io coding-style-patch-verification: ON
  *
index 0b6ec0e..58f9efe 100644 (file)
@@ -925,7 +925,7 @@ const static teib_vft_t ipsec_tun_teib_vft = {
   .nv_deleted = ipsec_tun_teib_entry_deleted,
 };
 
-static void
+void
 ipsec_tun_table_init (ip_address_family_t af, uword table_size, u32 n_buckets)
 {
   ipsec_main_t *im;
@@ -979,56 +979,6 @@ ipsec_tunnel_protect_init (vlib_main_t *vm)
 
 VLIB_INIT_FUNCTION (ipsec_tunnel_protect_init);
 
-static clib_error_t *
-ipsec_config (vlib_main_t * vm, unformat_input_t * input)
-{
-  unformat_input_t sub_input;
-
-  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (input, "ip4 %U", unformat_vlib_cli_sub_input, &sub_input))
-       {
-         uword table_size = ~0;
-         u32 n_buckets = ~0;
-
-         while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT)
-           {
-             if (unformat (&sub_input, "num-buckets %u", &n_buckets))
-               ;
-             else
-               return clib_error_return (0, "unknown input `%U'",
-                                         format_unformat_error, &sub_input);
-           }
-
-         ipsec_tun_table_init (AF_IP4, table_size, n_buckets);
-       }
-      else if (unformat (input, "ip6 %U", unformat_vlib_cli_sub_input,
-                        &sub_input))
-       {
-         uword table_size = ~0;
-         u32 n_buckets = ~0;
-
-         while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT)
-           {
-             if (unformat (&sub_input, "num-buckets %u", &n_buckets))
-               ;
-             else
-               return clib_error_return (0, "unknown input `%U'",
-                                         format_unformat_error, &sub_input);
-           }
-
-         ipsec_tun_table_init (AF_IP6, table_size, n_buckets);
-       }
-      else
-       return clib_error_return (0, "unknown input `%U'",
-                                 format_unformat_error, input);
-    }
-
-  return 0;
-}
-
-VLIB_CONFIG_FUNCTION (ipsec_config, "ipsec");
-
 /*
  * fd.io coding-style-patch-verification: ON
  *
index c79fb90..f452fa4 100644 (file)
@@ -163,6 +163,9 @@ extern u8 *format_ipsec_tun_protect_index (u8 * s, va_list * args);
 extern void ipsec_tun_register_nodes (ip_address_family_t af);
 extern void ipsec_tun_unregister_nodes (ip_address_family_t af);
 
+extern void ipsec_tun_table_init (ip_address_family_t af, uword table_size,
+                                 u32 n_buckets);
+
 /*
  * DP API
  */