misc: move ppp to a plugin

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 <joeahn@cisco.com>
This commit is contained in:
Joel Ahn
2024-11-28 13:54:10 -08:00
committed by Dave Wallace
parent 41ae1e20e6
commit 72bd2e585d
18 changed files with 105 additions and 40 deletions

View File

@ -868,6 +868,7 @@ Pollable
portranges
poweroff
ppc
ppp
pppoe
pps
pre

View 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>

View File

@ -40,9 +40,10 @@
#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);

View File

@ -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
)

View 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;

View 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
{

26
src/plugins/ppp/plugin.c Normal file
View File

@ -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",
};

View 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);
}

View 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:
@ -41,14 +41,14 @@
#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 */

View 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>

View 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 \

View File

@ -16,7 +16,7 @@
*/
#include <vlib/vlib.h>
#include <vnet/ppp/packet.h>
#include <ppp/packet.h>
#include <pppoe/pppoe.h>
typedef struct {

View 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
##############################################################################

View 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 */

View 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);
{

View 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);
{