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

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

42
src/plugins/ppp/error.def Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2015 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.
*/
/*
* ppp_error.def: ppp errors
*
* Copyright (c) 2008 Eliot Dresselhaus
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
ppp_error (NONE, "no error")
ppp_error (UNKNOWN_PROTOCOL, "unknown ppp protocol")
ppp_error (UNKNOWN_ADDRESS_CONTROL, "address, control != 0xff03")

381
src/plugins/ppp/node.c Normal file

File diff suppressed because it is too large Load Diff

199
src/plugins/ppp/packet.h Normal file
View File

@ -0,0 +1,199 @@
/*
* Copyright (c) 2015 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.
*/
#ifndef included_vnet_ppp_packet_h
#define included_vnet_ppp_packet_h
/*
* PPP packet format
*
* Copyright (c) 2009 Eliot Dresselhaus
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
See http://www.iana.org/assignments/ppp-numbers.
The Point-to-Point Protocol (PPP) Data Link Layer [146,147,175]
contains a 16 bit Protocol field to identify the the encapsulated
protocol. The Protocol field is consistent with the ISO 3309 (HDLC)
extension mechanism for Address fields. All Protocols MUST be
assigned such that the least significant bit of the most significant
octet equals "0", and the least significant bit of the least
significant octet equals "1".
*/
#define foreach_ppp_protocol \
_ (0x0001, padding) \
_ (0x0003, rohc_small_cid) \
_ (0x0005, rohc_large_cid) \
_ (0x0021, ip4) \
_ (0x0023, osi) \
_ (0x0025, xerox_ns_idp) \
_ (0x0027, decnet) \
_ (0x0029, appletalk) \
_ (0x002b, ipx) \
_ (0x002d, vj_compressed_tcp) \
_ (0x002f, vj_uncompressed_tcp) \
_ (0x0031, bpdu) \
_ (0x0033, streams) \
_ (0x0035, vines) \
_ (0x0039, appletalk_eddp) \
_ (0x003b, appletalk_smart_buffered) \
_ (0x003d, multilink) \
_ (0x003f, netbios_framing) \
_ (0x0041, cisco) \
_ (0x0043, timeplex) \
_ (0x0045, fujitsu_lblb) \
_ (0x0047, dca_remote_lan) \
_ (0x0049, sdtp) \
_ (0x004b, sna_over_802_2) \
_ (0x004d, sna) \
_ (0x004f, ip6_header_compression) \
_ (0x0051, knx) \
_ (0x0053, encryption) \
_ (0x0055, link_encryption) \
_ (0x0057, ip6) \
_ (0x0059, ppp_mux) \
_ (0x005b, vendor_specific_a) \
_ (0x0061, rtp_iphc_full_header) \
_ (0x0063, rtp_iphc_compressed_tcp) \
_ (0x0065, rtp_iphc_compressed_non_tcp) \
_ (0x0067, rtp_iphc_compressed_udp_8) \
_ (0x0069, rtp_iphc_compressed_rtp_8) \
_ (0x006f, stampede) \
_ (0x0073, mp_plus) \
_ (0x007d, control) \
_ (0x00c1, ntcits_ipi) \
_ (0x00cf, ppp_nlpid) \
_ (0x00fb, multilink_compression) \
_ (0x00fd, compressed_datagram) \
_ (0x0201, 802_1d_hello) \
_ (0x0203, ibm_source_routing) \
_ (0x0205, dec_lanbridge) \
_ (0x0207, cdp) \
_ (0x0209, netcs) \
_ (0x020b, stp) \
_ (0x020d, edp) \
_ (0x0211, oscp_a) \
_ (0x0213, oscp_b) \
_ (0x0231, luxcom) \
_ (0x0233, sigma) \
_ (0x0235, apple_client_server) \
_ (0x0281, mpls_unicast) \
_ (0x0283, mpls_multicast) \
_ (0x0285, ieee_p1284_4) \
_ (0x0287, tetra) \
_ (0x0289, multichannel_flow_treatment) \
_ (0x2063, rtp_iphc_compressed_tcp_no_delta) \
_ (0x2065, rtp_iphc_context_state) \
_ (0x2067, rtp_iphc_compressed_udp_16) \
_ (0x2069, rtp_iphc_compressed_rtp_16) \
_ (0x4001, cray) \
_ (0x4003, cdpd) \
_ (0x4005, expand) \
_ (0x4007, odsicp) \
_ (0x4009, docsis_dll) \
_ (0x400B, cetacean) \
_ (0x4021, lzs) \
_ (0x4023, reftek) \
_ (0x4025, fibre_channel) \
_ (0x4027, emit) \
_ (0x405b, vendor_specific_b) \
_ (0xc021, lcp) \
_ (0xc023, pap) \
_ (0xc025, link_quality_report) \
_ (0xc027, shiva_password) \
_ (0xc029, cbcp) \
_ (0xc02b, bacp) \
_ (0xc02d, bap) \
_ (0xc05b, vendor_specific_password) \
_ (0xc081, container_control) \
_ (0xc223, chap) \
_ (0xc225, rsa) \
_ (0xc227, extensible_authentication) \
_ (0xc229, mitsubishi_security_info) \
_ (0xc26f, stampede_authorization) \
_ (0xc281, proprietary_authentication_a) \
_ (0xc283, proprietary_authentication_b) \
_ (0xc481, proprietary_node_id_authentication)
typedef enum
{
#define _(n,f) PPP_PROTOCOL_##f = n,
foreach_ppp_protocol
#undef _
} ppp_protocol_t;
/* PPP Link Control Protocol (LCP) and Internet Protocol Control Protocol (IPCP) Codes
The Point-to-Point Protocol (PPP) Link Control Protocol (LCP),
the Compression Control Protocol (CCP), Internet Protocol Control
Protocol (IPCP), and other control protocols, contain an 8 bit
Code field which identifies the type of packet. */
#define foreach_ppp_lcp_code \
_ (0, vendor_specific) \
_ (1, configure_request) \
_ (2, configure_ack) \
_ (3, configure_nak) \
_ (4, configure_reject) \
_ (5, terminate_request) \
_ (6, terminate_ack) \
_ (7, code_reject) \
_ (8, protocol_reject) \
_ (9, echo_request) \
_ (10, echo_reply) \
_ (11, discard_request) \
_ (12, identification) \
_ (13, time_remaining) \
_ (14, reset_request) \
_ (15, reset_reply)
typedef struct
{
/* Set to 0xff 0x03 */
u8 address, control;
/* Layer 3 protocol for this packet. */
u16 protocol;
} ppp_header_t;
#endif /* included_vnet_ppp_packet_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

