Restore the plugin to its original state

When I started in my copy, I removed a bunch of code and options that I
felt were distracting. I also renamed lots of elements like 'linux-cp'
and 'Linux CP' and 'Linux-CP' to just be 'lcpng'.

Now, rename all of this back, and make it ready for upstreaming.

The only diffs between my repo and upstream now are the includes and the
lcpng_interface.[ch] code changes, which is good.
This commit is contained in:
Pim van Pelt
2021-08-12 21:18:44 +02:00
parent a6e71359c5
commit 97b9894dce
8 changed files with 128 additions and 89 deletions

28
lcpng.c
View File

@ -24,28 +24,28 @@
lcp_main_t lcp_main;
u8 *
lcp_get_netns (void)
lcp_get_default_ns (void)
{
lcp_main_t *lcpm = &lcp_main;
if (lcpm->netns_name[0] == 0)
if (lcpm->default_namespace[0] == 0)
return 0;
return lcpm->netns_name;
return lcpm->default_namespace;
}
int
lcp_get_netns_fd (void)
lcp_get_default_ns_fd (void)
{
lcp_main_t *lcpm = &lcp_main;
return lcpm->netns_fd;
return lcpm->default_ns_fd;
}
/*
* ns is expected to be or look like a NUL-terminated C string.
*/
int
lcp_set_netns (u8 *ns)
lcp_set_default_ns (u8 *ns)
{
lcp_main_t *lcpm = &lcp_main;
char *p;
@ -59,18 +59,18 @@ lcp_set_netns (u8 *ns)
if (!p || *p == 0)
{
clib_memset (lcpm->netns_name, 0,
sizeof (lcpm->netns_name));
if (lcpm->netns_fd > 0)
close (lcpm->netns_fd);
lcpm->netns_fd = 0;
clib_memset (lcpm->default_namespace, 0,
sizeof (lcpm->default_namespace));
if (lcpm->default_ns_fd > 0)
close (lcpm->default_ns_fd);
lcpm->default_ns_fd = 0;
return 0;
}
clib_strncpy ((char *) lcpm->netns_name, p, LCP_NS_LEN - 1);
clib_strncpy ((char *) lcpm->default_namespace, p, LCP_NS_LEN - 1);
s = format (0, "/var/run/netns/%s%c", (char *) lcpm->netns_name, 0);
lcpm->netns_fd = open ((char *) s, O_RDONLY);
s = format (0, "/var/run/netns/%s%c", (char *) lcpm->default_namespace, 0);
lcpm->default_ns_fd = open ((char *) s, O_RDONLY);
vec_free (s);
return 0;

12
lcpng.h
View File

@ -22,8 +22,8 @@
typedef struct lcp_main_s
{
u16 msg_id_base; /* API message ID base */
u8 netns_name[LCP_NS_LEN]; /* namespace, if set */
int netns_fd;
u8 default_namespace[LCP_NS_LEN]; /* default namespace if set */
int default_ns_fd;
/* Set when Unit testing */
u8 test_mode;
} lcp_main_t;
@ -31,11 +31,11 @@ typedef struct lcp_main_s
extern lcp_main_t lcp_main;
/**
* Get/Set the namespace in which to create LCP host taps.
* Get/Set the default namespace for LCP host taps.
*/
int lcp_set_netns (u8 *ns);
u8 *lcp_get_netns (void); /* Returns NULL or shared string */
int lcp_get_netns_fd (void);
int lcp_set_default_ns (u8 *ns);
u8 *lcp_get_default_ns (void); /* Returns NULL or shared string */
int lcp_get_default_ns_fd (void);
#endif

View File

@ -185,16 +185,16 @@ lcp_adj_show_cmd (vlib_main_t *vm, unformat_input_t *input,
if (unformat (input, "verbose"))
verbose = 1;
vlib_cli_output (vm, "lcpng Adjs:\n%U", BV (format_bihash), &lcp_adj_tbl,
vlib_cli_output (vm, "lcp Adjs:\n%U", BV (format_bihash), &lcp_adj_tbl,
verbose);
return 0;
}
VLIB_CLI_COMMAND (lcp_itf_pair_show_cmd_node, static) = {
.path = "show lcpng adj",
.path = "show lcp adj",
.function = lcp_adj_show_cmd,
.short_help = "show lcpng adj",
.short_help = "show lcp adj",
.is_mp_safe = 1,
};
@ -210,7 +210,7 @@ lcp_adj_init (vlib_main_t *vm)
{
adj_type = adj_delegate_register_new_type (&lcp_adj_vft);
BV (clib_bihash_init) (&lcp_adj_tbl, "lcpng ADJ table", 1024, 1 << 24);
BV (clib_bihash_init) (&lcp_adj_tbl, "lcp ADJ table", 1024, 1 << 24);
BV (clib_bihash_set_kvp_format_fn) (&lcp_adj_tbl, format_lcp_adj_kvp);
return (NULL);

View File

@ -21,34 +21,34 @@ option version = "1.0.0";
import "vnet/interface_types.api";
/** \brief Set the namespace for Linux Control Plane host taps
/** \brief Set the default Linux Control Plane namespace
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param namespace - the new namespace; namespace[0] == 0 iff none
@param namespace - the new default namespace; namespace[0] == 0 iff none
*/
autoreply define lcp_netns_set
autoreply define lcp_default_ns_set
{
u32 client_index;
u32 context;
string namespace[32]; /* LCP_NS_LEN */
};
/** \brief get the Linux Control Plane namespace
/** \brief get the default Linux Control Plane namespace
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
*/
define lcp_netns_get
define lcp_default_ns_get
{
u32 client_index;
u32 context;
};
/** \brief get the Linux Control Plane namespace
/** \brief get the default Linux Control Plane namespace
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param namespace - the namespace; namespace[0] == 0 iff none
@param namespace - the default namespace; namespace[0] == 0 iff none
*/
define lcp_netns_get_reply
define lcp_default_ns_get_reply
{
u32 context;
string namespace[32]; /* LCP_NS_LEN */
@ -171,8 +171,8 @@ counters linuxcp {
};
paths {
"/err/lcpng-arp-phy" "lcpng";
"/err/lcpng-arp-host" "lcpng";
"/err/linux-cp-arp-phy" "linuxcp";
"/err/linux-cp-arp-host" "linuxcp";
};
/*

View File

@ -169,22 +169,22 @@ vl_api_lcp_itf_pair_get_t_handler (vl_api_lcp_itf_pair_get_t *mp)
}
static void
vl_api_lcp_netns_set_t_handler (vl_api_lcp_netns_set_t *mp)
vl_api_lcp_default_ns_set_t_handler (vl_api_lcp_default_ns_set_t *mp)
{
vl_api_lcp_netns_set_reply_t *rmp;
vl_api_lcp_default_ns_set_reply_t *rmp;
int rv;
mp->namespace[LCP_NS_LEN - 1] = 0;
rv = lcp_set_netns (mp->namespace);
rv = lcp_set_default_ns (mp->namespace);
REPLY_MACRO (VL_API_LCP_NETNS_SET_REPLY);
REPLY_MACRO (VL_API_LCP_DEFAULT_NS_SET_REPLY);
}
static void
vl_api_lcp_netns_get_t_handler (vl_api_lcp_netns_get_t *mp)
vl_api_lcp_default_ns_get_t_handler (vl_api_lcp_default_ns_get_t *mp)
{
lcp_main_t *lcpm = &lcp_main;
vl_api_lcp_netns_get_reply_t *rmp;
vl_api_lcp_default_ns_get_reply_t *rmp;
vl_api_registration_t *reg;
char *ns;
@ -194,10 +194,10 @@ vl_api_lcp_netns_get_t_handler (vl_api_lcp_netns_get_t *mp)
rmp = vl_msg_api_alloc (sizeof (*rmp));
clib_memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = (VL_API_LCP_NETNS_GET_REPLY + lcpm->msg_id_base);
rmp->_vl_msg_id = (VL_API_LCP_DEFAULT_NS_GET_REPLY + lcpm->msg_id_base);
rmp->context = mp->context;
ns = (char *) lcp_get_netns ();
ns = (char *) lcp_get_default_ns ();
if (ns)
clib_strncpy ((char *) rmp->namespace, ns, LCP_NS_LEN - 1);

View File

@ -99,18 +99,57 @@ lcp_itf_pair_create_command_fn (vlib_main_t *vm, unformat_input_t *input,
vec_free (ns);
if (r)
return clib_error_return (0, "lcpng pair creation failed (%d)", r);
return clib_error_return (0, "lcp pair creation failed (%d)", r);
return 0;
}
VLIB_CLI_COMMAND (lcp_itf_pair_create_command, static) = {
.path = "lcpng create",
.short_help = "lcpng create <sw_if_index>|<if-name> host-if <host-if-name> "
.path = "lcp create",
.short_help = "lcp create <sw_if_index>|<if-name> host-if <host-if-name> "
"netns <namespace> [tun]",
.function = lcp_itf_pair_create_command_fn,
};
static clib_error_t *
lcp_default_netns_command_fn (vlib_main_t *vm, unformat_input_t *input,
vlib_cli_command_t *cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
u8 *ns;
int r;
if (!unformat_user (input, unformat_line_input, line_input))
return 0;
ns = 0;
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "netns %s", &ns))
;
else if (unformat (line_input, "clear netns"))
;
}
unformat_free (line_input);
vlib_cli_output (vm, "lcp set default netns '%s'\n", (char *) ns);
r = lcp_set_default_ns (ns);
if (r)
return clib_error_return (0, "linux-cp set default netns failed (%d)", r);
return 0;
}
VLIB_CLI_COMMAND (lcp_default_netns_command, static) = {
.path = "lcp default",
.short_help = "lcp default netns [<namespace>]",
.function = lcp_default_netns_command_fn,
};
static clib_error_t *
lcp_itf_pair_delete_command_fn (vlib_main_t *vm, unformat_input_t *input,
vlib_cli_command_t *cmd)
@ -145,13 +184,13 @@ lcp_itf_pair_delete_command_fn (vlib_main_t *vm, unformat_input_t *input,
r = lcp_itf_pair_delete (sw_if_index);
if (r)
return clib_error_return (0, "lcpng pair deletion failed (%d)", r);
return clib_error_return (0, "lcp pair deletion failed (%d)", r);
return 0;
}
VLIB_CLI_COMMAND (lcp_itf_pair_delete_command, static) = {
.path = "lcpng delete",
.short_help = "lcpng delete <sw_if_index>|<if-name>",
.path = "lcp delete",
.short_help = "lcp delete <sw_if_index>|<if-name>",
.function = lcp_itf_pair_delete_command_fn,
};
@ -180,9 +219,9 @@ lcp_itf_pair_show_cmd (vlib_main_t *vm, unformat_input_t *input,
}
VLIB_CLI_COMMAND (lcp_itf_pair_show_cmd_node, static) = {
.path = "show lcpng",
.path = "show lcp",
.function = lcp_itf_pair_show_cmd,
.short_help = "show lcpng [phy <interface>]",
.short_help = "show lcp [phy <interface>]",
.is_mp_safe = 1,
};

View File

@ -145,7 +145,7 @@ VLIB_NODE_FN (lip_punt_node)
}
VLIB_REGISTER_NODE (lip_punt_node) = {
.name = "lcpng-punt",
.name = "linux-cp-punt",
.vector_size = sizeof (u32),
.format_trace = format_lip_punt_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
@ -180,7 +180,7 @@ format_lcp_punt_l3_trace (u8 *s, va_list *args)
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
lcp_punt_l3_trace_t *t = va_arg (*args, lcp_punt_l3_trace_t *);
s = format (s, "lcpng-punt-l3: %u", t->phy_sw_if_index);
s = format (s, "linux-cp-punt-l3: %u", t->phy_sw_if_index);
return s;
}
@ -248,7 +248,7 @@ VLIB_NODE_FN (lcp_punt_l3_node)
}
VLIB_REGISTER_NODE (lcp_punt_l3_node) = {
.name = "lcpng-punt-l3",
.name = "linux-cp-punt-l3",
.vector_size = sizeof (u32),
.format_trace = format_lcp_punt_l3_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
@ -261,13 +261,13 @@ VLIB_REGISTER_NODE (lcp_punt_l3_node) = {
VNET_FEATURE_INIT (lcp_punt_l3_ip4, static) = {
.arc_name = "ip4-punt",
.node_name = "lcpng-punt-l3",
.node_name = "linux-cp-punt-l3",
.runs_before = VNET_FEATURES ("ip4-punt-redirect"),
};
VNET_FEATURE_INIT (lip_punt_l3_ip6, static) = {
.arc_name = "ip6-punt",
.node_name = "lcpng-punt-l3",
.node_name = "linux-cp-punt-l3",
.runs_before = VNET_FEATURES ("ip6-punt-redirect"),
};
@ -406,7 +406,7 @@ VLIB_NODE_FN (lcp_xc_ip6)
return (lcp_xc_inline (vm, node, frame, AF_IP6));
}
VLIB_REGISTER_NODE (lcp_xc_ip4) = { .name = "lcpng-xc-ip4",
VLIB_REGISTER_NODE (lcp_xc_ip4) = { .name = "linux-cp-xc-ip4",
.vector_size = sizeof (u32),
.format_trace = format_lcp_xc_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
@ -414,14 +414,14 @@ VLIB_REGISTER_NODE (lcp_xc_ip4) = { .name = "lcpng-xc-ip4",
VNET_FEATURE_INIT (lcp_xc_ip4_ucast_node, static) = {
.arc_name = "ip4-unicast",
.node_name = "lcpng-xc-ip4",
.node_name = "linux-cp-xc-ip4",
};
VNET_FEATURE_INIT (lcp_xc_ip4_mcast_node, static) = {
.arc_name = "ip4-multicast",
.node_name = "lcpng-xc-ip4",
.node_name = "linux-cp-xc-ip4",
};
VLIB_REGISTER_NODE (lcp_xc_ip6) = { .name = "lcpng-xc-ip6",
VLIB_REGISTER_NODE (lcp_xc_ip6) = { .name = "linux-cp-xc-ip6",
.vector_size = sizeof (u32),
.format_trace = format_lcp_xc_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
@ -429,11 +429,11 @@ VLIB_REGISTER_NODE (lcp_xc_ip6) = { .name = "lcpng-xc-ip6",
VNET_FEATURE_INIT (lcp_xc_ip6_ucast_node, static) = {
.arc_name = "ip6-unicast",
.node_name = "lcpng-xc-ip6",
.node_name = "linux-cp-xc-ip6",
};
VNET_FEATURE_INIT (lcp_xc_ip6_mcast_node, static) = {
.arc_name = "ip6-multicast",
.node_name = "lcpng-xc-ip6",
.node_name = "linux-cp-xc-ip6",
};
typedef enum
@ -526,7 +526,7 @@ VLIB_NODE_FN (lcp_xc_l3_ip6_node)
}
VLIB_REGISTER_NODE (lcp_xc_l3_ip4_node) = {
.name = "lcpng-xc-l3-ip4",
.name = "linux-cp-xc-l3-ip4",
.vector_size = sizeof (u32),
.format_trace = format_lcp_xc_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
@ -539,16 +539,16 @@ VLIB_REGISTER_NODE (lcp_xc_l3_ip4_node) = {
VNET_FEATURE_INIT (lcp_xc_node_l3_ip4_unicast, static) = {
.arc_name = "ip4-unicast",
.node_name = "lcpng-xc-l3-ip4",
.node_name = "linux-cp-xc-l3-ip4",
};
VNET_FEATURE_INIT (lcp_xc_node_l3_ip4_multicaast, static) = {
.arc_name = "ip4-multicast",
.node_name = "lcpng-xc-l3-ip4",
.node_name = "linux-cp-xc-l3-ip4",
};
VLIB_REGISTER_NODE (lcp_xc_l3_ip6_node) = {
.name = "lcpng-xc-l3-ip6",
.name = "linux-cp-xc-l3-ip6",
.vector_size = sizeof (u32),
.format_trace = format_lcp_xc_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
@ -561,12 +561,12 @@ VLIB_REGISTER_NODE (lcp_xc_l3_ip6_node) = {
VNET_FEATURE_INIT (lcp_xc_node_l3_ip6_unicast, static) = {
.arc_name = "ip6-unicast",
.node_name = "lcpng-xc-l3-ip6",
.node_name = "linux-cp-xc-l3-ip6",
};
VNET_FEATURE_INIT (lcp_xc_node_l3_ip6_multicast, static) = {
.arc_name = "ip6-multicast",
.node_name = "lcpng-xc-l3-ip6",
.node_name = "linux-cp-xc-l3-ip6",
};
#define foreach_lcp_arp \
@ -800,7 +800,7 @@ VLIB_NODE_FN (lcp_arp_phy_node)
}
VLIB_REGISTER_NODE (lcp_arp_phy_node) = {
.name = "lcpng-arp-phy",
.name = "linux-cp-arp-phy",
.vector_size = sizeof (u32),
.format_trace = format_lcp_arp_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
@ -817,7 +817,7 @@ VLIB_REGISTER_NODE (lcp_arp_phy_node) = {
VNET_FEATURE_INIT (lcp_arp_phy_arp_feat, static) = {
.arc_name = "arp",
.node_name = "lcpng-arp-phy",
.node_name = "linux-cp-arp-phy",
.runs_before = VNET_FEATURES ("arp-reply"),
};
@ -884,7 +884,7 @@ VLIB_NODE_FN (lcp_arp_host_node)
}
VLIB_REGISTER_NODE (lcp_arp_host_node) = {
.name = "lcpng-arp-host",
.name = "linux-cp-arp-host",
.vector_size = sizeof (u32),
.format_trace = format_lcp_arp_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
@ -901,7 +901,7 @@ VLIB_REGISTER_NODE (lcp_arp_host_node) = {
VNET_FEATURE_INIT (lcp_arp_host_arp_feat, static) = {
.arc_name = "arp",
.node_name = "lcpng-arp-host",
.node_name = "linux-cp-arp-host",
.runs_before = VNET_FEATURES ("arp-reply"),
};

View File

@ -137,7 +137,7 @@ lcp_itf_pair_show (u32 phy_sw_if_index)
index_t api;
vm = vlib_get_main ();
ns = lcp_get_netns ();
ns = lcp_get_default_ns ();
vlib_cli_output (vm, "lcpng netns '%s'\n",
ns ? (char *) ns : "<unset>");
@ -193,12 +193,12 @@ lcp_itf_pair_add_sub (u32 vif, u8 *host_if_name, u32 sub_sw_if_index,
const char *lcp_itf_l3_feat_names[N_LCP_ITF_HOST][N_AF] = {
[LCP_ITF_HOST_TAP] = {
[AF_IP4] = "lcpng-xc-ip4",
[AF_IP6] = "lcpng-xc-ip6",
[AF_IP4] = "linux-cp-xc-ip4",
[AF_IP6] = "linux-cp-xc-ip6",
},
[LCP_ITF_HOST_TUN] = {
[AF_IP4] = "lcpng-xc-l3-ip4",
[AF_IP6] = "lcpng-xc-l3-ip6",
[AF_IP4] = "linux-cp-xc-l3-ip4",
[AF_IP6] = "linux-cp-xc-l3-ip6",
},
};
@ -318,16 +318,16 @@ lcp_itf_pair_add (u32 host_sw_if_index, u32 phy_sw_if_index, u8 *host_name,
/* enable ARP feature node for broadcast interfaces */
if (lip->lip_host_type != LCP_ITF_HOST_TUN)
{
vnet_feature_enable_disable ("arp", "lcpng-arp-phy",
vnet_feature_enable_disable ("arp", "linux-cp-arp-phy",
lip->lip_phy_sw_if_index, 1, NULL, 0);
vnet_feature_enable_disable ("arp", "lcpng-arp-host",
vnet_feature_enable_disable ("arp", "linux-cp-arp-host",
lip->lip_host_sw_if_index, 1, NULL, 0);
}
else
{
vnet_feature_enable_disable ("ip4-punt", "lcpng-punt-l3", 0, 1, NULL,
vnet_feature_enable_disable ("ip4-punt", "linux-cp-punt-l3", 0, 1, NULL,
0);
vnet_feature_enable_disable ("ip6-punt", "lcpng-punt-l3", 0, 1, NULL,
vnet_feature_enable_disable ("ip6-punt", "linux-cp-punt-l3", 0, 1, NULL,
0);
}
@ -448,16 +448,16 @@ lcp_itf_pair_del (u32 phy_sw_if_index)
/* disable ARP feature node for broadcast interfaces */
if (lip->lip_host_type != LCP_ITF_HOST_TUN)
{
vnet_feature_enable_disable ("arp", "lcpng-arp-phy",
vnet_feature_enable_disable ("arp", "linux-cp-arp-phy",
lip->lip_phy_sw_if_index, 0, NULL, 0);
vnet_feature_enable_disable ("arp", "lcpng-arp-host",
vnet_feature_enable_disable ("arp", "linux-cp-arp-host",
lip->lip_host_sw_if_index, 0, NULL, 0);
}
else
{
vnet_feature_enable_disable ("ip4-punt", "lcpng-punt-l3", 0, 0, NULL,
vnet_feature_enable_disable ("ip4-punt", "linux-cp-punt-l3", 0, 0, NULL,
0);
vnet_feature_enable_disable ("ip6-punt", "lcpng-punt-l3", 0, 0, NULL,
vnet_feature_enable_disable ("ip6-punt", "linux-cp-punt-l3", 0, 0, NULL,
0);
}
@ -538,7 +538,7 @@ lcp_itf_pair_config (vlib_main_t *vm, unformat_input_t *input)
if (unformat (input, "netns %v", &netns))
{
vec_add1 (netns, 0);
if (lcp_set_netns (netns) < 0)
if (lcp_set_default_ns (netns) < 0)
{
return clib_error_return (0,
"lcpng namespace must be less than %d characters",
@ -703,7 +703,7 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
* Otherwise, use netns if defined, otherwise use the OS default.
*/
if (ns == 0 || ns[0] == 0)
ns = lcp_get_netns ();
ns = lcp_get_default_ns ();
/* sub interfaces do not need a tap created */
if (vnet_sw_interface_is_sub (vnm, phy_sw_if_index))
@ -1087,11 +1087,11 @@ VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (lcp_itf_pair_link_up_down);
static clib_error_t *
lcp_itf_pair_init (vlib_main_t *vm)
{
vlib_punt_hdl_t punt_hdl = vlib_punt_client_register ("lcpng");
vlib_punt_hdl_t punt_hdl = vlib_punt_client_register ("linux-cp");
/* punt IKE */
vlib_punt_register (punt_hdl, ipsec_punt_reason[IPSEC_PUNT_IP4_SPI_UDP_0],
"lcpng-punt");
"linux-cp-punt");
/* punt all unknown ports */
udp_punt_unknown (vm, 0, 1);
@ -1099,7 +1099,7 @@ lcp_itf_pair_init (vlib_main_t *vm)
tcp_punt_unknown (vm, 0, 1);
tcp_punt_unknown (vm, 1, 1);
lcp_itf_pair_logger = vlib_log_register_class ("lcpng", "itf");
lcp_itf_pair_logger = vlib_log_register_class ("linux-cp", "if");
return NULL;
}