Sync interface state from VPP to LCP

This is the first in a series of functions that aims to copy forward
interface changes in the VPP dataplane into the linux interfaces.

Capture link state changes (set interface state ...) and apply them
to Linux.

There's an important dissonance here:
- When Linux sets a parent interface up, all children also go up.

ip link set enp66s0f1 down
ip link add link enp66s0f1 name foo type vlan id 1234
ip link set foo down
ip link | grep enp66s0f1
9: enp66s0f1: <BROADCAST,MULTICAST> mtu 9000 qdisc mq state DOWN mode DEFAULT group default qlen 1000
61: foo@enp66s0f1: <BROADCAST,MULTICAST,M-DOWN> mtu 9000 qdisc noop state DOWN mode DEFAULT group default qlen 1000

ip link set enp66s0f1 up
ip link | grep s0f1
9: enp66s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc mq state UP mode DEFAULT group default qlen 1000
61: foo@enp66s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc noqueue state UP mode DEFAULT group default qlen 1000

While in VPP this is not so, there each individual interface and
sub-interface stands for itself. I think the proper fix here is to walk
all sub-interfaces when a phy changes, and force a sync of those from
VPP to LCP as well. I'll do that in a followup commit so it's easier to
roll back.
This commit is contained in:
Pim van Pelt
2021-08-12 22:29:13 +02:00
parent 97b9894dce
commit 7c15c84f6c
10 changed files with 342 additions and 294 deletions

View File

