some cleanups
Subsystems (3)
Geliang Tang
reviewercover some cleanups
From: Geliang Tang <[email protected]>
Depends on:
- dump for userspace pm, v14
Geliang Tang (8):
mptcp: make pm_remove_addrs_and_subflows static
mptcp: drop duplicate header inclusions
mptcp: update set_flags interfaces
mptcp: set error messages for set_flags
mptcp: drop lookup_by_id in lookup_addr
mptcp: add use_id parameter for addresses_equal
mptcp: add check_id for lookup_anno_list_by_saddr
selftests: mptcp: flush userspace addrs list
net/mptcp/diag.c | 1 - net/mptcp/mptcp_diag.c | 1 - net/mptcp/pm.c | 15 +-- net/mptcp/pm_netlink.c | 120 +++++++++--------- net/mptcp/pm_userspace.c | 47 +++++-- net/mptcp/protocol.c | 1 - net/mptcp/protocol.h | 18 +-- net/mptcp/subflow.c | 2 - .../testing/selftests/net/mptcp/mptcp_join.sh | 46 ++++++- 9 files changed, 147 insertions(+), 104 deletions(-)
Signature · 1 line
2.40.1
Geliang Tang
reviewerPATCH 1/8 mptcp: make pm_remove_addrs_and_subflows static
From: Geliang Tang <[email protected]>
mptcp_pm_remove_addrs_and_subflows() is only used in pm_netlink.c, it's no longer used in pm_userspace.c any more since the commit 8b1c94da1e48 ("mptcp: only send RM_ADDR in nl_cmd_remove"). So this patch changes it to a static function.
--- net/mptcp/pm_netlink.c | 4 ++-- net/mptcp/protocol.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-)
net/mptcp/pm_netlink.c +2 -2
@@ -1547,8 +1547,8 @@ void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list) } } -void mptcp_pm_remove_addrs_and_subflows (struct mptcp_sock *msk, -struct list_head *rm_list) +static void mptcp_pm_remove_addrs_and_subflows (struct mptcp_sock *msk, +struct list_head *rm_list) {struct mptcp_rm_list alist = { .nr =0 }, slist = { .nr =0 };struct mptcp_pm_addr_entry *entry;
net/mptcp/protocol.h +0 -2
@@ -988,8 +988,6 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,int mptcp_pm_remove_addr (struct mptcp_sock *msk,const struct mptcp_rm_list *rm_list);int mptcp_pm_remove_subflow (struct mptcp_sock *msk,const struct mptcp_rm_list *rm_list);void mptcp_pm_remove_addrs (struct mptcp_sock *msk,struct list_head *rm_list); -void mptcp_pm_remove_addrs_and_subflows (struct mptcp_sock *msk, -struct list_head *rm_list);void mptcp_free_local_addr_list (struct mptcp_sock *msk);
Signature · 1 line
2.40.1
Geliang Tang
reviewerPATCH 2/8 mptcp: drop duplicate header inclusions
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The headers net/tcp.h, net/genetlink.h and uapi/linux/mptcp.h are included in protocol.h already, no need to include them again directly. This patch removes these duplicate header inclusions.
--- net/mptcp/diag.c | 1 - net/mptcp/mptcp_diag.c | 1 - net/mptcp/pm.c | 1 - net/mptcp/pm_netlink.c | 3 --- net/mptcp/protocol.c | 1 - net/mptcp/subflow.c | 2 -- 6 files changed, 9 deletions(-)
net/mptcp/diag.c +0 -1
@@ -10,7 +10,6 @@#include <linux/net.h> #include <linux/inet_diag.h> #include <net/netlink.h> -#include <uapi/linux/mptcp.h> #include "protocol.h" static int subflow_get_info (struct sock *sk,struct sk_buff *skb)
net/mptcp/mptcp_diag.c +0 -1
@@ -10,7 +10,6 @@#include <linux/net.h> #include <linux/inet_diag.h> #include <net/netlink.h> -#include <uapi/linux/mptcp.h> #include "protocol.h" static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
net/mptcp/pm.c +0 -1
@@ -6,7 +6,6 @@#define pr_fmt (fmt) "MPTCP: " fmt#include <linux/kernel.h> -#include <net/tcp.h> #include <net/mptcp.h> #include "protocol.h"
net/mptcp/pm_netlink.c +0 -3
@@ -8,12 +8,9 @@#include <linux/inet.h> #include <linux/kernel.h> -#include <net/tcp.h> #include <net/inet_common.h> #include <net/netns/generic.h> #include <net/mptcp.h> -#include <net/genetlink.h> -#include <uapi/linux/mptcp.h> #include "protocol.h" #include "mib.h"
net/mptcp/protocol.c +0 -1
@@ -15,7 +15,6 @@#include <net/inet_common.h> #include <net/inet_hashtables.h> #include <net/protocol.h> -#include <net/tcp.h> #include <net/tcp_states.h> #if IS_ENABLED (CONFIG_MPTCP_IPV6 )#include <net/transp_v6.h>
net/mptcp/subflow.c +0 -2
@@ -15,13 +15,11 @@#include <net/inet_common.h> #include <net/inet_hashtables.h> #include <net/protocol.h> -#include <net/tcp.h> #if IS_ENABLED (CONFIG_MPTCP_IPV6 )#include <net/ip6_route.h> #include <net/transp_v6.h> #endif #include <net/mptcp.h> -#include <uapi/linux/mptcp.h> #include "protocol.h" #include "mib.h"
Signature · 1 line
2.40.1
Geliang Tang
reviewerPATCH 3/8 mptcp: update set_flags interfaces
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch updates set_flags interfaces, make it more similar to the interfaces of dump_addr and get_addr:
mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
--- net/mptcp/pm.c | 10 +++---- net/mptcp/pm_netlink.c | 58 +++++++++++++++++----------------------- net/mptcp/pm_userspace.c | 32 +++++++++++++++++----- net/mptcp/protocol.h | 10 +++---- 4 files changed, 58 insertions(+), 52 deletions(-)
net/mptcp/pm.c +4 -6
@@ -456,13 +456,11 @@ int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)return mptcp_pm_nl_dump_addr (msg, cb); } -int mptcp_pm_set_flags (struct net *net,struct nlattr *token, -struct mptcp_pm_addr_entry *loc, -struct mptcp_pm_addr_entry *rem,u8 bkup) +int mptcp_pm_set_flags (struct sk_buff *skb,struct genl_info *info) { -if (token) -return mptcp_userspace_pm_set_flags (net, token, loc, rem, bkup); -return mptcp_pm_nl_set_flags (net, loc, bkup); +if (info->attrs[MPTCP_PM_ATTR_TOKEN ]) +return mptcp_userspace_pm_set_flags (skb, info); +return mptcp_pm_nl_set_flags (skb, info); }void mptcp_pm_subflow_chk_stale (const struct mptcp_sock *msk,struct sock *ssk)
net/mptcp/pm_netlink.c +25 -33
91 lines not on this page · raw message
net/mptcp/pm_userspace.c +26 -6
@@ -546,14 +546,19 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *inforeturn err; } -int mptcp_userspace_pm_set_flags (struct net *net,struct nlattr *token, -struct mptcp_pm_addr_entry *loc, -struct mptcp_pm_addr_entry *rem,u8 bkup) +int mptcp_userspace_pm_set_flags (struct sk_buff *skb,struct genl_info *info) { +struct mptcp_pm_addr_entry loc = { .addr = { .family =AF_UNSPEC }, }; +struct mptcp_pm_addr_entry rem = { .addr = { .family =AF_UNSPEC }, }; +struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; +struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN ]; +struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ]; +struct net *net =sock_net (skb->sk);struct mptcp_sock *msk;int ret = -EINVAL ;struct sock *sk;u32 token_val; +u8 bkup =0 ; token_val =nla_get_u32 (token);
@@ -566,12 +571,27 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token,if (!mptcp_pm_is_userspace (msk)) goto set_flags_err; -if (loc->addr.family ==AF_UNSPEC || - rem->addr.family ==AF_UNSPEC ) + ret =mptcp_pm_parse_entry (attr, info, false, &loc); +if (ret <0 ) + goto set_flags_err; + +if (attr_rem) { + ret =mptcp_pm_parse_entry (attr_rem, info, false, &rem); +if (ret <0 ) + goto set_flags_err; + } + +if (loc.addr.family ==AF_UNSPEC || + rem.addr.family ==AF_UNSPEC ) { + ret = -EINVAL ; goto set_flags_err; + } + +if (loc.flags &MPTCP_PM_ADDR_FLAG_BACKUP ) + bkup =1 ;lock_sock (sk); - ret =mptcp_pm_nl_mp_prio_send_ack (msk, &loc->addr, &rem->addr, bkup); + ret =mptcp_pm_nl_mp_prio_send_ack (msk, &loc.addr, &rem.addr, bkup);release_sock (sk); set_flags_err:
net/mptcp/protocol.h +3 -7
@@ -975,13 +975,9 @@ int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned intint mptcp_userspace_pm_get_flags_and_ifindex_by_id (struct mptcp_sock *msk,unsigned int id,u8 *flags,int *ifindex); -int mptcp_pm_set_flags (struct net *net,struct nlattr *token, -struct mptcp_pm_addr_entry *loc, -struct mptcp_pm_addr_entry *rem,u8 bkup); -int mptcp_pm_nl_set_flags (struct net *net,struct mptcp_pm_addr_entry *addr,u8 bkup); -int mptcp_userspace_pm_set_flags (struct net *net,struct nlattr *token, -struct mptcp_pm_addr_entry *loc, -struct mptcp_pm_addr_entry *rem,u8 bkup); +int mptcp_pm_set_flags (struct sk_buff *skb,struct genl_info *info); +int mptcp_pm_nl_set_flags (struct sk_buff *skb,struct genl_info *info); +int mptcp_userspace_pm_set_flags (struct sk_buff *skb,struct genl_info *info);int mptcp_pm_announce_addr (struct mptcp_sock *msk,const struct mptcp_addr_info *addr,bool echo);
Signature · 1 line
2.40.1
Geliang Tang
reviewerPATCH 4/8 mptcp: set error messages for set_flags
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
In addition to returning the error value, this patch also sets an error messages with GENL_SET_ERR_MSG or NL_SET_ERR_MSG_ATTR both for pm_netlink.c and pm_userspace.c.
--- net/mptcp/pm_netlink.c | 6 +++++- net/mptcp/pm_userspace.c | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-)
net/mptcp/pm_netlink.c +5 -1
@@ -1908,8 +1908,10 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)if (addr.addr.family ==AF_UNSPEC ) { lookup_by_id =1 ; -if (!addr.addr.id) +if (!addr.addr.id) { +GENL_SET_ERR_MSG (info,"missing required inputs" );return -EOPNOTSUPP ; + } }if (addr.flags &MPTCP_PM_ADDR_FLAG_BACKUP )
@@ -1919,11 +1921,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) entry =__lookup_addr (pernet, &addr.addr, lookup_by_id);if (!entry) {spin_unlock_bh (&pernet->lock); +GENL_SET_ERR_MSG (info,"address not found" );return -EINVAL ; }if ((addr.flags &MPTCP_PM_ADDR_FLAG_FULLMESH ) && (entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) {spin_unlock_bh (&pernet->lock); +GENL_SET_ERR_MSG (info,"invalid addr flags" );return -EINVAL ; }
net/mptcp/pm_userspace.c +7 -2
@@ -563,13 +563,17 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) token_val =nla_get_u32 (token); msk =mptcp_token_get_sock (net, token_val); -if (!msk) +if (!msk) { +NL_SET_ERR_MSG_ATTR (info->extack, token,"invalid token" );return ret; + } sk = (struct sock *)msk; -if (!mptcp_pm_is_userspace (msk)) +if (!mptcp_pm_is_userspace (msk)) { +GENL_SET_ERR_MSG (info,"invalid request; userspace PM not selected" ); goto set_flags_err; + } ret =mptcp_pm_parse_entry (attr, info, false, &loc);if (ret <0 )
@@ -583,6 +587,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)if (loc.addr.family ==AF_UNSPEC || rem.addr.family ==AF_UNSPEC ) { +GENL_SET_ERR_MSG (info,"address families do not match" ); ret = -EINVAL ; goto set_flags_err; }
Signature · 1 line
2.40.1
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 4/8] mptcp: set error messages for set_flags
Hi Geliang,
Quoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
In addition to returning the error value, this patch also sets an error messages with
GENL_SET_ERR_MSGorNL_SET_ERR_MSG_ATTRboth forpm_netlink.candpm_userspace.c.
Good idea!
Even if it might be obvious, please *always* explain the reason(s) why having this is interesting. Here, just one sentence is enough:
It will help the userspace to identify the issue.
(same for other patches in general: please *always* add the reason(s))
(...)
Quoted 9 lines
net/mptcp/pm_userspace.c +0
-1@@ -563,13 +563,17 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) token_val =nla_get_u32 (token); msk =mptcp_token_get_sock (net, token_val); -if (!msk)
net/mptcp/pm_userspace.c int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) · line 574
Quoted 10 lines
net/mptcp/pm_userspace.c +5
-1+if (!msk) { +NL_SET_ERR_MSG_ATTR (info->extack, token,"invalid token" );return ret; + } sk = (struct sock *)msk; -if (!mptcp_pm_is_userspace (msk)) +if (!mptcp_pm_is_userspace (msk)) { +GENL_SET_ERR_MSG (info,"invalid request; userspace PM not selected" );
Maybe just "userspace PM not selected"?
net/mptcp/pm_userspace.c int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) · line 590
Quoted 10 lines
net/mptcp/pm_userspace.c +2
-0goto set_flags_err; + } ret =mptcp_pm_parse_entry (attr, info, false, &loc);if (ret <0 )@@ -583,6 +587,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)if (loc.addr.family ==AF_UNSPEC || rem.addr.family ==AF_UNSPEC ) { +GENL_SET_ERR_MSG (info,"address families do not match" );
Maybe better with this?
"invalid address families"
net/mptcp/pm_userspace.c int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) · line 593
Quoted 3 lines
net/mptcp/pm_userspace.c +0
-0ret = -EINVAL ; goto set_flags_err; }
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH 5/8 mptcp: drop lookup_by_id in lookup_addr
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
When the lookup_by_id parameter of __lookup_addr() is true, it's the same as __lookup_addr_by_id(), it can be replaced by __lookup_addr_by_id() directly. So drop this parameter, let __lookup_addr() only looks up address on the local address list by comparing addresses in it, not address ids.
--- net/mptcp/pm_netlink.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
net/mptcp/pm_netlink.c +5 -7
@@ -499,15 +499,12 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id) }static struct mptcp_pm_addr_entry * -__lookup_addr (struct pm_nl_pernet *pernet,const struct mptcp_addr_info *info, -bool lookup_by_id) +__lookup_addr (struct pm_nl_pernet *pernet,const struct mptcp_addr_info *info) {struct mptcp_pm_addr_entry *entry;list_for_each_entry (entry, &pernet->local_addr_list, list) { -if ((!lookup_by_id && -mptcp_addresses_equal (&entry->addr, info, entry->addr.port)) || - (lookup_by_id && entry->addr.id == info->id)) +if (mptcp_addresses_equal (&entry->addr, info, entry->addr.port))return entry; }return NULL ;
@@ -537,7 +534,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)mptcp_local_address ((struct sock_common *)msk->first, &mpc_addr);rcu_read_lock (); - entry =__lookup_addr (pernet, &mpc_addr, false); + entry =__lookup_addr (pernet, &mpc_addr);if (entry) {__clear_bit (entry->addr.id, msk->pm.id_avail_bitmap); msk->mpc_endpoint_id = entry->addr.id;
@@ -1918,7 +1915,8 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) bkup =1 ;spin_lock_bh (&pernet->lock); - entry =__lookup_addr (pernet, &addr.addr, lookup_by_id); + entry = lookup_by_id ?__lookup_addr_by_id (pernet, addr.addr.id) : +__lookup_addr (pernet, &addr.addr);if (!entry) {spin_unlock_bh (&pernet->lock);GENL_SET_ERR_MSG (info,"address not found" );
Signature · 1 line
2.40.1
Geliang Tang
reviewerPATCH 6/8 mptcp: add use_id parameter for addresses_equal
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds a new parameter use_id for mptcp_addresses_equal() to test the address ids, as well as the address. This can be used to test if the two given addresses are identically equal, they have both the same address and the same address id.
--- net/mptcp/pm.c | 2 +- net/mptcp/pm_netlink.c | 32 +++++++++++++++++++------------- net/mptcp/pm_userspace.c | 6 +++--- net/mptcp/protocol.h | 3 ++- 4 files changed, 25 insertions(+), 18 deletions(-)
net/mptcp/pm.c +1 -1
@@ -418,7 +418,7 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)*/ mptcp_local_address ((struct sock_common *)msk, &msk_local);mptcp_local_address ((struct sock_common *)skc, &skc_local); -if (mptcp_addresses_equal (&msk_local, &skc_local, false)) +if (mptcp_addresses_equal (&msk_local, &skc_local, false, false))return 0 ;if (mptcp_pm_is_userspace (msk))
net/mptcp/pm_netlink.c +19 -13
@@ -54,7 +54,8 @@ pm_nl_get_pernet_from_msk(const struct mptcp_sock *msk) }bool mptcp_addresses_equal (const struct mptcp_addr_info *a, -const struct mptcp_addr_info *b,bool use_port) +const struct mptcp_addr_info *b, +bool use_port,bool use_id) {bool addr_equals = false;
@@ -75,10 +76,14 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info *a,if (!addr_equals)return false; -if (!use_port) +if (!use_port && !use_id)return true; -return a->port == b->port; +if (use_port && use_id) +return (a->port == b->port) && (a->id == b->id); +if (use_port) +return a->port == b->port; +return a->id == b->id; }void mptcp_local_address (const struct sock_common *skc,struct mptcp_addr_info *addr)
@@ -117,7 +122,7 @@ static bool lookup_subflow_by_saddr(const struct list_head *list, skc = (struct sock_common *)mptcp_subflow_tcp_sock (subflow);mptcp_local_address (skc, &cur); -if (mptcp_addresses_equal (&cur, saddr, saddr->port)) +if (mptcp_addresses_equal (&cur, saddr, saddr->port, false))return true; }
@@ -135,7 +140,7 @@ static bool lookup_subflow_by_daddr(const struct list_head *list, skc = (struct sock_common *)mptcp_subflow_tcp_sock (subflow);remote_address (skc, &cur); -if (mptcp_addresses_equal (&cur, daddr, daddr->port)) +if (mptcp_addresses_equal (&cur, daddr, daddr->port, false))return true; }
@@ -244,7 +249,7 @@ mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk,lockdep_assert_held (&msk->pm.lock);list_for_each_entry (entry, &msk->pm.anno_list, list) { -if (mptcp_addresses_equal (&entry->addr, addr, true)) +if (mptcp_addresses_equal (&entry->addr, addr, true, false))return entry; }
@@ -261,7 +266,7 @@ bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk)spin_lock_bh (&msk->pm.lock);list_for_each_entry (entry, &msk->pm.anno_list, list) { -if (mptcp_addresses_equal (&entry->addr, &saddr, true)) { +if (mptcp_addresses_equal (&entry->addr, &saddr, true, false)) { ret = true; goto out; }
@@ -504,7 +509,7 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)struct mptcp_pm_addr_entry *entry;list_for_each_entry (entry, &pernet->local_addr_list, list) { -if (mptcp_addresses_equal (&entry->addr, info, entry->addr.port)) +if (mptcp_addresses_equal (&entry->addr, info, entry->addr.port, false))return entry; }return NULL ;
@@ -744,12 +749,12 @@ int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,struct mptcp_addr_info local, remote;mptcp_local_address ((struct sock_common *)ssk, &local); -if (!mptcp_addresses_equal (&local, addr, addr->port)) +if (!mptcp_addresses_equal (&local, addr, addr->port, false))continue ;if (rem && rem->family !=AF_UNSPEC ) {remote_address ((struct sock_common *)ssk, &remote); -if (!mptcp_addresses_equal (&remote, rem, rem->port)) +if (!mptcp_addresses_equal (&remote, rem, rem->port, false))continue ; }
@@ -924,7 +929,8 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, entry->addr.port =0 ;list_for_each_entry (cur, &pernet->local_addr_list, list) {if (mptcp_addresses_equal (&cur->addr, &entry->addr, - cur->addr.port || entry->addr.port)) { + cur->addr.port || entry->addr.port, + false)) {/* allow replacing the exiting endpoint only if such * endpoint is an implicit one and the user-space * did not provide an endpoint id
@@ -1067,7 +1073,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skcrcu_read_lock ();list_for_each_entry_rcu (entry, &pernet->local_addr_list, list) { -if (mptcp_addresses_equal (&entry->addr, skc, entry->addr.port)) { +if (mptcp_addresses_equal (&entry->addr, skc, entry->addr.port, false)) { ret = entry->addr.id;break ; }
@@ -1456,7 +1462,7 @@ static int mptcp_nl_remove_id_zero_address(struct net *net, goto next;mptcp_local_address ((struct sock_common *)msk, &msk_local); -if (!mptcp_addresses_equal (&msk_local, addr, addr->port)) +if (!mptcp_addresses_equal (&msk_local, addr, addr->port, false)) goto next;lock_sock (sk);
net/mptcp/pm_userspace.c +3 -3
@@ -41,7 +41,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,spin_lock_bh (&msk->pm.lock);list_for_each_entry (e, &msk->pm.userspace_pm_local_addr_list, list) { - addr_match =mptcp_addresses_equal (&e->addr, &entry->addr, true); + addr_match =mptcp_addresses_equal (&e->addr, &entry->addr, true, false);if (addr_match && entry->addr.id ==0 && needs_id) entry->addr.id = e->addr.id; id_match = (e->addr.id == entry->addr.id);
@@ -92,7 +92,7 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk,struct mptcp_pm_addr_entry *entry, *tmp;list_for_each_entry_safe (entry, tmp, &msk->pm.userspace_pm_local_addr_list, list) { -if (mptcp_addresses_equal (&entry->addr, &addr->addr, false)) { +if (mptcp_addresses_equal (&entry->addr, &addr->addr, false, false)) {/* TODO: a refcount is needed because the entry can * be used multiple times (e.g. fullmesh mode). */
@@ -144,7 +144,7 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk,spin_lock_bh (&msk->pm.lock);list_for_each_entry (e, &msk->pm.userspace_pm_local_addr_list, list) { -if (mptcp_addresses_equal (&e->addr, skc, false)) { +if (mptcp_addresses_equal (&e->addr, skc, false, false)) { entry = e;break ; }
net/mptcp/protocol.h +2 -1
@@ -670,7 +670,8 @@ void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk);void mptcp_set_state (struct sock *sk,int state);bool mptcp_addresses_equal (const struct mptcp_addr_info *a, -const struct mptcp_addr_info *b,bool use_port); +const struct mptcp_addr_info *b, +bool use_port,bool use_id);void mptcp_local_address (const struct sock_common *skc,struct mptcp_addr_info *addr);/* called with sk socket lock held */
Signature · 1 line
2.40.1
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 6/8] mptcp: add use_id parameter for addresses_equal
Hi Geliang,
Quoted 6 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch adds a new parameter
use_idformptcp_addresses_equal()to test the address ids, as well as the address. This can be used to test if the two given addresses are identically equal, they have both the same address and the same address id.
(...)
net/mptcp/protocol.h void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk); · line 674
Quoted 11 lines
net/mptcp/protocol.h +2
-1@@ -670,7 +670,8 @@ void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk);void mptcp_set_state (struct sock *sk,int state);bool mptcp_addresses_equal (const struct mptcp_addr_info *a, -const struct mptcp_addr_info *b,bool use_port); +const struct mptcp_addr_info *b, +bool use_port,bool use_id);
That's a lot of modifications just to introduce one new parameter. Would it not be better to use a macro?
#define mptcp_addresses_equal(a, b, use_port) \
mptcp_addresses_equal_check_id(a, b, use_port, false)Or maybe better with an "inline" function?
Or extending the function:
bool mptcp_addresses_equal_check_id(...)
{
return mptcp_addresses_equal(...) ? a->id == b->id : false;
}=> Or only do this extra check in mptcp_lookup_anno_list_by_saddr() where you need that, no?
I will check with Mat what he thinks about that.
net/mptcp/protocol.h void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk); · line 677
Quoted 3 lines
net/mptcp/protocol.h +0
-0void mptcp_local_address (const struct sock_common *skc,struct mptcp_addr_info *addr);/* called with sk socket lock held */
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH 7/8 mptcp: add check_id for lookup_anno_list_by_saddr
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Add a new parameter check_id for mptcp_lookup_anno_list_by_saddr(), and pass it to mptcp_addresses_equal(). Then in mptcp_pm_del_add_timer(), the input parameter check_id can be passed as the new parameter into mptcp_lookup_anno_list_by_saddr(). After this, this condition:
(!check_id || entry->addr.id == addr->id)
can be dropped, only test if 'entry' is NULL is enough.
--- net/mptcp/pm.c | 2 +- net/mptcp/pm_netlink.c | 13 +++++++------ net/mptcp/protocol.h | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-)
net/mptcp/pm.c +1 -1
@@ -257,7 +257,7 @@ void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk,spin_lock_bh (&pm->lock); -if (mptcp_lookup_anno_list_by_saddr (msk, addr) &&READ_ONCE (pm->work_pending)) +if (mptcp_lookup_anno_list_by_saddr (msk, addr, false) &&READ_ONCE (pm->work_pending))mptcp_pm_schedule_work (msk,MPTCP_PM_SUBFLOW_ESTABLISHED );spin_unlock_bh (&pm->lock);
net/mptcp/pm_netlink.c +7 -6
@@ -242,14 +242,15 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk)struct mptcp_pm_add_entry *mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk, -const struct mptcp_addr_info *addr) +const struct mptcp_addr_info *addr, +bool check_id) {struct mptcp_pm_add_entry *entry;lockdep_assert_held (&msk->pm.lock);list_for_each_entry (entry, &msk->pm.anno_list, list) { -if (mptcp_addresses_equal (&entry->addr, addr, true, false)) +if (mptcp_addresses_equal (&entry->addr, addr, true, check_id))return entry; }
@@ -329,12 +330,12 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,struct sock *sk = (struct sock *)msk;spin_lock_bh (&msk->pm.lock); - entry =mptcp_lookup_anno_list_by_saddr (msk, addr); -if (entry && (!check_id || entry->addr.id == addr->id)) + entry =mptcp_lookup_anno_list_by_saddr (msk, addr, check_id); +if (entry) entry->retrans_times =ADD_ADDR_RETRANS_MAX ;spin_unlock_bh (&msk->pm.lock); -if (entry && (!check_id || entry->addr.id == addr->id)) +if (entry)sk_stop_timer_sync (sk, &entry->add_timer);return entry;
@@ -349,7 +350,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,lockdep_assert_held (&msk->pm.lock); - add_entry =mptcp_lookup_anno_list_by_saddr (msk, addr); + add_entry =mptcp_lookup_anno_list_by_saddr (msk, addr, false);if (add_entry) {if (mptcp_pm_is_kernel (msk))
net/mptcp/protocol.h +2 -1
@@ -967,7 +967,8 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool check_id);struct mptcp_pm_add_entry *mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk, -const struct mptcp_addr_info *addr); +const struct mptcp_addr_info *addr, +bool check_id);int mptcp_pm_get_flags_and_ifindex_by_id (struct mptcp_sock *msk,unsigned int id,u8 *flags,int *ifindex);
Signature · 1 line
2.40.1
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 7/8] mptcp: add check_id for lookup_anno_list_by_saddr
Quoted 10 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Add a new parameter
check_idformptcp_lookup_anno_list_by_saddr(), and pass it tomptcp_addresses_equal(). Then inmptcp_pm_del_add_timer(), the input parametercheck_idcan be passed as the new parameter intomptcp_lookup_anno_list_by_saddr(). After this, this condition:(!check_id || entry->addr.id == addr->id)can be dropped, only test if 'entry' is NULL is enough.
(...)
Quoted 4 lines
net/mptcp/pm_netlink.c +0
-0
(...)
net/mptcp/pm_netlink.c mptcp_pm_del_add_timer(struct mptcp_sock *msk, · line 338
Quoted 13 lines
net/mptcp/pm_netlink.c +3
-3@@ -329,12 +330,12 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,struct sock *sk = (struct sock *)msk;spin_lock_bh (&msk->pm.lock); - entry =mptcp_lookup_anno_list_by_saddr (msk, addr); -if (entry && (!check_id || entry->addr.id == addr->id)) + entry =mptcp_lookup_anno_list_by_saddr (msk, addr, check_id); +if (entry) entry->retrans_times =ADD_ADDR_RETRANS_MAX ;spin_unlock_bh (&msk->pm.lock); -if (entry && (!check_id || entry->addr.id == addr->id)) +if (entry)
Instead of all these modifications in mptcp_addresses_equal() and mptcp_lookup_anno_list_by_saddr() just for this specific case here, can we not use an extra variable?
bool stop_retrans;
(...)
spin_lock_bh(&msk->pm.lock);
entry = mptcp_lookup_anno_list_by_saddr(msk, addr);
stop_retrans = entry && (!check_id || entry->addr.id == addr->id);
if (stop_retrans) // or in one line, merged with ↑ ?
entry->retrans_times = ADD_ADDR_RETRANS_MAX;
spin_unlock_bh(&msk->pm.lock);
if (stop_retrans)
sk_stop_timer_sync(sk, &entry->add_timer);net/mptcp/pm_netlink.c mptcp_pm_del_add_timer(struct mptcp_sock *msk, · line 341
Quoted 3 lines
net/mptcp/pm_netlink.c +0
-0sk_stop_timer_sync (sk, &entry->add_timer);return entry;
(...)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH 8/8 selftests: mptcp: flush userspace addrs list
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds a new helper userspace_pm_flush() to flush all addresses for the userspace PM. Invoke it in userspace pm dump address and subflow tests. And use dump commands to check if the userspace pm local address list is empty after addresses flushing.
--- .../testing/selftests/net/mptcp/mptcp_join.sh | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +39 -7
@@ -3374,6 +3374,34 @@ userspace_pm_get_addr() ip netns exec $1 ./pm_nl_ctl get $2 token $tk } +# $1: ns ; $2: addr +userspace_pm_flush() +{ + if mptcp_lib_kallsyms_has "mptcp_userspace_pm_dump_addr$"; then + local ns=$1 + local line + + userspace_pm_dump $ns | while read -r line; do + local arr=($line) + local nr=0 + local id + local addr + local i + for i in "${arr[@]}"; do + if [ $i = "id" ]; then + id=${arr[$nr+1]} + fi + nr=$((nr + 1)) + done + addr=${arr[$nr-1]} + userspace_pm_rm_addr $ns $id + userspace_pm_rm_sf $ns "$addr" $SUB_ESTABLISHED + done + else + print_skip + fi +} + userspace_pm_chk_dump_addr() { local ns="${1}"
@@ -3518,25 +3546,29 @@ userspace_tests() if reset_with_events "userspace pm create destroy subflow" && continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then set_userspace_pm $ns2 - pm_nl_set_limits $ns1 0 1 + pm_nl_set_limits $ns1 0 2 speed=5 \ run_tests $ns1 $ns2 10.0.1.1 & local tests_pid=$! wait_mpj $ns2 + userspace_pm_add_sf $ns2 10.0.2.2 10 userspace_pm_add_sf $ns2 10.0.3.2 20 - chk_join_nr 1 1 1 - chk_mptcp_info subflows 1 subflows 1 - chk_subflows_total 2 2 + chk_join_nr 2 2 2 + chk_mptcp_info subflows 2 subflows 2 + chk_subflows_total 3 3 userspace_pm_chk_dump_addr "${ns2}" \ - "id 20 flags subflow 10.0.3.2" \ + $'id 10 flags subflow 10.0.2.2\nid 20 flags subflow 10.0.3.2' \ "subflow" + userspace_pm_chk_get_addr "${ns2}" "10" "id 10 flags subflow 10.0.2.2" userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2" userspace_pm_rm_addr $ns2 20 userspace_pm_rm_sf $ns2 10.0.3.2 $SUB_ESTABLISHED userspace_pm_chk_dump_addr "${ns2}" \ - "" \ + "id 10 flags subflow 10.0.2.2" \ "after rm_addr 20" - chk_rm_nr 1 1 + userspace_pm_flush $ns2 + userspace_pm_chk_dump_addr "${ns2}" "" "after flush" + chk_rm_nr 2 2 chk_mptcp_info subflows 0 subflows 0 chk_subflows_total 1 1 kill_events_pids
Signature · 1 line
2.40.1
Re: selftests: mptcp: flush userspace addrs list: Tests Results
Hi Geliang,
Thank you for your modifications, that's great!
Our CI (GitHub Action) did some validations and here is its report:
- KVM Validation: normal:
- Unstable: 1 failed test(s): packetdrill_regressions 🔴:
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/7991240119
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/8bd552ab6146
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 8/8] selftests: mptcp: flush userspace addrs list
In reply to Geliang TangHi Geliang,
Quoted 18 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch adds a new helper
userspace_pm_flush()to flush all addresses for the userspace PM. Invoke it in userspace pm dump address and subflow tests. And use dump commands to check if the userspace pm local address list is empty after addresses flushing.Signed-off-by Geliang Tang <[email protected]>--- .../testing/selftests/net/mptcp/mptcp_join.sh | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-)tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -3374,6 +3374,34 @@ userspace_pm_get_addr() ip netns exec $1 ./pm_nl_ctl get $2 token $tk
tools/testing/selftests/net/mptcp/mptcp_join.sh userspace_pm_get_addr() · line 3384
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +8
-0} +# $1: ns ; $2: addr +userspace_pm_flush() +{ + if mptcp_lib_kallsyms_has "mptcp_userspace_pm_dump_addr$"; then + local ns=$1 + local line + + userspace_pm_dump $ns | while read -r line; do
This will create a subshell: it means that variables that are changed here below will only be valid in this restricted scope. In other words, if there is a failure below, the 'failure' message will be printed, but 'ret=1' will only be set here in this scope, so the test will not be marked as failed: the check will be ignored. You cannot do it like that.
What you can do is something like that to avoid a subshell:
while read -r line; do (...); done <<< $(cmd)
but...
tools/testing/selftests/net/mptcp/mptcp_join.sh userspace_pm_get_addr() · line 3396
Quoted 12 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +12
-0+ local arr=($line) + local nr=0 + local id + local addr + local i + for i in "${arr[@]}"; do + if [ $i = "id" ]; then + id=${arr[$nr+1]} + fi + nr=$((nr + 1)) + done + addr=${arr[$nr-1]}
Can you not use read to do the parsing if it is always the same output:
read -r _ id _ _ addr
tools/testing/selftests/net/mptcp/mptcp_join.sh userspace_pm_get_addr() · line 3401
Quoted 5 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +5
-0+ userspace_pm_rm_addr $ns $id + userspace_pm_rm_sf $ns "$addr" $SUB_ESTABLISHED + done + else + print_skip
The skip doesn't make sense here: there is no 'check' in progress.
But that's not it, the behaviour is wrong too: if the feature is not supported, it means that the subflows and addresses will not be removed, then the rest of the test will be wrong on kernels not supporting the features because the counters will be different.
Maybe we could do that in a new dedicated test where everything is skipped if "dump addresses" is not supported. But, does this test increase the code coverage? I understand that doing the flush is a good "summary", but it looks like this has already been validated, no? So maybe easier to drop this?
tools/testing/selftests/net/mptcp/mptcp_join.sh userspace_pm_get_addr() · line 3407
Quoted 6 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +3
-0+ fi +} + userspace_pm_chk_dump_addr() { local ns="${1}"
(...)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerHi Geliang,
Quoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Depends on:
- dump for userspace pm, v14
Quoted 9 lines
Geliang Tang (8):
mptcp: makepm_remove_addrs_and_subflowsstatic
mptcp: drop duplicate header inclusions
mptcp: updateset_flagsinterfaces
mptcp: set error messages forset_flags
mptcp: droplookup_by_idinlookup_addr
mptcp: adduse_idparameter foraddresses_equal
mptcp: addcheck_idforlookup_anno_list_by_saddr
selftests: mptcp: flush userspace addrs list
Thank you for this clean-up!
Patches 1-3, 5 look good to me. But I have some comments for the others. I think patches 6-7 can be simplified by just using one new variable, not sure about patch 8.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.