114
src/plugins/ppp/pg.c Normal file
View File

@ -0,0 +1,114 @@
/*
* Copyright (c) 2015 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.
*/
/*
* ppp_pg.c: packet generator ppp interface
*
* Copyright (c) 2008 Eliot Dresselhaus
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <vlib/vlib.h>
#include <vnet/pg/pg.h>
#include <plugins/ppp/ppp.h>
typedef struct
{
pg_edit_t address;
pg_edit_t control;
pg_edit_t protocol;
} pg_ppp_header_t;
static inline void
pg_ppp_header_init (pg_ppp_header_t * e)
{
pg_edit_init (&e->address, ppp_header_t, address);
pg_edit_init (&e->control, ppp_header_t, control);
pg_edit_init (&e->protocol, ppp_header_t, protocol);
}
uword
unformat_pg_ppp_header (unformat_input_t * input, va_list * args)
{
pg_stream_t *s = va_arg (*args, pg_stream_t *);
pg_ppp_header_t *h;
u32 group_index, error;
h = pg_create_edit_group (s, sizeof (h[0]), sizeof (ppp_header_t),
&group_index);
pg_ppp_header_init (h);
pg_edit_set_fixed (&h->address, 0xff);
pg_edit_set_fixed (&h->control, 0x03);
error = 1;
if (!unformat (input, "%U",
unformat_pg_edit,
unformat_ppp_protocol_net_byte_order, &h->protocol))
goto done;
{
ppp_main_t *pm = &ppp_main;
ppp_protocol_info_t *pi = 0;
pg_node_t *pg_node = 0;
if (h->protocol.type == PG_EDIT_FIXED)
{
u16 t = *(u16 *) h->protocol.values[PG_EDIT_LO];
pi = ppp_get_protocol_info (pm, clib_net_to_host_u16 (t));
if (pi && pi->node_index != ~0)
pg_node = pg_get_node (pi->node_index);
}
if (pg_node && pg_node->unformat_edit
&& unformat_user (input, pg_node->unformat_edit, s))
;
else if (!unformat_user (input, unformat_pg_payload, s))
goto done;
}
error = 0;
done:
if (error)
pg_free_edit_group (s);
return error == 0;
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

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

270
src/plugins/ppp/ppp.c Normal file
View File

@ -0,0 +1,270 @@
/*
* 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.
*/
/*
* ppp.c: ppp support
*
* Copyright (c) 2010 Eliot Dresselhaus
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <vnet/vnet.h>
#include <plugins/ppp/ppp.h>
/* Global main structure. */
ppp_main_t ppp_main;
u8 *
format_ppp_protocol (u8 * s, va_list * args)
{
ppp_protocol_t p = va_arg (*args, u32);
ppp_main_t *pm = &ppp_main;
ppp_protocol_info_t *pi = ppp_get_protocol_info (pm, p);
if (pi)
s = format (s, "%s", pi->name);
else
s = format (s, "0x%04x", p);
return s;
}
u8 *
format_ppp_header_with_length (u8 * s, va_list * args)
{
ppp_main_t *pm = &ppp_main;
ppp_header_t *h = va_arg (*args, ppp_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
ppp_protocol_t p = clib_net_to_host_u16 (h->protocol);
u32 indent, header_bytes;
header_bytes = sizeof (h[0]);
if (max_header_bytes != 0 && header_bytes > max_header_bytes)
return format (s, "ppp header truncated");
indent = format_get_indent (s);
s = format (s, "PPP %U", format_ppp_protocol, p);
if (h->address != 0xff)
s = format (s, ", address 0x%02x", h->address);
if (h->control != 0x03)
s = format (s, ", control 0x%02x", h->control);
if (max_header_bytes != 0 && header_bytes > max_header_bytes)
{
ppp_protocol_info_t *pi = ppp_get_protocol_info (pm, p);
vlib_node_t *node = vlib_get_node (pm->vlib_main, pi->node_index);
if (node->format_buffer)
s = format (s, "\n%U%U",
format_white_space, indent,
node->format_buffer, (void *) (h + 1),
max_header_bytes - header_bytes);
}
return s;
}
u8 *
format_ppp_header (u8 * s, va_list * args)
{
ppp_header_t *h = va_arg (*args, ppp_header_t *);
return format (s, "%U", format_ppp_header_with_length, h, 0);
}
/* Returns ppp protocol as an int in host byte order. */
uword
unformat_ppp_protocol_host_byte_order (unformat_input_t * input,
va_list * args)
{
u16 *result = va_arg (*args, u16 *);
ppp_main_t *pm = &ppp_main;
int p, i;
/* Numeric type. */
if (unformat (input, "0x%x", &p) || unformat (input, "%d", &p))
{
if (p >= (1 << 16))
return 0;
*result = p;
return 1;
}
/* Named type. */
if (unformat_user (input, unformat_vlib_number_by_name,
pm->protocol_info_by_name, &i))
{
ppp_protocol_info_t *pi = vec_elt_at_index (pm->protocol_infos, i);
*result = pi->protocol;
return 1;
}
return 0;
}
uword
unformat_ppp_protocol_net_byte_order (unformat_input_t * input,
va_list * args)
{
u16 *result = va_arg (*args, u16 *);
if (!unformat_user (input, unformat_ppp_protocol_host_byte_order, result))
return 0;
*result = clib_host_to_net_u16 ((u16) * result);
return 1;
}
uword
unformat_ppp_header (unformat_input_t * input, va_list * args)
{
u8 **result = va_arg (*args, u8 **);
ppp_header_t _h, *h = &_h;
u16 p;
if (!unformat (input, "%U", unformat_ppp_protocol_host_byte_order, &p))
return 0;
h->address = 0xff;
h->control = 0x03;
h->protocol = clib_host_to_net_u16 (p);
/* Add header to result. */
{
void *p;
u32 n_bytes = sizeof (h[0]);
vec_add2 (*result, p, n_bytes);
clib_memcpy (p, h, n_bytes);
}
return 1;
}
static u8 *
ppp_build_rewrite (vnet_main_t * vnm,
u32 sw_if_index,
vnet_link_t link_type, const void *dst_hw_address)
{
ppp_header_t *h;
u8 *rewrite = NULL;
ppp_protocol_t protocol;
switch (link_type)
{
#define _(a,b) case VNET_LINK_##a: protocol = PPP_PROTOCOL_##b; break
_(IP4, ip4);
_(IP6, ip6);
_(MPLS, mpls_unicast);
#undef _
default:
return (NULL);
}
vec_validate (rewrite, sizeof (*h) - 1);
h = (ppp_header_t *) rewrite;
h->address = 0xff;
h->control = 0x03;
h->protocol = clib_host_to_net_u16 (protocol);
return (rewrite);
}
VNET_HW_INTERFACE_CLASS (ppp_hw_interface_class) = {
.name = "PPP",
.format_header = format_ppp_header_with_length,
.unformat_header = unformat_ppp_header,
.build_rewrite = ppp_build_rewrite,
.flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
};
static void
add_protocol (ppp_main_t * pm, ppp_protocol_t protocol, char *protocol_name)
{
ppp_protocol_info_t *pi;
u32 i;
vec_add2 (pm->protocol_infos, pi, 1);
i = pi - pm->protocol_infos;
pi->name = protocol_name;
pi->protocol = protocol;
pi->next_index = pi->node_index = ~0;
hash_set (pm->protocol_info_by_protocol, protocol, i);
hash_set_mem (pm->protocol_info_by_name, pi->name, i);
}
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));
#define _(n,s) add_protocol (pm, PPP_PROTOCOL_##s, #s);
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);
}
VLIB_INIT_FUNCTION (ppp_init);
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

