From 532858f8b73017b2d8f69b65cec20a3d762d6a8a Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Wed, 11 Jan 2023 11:12:39 +0100 Subject: [PATCH 1/6] Reduce message to DBG per upstream d3ccb0c --- lcpng_netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lcpng_netlink.c b/lcpng_netlink.c index db4e1e2..089dfdf 100644 --- a/lcpng_netlink.c +++ b/lcpng_netlink.c @@ -300,8 +300,8 @@ lcp_nl_process_msgs (void) } else { - NL_INFO ("process_msgs: Processed %u messages in %llu usecs", n_msgs, - usecs); + NL_DBG ("process_msgs: Processed %u messages in %llu usecs", n_msgs, + usecs); } } From e03520316258add3a925f7a370a390b2245fa836 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Wed, 11 Jan 2023 11:13:40 +0100 Subject: [PATCH 2/6] Fix memory leak on failed tap creation per upstream 37b5cccb; Also, sync the RX/TX queues to be the same as upstream linux-cp --- lcpng_interface.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lcpng_interface.c b/lcpng_interface.c index 0fce5ec..412058f 100644 --- a/lcpng_interface.c +++ b/lcpng_interface.c @@ -951,13 +951,16 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name, else { tap_create_if_args_t args = { - .num_rx_queues = 1, + .num_rx_queues = clib_max (1, vlib_num_workers ()), + .num_tx_queues = 1, .id = hw->hw_if_index, .sw_if_index = ~0, .rx_ring_sz = 256, .tx_ring_sz = 256, .host_if_name = host_if_name, .host_namespace = 0, + .rv = 0, + .error = NULL, }; ethernet_interface_t *ei; u32 host_sw_mtu_size; @@ -996,6 +999,7 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name, { LCP_ITF_PAIR_ERR ("pair_create: could not create tap, retval:%d", args.rv); + clib_error_free (args.error); return args.rv; } From efc385c17f5479b1892f1f7d5641b73ae92dfef1 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Wed, 11 Jan 2023 11:14:33 +0100 Subject: [PATCH 3/6] Fix endianness per upstream c8cd079a0 --- lcpng_if.api | 24 +++++++++---------- lcpng_if_api.c | 62 +++++++++++++++++++------------------------------- 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/lcpng_if.api b/lcpng_if.api index 319dd3e..059ce64 100644 --- a/lcpng_if.api +++ b/lcpng_if.api @@ -21,19 +21,19 @@ option version = "1.0.0"; import "vnet/interface_types.api"; -/** \brief Set the default Linux Control Plane namespace +/** \brief Set the default Linux Control Plane netns @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request - @param namespace - the new default namespace; namespace[0] == 0 iff none + @param netns - the new default netns; netns[0] == 0 iff none */ autoreply define lcp_default_ns_set { u32 client_index; u32 context; - string namespace[32]; /* LCP_NS_LEN */ + string netns[32]; /* LCP_NS_LEN */ }; -/** \brief get the default Linux Control Plane namespace +/** \brief get the default Linux Control Plane netns @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request */ @@ -43,15 +43,15 @@ define lcp_default_ns_get u32 context; }; -/** \brief get the default Linux Control Plane namespace +/** \brief get the default Linux Control Plane netns @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request - @param namespace - the default namespace; namespace[0] == 0 iff none + @param netns - the default netns; netns[0] == 0 iff none */ define lcp_default_ns_get_reply { u32 context; - string namespace[32]; /* LCP_NS_LEN */ + string netns[32]; /* LCP_NS_LEN */ }; enum lcp_itf_host_type : u8 @@ -67,7 +67,7 @@ enum lcp_itf_host_type : u8 @param sw_if_index - index of VPP PHY SW interface @param host_if_name - host tap interface name @param host_if_type - the type of host interface to create (tun, tap) - @param namespace - optional tap namespace; namespace[0] == 0 iff none + @param netns - optional tap netns; netns[0] == 0 iff none */ autoreply autoendian define lcp_itf_pair_add_del { @@ -77,7 +77,7 @@ autoreply autoendian define lcp_itf_pair_add_del vl_api_interface_index_t sw_if_index; string host_if_name[16]; /* IFNAMSIZ */ vl_api_lcp_itf_host_type_t host_if_type; - string namespace[32]; /* LCP_NS_LEN */ + string netns[32]; /* LCP_NS_LEN */ }; autoendian define lcp_itf_pair_add_del_v2 { @@ -87,7 +87,7 @@ autoendian define lcp_itf_pair_add_del_v2 vl_api_interface_index_t sw_if_index; string host_if_name[16]; /* IFNAMSIZ */ vl_api_lcp_itf_host_type_t host_if_type; - string namespace[32]; /* LCP_NS_LEN */ + string netns[32]; /* LCP_NS_LEN */ }; define lcp_itf_pair_add_del_v2_reply { @@ -121,7 +121,7 @@ define lcp_itf_pair_get_reply @param vif_index - tap linux index @param host_if_name - host interface name @param host_if_type - host interface type (tun, tap) - @param namespace - host interface namespace + @param netns - host interface netns */ autoendian define lcp_itf_pair_details { @@ -131,7 +131,7 @@ autoendian define lcp_itf_pair_details u32 vif_index; string host_if_name[16]; /* IFNAMSIZ */ vl_api_lcp_itf_host_type_t host_if_type; - string namespace[32]; /* LCP_NS_LEN */ + string netns[32]; /* LCP_NS_LEN */ }; service { diff --git a/lcpng_if_api.c b/lcpng_if_api.c index 7f59c20..69a4dd1 100644 --- a/lcpng_if_api.c +++ b/lcpng_if_api.c @@ -44,7 +44,7 @@ api_encode_host_type (lip_host_type_t type) static int vl_api_lcp_itf_pair_add (u32 phy_sw_if_index, lip_host_type_t lip_host_type, u8 *mp_host_if_name, size_t sizeof_host_if_name, - u8 *mp_namespace, size_t sizeof_mp_namespace, + u8 *mp_netns, size_t sizeof_mp_netns, u32 *host_sw_if_index_p) { u8 *host_if_name, *netns; @@ -57,8 +57,8 @@ vl_api_lcp_itf_pair_add (u32 phy_sw_if_index, lip_host_type_t lip_host_type, vec_add (host_if_name, mp_host_if_name, host_len); vec_add1 (host_if_name, 0); - netns_len = clib_strnlen ((char *) mp_namespace, sizeof_mp_namespace - 1); - vec_add (netns, mp_namespace, netns_len); + netns_len = clib_strnlen ((char *) mp_netns, sizeof_mp_netns - 1); + vec_add (netns, mp_netns, netns_len); vec_add1 (netns, 0); rv = lcp_itf_pair_create (phy_sw_if_index, host_if_name, lip_host_type, @@ -78,20 +78,15 @@ vl_api_lcp_itf_pair_add_del_t_handler (vl_api_lcp_itf_pair_add_del_t *mp) lip_host_type_t lip_host_type; int rv; - if (!vnet_sw_if_index_is_api_valid (mp->sw_if_index)) - { - rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; - goto bad_sw_if_index; - } + VALIDATE_SW_IF_INDEX_END (mp); phy_sw_if_index = mp->sw_if_index; lip_host_type = api_decode_host_type (mp->host_if_type); if (mp->is_add) { - rv = - vl_api_lcp_itf_pair_add (phy_sw_if_index, lip_host_type, - mp->host_if_name, sizeof (mp->host_if_name), - mp->namespace, sizeof (mp->namespace), NULL); + rv = vl_api_lcp_itf_pair_add ( + phy_sw_if_index, lip_host_type, mp->host_if_name, + sizeof (mp->host_if_name), mp->netns, sizeof (mp->netns), NULL); } else { @@ -99,7 +94,7 @@ vl_api_lcp_itf_pair_add_del_t_handler (vl_api_lcp_itf_pair_add_del_t *mp) } BAD_SW_IF_INDEX_LABEL; - REPLY_MACRO (VL_API_LCP_ITF_PAIR_ADD_DEL_REPLY); + REPLY_MACRO_END (VL_API_LCP_ITF_PAIR_ADD_DEL_REPLY); } static void @@ -110,11 +105,7 @@ vl_api_lcp_itf_pair_add_del_v2_t_handler (vl_api_lcp_itf_pair_add_del_v2_t *mp) lip_host_type_t lip_host_type; int rv; - if (!vnet_sw_if_index_is_api_valid (mp->sw_if_index)) - { - rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; - goto bad_sw_if_index; - } + VALIDATE_SW_IF_INDEX_END (mp); phy_sw_if_index = mp->sw_if_index; lip_host_type = api_decode_host_type (mp->host_if_type); @@ -122,8 +113,8 @@ vl_api_lcp_itf_pair_add_del_v2_t_handler (vl_api_lcp_itf_pair_add_del_v2_t *mp) { rv = vl_api_lcp_itf_pair_add (phy_sw_if_index, lip_host_type, mp->host_if_name, - sizeof (mp->host_if_name), mp->namespace, - sizeof (mp->namespace), &host_sw_if_index); + sizeof (mp->host_if_name), mp->netns, + sizeof (mp->netns), &host_sw_if_index); } else { @@ -131,8 +122,8 @@ vl_api_lcp_itf_pair_add_del_v2_t_handler (vl_api_lcp_itf_pair_add_del_v2_t *mp) } BAD_SW_IF_INDEX_LABEL; - REPLY_MACRO2 (VL_API_LCP_ITF_PAIR_ADD_DEL_V2_REPLY, - { rmp->host_sw_if_index = ntohl (host_sw_if_index); }); + REPLY_MACRO2_END (VL_API_LCP_ITF_PAIR_ADD_DEL_V2_REPLY, + { rmp->host_sw_if_index = ntohl (host_sw_if_index); }); } static void @@ -153,9 +144,9 @@ send_lcp_itf_pair_details (index_t lipi, vl_api_registration_t *rp, lcp_pair->lip_host_name, vec_len (lcp_pair->lip_host_name)); rmp->host_if_name[vec_len (lcp_pair->lip_host_name)] = 0; - memcpy_s (rmp->namespace, sizeof (rmp->namespace), - lcp_pair->lip_namespace, vec_len (lcp_pair->lip_namespace)); - rmp->namespace[vec_len (lcp_pair->lip_namespace)] = 0; + memcpy_s (rmp->netns, sizeof (rmp->netns), lcp_pair->lip_namespace, + vec_len (lcp_pair->lip_namespace)); + rmp->netns[vec_len (lcp_pair->lip_namespace)] = 0; })); } @@ -175,15 +166,14 @@ 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; int rv; - mp->namespace[LCP_NS_LEN - 1] = 0; - rv = lcp_set_default_ns(mp->namespace); + mp->netns[LCP_NS_LEN - 1] = 0; + rv = lcp_set_default_ns (mp->netns); REPLY_MACRO(VL_API_LCP_DEFAULT_NS_SET_REPLY); } static void 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_default_ns_get_reply_t *rmp; vl_api_registration_t *reg; char *ns; @@ -192,16 +182,12 @@ vl_api_lcp_default_ns_get_t_handler(vl_api_lcp_default_ns_get_t *mp) { if (!reg) return; - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = (VL_API_LCP_DEFAULT_NS_GET_REPLY + lcpm->msg_id_base); - rmp->context = mp->context; - - ns = (char *)lcp_get_default_ns(); - if (ns) - clib_strncpy ((char *) rmp->namespace, ns, LCP_NS_LEN - 1); - - vl_api_send_msg (reg, (u8 *) rmp); + REPLY_MACRO_DETAILS2_END (VL_API_LCP_DEFAULT_NS_GET_REPLY, ({ + ns = (char *) lcp_get_default_ns (); + if (ns) + clib_strncpy ((char *) rmp->netns, ns, + LCP_NS_LEN - 1); + })); } static void From 43eb442624b58463b62ce68f41d3d040b99c4288 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Wed, 11 Jan 2023 12:35:16 +0100 Subject: [PATCH 4/6] Fix endianness bug in lcp_pair_add_v2() --- lcpng_if_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lcpng_if_api.c b/lcpng_if_api.c index 69a4dd1..747cbee 100644 --- a/lcpng_if_api.c +++ b/lcpng_if_api.c @@ -123,7 +123,7 @@ vl_api_lcp_itf_pair_add_del_v2_t_handler (vl_api_lcp_itf_pair_add_del_v2_t *mp) BAD_SW_IF_INDEX_LABEL; REPLY_MACRO2_END (VL_API_LCP_ITF_PAIR_ADD_DEL_V2_REPLY, - { rmp->host_sw_if_index = ntohl (host_sw_if_index); }); + { rmp->host_sw_if_index = host_sw_if_index; }); } static void From b7fd36bda4dd22140e5a502ab925eb01feda5d8e Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Wed, 11 Jan 2023 13:08:03 +0100 Subject: [PATCH 5/6] Add entry flags per upstream f0781829d --- lcpng_nl_sync.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lcpng_nl_sync.c b/lcpng_nl_sync.c index f98686b..4eedfde 100644 --- a/lcpng_nl_sync.c +++ b/lcpng_nl_sync.c @@ -517,7 +517,18 @@ lcp_nl_route_add (struct rtnl_route *rr) } else { - fib_source_t fib_src = lcp_nl_proto_fib_source (rproto); + fib_source_t fib_src; + const fib_route_path_t *rpath; + + vec_foreach (rpath, np.paths) + { + if (fib_route_path_is_attached (rpath)) + { + entry_flags |= FIB_ENTRY_FLAG_ATTACHED; + break; + } + } + fib_src = lcp_nl_proto_fib_source (rproto); NL_INFO ("route_add: table %d prefix %U flags %U", rtnl_route_get_table (rr), format_fib_prefix, &pfx, From 263ff9d02c55af4d02909992007acccef8f5e54f Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Wed, 11 Jan 2023 13:08:54 +0100 Subject: [PATCH 6/6] Initialize var in case of error return, per upstream a01be735f2 --- lcpng_interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lcpng_interface.c b/lcpng_interface.c index 412058f..6b0a3a0 100644 --- a/lcpng_interface.c +++ b/lcpng_interface.c @@ -763,7 +763,7 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name, { vlib_main_t *vm; vnet_main_t *vnm; - u32 vif_index = 0, host_sw_if_index; + u32 vif_index = 0, host_sw_if_index = ~1; const vnet_sw_interface_t *sw; const vnet_hw_interface_t *hw; lcp_itf_pair_t *lip;