@ -44,6 +44,7 @@ add_vpp_plugin(lcpng_if
lcpng_if_api.c lcpng_if_api.c
lcpng_if_cli.c lcpng_if_cli.c
lcpng_if_node.c lcpng_if_node.c
lcpng_if_sync.c
API_FILES API_FILES
lcpng_if.api lcpng_if.api

25
lcpng.c
View File

@ -23,9 +23,7 @@
lcp_main_t lcp_main; lcp_main_t lcp_main;
u8 * u8 *lcp_get_default_ns(void) {
lcp_get_default_ns (void)
{
lcp_main_t *lcpm = &lcp_main; lcp_main_t *lcpm = &lcp_main;
if (lcpm->default_namespace[0] == 0) if (lcpm->default_namespace[0] == 0)
@ -33,9 +31,7 @@ lcp_get_default_ns (void)
return lcpm->default_namespace; return lcpm->default_namespace;
} }
int int lcp_get_default_ns_fd(void) {
lcp_get_default_ns_fd (void)
{
lcp_main_t *lcpm = &lcp_main; lcp_main_t *lcpm = &lcp_main;
return lcpm->default_ns_fd; return lcpm->default_ns_fd;
@ -44,9 +40,7 @@ lcp_get_default_ns_fd (void)
/* /*
* ns is expected to be or look like a NUL-terminated C string. * ns is expected to be or look like a NUL-terminated C string.
*/ */
int int lcp_set_default_ns(u8 *ns) {
lcp_set_default_ns (u8 *ns)
{
lcp_main_t *lcpm = &lcp_main; lcp_main_t *lcpm = &lcp_main;
char *p; char *p;
int len; int len;
@ -59,19 +53,18 @@ lcp_set_default_ns (u8 *ns)
if (!p || *p == 0) if (!p || *p == 0)
{ {
clib_memset (lcpm->default_namespace, 0, clib_memset(lcpm->default_namespace, 0, sizeof(lcpm->default_namespace));
sizeof (lcpm->default_namespace));
if (lcpm->default_ns_fd > 0) if (lcpm->default_ns_fd > 0)
close (lcpm->default_ns_fd); close(lcpm->default_ns_fd);
lcpm->default_ns_fd = 0; lcpm->default_ns_fd = 0;
return 0; return 0;
} }
clib_strncpy ((char *) lcpm->default_namespace, 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->default_namespace, 0); s = format(0, "/var/run/netns/%s%c", (char *)lcpm->default_namespace, 0);
lcpm->default_ns_fd = open ((char *) s, O_RDONLY); lcpm->default_ns_fd = open((char *)s, O_RDONLY);
vec_free (s); vec_free(s);
return 0; return 0;
} }

View File

@ -33,9 +33,9 @@ extern lcp_main_t lcp_main;
/** /**
* Get/Set the default namespace for LCP host taps. * Get/Set the default namespace for LCP host taps.
*/ */
int lcp_set_default_ns (u8 *ns); int lcp_set_default_ns(u8 *ns);
u8 *lcp_get_default_ns (void); /* Returns NULL or shared string */ u8 *lcp_get_default_ns(void); /* Returns NULL or shared string */
int lcp_get_default_ns_fd (void); int lcp_get_default_ns_fd(void);
#endif #endif

View File

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

View File

@ -169,20 +169,18 @@ vl_api_lcp_itf_pair_get_t_handler (vl_api_lcp_itf_pair_get_t *mp)
} }
static void static void
vl_api_lcp_default_ns_set_t_handler (vl_api_lcp_default_ns_set_t *mp) vl_api_lcp_default_ns_set_t_handler(vl_api_lcp_default_ns_set_t *mp) {
{
vl_api_lcp_default_ns_set_reply_t *rmp; vl_api_lcp_default_ns_set_reply_t *rmp;
int rv; int rv;
mp->namespace[LCP_NS_LEN - 1] = 0; mp->namespace[LCP_NS_LEN - 1] = 0;
rv = lcp_set_default_ns (mp->namespace); rv = lcp_set_default_ns(mp->namespace);
REPLY_MACRO (VL_API_LCP_DEFAULT_NS_SET_REPLY); REPLY_MACRO(VL_API_LCP_DEFAULT_NS_SET_REPLY);
} }
static void static void
vl_api_lcp_default_ns_get_t_handler (vl_api_lcp_default_ns_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; lcp_main_t *lcpm = &lcp_main;
vl_api_lcp_default_ns_get_reply_t *rmp; vl_api_lcp_default_ns_get_reply_t *rmp;
vl_api_registration_t *reg; vl_api_registration_t *reg;
@ -197,7 +195,7 @@ vl_api_lcp_default_ns_get_t_handler (vl_api_lcp_default_ns_get_t *mp)
rmp->_vl_msg_id = (VL_API_LCP_DEFAULT_NS_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; rmp->context = mp->context;
ns = (char *) lcp_get_default_ns (); ns = (char *)lcp_get_default_ns();
if (ns) if (ns)
clib_strncpy ((char *) rmp->namespace, ns, LCP_NS_LEN - 1); clib_strncpy ((char *) rmp->namespace, ns, LCP_NS_LEN - 1);

View File

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

View File

@ -144,14 +144,15 @@ VLIB_NODE_FN (lip_punt_node)
return frame->n_vectors; return frame->n_vectors;
} }
VLIB_REGISTER_NODE (lip_punt_node) = { VLIB_REGISTER_NODE(lip_punt_node) = {
.name = "linux-cp-punt", .name = "linux-cp-punt",
.vector_size = sizeof (u32), .vector_size = sizeof(u32),
.format_trace = format_lip_punt_trace, .format_trace = format_lip_punt_trace,
.type = VLIB_NODE_TYPE_INTERNAL, .type = VLIB_NODE_TYPE_INTERNAL,
.n_next_nodes = LIP_PUNT_N_NEXT, .n_next_nodes = LIP_PUNT_N_NEXT,
.next_nodes = { .next_nodes =
{
[LIP_PUNT_NEXT_DROP] = "error-drop", [LIP_PUNT_NEXT_DROP] = "error-drop",
[LIP_PUNT_NEXT_IO] = "interface-output", [LIP_PUNT_NEXT_IO] = "interface-output",
}, },
@ -180,7 +181,7 @@ format_lcp_punt_l3_trace (u8 *s, va_list *args)
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); 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 *); lcp_punt_l3_trace_t *t = va_arg (*args, lcp_punt_l3_trace_t *);
s = format (s, "linux-cp-punt-l3: %u", t->phy_sw_if_index); s = format(s, "linux-cp-punt-l3: %u", t->phy_sw_if_index);
return s; return s;
} }
@ -247,28 +248,29 @@ VLIB_NODE_FN (lcp_punt_l3_node)
return frame->n_vectors; return frame->n_vectors;
} }
VLIB_REGISTER_NODE (lcp_punt_l3_node) = { VLIB_REGISTER_NODE(lcp_punt_l3_node) = {
.name = "linux-cp-punt-l3", .name = "linux-cp-punt-l3",
.vector_size = sizeof (u32), .vector_size = sizeof(u32),
.format_trace = format_lcp_punt_l3_trace, .format_trace = format_lcp_punt_l3_trace,
.type = VLIB_NODE_TYPE_INTERNAL, .type = VLIB_NODE_TYPE_INTERNAL,
.n_next_nodes = 1, .n_next_nodes = 1,
.next_nodes = { .next_nodes =
{
[LCP_LOCAL_NEXT_DROP] = "error-drop", [LCP_LOCAL_NEXT_DROP] = "error-drop",
}, },
}; };
VNET_FEATURE_INIT (lcp_punt_l3_ip4, static) = { VNET_FEATURE_INIT(lcp_punt_l3_ip4, static) = {
.arc_name = "ip4-punt", .arc_name = "ip4-punt",
.node_name = "linux-cp-punt-l3", .node_name = "linux-cp-punt-l3",
.runs_before = VNET_FEATURES ("ip4-punt-redirect"), .runs_before = VNET_FEATURES("ip4-punt-redirect"),
}; };
VNET_FEATURE_INIT (lip_punt_l3_ip6, static) = { VNET_FEATURE_INIT(lip_punt_l3_ip6, static) = {
.arc_name = "ip6-punt", .arc_name = "ip6-punt",
.node_name = "linux-cp-punt-l3", .node_name = "linux-cp-punt-l3",
.runs_before = VNET_FEATURES ("ip6-punt-redirect"), .runs_before = VNET_FEATURES("ip6-punt-redirect"),
}; };
#define foreach_lcp_xc \ #define foreach_lcp_xc \
@ -406,32 +408,32 @@ VLIB_NODE_FN (lcp_xc_ip6)
return (lcp_xc_inline (vm, node, frame, AF_IP6)); return (lcp_xc_inline (vm, node, frame, AF_IP6));
} }
VLIB_REGISTER_NODE (lcp_xc_ip4) = { .name = "linux-cp-xc-ip4", VLIB_REGISTER_NODE(lcp_xc_ip4) = {.name = "linux-cp-xc-ip4",
.vector_size = sizeof (u32), .vector_size = sizeof(u32),
.format_trace = format_lcp_xc_trace, .format_trace = format_lcp_xc_trace,
.type = VLIB_NODE_TYPE_INTERNAL, .type = VLIB_NODE_TYPE_INTERNAL,
.sibling_of = "ip4-rewrite" }; .sibling_of = "ip4-rewrite"};
VNET_FEATURE_INIT (lcp_xc_ip4_ucast_node, static) = { VNET_FEATURE_INIT(lcp_xc_ip4_ucast_node, static) = {
.arc_name = "ip4-unicast", .arc_name = "ip4-unicast",
.node_name = "linux-cp-xc-ip4", .node_name = "linux-cp-xc-ip4",
}; };
VNET_FEATURE_INIT (lcp_xc_ip4_mcast_node, static) = { VNET_FEATURE_INIT(lcp_xc_ip4_mcast_node, static) = {
.arc_name = "ip4-multicast", .arc_name = "ip4-multicast",
.node_name = "linux-cp-xc-ip4", .node_name = "linux-cp-xc-ip4",
}; };
VLIB_REGISTER_NODE (lcp_xc_ip6) = { .name = "linux-cp-xc-ip6", VLIB_REGISTER_NODE(lcp_xc_ip6) = {.name = "linux-cp-xc-ip6",
.vector_size = sizeof (u32), .vector_size = sizeof(u32),
.format_trace = format_lcp_xc_trace, .format_trace = format_lcp_xc_trace,
.type = VLIB_NODE_TYPE_INTERNAL, .type = VLIB_NODE_TYPE_INTERNAL,
.sibling_of = "ip6-rewrite" }; .sibling_of = "ip6-rewrite"};
VNET_FEATURE_INIT (lcp_xc_ip6_ucast_node, static) = { VNET_FEATURE_INIT(lcp_xc_ip6_ucast_node, static) = {
.arc_name = "ip6-unicast", .arc_name = "ip6-unicast",
.node_name = "linux-cp-xc-ip6", .node_name = "linux-cp-xc-ip6",
}; };
VNET_FEATURE_INIT (lcp_xc_ip6_mcast_node, static) = { VNET_FEATURE_INIT(lcp_xc_ip6_mcast_node, static) = {
.arc_name = "ip6-multicast", .arc_name = "ip6-multicast",
.node_name = "linux-cp-xc-ip6", .node_name = "linux-cp-xc-ip6",
}; };
@ -525,46 +527,48 @@ VLIB_NODE_FN (lcp_xc_l3_ip6_node)
return (lcp_xc_l3_inline (vm, node, frame, AF_IP6)); return (lcp_xc_l3_inline (vm, node, frame, AF_IP6));
} }
VLIB_REGISTER_NODE (lcp_xc_l3_ip4_node) = { VLIB_REGISTER_NODE(lcp_xc_l3_ip4_node) = {
.name = "linux-cp-xc-l3-ip4", .name = "linux-cp-xc-l3-ip4",
.vector_size = sizeof (u32), .vector_size = sizeof(u32),
.format_trace = format_lcp_xc_trace, .format_trace = format_lcp_xc_trace,
.type = VLIB_NODE_TYPE_INTERNAL, .type = VLIB_NODE_TYPE_INTERNAL,
.n_next_nodes = LCP_XC_L3_N_NEXT, .n_next_nodes = LCP_XC_L3_N_NEXT,
.next_nodes = { .next_nodes =
{
[LCP_XC_L3_NEXT_XC] = "ip4-midchain", [LCP_XC_L3_NEXT_XC] = "ip4-midchain",
}, },
}; };
VNET_FEATURE_INIT (lcp_xc_node_l3_ip4_unicast, static) = { VNET_FEATURE_INIT(lcp_xc_node_l3_ip4_unicast, static) = {
.arc_name = "ip4-unicast", .arc_name = "ip4-unicast",
.node_name = "linux-cp-xc-l3-ip4", .node_name = "linux-cp-xc-l3-ip4",
}; };
VNET_FEATURE_INIT (lcp_xc_node_l3_ip4_multicaast, static) = { VNET_FEATURE_INIT(lcp_xc_node_l3_ip4_multicaast, static) = {
.arc_name = "ip4-multicast", .arc_name = "ip4-multicast",
.node_name = "linux-cp-xc-l3-ip4", .node_name = "linux-cp-xc-l3-ip4",
}; };
VLIB_REGISTER_NODE (lcp_xc_l3_ip6_node) = { VLIB_REGISTER_NODE(lcp_xc_l3_ip6_node) = {
.name = "linux-cp-xc-l3-ip6", .name = "linux-cp-xc-l3-ip6",
.vector_size = sizeof (u32), .vector_size = sizeof(u32),
.format_trace = format_lcp_xc_trace, .format_trace = format_lcp_xc_trace,
.type = VLIB_NODE_TYPE_INTERNAL, .type = VLIB_NODE_TYPE_INTERNAL,
.n_next_nodes = LCP_XC_L3_N_NEXT, .n_next_nodes = LCP_XC_L3_N_NEXT,
.next_nodes = { .next_nodes =
{
[LCP_XC_L3_NEXT_XC] = "ip6-midchain", [LCP_XC_L3_NEXT_XC] = "ip6-midchain",
}, },
}; };
VNET_FEATURE_INIT (lcp_xc_node_l3_ip6_unicast, static) = { VNET_FEATURE_INIT(lcp_xc_node_l3_ip6_unicast, static) = {
.arc_name = "ip6-unicast", .arc_name = "ip6-unicast",
.node_name = "linux-cp-xc-l3-ip6", .node_name = "linux-cp-xc-l3-ip6",
}; };
VNET_FEATURE_INIT (lcp_xc_node_l3_ip6_multicast, static) = { VNET_FEATURE_INIT(lcp_xc_node_l3_ip6_multicast, static) = {
.arc_name = "ip6-multicast", .arc_name = "ip6-multicast",
.node_name = "linux-cp-xc-l3-ip6", .node_name = "linux-cp-xc-l3-ip6",
}; };
@ -799,9 +803,9 @@ VLIB_NODE_FN (lcp_arp_phy_node)
return frame->n_vectors; return frame->n_vectors;
} }
VLIB_REGISTER_NODE (lcp_arp_phy_node) = { VLIB_REGISTER_NODE(lcp_arp_phy_node) = {
.name = "linux-cp-arp-phy", .name = "linux-cp-arp-phy",
.vector_size = sizeof (u32), .vector_size = sizeof(u32),
.format_trace = format_lcp_arp_trace, .format_trace = format_lcp_arp_trace,
.type = VLIB_NODE_TYPE_INTERNAL, .type = VLIB_NODE_TYPE_INTERNAL,
@ -809,16 +813,17 @@ VLIB_REGISTER_NODE (lcp_arp_phy_node) = {
.error_counters = linuxcp_error_counters, .error_counters = linuxcp_error_counters,
.n_next_nodes = LCP_ARP_N_NEXT, .n_next_nodes = LCP_ARP_N_NEXT,
.next_nodes = { .next_nodes =
{
[LCP_ARP_NEXT_DROP] = "error-drop", [LCP_ARP_NEXT_DROP] = "error-drop",
[LCP_ARP_NEXT_IO] = "interface-output", [LCP_ARP_NEXT_IO] = "interface-output",
}, },
}; };
VNET_FEATURE_INIT (lcp_arp_phy_arp_feat, static) = { VNET_FEATURE_INIT(lcp_arp_phy_arp_feat, static) = {
.arc_name = "arp", .arc_name = "arp",
.node_name = "linux-cp-arp-phy", .node_name = "linux-cp-arp-phy",
.runs_before = VNET_FEATURES ("arp-reply"), .runs_before = VNET_FEATURES("arp-reply"),
}; };
/** /**
@ -883,9 +888,9 @@ VLIB_NODE_FN (lcp_arp_host_node)
return frame->n_vectors; return frame->n_vectors;
} }
VLIB_REGISTER_NODE (lcp_arp_host_node) = { VLIB_REGISTER_NODE(lcp_arp_host_node) = {
.name = "linux-cp-arp-host", .name = "linux-cp-arp-host",
.vector_size = sizeof (u32), .vector_size = sizeof(u32),
.format_trace = format_lcp_arp_trace, .format_trace = format_lcp_arp_trace,
.type = VLIB_NODE_TYPE_INTERNAL, .type = VLIB_NODE_TYPE_INTERNAL,
@ -893,16 +898,17 @@ VLIB_REGISTER_NODE (lcp_arp_host_node) = {
.error_counters = linuxcp_error_counters, .error_counters = linuxcp_error_counters,
.n_next_nodes = LCP_ARP_N_NEXT, .n_next_nodes = LCP_ARP_N_NEXT,
.next_nodes = { .next_nodes =
{
[LCP_ARP_NEXT_DROP] = "error-drop", [LCP_ARP_NEXT_DROP] = "error-drop",
[LCP_ARP_NEXT_IO] = "interface-output", [LCP_ARP_NEXT_IO] = "interface-output",
}, },
}; };
VNET_FEATURE_INIT (lcp_arp_host_arp_feat, static) = { VNET_FEATURE_INIT(lcp_arp_host_arp_feat, static) = {
.arc_name = "arp", .arc_name = "arp",
.node_name = "linux-cp-arp-host", .node_name = "linux-cp-arp-host",
.runs_before = VNET_FEATURES ("arp-reply"), .runs_before = VNET_FEATURES("arp-reply"),
}; };
/* /*

72
lcpng_if_sync.c Normal file
View File

@ -0,0 +1,72 @@
/* Hey Emacs use -*- mode: C -*- */
/*
* Copyright 2021 Pim van Pelt <pim@ipng.nl>
*
* 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 <sys/socket.h>
#include <linux/if.h>
#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <plugins/lcpng/lcpng_interface.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vpp/app/version.h>
#include <vnet/format_fns.h>
#include <vnet/udp/udp.h>
#include <vnet/tcp/tcp.h>
#include <vnet/devices/tap/tap.h>
#include <vnet/devices/netlink.h>
static clib_error_t *
lcp_itf_admin_state_change (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
{
const lcp_itf_pair_t *lip;
vnet_hw_interface_t *hi;
vnet_sw_interface_t *si;
LCP_ITF_PAIR_DBG ("admin_state_change: sw %U %u",
format_vnet_sw_if_index_name, vnm, sw_if_index,
flags);
// Sync interface state changes into host
lip = lcp_itf_pair_get (lcp_itf_pair_find_by_phy (sw_if_index));
if (!lip) return NULL;
LCP_ITF_PAIR_INFO ("admin_state_change: %U flags %u", format_lcp_itf_pair, lip, flags);
lcp_itf_set_link_state (lip, (flags & VNET_HW_INTERFACE_FLAG_LINK_UP));
// Sync PHY carrier changes into TAP
hi = vnet_get_hw_interface_or_null (vnm, sw_if_index);
si = vnet_get_sw_interface_or_null (vnm, lip->lip_host_sw_if_index);
if (!si || !hi) return NULL;
LCP_ITF_PAIR_INFO ("admin_state_change: hi %U si %U %u",
format_vnet_sw_if_index_name, vnm, hi->hw_if_index,
format_vnet_sw_if_index_name, vnm, si->sw_if_index,
flags);
tap_set_carrier (si->hw_if_index, (flags & VNET_HW_INTERFACE_FLAG_LINK_UP));
/* TODO(pim): is this right? see tap_set_speed() "Cannot open netns" error
if (flags & VNET_HW_INTERFACE_FLAG_LINK_UP) {
tap_set_speed (si->hw_if_index, hi->link_speed);
}
*/
return NULL;
}
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(lcp_itf_admin_state_change);