120
src/plugins/ppp/ppp.h Normal file
View File

@ -0,0 +1,120 @@
/*
* 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.
*/
/*
* ppp.h: types/functions for ppp.
*
* Copyright (c) 2008 Eliot Dresselhaus
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef included_ppp_h
#define included_ppp_h
#include <vnet/vnet.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 <ppp/error.def>
#undef ppp_error
PPP_N_ERROR,
} ppp_error_t;
typedef struct
{
/* Name (a c string). */
char *name;
/* PPP protocol type in host byte order. */
ppp_protocol_t protocol;
/* Node which handles this type. */
u32 node_index;
/* Next index for this type. */
u32 next_index;
} ppp_protocol_info_t;
typedef struct
{
vlib_main_t *vlib_main;
ppp_protocol_info_t *protocol_infos;
/* Hash tables mapping name/protocol to protocol info index. */
uword *protocol_info_by_name, *protocol_info_by_protocol;
} ppp_main_t;
always_inline ppp_protocol_info_t *
ppp_get_protocol_info (ppp_main_t * em, ppp_protocol_t protocol)
{
uword *p = hash_get (em->protocol_info_by_protocol, protocol);
return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0;
}
extern ppp_main_t ppp_main;
/* Register given node index to take input for given ppp type. */
void
ppp_register_input_type (vlib_main_t * vm,
ppp_protocol_t protocol, u32 node_index);
format_function_t format_ppp_protocol;
format_function_t format_ppp_header;
format_function_t format_ppp_header_with_length;
/* Parse ppp protocol as 0xXXXX or protocol name.
In either host or network byte order. */
unformat_function_t unformat_ppp_protocol_host_byte_order;
unformat_function_t unformat_ppp_protocol_net_byte_order;
/* Parse ppp header. */
unformat_function_t unformat_ppp_header;
unformat_function_t unformat_pg_ppp_header;
__clib_export void ppp_register_input_protocol (vlib_main_t *vm,
ppp_protocol_t protocol,
u32 node_index);
#endif /* included_ppp_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

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 {