gre: move to a plugin

Move GRE 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.

JIRA: VPP-2044

Type: improvement
Change-Id: I7f64cecd97538a7492e56a41558dab58281a9fa5
Signed-off-by: Chuhao Tang <nicotang@cisco.com>
This commit is contained in:
Chuhao Tang
2023-04-27 15:43:42 +02:00
committed by Beno�t Ganne
parent 683bdb6743
commit cefb178aa4
13 changed files with 381 additions and 397 deletions
+35
View File
@@ -0,0 +1,35 @@
# Copyright (c) 2023 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(gre
SOURCES
gre.c
node.c
gre_api.c
interface.c
pg.c
plugin.c
MULTIARCH_SOURCES
node.c
gre.c
INSTALL_HEADERS
gre.h
error.def
API_FILES
gre.api
)
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -32,7 +32,7 @@ extern vnet_hw_interface_class_t mgre_hw_interface_class;
typedef enum
{
#define gre_error(n,s) GRE_ERROR_##n,
#include <vnet/gre/error.def>
#include <gre/error.def>
#undef gre_error
GRE_N_ERROR,
} gre_error_t;
@@ -23,26 +23,26 @@
#include <vnet/interface.h>
#include <vnet/api_errno.h>
#include <vnet/gre/gre.h>
#include <gre/gre.h>
#include <vnet/fib/fib_table.h>
#include <vnet/tunnel/tunnel_types_api.h>
#include <vnet/ip/ip_types_api.h>
#include <vnet/gre/gre.api_enum.h>
#include <vnet/gre/gre.api_types.h>
#include <gre/gre.api_enum.h>
#include <gre/gre.api_types.h>
#define REPLY_MSG_ID_BASE gre_main.msg_id_base
#include <vlibapi/api_helper_macros.h>
static int
gre_tunnel_type_decode (vl_api_gre_tunnel_type_t in, gre_tunnel_type_t * out)
gre_tunnel_type_decode (vl_api_gre_tunnel_type_t in, gre_tunnel_type_t *out)
{
switch (in)
{
#define _(n, v) \
case GRE_API_TUNNEL_TYPE_##n: \
*out = GRE_TUNNEL_TYPE_##n; \
return (0);
#define _(n, v) \
case GRE_API_TUNNEL_TYPE_##n: \
*out = GRE_TUNNEL_TYPE_##n; \
return (0);
foreach_gre_tunnel_type
#undef _
}
@@ -57,10 +57,10 @@ gre_tunnel_type_encode (gre_tunnel_type_t in)
switch (in)
{
#define _(n, v) \
case GRE_TUNNEL_TYPE_##n: \
out = GRE_API_TUNNEL_TYPE_##n; \
break;
#define _(n, v) \
case GRE_TUNNEL_TYPE_##n: \
out = GRE_API_TUNNEL_TYPE_##n; \
break;
foreach_gre_tunnel_type
#undef _
}
@@ -68,10 +68,10 @@ gre_tunnel_type_encode (gre_tunnel_type_t in)
return (out);
}
static void vl_api_gre_tunnel_add_del_t_handler
(vl_api_gre_tunnel_add_del_t * mp)
static void
vl_api_gre_tunnel_add_del_t_handler (vl_api_gre_tunnel_add_del_t *mp)
{
vnet_gre_tunnel_add_del_args_t _a = { }, *a = &_a;
vnet_gre_tunnel_add_del_args_t _a = {}, *a = &_a;
vl_api_gre_tunnel_add_del_reply_t *rmp;
tunnel_encap_decap_flags_t flags;
u32 sw_if_index = ~0;
@@ -119,40 +119,38 @@ static void vl_api_gre_tunnel_add_del_t_handler
out:
/* *INDENT-OFF* */
REPLY_MACRO2(VL_API_GRE_TUNNEL_ADD_DEL_REPLY,
({
rmp->sw_if_index = ntohl (sw_if_index);
}));
/* *INDENT-ON* */
}
static void send_gre_tunnel_details
(gre_tunnel_t * t, vl_api_gre_tunnel_dump_t * mp)
{
vl_api_gre_tunnel_details_t *rmp;
/* *INDENT-OFF* */
REPLY_MACRO_DETAILS2(VL_API_GRE_TUNNEL_DETAILS,
({
ip_address_encode (&t->tunnel_src, IP46_TYPE_ANY, &rmp->tunnel.src);
ip_address_encode (&t->tunnel_dst.fp_addr, IP46_TYPE_ANY, &rmp->tunnel.dst);
rmp->tunnel.outer_table_id =
htonl (fib_table_get_table_id
(t->outer_fib_index, t->tunnel_dst.fp_proto));
rmp->tunnel.type = gre_tunnel_type_encode (t->type);
rmp->tunnel.mode = tunnel_mode_encode (t->mode);
rmp->tunnel.flags = tunnel_encap_decap_flags_encode (t->flags);
rmp->tunnel.instance = htonl (t->user_instance);
rmp->tunnel.sw_if_index = htonl (t->sw_if_index);
rmp->tunnel.session_id = htons (t->session_id);
}));
REPLY_MACRO2 (VL_API_GRE_TUNNEL_ADD_DEL_REPLY,
({ rmp->sw_if_index = ntohl (sw_if_index); }));
/* *INDENT-ON* */
}
static void
vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
send_gre_tunnel_details (gre_tunnel_t *t, vl_api_gre_tunnel_dump_t *mp)
{
vl_api_gre_tunnel_details_t *rmp;
/* *INDENT-OFF* */
REPLY_MACRO_DETAILS2 (
VL_API_GRE_TUNNEL_DETAILS, ({
ip_address_encode (&t->tunnel_src, IP46_TYPE_ANY, &rmp->tunnel.src);
ip_address_encode (&t->tunnel_dst.fp_addr, IP46_TYPE_ANY,
&rmp->tunnel.dst);
rmp->tunnel.outer_table_id = htonl (
fib_table_get_table_id (t->outer_fib_index, t->tunnel_dst.fp_proto));
rmp->tunnel.type = gre_tunnel_type_encode (t->type);
rmp->tunnel.mode = tunnel_mode_encode (t->mode);
rmp->tunnel.flags = tunnel_encap_decap_flags_encode (t->flags);
rmp->tunnel.instance = htonl (t->user_instance);
rmp->tunnel.sw_if_index = htonl (t->sw_if_index);
rmp->tunnel.session_id = htons (t->session_id);
}));
/* *INDENT-ON* */
}
static void
vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t *mp)
{
vl_api_registration_t *reg;
gre_main_t *gm = &gre_main;
@@ -169,9 +167,9 @@ vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
{
/* *INDENT-OFF* */
pool_foreach (t, gm->tunnels)
{
send_gre_tunnel_details(t, mp);
}
{
send_gre_tunnel_details (t, mp);
}
/* *INDENT-ON* */
}
@@ -196,10 +194,10 @@ vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
*/
/* API definitions */
#include <vnet/format_fns.h>
#include <vnet/gre/gre.api.c>
#include <gre/gre.api.c>
static clib_error_t *
gre_api_hookup (vlib_main_t * vm)
gre_api_hookup (vlib_main_t *vm)
{
/*
* Set up the (msg_name, crc, message-id) table
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+6 -8
View File
@@ -17,7 +17,7 @@
#include <vlib/vlib.h>
#include <vnet/pg/pg.h>
#include <vnet/gre/gre.h>
#include <gre/gre.h>
typedef struct
{
@@ -26,14 +26,14 @@ typedef struct
} pg_gre_header_t;
static inline void
pg_gre_header_init (pg_gre_header_t * e)
pg_gre_header_init (pg_gre_header_t *e)
{
pg_edit_init (&e->flags_and_version, gre_header_t, flags_and_version);
pg_edit_init (&e->protocol, gre_header_t, protocol);
}
uword
unformat_pg_gre_header (unformat_input_t * input, va_list * args)
unformat_pg_gre_header (unformat_input_t *input, va_list *args)
{
pg_stream_t *s = va_arg (*args, pg_stream_t *);
pg_gre_header_t *h;
@@ -46,8 +46,7 @@ unformat_pg_gre_header (unformat_input_t * input, va_list * args)
pg_edit_set_fixed (&h->flags_and_version, 0);
error = 1;
if (!unformat (input, "%U",
unformat_pg_edit,
if (!unformat (input, "%U", unformat_pg_edit,
unformat_gre_protocol_net_byte_order, &h->protocol))
goto done;
@@ -64,8 +63,8 @@ unformat_pg_gre_header (unformat_input_t * input, va_list * args)
pg_node = pg_get_node (pi->node_index);
}
if (pg_node && pg_node->unformat_edit
&& unformat_user (input, pg_node->unformat_edit, s))
if (pg_node && pg_node->unformat_edit &&
unformat_user (input, pg_node->unformat_edit, s))
;
}
@@ -76,7 +75,6 @@ done:
return error == 0;
}
/*
* fd.io coding-style-patch-verification: ON
*
+26
View File
@@ -0,0 +1,26 @@
/*
* plugin.c: gre
*
* Copyright (c) 2023 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 = "Generic Routing Encapsulation (GRE) plugin",
};
+1 -1
View File
@@ -18,7 +18,7 @@
#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <nsh/nsh.h>
#include <vnet/gre/gre.h>
#include <gre/gre.h>
#include <vxlan/vxlan.h>
#include <vnet/vxlan-gpe/vxlan_gpe.h>
#include <vnet/l2/l2_classify.h>
-17
View File
@@ -668,27 +668,10 @@ list(APPEND VNET_API_FILES udp/udp.api)
##############################################################################
# Tunnel protocol: gre
##############################################################################
list(APPEND VNET_SOURCES
gre/gre.c
gre/node.c
gre/interface.c
gre/pg.c
gre/gre_api.c
)
list(APPEND VNET_MULTIARCH_SOURCES
gre/node.c
gre/gre.c
)
list(APPEND VNET_HEADERS
gre/gre.h
gre/packet.h
gre/error.def
)
list(APPEND VNET_API_FILES gre/gre.api)
##############################################################################
# Tunnel protocol: ipip
##############################################################################