View File

@ -39,7 +39,7 @@
#include <vlibapi/api_helper_macros.h> #include <vlibapi/api_helper_macros.h>
#include <vnet/ipsec/ipsec_punt.h> #include <vnet/ipsec/ipsec_punt.h>
static vlib_log_class_t lcp_itf_pair_logger; vlib_log_class_t lcp_itf_pair_logger;
/** /**
* Pool of LIP objects * Pool of LIP objects
@ -73,15 +73,6 @@ lcp_itf_pair_register_vft (lcp_itf_pair_vft_t *lcp_itf_vft)
vec_add1 (lcp_itf_vfts, *lcp_itf_vft); vec_add1 (lcp_itf_vfts, *lcp_itf_vft);
} }
#define LCP_ITF_PAIR_DBG(...) \
vlib_log_notice (lcp_itf_pair_logger, __VA_ARGS__);
#define LCP_ITF_PAIR_INFO(...) \
vlib_log_notice (lcp_itf_pair_logger, __VA_ARGS__);
#define LCP_ITF_PAIR_ERR(...) \
vlib_log_err (lcp_itf_pair_logger, __VA_ARGS__);
u8 * u8 *
format_lcp_itf_pair (u8 *s, va_list *args) format_lcp_itf_pair (u8 *s, va_list *args)
{ {
@ -137,7 +128,7 @@ lcp_itf_pair_show (u32 phy_sw_if_index)
index_t api; index_t api;
vm = vlib_get_main (); vm = vlib_get_main ();
ns = lcp_get_default_ns (); ns = lcp_get_default_ns();
vlib_cli_output (vm, "lcpng netns '%s'\n", vlib_cli_output (vm, "lcpng netns '%s'\n",
ns ? (char *) ns : "<unset>"); ns ? (char *) ns : "<unset>");
@ -157,6 +148,7 @@ lcp_itf_pair_t *
lcp_itf_pair_get (u32 index) lcp_itf_pair_get (u32 index)
{ {
if (!lcp_itf_pair_pool) return NULL; if (!lcp_itf_pair_pool) return NULL;
if (index == INDEX_INVALID) return NULL;
return pool_elt_at_index (lcp_itf_pair_pool, index); return pool_elt_at_index (lcp_itf_pair_pool, index);
} }
@ -192,11 +184,13 @@ 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] = { const char *lcp_itf_l3_feat_names[N_LCP_ITF_HOST][N_AF] = {
[LCP_ITF_HOST_TAP] = { [LCP_ITF_HOST_TAP] =
{
[AF_IP4] = "linux-cp-xc-ip4", [AF_IP4] = "linux-cp-xc-ip4",
[AF_IP6] = "linux-cp-xc-ip6", [AF_IP6] = "linux-cp-xc-ip6",
}, },
[LCP_ITF_HOST_TUN] = { [LCP_ITF_HOST_TUN] =
{
[AF_IP4] = "linux-cp-xc-l3-ip4", [AF_IP4] = "linux-cp-xc-l3-ip4",
[AF_IP6] = "linux-cp-xc-l3-ip6", [AF_IP6] = "linux-cp-xc-l3-ip6",
}, },
@ -318,16 +312,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 */ /* enable ARP feature node for broadcast interfaces */
if (lip->lip_host_type != LCP_ITF_HOST_TUN) if (lip->lip_host_type != LCP_ITF_HOST_TUN)
{ {
vnet_feature_enable_disable ("arp", "linux-cp-arp-phy", vnet_feature_enable_disable("arp", "linux-cp-arp-phy",
lip->lip_phy_sw_if_index, 1, NULL, 0); lip->lip_phy_sw_if_index, 1, NULL, 0);
vnet_feature_enable_disable ("arp", "linux-cp-arp-host", vnet_feature_enable_disable("arp", "linux-cp-arp-host",
lip->lip_host_sw_if_index, 1, NULL, 0); lip->lip_host_sw_if_index, 1, NULL, 0);
} }
else else
{ {
vnet_feature_enable_disable ("ip4-punt", "linux-cp-punt-l3", 0, 1, NULL, vnet_feature_enable_disable("ip4-punt", "linux-cp-punt-l3", 0, 1, NULL,
0); 0);
vnet_feature_enable_disable ("ip6-punt", "linux-cp-punt-l3", 0, 1, NULL, vnet_feature_enable_disable("ip6-punt", "linux-cp-punt-l3", 0, 1, NULL,
0); 0);
} }
@ -448,16 +442,16 @@ lcp_itf_pair_del (u32 phy_sw_if_index)
/* disable ARP feature node for broadcast interfaces */ /* disable ARP feature node for broadcast interfaces */
if (lip->lip_host_type != LCP_ITF_HOST_TUN) if (lip->lip_host_type != LCP_ITF_HOST_TUN)
{ {
vnet_feature_enable_disable ("arp", "linux-cp-arp-phy", vnet_feature_enable_disable("arp", "linux-cp-arp-phy",
lip->lip_phy_sw_if_index, 0, NULL, 0); lip->lip_phy_sw_if_index, 0, NULL, 0);
vnet_feature_enable_disable ("arp", "linux-cp-arp-host", vnet_feature_enable_disable("arp", "linux-cp-arp-host",
lip->lip_host_sw_if_index, 0, NULL, 0); lip->lip_host_sw_if_index, 0, NULL, 0);
} }
else else
{ {
vnet_feature_enable_disable ("ip4-punt", "linux-cp-punt-l3", 0, 0, NULL, vnet_feature_enable_disable("ip4-punt", "linux-cp-punt-l3", 0, 0, NULL,
0); 0);
vnet_feature_enable_disable ("ip6-punt", "linux-cp-punt-l3", 0, 0, NULL, vnet_feature_enable_disable("ip6-punt", "linux-cp-punt-l3", 0, 0, NULL,
0); 0);
} }
@ -538,10 +532,9 @@ lcp_itf_pair_config (vlib_main_t *vm, unformat_input_t *input)
if (unformat (input, "netns %v", &netns)) if (unformat (input, "netns %v", &netns))
{ {
vec_add1 (netns, 0); vec_add1 (netns, 0);
if (lcp_set_default_ns (netns) < 0) if (lcp_set_default_ns(netns) < 0) {
{ return clib_error_return(
return clib_error_return (0, 0, "lcpng namespace must be less than %d characters",
"lcpng namespace must be less than %d characters",
LCP_NS_LEN); LCP_NS_LEN);
} }
} }
@ -594,22 +587,24 @@ lcp_validate_if_name (u8 *name)
return 1; return 1;
} }
static void void
lcp_itf_set_vif_link_state (u32 vif_index, u8 up, u8 *ns) lcp_itf_set_link_state (const lcp_itf_pair_t *lip, u8 state)
{ {
int curr_ns_fd, vif_ns_fd; int curr_ns_fd, vif_ns_fd;
if (!lip) return;
curr_ns_fd = vif_ns_fd = -1; curr_ns_fd = vif_ns_fd = -1;
if (ns) if (lip->lip_namespace)
{ {
curr_ns_fd = clib_netns_open (NULL /* self */); curr_ns_fd = clib_netns_open (NULL /* self */);
vif_ns_fd = clib_netns_open (ns); vif_ns_fd = clib_netns_open (lip->lip_namespace);
if (vif_ns_fd != -1) if (vif_ns_fd != -1)
clib_setns (vif_ns_fd); clib_setns (vif_ns_fd);
} }
vnet_netlink_set_link_state (vif_index, up); vnet_netlink_set_link_state (lip->lip_vif_index, state);
if (vif_ns_fd != -1) if (vif_ns_fd != -1)
close (vif_ns_fd); close (vif_ns_fd);
@ -619,6 +614,8 @@ lcp_itf_set_vif_link_state (u32 vif_index, u8 up, u8 *ns)
clib_setns (curr_ns_fd); clib_setns (curr_ns_fd);
close (curr_ns_fd); close (curr_ns_fd);
} }
return;
} }
typedef struct typedef struct
@ -639,7 +636,7 @@ lcp_itf_pair_find_walk (vnet_main_t *vnm, u32 sw_if_index, void *arg)
sw = vnet_get_sw_interface_or_null (vnm, sw_if_index); sw = vnet_get_sw_interface_or_null (vnm, sw_if_index);
if (sw && (sw->sub.eth.inner_vlan_id == 0) && (sw->sub.eth.outer_vlan_id == match->vlan) && (sw->sub.eth.flags.dot1ad == match->dot1ad)) { if (sw && (sw->sub.eth.inner_vlan_id == 0) && (sw->sub.eth.outer_vlan_id == match->vlan) && (sw->sub.eth.flags.dot1ad == match->dot1ad)) {
LCP_ITF_PAIR_ERR ("pair_create: found match %U outer %d dot1ad %d inner-dot1q %d", LCP_ITF_PAIR_DBG ("pair_create: found match %U outer %d dot1ad %d inner-dot1q %d",
format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index, format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
sw->sub.eth.outer_vlan_id, sw->sub.eth.flags.dot1ad, sw->sub.eth.inner_vlan_id); sw->sub.eth.outer_vlan_id, sw->sub.eth.flags.dot1ad, sw->sub.eth.inner_vlan_id);
match->matched_sw_if_index = sw_if_index; match->matched_sw_if_index = sw_if_index;
@ -678,6 +675,7 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
u32 vif_index = 0, host_sw_if_index; u32 vif_index = 0, host_sw_if_index;
const vnet_sw_interface_t *sw; const vnet_sw_interface_t *sw;
const vnet_hw_interface_t *hw; const vnet_hw_interface_t *hw;
const lcp_itf_pair_t *lip;
if (!vnet_sw_if_index_is_api_valid (phy_sw_if_index)) { if (!vnet_sw_if_index_is_api_valid (phy_sw_if_index)) {
LCP_ITF_PAIR_ERR ("pair_create: invalid phy index %u", phy_sw_if_index); LCP_ITF_PAIR_ERR ("pair_create: invalid phy index %u", phy_sw_if_index);
@ -703,12 +701,12 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
* Otherwise, use netns if defined, otherwise use the OS default. * Otherwise, use netns if defined, otherwise use the OS default.
*/ */
if (ns == 0 || ns[0] == 0) if (ns == 0 || ns[0] == 0)
ns = lcp_get_default_ns (); ns = lcp_get_default_ns();
/* sub interfaces do not need a tap created */ /* sub interfaces do not need a tap created */
if (vnet_sw_interface_is_sub (vnm, phy_sw_if_index)) if (vnet_sw_interface_is_sub (vnm, phy_sw_if_index))
{ {
const lcp_itf_pair_t *lip, *llip; const lcp_itf_pair_t *llip;
index_t parent_if_index, linux_parent_if_index; index_t parent_if_index, linux_parent_if_index;
int orig_ns_fd, ns_fd; int orig_ns_fd, ns_fd;
clib_error_t *err; clib_error_t *err;
@ -771,8 +769,8 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
return VNET_API_ERROR_INVALID_ARGUMENT; return VNET_API_ERROR_INVALID_ARGUMENT;
} }
LCP_ITF_PAIR_ERR ("pair_create: parent %U", format_lcp_itf_pair, lip); LCP_ITF_PAIR_DBG ("pair_create: parent %U", format_lcp_itf_pair, lip);
LCP_ITF_PAIR_ERR ("pair_create: linux parent %U", format_lcp_itf_pair, llip); LCP_ITF_PAIR_DBG ("pair_create: linux parent %U", format_lcp_itf_pair, llip);
/* /*
* see if the requested host interface has already been created * see if the requested host interface has already been created
@ -895,20 +893,11 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
*/ */
hw = vnet_get_sup_hw_interface (vnm, args.sw_if_index); hw = vnet_get_sup_hw_interface (vnm, args.sw_if_index);
/*
* Copy the link state from VPP inon the host side.
* This controls whether the host can RX/TX.
*/
virtio_main_t *mm = &virtio_main; virtio_main_t *mm = &virtio_main;
virtio_if_t *vif = pool_elt_at_index (mm->interfaces, hw->dev_instance); virtio_if_t *vif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
vif_index = vif->ifindex;
lcp_itf_set_vif_link_state (vif->ifindex, sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP,
args.host_namespace);
/* /*
* Leave the TAP permanently up on the VPP side.
* This TAP will be shared by many sub-interface.
* Therefore we can't use it to manage admin state.
* force the tap in promiscuous mode. * force the tap in promiscuous mode.
*/ */
if (host_if_type == LCP_ITF_HOST_TAP) if (host_if_type == LCP_ITF_HOST_TAP)
@ -917,7 +906,6 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
ei->flags |= ETHERNET_INTERFACE_FLAG_STATUS_L3; ei->flags |= ETHERNET_INTERFACE_FLAG_STATUS_L3;
} }
vif_index = vif->ifindex;
host_sw_if_index = args.sw_if_index; host_sw_if_index = args.sw_if_index;
} }
@ -930,15 +918,28 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
return -1; return -1;
} }
vnet_sw_interface_admin_up (vnm, host_sw_if_index);
lcp_itf_pair_add (host_sw_if_index, phy_sw_if_index, host_if_name, vif_index,
host_if_type, ns);
LCP_ITF_PAIR_INFO ("pair create: {%U, %U, %s}", LCP_ITF_PAIR_INFO ("pair create: {%U, %U, %s}",
format_vnet_sw_if_index_name, vnet_get_main (), phy_sw_if_index, format_vnet_sw_if_index_name, vnet_get_main (), phy_sw_if_index,
format_vnet_sw_if_index_name, vnet_get_main (), host_sw_if_index, format_vnet_sw_if_index_name, vnet_get_main (), host_sw_if_index,
host_if_name); host_if_name);
lcp_itf_pair_add (host_sw_if_index, phy_sw_if_index, host_if_name, vif_index,
host_if_type, ns);
/*
* Copy the link state from VPP inon the host side.
* The TAP is shared by many interfaces, always keep it up.
* This controls whether the host can RX/TX.
*/
vnet_sw_interface_admin_up (vnm, host_sw_if_index);
lip = lcp_itf_pair_get (lcp_itf_pair_find_by_vif(vif_index));
LCP_ITF_PAIR_INFO ("pair_create: copy link state %u from %U to %U",
sw->flags,
format_vnet_sw_if_index_name, vnet_get_main (), sw->sw_if_index,
format_lcp_itf_pair, lip);
lcp_itf_set_link_state (lip, sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP);
if (host_sw_if_indexp) if (host_sw_if_indexp)
*host_sw_if_indexp = host_sw_if_index; *host_sw_if_indexp = host_sw_if_index;
@ -1047,50 +1048,13 @@ lcp_itf_phy_add (vnet_main_t *vnm, u32 sw_if_index, u32 is_create)
VNET_SW_INTERFACE_ADD_DEL_FUNCTION (lcp_itf_phy_add); VNET_SW_INTERFACE_ADD_DEL_FUNCTION (lcp_itf_phy_add);
static clib_error_t *
lcp_itf_pair_link_up_down (vnet_main_t *vnm, u32 hw_if_index, u32 flags)
{
vnet_hw_interface_t *hi;
vnet_sw_interface_t *si;
index_t lipi;
lcp_itf_pair_t *lip;
hi = vnet_get_hw_interface_or_null (vnm, hw_if_index);
if (!hi)
return 0;
lipi = lcp_itf_pair_find_by_phy (hi->sw_if_index);
if (lipi == INDEX_INVALID)
return 0;
lip = lcp_itf_pair_get (lipi);
si = vnet_get_sw_interface_or_null (vnm, lip->lip_host_sw_if_index);
if (!si)
return 0;
if (!lcp_main.test_mode)
{
tap_set_carrier (si->hw_if_index,
(flags & VNET_HW_INTERFACE_FLAG_LINK_UP));
if (flags & VNET_HW_INTERFACE_FLAG_LINK_UP)
{
tap_set_speed (si->hw_if_index, hi->link_speed / 1000);
}
}
return 0;
}
VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (lcp_itf_pair_link_up_down);
static clib_error_t * static clib_error_t *
lcp_itf_pair_init (vlib_main_t *vm) lcp_itf_pair_init (vlib_main_t *vm)
{ {
vlib_punt_hdl_t punt_hdl = vlib_punt_client_register ("linux-cp"); vlib_punt_hdl_t punt_hdl = vlib_punt_client_register("linux-cp");
/* punt IKE */ /* punt IKE */
vlib_punt_register (punt_hdl, ipsec_punt_reason[IPSEC_PUNT_IP4_SPI_UDP_0], vlib_punt_register(punt_hdl, ipsec_punt_reason[IPSEC_PUNT_IP4_SPI_UDP_0],
"linux-cp-punt"); "linux-cp-punt");
/* punt all unknown ports */ /* punt all unknown ports */
@ -1099,7 +1063,7 @@ lcp_itf_pair_init (vlib_main_t *vm)
tcp_punt_unknown (vm, 0, 1); tcp_punt_unknown (vm, 0, 1);
tcp_punt_unknown (vm, 1, 1); tcp_punt_unknown (vm, 1, 1);
lcp_itf_pair_logger = vlib_log_register_class ("linux-cp", "if"); lcp_itf_pair_logger = vlib_log_register_class("linux-cp", "if");
return NULL; return NULL;
} }

