Ensure the plugin works well with namespaces

I've made a few cosmetic adjustments:
- introduce debug, info, notice, warn and err loggers
- remove redundant logging, and set correct (conservative) log levels
- turn the sync-state error into a warning

And a little debt paydown:
- refactor sync-state into its own function, to be called instead of
  all the spot fixes elsewhere. It's going to be the case that
  sync-state is "the reconsiliation function".
- Fix a bug in lip->lip_namespace copy: vec_dup() there doesn't seem
  to work for me, use strdup() instead and make a mental note to
  reviist.

The plugin now works with 'lcpng default netns dataplane' in its
startup.conf; and with 'lcp default netns dataplane' as its first
command. A few of these fixes should go upstream, too, which I'll
do next.
This commit is contained in:
Pim van Pelt
2021-08-14 09:40:43 +02:00
parent aab11196cf
commit 10f10d534c
3 changed files with 69 additions and 54 deletions

View File

@ -36,28 +36,23 @@
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
/* walk function to copy forward all sw interface link state flags
/* helper function to copy forward all sw interface link state flags
* MTU, and IP addresses into their counterpart LIP interface.
*
* This is called upon MTU changes and state changes.
*/
static walk_rc_t
lcp_itf_pair_walk_sync_state_cb (index_t lipi, void *ctx)
void
lcp_itf_pair_sync_state (lcp_itf_pair_t *lip)
{
lcp_itf_pair_t *lip;
vnet_sw_interface_t *sw;
vnet_sw_interface_t *sup_sw;
int curr_ns_fd = -1;
int vif_ns_fd = -1;
lip = lcp_itf_pair_get (lipi);
if (!lip)
return WALK_CONTINUE;
sw =
vnet_get_sw_interface_or_null (vnet_get_main (), lip->lip_phy_sw_if_index);
if (!sw)
return WALK_CONTINUE;
return;
sup_sw =
vnet_get_sw_interface_or_null (vnet_get_main (), sw->sup_sw_if_index);
@ -69,9 +64,9 @@ lcp_itf_pair_walk_sync_state_cb (index_t lipi, void *ctx)
clib_setns (vif_ns_fd);
}
LCP_ITF_PAIR_DBG ("walk_sync_state: %U flags %u mtu %u sup-mtu %u",
format_lcp_itf_pair, lip, sw->flags, sw->mtu[VNET_MTU_L3],
sup_sw->mtu[VNET_MTU_L3]);
LCP_ITF_PAIR_INFO ("sync_state: %U flags %u mtu %u sup-mtu %u",
format_lcp_itf_pair, lip, sw->flags, sw->mtu[VNET_MTU_L3],
sup_sw->mtu[VNET_MTU_L3]);
lcp_itf_set_link_state (lip, (sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP));
/* Linux will clamp MTU of children when the parent is lower. VPP is fine
@ -79,7 +74,7 @@ lcp_itf_pair_walk_sync_state_cb (index_t lipi, void *ctx)
*/
if (sup_sw->mtu[VNET_MTU_L3] < sw->mtu[VNET_MTU_L3])
{
LCP_ITF_PAIR_ERR ("walk_sync_state: %U flags %u mtu %u sup-mtu %u: "
LCP_ITF_PAIR_WARN ("sync_state: %U flags %u mtu %u sup-mtu %u: "
"clamping to sup-mtu to satisfy netlink",
format_lcp_itf_pair, lip, sw->flags,
sw->mtu[VNET_MTU_L3], sup_sw->mtu[VNET_MTU_L3]);
@ -89,13 +84,9 @@ lcp_itf_pair_walk_sync_state_cb (index_t lipi, void *ctx)
}
/* Linux will remove IPv6 addresses on children when the master state
* goes down, so we ensure all IPv4/IPv6 addresses are set when the phy
* comes back up.
* goes down, so we ensure all IPv4/IPv6 addresses are synced.
*/
if (sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
{
lcp_itf_set_interface_addr (lip);
}
lcp_itf_set_interface_addr (lip);
if (vif_ns_fd != -1)
close (vif_ns_fd);
@ -106,6 +97,18 @@ lcp_itf_pair_walk_sync_state_cb (index_t lipi, void *ctx)
close (curr_ns_fd);
}
return;
}
static walk_rc_t
lcp_itf_pair_walk_sync_state_cb (index_t lipi, void *ctx)
{
lcp_itf_pair_t *lip;
lip = lcp_itf_pair_get (lipi);
if (!lip)
return WALK_CONTINUE;
lcp_itf_pair_sync_state (lip);
return WALK_CONTINUE;
}
@ -171,7 +174,7 @@ static clib_error_t *
lcp_itf_mtu_change (vnet_main_t *vnm, u32 sw_if_index, u32 flags)
{
const lcp_itf_pair_t *lip;
vnet_sw_interface_t *si;
vnet_sw_interface_t *sw;
int curr_ns_fd = -1;
int vif_ns_fd = -1;
@ -183,8 +186,8 @@ lcp_itf_mtu_change (vnet_main_t *vnm, u32 sw_if_index, u32 flags)
if (!lip)
return NULL;
si = vnet_get_sw_interface_or_null (vnm, sw_if_index);
if (!si)
sw = vnet_get_sw_interface_or_null (vnm, sw_if_index);
if (!sw)
return NULL;
if (lip->lip_namespace)
@ -196,8 +199,8 @@ lcp_itf_mtu_change (vnet_main_t *vnm, u32 sw_if_index, u32 flags)
}
LCP_ITF_PAIR_INFO ("mtu_change: %U mtu %u", format_lcp_itf_pair, lip,
si->mtu[VNET_MTU_L3]);
vnet_netlink_set_link_mtu (lip->lip_vif_index, si->mtu[VNET_MTU_L3]);
sw->mtu[VNET_MTU_L3]);
vnet_netlink_set_link_mtu (lip->lip_vif_index, sw->mtu[VNET_MTU_L3]);
if (vif_ns_fd != -1)
close (vif_ns_fd);