misc: move ppp to a plugin 56/41956/7
authorJoel Ahn <[email protected]>
Thu, 28 Nov 2024 21:54:10 +0000 (13:54 -0800)
committerDave Wallace <[email protected]>
Fri, 6 Dec 2024 22:18:42 +0000 (22:18 +0000)
Type: refactor

Move PPP folder under vnet to the plugin folder, and modify some of path
of the #inlude<header> to the new path.

Add a plugin.c file to register a plugin.

Resolve ip4_input and ip6_input's dependency on PPP functions by moving
those calls to PPP's initialization.

Resolve osi's inter-plugin dependency on PPP by having it retrieve the
function pointer

Add ppp to the list of valid spelling words

JIRA: VPP-2052

Change-Id: I1a26ef0663a91857d13f7d87a3bb14bc38893194
Signed-off-by: Joel Ahn <[email protected]>
18 files changed:
docs/spelling_wordlist.txt
src/plugins/cdp/cdp_periodic.c
src/plugins/osi/node.c
src/plugins/ppp/CMakeLists.txt [new file with mode: 0644]
src/plugins/ppp/error.def [moved from src/vnet/ppp/error.def with 100% similarity]
src/plugins/ppp/node.c [moved from src/vnet/ppp/node.c with 98% similarity]
src/plugins/ppp/packet.h [moved from src/vnet/ppp/packet.h with 100% similarity]
src/plugins/ppp/pg.c [moved from src/vnet/ppp/pg.c with 99% similarity]
src/plugins/ppp/plugin.c [new file with mode: 0644]
src/plugins/ppp/ppp.c [moved from src/vnet/ppp/ppp.c with 90% similarity]
src/plugins/ppp/ppp.h [moved from src/vnet/ppp/ppp.h with 94% similarity]
src/plugins/pppoe/pppoe.c
src/plugins/pppoe/pppoe_cp_node.c
src/plugins/pppoe/pppoe_decap.c
src/vnet/CMakeLists.txt
src/vnet/ip/ip4_forward.c
src/vnet/ip/ip4_input.c
src/vnet/ip/ip6_input.c

index d6c5b97..7f62393 100644 (file)
@@ -868,6 +868,7 @@ Pollable
 portranges
 poweroff
 ppc
+ppp
 pppoe
 pps
 pre
index 03a2de0..3e700ae 100644 (file)
@@ -16,7 +16,7 @@
 #include <vppinfra/hash.h>
 #include <vppinfra/pcap.h>
 #include <vnet/srp/srp.h>
-#include <vnet/ppp/ppp.h>
+#include <plugins/ppp/ppp.h>
 #include <vnet/hdlc/hdlc.h>
 #include <vnet/srp/packet.h>
 
index a36b152..51a3dc6 100644 (file)
 #include <vlib/vlib.h>
 #include <vnet/pg/pg.h>
 #include <osi/osi.h>
-#include <vnet/ppp/ppp.h>
+#include <plugins/ppp/ppp.h>
 #include <vnet/hdlc/hdlc.h>
 #include <vnet/llc/llc.h>
+#include <vnet/plugin/plugin.h>
 
 #define foreach_osi_input_next                 \
   _ (PUNT, "error-punt")                       \
@@ -271,11 +272,24 @@ osi_setup_node (vlib_main_t *vm, u32 node_index)
   pn->unformat_edit = unformat_pg_osi_header;
 }
 
+typedef void (*ppp_register_input_protocol_fn) (vlib_main_t *vm,
+                                               ppp_protocol_t protocol,
+                                               u32 node_index);
+
 static clib_error_t *
 osi_input_init (vlib_main_t * vm)
 {
   clib_error_t *error = 0;
   osi_main_t *lm = &osi_main;
+  ppp_register_input_protocol_fn ppp_register_input_protocol_fn_ptr;
+
+  ppp_register_input_protocol_fn_ptr =
+    vlib_get_plugin_symbol ("ppp_plugin.so", "ppp_register_input_protocol");
+  if (ppp_register_input_protocol_fn_ptr == 0)
+    {
+      error = clib_error_return (0, "ppp_plugin.so is not loaded");
+      return error;
+    }
 
   if ((error = vlib_call_init_function (vm, osi_init)))
     return error;
@@ -288,7 +302,8 @@ osi_input_init (vlib_main_t * vm)
       lm->input_next_by_protocol[i] = OSI_INPUT_NEXT_DROP;
   }
 
-  ppp_register_input_protocol (vm, PPP_PROTOCOL_osi, osi_input_node.index);
+  ppp_register_input_protocol_fn_ptr (vm, PPP_PROTOCOL_osi,
+                                     osi_input_node.index);
   hdlc_register_input_protocol (vm, HDLC_PROTOCOL_osi, osi_input_node.index);
   llc_register_input_protocol (vm, LLC_PROTOCOL_osi_layer1,
                               osi_input_node.index);