View File

@ -21,6 +21,18 @@
#include <plugins/lcpng/lcpng.h> #include <plugins/lcpng/lcpng.h>
extern vlib_log_class_t lcp_itf_pair_logger;
#define LCP_ITF_PAIR_DBG(...) \
vlib_log_notice (lcp_itf_pair_logger, __VA_ARGS__);
#define LCP_ITF_PAIR_INFO(...) \
vlib_log_notice (lcp_itf_pair_logger, __VA_ARGS__);
#define LCP_ITF_PAIR_ERR(...) \
vlib_log_err (lcp_itf_pair_logger, __VA_ARGS__);
#define foreach_lcp_itf_pair_flag _ (STALE, 0, "stale") #define foreach_lcp_itf_pair_flag _ (STALE, 0, "stale")
typedef enum lip_flag_t_ typedef enum lip_flag_t_
@ -154,6 +166,10 @@ typedef struct lcp_itf_pair_vft
} lcp_itf_pair_vft_t; } lcp_itf_pair_vft_t;
void lcp_itf_pair_register_vft (lcp_itf_pair_vft_t *lcp_itf_vft); void lcp_itf_pair_register_vft (lcp_itf_pair_vft_t *lcp_itf_vft);
/* Set TAP and Linux host link state */
void lcp_itf_set_link_state (const lcp_itf_pair_t *lip, u8 state);
/* /*
* fd.io coding-style-patch-verification: ON * fd.io coding-style-patch-verification: ON
* *