diff --git a/src/plugins/ppp/CMakeLists.txt b/src/plugins/ppp/CMakeLists.txt
new file mode 100644 (file)
index 0000000..771d4dc
--- /dev/null
@@ -0,0 +1,25 @@
+# Copyright (c) 2024 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+add_vpp_plugin(ppp
+  SOURCES
+  node.c
+  pg.c
+  ppp.c
+  plugin.c
+
+  INSTALL_HEADERS
+  ppp.h
+  error.def
+  packet.h
+)
\ No newline at end of file
similarity index 98%
rename from src/vnet/ppp/node.c
rename to src/plugins/ppp/node.c
index fa056bf..4c252e4 100644 (file)
@@ -39,7 +39,7 @@
 
 #include <vlib/vlib.h>
 #include <vnet/pg/pg.h>
-#include <vnet/ppp/ppp.h>
+#include <plugins/ppp/ppp.h>
 #include <vppinfra/sparse_vec.h>
 
 #define foreach_ppp_input_next                 \
@@ -323,7 +323,6 @@ ppp_setup_node (vlib_main_t *vm, u32 node_index)
 static clib_error_t *
 ppp_input_init (vlib_main_t * vm)
 {
-
   {
     clib_error_t *error = vlib_call_init_function (vm, ppp_init);
     if (error)
@@ -339,9 +338,9 @@ ppp_input_init (vlib_main_t * vm)
 VLIB_INIT_FUNCTION (ppp_input_init);
 VLIB_WORKER_INIT_FUNCTION (ppp_input_runtime_init);
 
-void
-ppp_register_input_protocol (vlib_main_t * vm,
-                            ppp_protocol_t protocol, u32 node_index)
+__clib_export void
+ppp_register_input_protocol (vlib_main_t *vm, ppp_protocol_t protocol,
+                            u32 node_index)
 {
   ppp_main_t *em = &ppp_main;
   ppp_protocol_info_t *pi;
similarity index 99%
rename from src/vnet/ppp/pg.c
rename to src/plugins/ppp/pg.c
index 0b46ccb..39f6c25 100644 (file)
@@ -39,7 +39,7 @@
 
 #include <vlib/vlib.h>
 #include <vnet/pg/pg.h>
-#include <vnet/ppp/ppp.h>
+#include <plugins/ppp/ppp.h>
 
 typedef struct
 {
diff --git a/src/plugins/ppp/plugin.c b/src/plugins/ppp/plugin.c
new file mode 100644 (file)
index 0000000..fac25b3
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * plugin.c: ppp
+ *
+ * Copyright (c) 2024 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vlib/vlib.h>
+#include <vnet/plugin/plugin.h>
+#include <vpp/app/version.h>
+
+// register a plugin
+VLIB_PLUGIN_REGISTER () = {
+  .version = VPP_BUILD_VER,
+  .description = "Point-to-Point Protocol (PPP) plugin",
+};
similarity index 90%
rename from src/vnet/ppp/ppp.c
rename to src/plugins/ppp/ppp.c
index 8aa8504..8b394dc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco and/or its affiliates.
+ * Copyright (c) 2024 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
@@ -38,7 +38,7 @@
  */
 
 #include <vnet/vnet.h>
-#include <vnet/ppp/ppp.h>
+#include <plugins/ppp/ppp.h>
 
 /* Global main structure. */
 ppp_main_t ppp_main;
@@ -226,10 +226,21 @@ static clib_error_t *
 ppp_init (vlib_main_t * vm)
 {
   ppp_main_t *pm = &ppp_main;
+  clib_error_t *error;
+  vlib_node_t *ip4_input_node, *ip6_input_node;
 
   clib_memset (pm, 0, sizeof (pm[0]));
   pm->vlib_main = vm;
 
+  if ((error = vlib_call_init_function (vm, ip_main_init)))
+    return error;
+
+  if ((error = vlib_call_init_function (vm, ip4_init)))
+    return error;
+
+  if ((error = vlib_call_init_function (vm, ip6_init)))
+    return error;
+
   pm->protocol_info_by_name = hash_create_string (0, sizeof (uword));
   pm->protocol_info_by_protocol = hash_create (0, sizeof (uword));
 
@@ -237,6 +248,14 @@ ppp_init (vlib_main_t * vm)
   foreach_ppp_protocol;
 #undef _
 
+  ip4_input_node = vlib_get_node_by_name (vm, (u8 *) "ip4-input");
+  ASSERT (ip4_input_node);
+  ip6_input_node = vlib_get_node_by_name (vm, (u8 *) "ip6-input");
+  ASSERT (ip6_input_node);
+
+  ppp_register_input_protocol (vm, PPP_PROTOCOL_ip4, ip4_input_node->index);
+  ppp_register_input_protocol (vm, PPP_PROTOCOL_ip6, ip6_input_node->index);
+
   return vlib_call_init_function (vm, ppp_input_init);
 }
 
similarity index 94%
rename from src/vnet/ppp/ppp.h
rename to src/plugins/ppp/ppp.h
index 77da8c1..b94f096 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco and/or its affiliates.
+ * Copyright (c) 2024 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
 #define included_ppp_h
 
 #include <vnet/vnet.h>
-#include <vnet/ppp/packet.h>
+#include <ppp/packet.h>
 
 extern vnet_hw_interface_class_t ppp_hw_interface_class;
 
 typedef enum
 {
 #define ppp_error(n,s) PPP_ERROR_##n,
-#include <vnet/ppp/error.def>
+#include <ppp/error.def>
 #undef ppp_error
   PPP_N_ERROR,
 } ppp_error_t;
@@ -105,9 +105,9 @@ unformat_function_t unformat_ppp_protocol_net_byte_order;
 unformat_function_t unformat_ppp_header;
 unformat_function_t unformat_pg_ppp_header;
 
-void
-ppp_register_input_protocol (vlib_main_t * vm,
-                            ppp_protocol_t protocol, u32 node_index);
+__clib_export void ppp_register_input_protocol (vlib_main_t *vm,
+                                               ppp_protocol_t protocol,
+                                               u32 node_index);
 
 #endif /* included_ppp_h */
 
index 0d5f9c1..497fbc0 100644 (file)
@@ -27,7 +27,7 @@
 #include <vnet/dpo/interface_tx_dpo.h>
 #include <vnet/plugin/plugin.h>
 #include <vpp/app/version.h>
-#include <vnet/ppp/packet.h>
+#include <ppp/packet.h>
 #include <pppoe/pppoe.h>
 #include <vnet/adj/adj_midchain.h>
 #include <vnet/adj/adj_mcast.h>
index 1a44b5d..c965596 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #include <vlib/vlib.h>
-#include <vnet/ppp/packet.h>
+#include <ppp/packet.h>
 #include <pppoe/pppoe.h>
 
 #define foreach_pppoe_cp_next        \
index 7c456a7..854364b 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #include <vlib/vlib.h>
-#include <vnet/ppp/packet.h>
+#include <ppp/packet.h>
 #include <pppoe/pppoe.h>
 
 typedef struct {
index 254849c..46b1a87 100644 (file)
@@ -268,21 +268,6 @@ list(APPEND VNET_HEADERS
   srp/srp.h
 )
 
-##############################################################################
-# Layer 2 protocol: PPP
-##############################################################################
-list(APPEND VNET_SOURCES
-  ppp/node.c
-  ppp/pg.c
-  ppp/ppp.c
-)
-
-list(APPEND VNET_HEADERS
-  ppp/error.def
-  ppp/ppp.h
-  ppp/packet.h
-)
-
 ##############################################################################
 # Layer 2 protocol: HDLC
 ##############################################################################
index ff74b52..a378dc5 100644 (file)
@@ -42,7 +42,6 @@
 #include <vnet/ip/ip_frag.h>
 #include <vnet/ethernet/ethernet.h>    /* for ethernet_header_t */
 #include <vnet/ethernet/arp_packet.h>  /* for ethernet_arp_header_t */
-#include <vnet/ppp/ppp.h>
 #include <vnet/srp/srp.h>      /* for srp_hw_interface_class */
 #include <vnet/api_errno.h>    /* for API error numbers */
 #include <vnet/fib/fib_table.h>        /* for FIB table and entry creation */
index 106d17d..af2b89a 100644 (file)
@@ -40,7 +40,6 @@
 #include <vnet/ip/ip4_input.h>
 #include <vnet/ethernet/ethernet.h>
 #include <vnet/pg/pg.h>
-#include <vnet/ppp/ppp.h>
 #include <vnet/hdlc/hdlc.h>
 #include <vnet/util/throttle.h>
 
@@ -411,7 +410,6 @@ ip4_init (vlib_main_t * vm)
   clib_error_t *error;
 
   ethernet_register_input_type (vm, ETHERNET_TYPE_IP4, ip4_input_node.index);
-  ppp_register_input_protocol (vm, PPP_PROTOCOL_ip4, ip4_input_node.index);
   hdlc_register_input_protocol (vm, HDLC_PROTOCOL_ip4, ip4_input_node.index);
 
   {
index 64c9d76..ae59b76 100644 (file)
@@ -39,7 +39,6 @@
 
 #include <vnet/ip/ip6_input.h>
 #include <vnet/ethernet/ethernet.h>
-#include <vnet/ppp/ppp.h>
 #include <vnet/hdlc/hdlc.h>
 #include <vnet/pg/pg.h>
 
@@ -242,7 +241,6 @@ static clib_error_t *
 ip6_init (vlib_main_t * vm)
 {
   ethernet_register_input_type (vm, ETHERNET_TYPE_IP6, ip6_input_node.index);
-  ppp_register_input_protocol (vm, PPP_PROTOCOL_ip6, ip6_input_node.index);
   hdlc_register_input_protocol (vm, HDLC_PROTOCOL_ip6, ip6_input_node.index);
 
   {