dump for userspace pm
Subsystems (3)
cover dump for userspace pm
Address Mat's comments in "userspace pm enhancements" v14.
Geliang Tang (12):
mptcp: add mptcp_pm_nl_put_entry_msg helper
mptcp: implement mptcp_userspace_pm_dump_addr
mptcp: dump addrs in userspace pm list
mptcp: check userspace pm subflow flag
selftests: mptcp: add userspace pm subflow flag
selftests: mptcp: dump userspace addrs list
mptcp: add userspace_pm_lookup_addr_by_id helper
mptcp: add mptcp_pm_nl_put_entry_info helper
mptcp: implement mptcp_userspace_pm_get_addr
mptcp: get addr in userspace pm list
selftests: mptcp: add token for get_addr
selftests: mptcp: userspace pm get addr tests
net/mptcp/mptcp_pm_gen.c | 5 +- net/mptcp/mptcp_pm_gen.h | 2 +- net/mptcp/pm_netlink.c | 94 +++++++++++++------ net/mptcp/pm_userspace.c | 94 +++++++++++++++---- net/mptcp/protocol.h | 9 ++ .../testing/selftests/net/mptcp/mptcp_join.sh | 91 ++++++++++++++++++ tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 22 ++++- 7 files changed, 266 insertions(+), 51 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/12 mptcp: add mptcp_pm_nl_put_entry_msg helper
Extract the genlmsg related code from mptcp_pm_nl_get_addr_dumpit() into a new helper mptcp_pm_nl_put_entry_msg(). It will be used in the userspace PM dump_addr().
--- net/mptcp/pm_netlink.c | 35 ++++++++++++++++++++++++----------- net/mptcp/protocol.h | 3 +++ 2 files changed, 27 insertions(+), 11 deletions(-)
net/mptcp/pm_netlink.c +24 -11
@@ -1656,6 +1656,29 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,return -EMSGSIZE ; } +int mptcp_pm_nl_put_entry_msg (struct sk_buff *msg, +struct netlink_callback *cb, +struct mptcp_pm_addr_entry *entry) +{ +void *hdr; +int ret; + + hdr =genlmsg_put (msg,NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, &mptcp_genl_family, +NLM_F_MULTI ,MPTCP_PM_CMD_GET_ADDR ); +if (!hdr) +return -EMSGSIZE ; + + ret =mptcp_nl_fill_addr (msg, entry); +if (ret <0 ) { +genlmsg_cancel (msg, hdr); +return ret; + } + +genlmsg_end (msg, hdr); +return 0 ; +} +int mptcp_pm_nl_get_addr_doit (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ];
@@ -1713,7 +1736,6 @@ int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,struct mptcp_pm_addr_entry *entry;struct pm_nl_pernet *pernet;int id = cb->args[0 ]; -void *hdr;int i; pernet =pm_nl_get_pernet (net);
@@ -1728,19 +1750,10 @@ int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,if (entry->addr.id <= id)continue ; - hdr =genlmsg_put (msg,NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, -NLM_F_MULTI ,MPTCP_PM_CMD_GET_ADDR ); -if (!hdr) -break ; - -if (mptcp_nl_fill_addr (msg, entry) <0 ) { -genlmsg_cancel (msg, hdr); +if (mptcp_pm_nl_put_entry_msg (msg, cb, entry))break ; - } id = entry->addr.id; -genlmsg_end (msg, hdr); } }spin_unlock_bh (&pernet->lock);
net/mptcp/protocol.h +3 -0
@@ -1022,6 +1022,9 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, const struct sk_buff *skb, bool *drop_other_suboptions);bool mptcp_pm_rm_addr_signal (struct mptcp_sock *msk,unsigned int remaining,struct mptcp_rm_list *rm_list); +int mptcp_pm_nl_put_entry_msg (struct sk_buff *msg, +struct netlink_callback *cb, +struct mptcp_pm_addr_entry *entry);int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc);int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc);int mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc);
Signature · 1 line
2.35.3
PATCH 2/12 mptcp: implement mptcp_userspace_pm_dump_addr
In reply to Geliang TangThis patch implements mptcp_userspace_pm_dump_addr() to dump addresses from userspace pm address list. For each msk in this net, if userspace PM is enabled in it, traverse each address entry in address list, put every entry to userspace using mptcp_pm_nl_put_entry_msg().
--- net/mptcp/pm_userspace.c | 29 +++++++++++++++++++++++++++++ net/mptcp/protocol.h | 2 ++ 2 files changed, 31 insertions(+)
net/mptcp/pm_userspace.c +29 -0
@@ -550,3 +550,32 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token,sock_put (sk);return ret; } + +int mptcp_userspace_pm_dump_addr (struct sk_buff *msg, +struct netlink_callback *cb) +{ +struct net *net =sock_net (msg->sk); +struct mptcp_pm_addr_entry *entry; +long s_slot =0 , s_num =0 ; +struct mptcp_sock *msk; + +while ((msk =mptcp_token_iter_next (net, &s_slot, &s_num)) !=NULL ) { +struct sock *sk = (struct sock *)msk; + +if (mptcp_pm_is_userspace (msk)) { +lock_sock (sk); +spin_lock_bh (&msk->pm.lock); +list_for_each_entry (entry, &msk->pm.userspace_pm_local_addr_list, list) { +if (mptcp_pm_nl_put_entry_msg (msg, cb, entry)) +break ; + } +spin_unlock_bh (&msk->pm.lock); +release_sock (sk); + } + +sock_put (sk); +cond_resched (); + } + +return msg->len; +}
net/mptcp/protocol.h +2 -0
@@ -1028,6 +1028,8 @@ int mptcp_pm_nl_put_entry_msg(struct sk_buff *msg,int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc);int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc);int mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc); +int mptcp_userspace_pm_dump_addr (struct sk_buff *msg, +struct netlink_callback *cb);void __init mptcp_pm_nl_init (void );void mptcp_pm_nl_work (struct mptcp_sock *msk);
Signature · 1 line
2.35.3
Mat Martineau
maintainerRe: [PATCH mptcp-next 02/12] mptcp: implement mptcp_userspace_pm_dump_addr
Quoted 16 lines · Geliang Tang
This patch implements
mptcp_userspace_pm_dump_addr()to dump addresses from userspace pm address list. For each msk in this net, if userspace PM is enabled in it, traverse each address entry in address list, put every entry to userspace usingmptcp_pm_nl_put_entry_msg().Signed-off-by Geliang Tang <[email protected]>---
net/mptcp/pm_userspace.c| 29 +++++++++++++++++++++++++++++net/mptcp/protocol.h| 2 ++2 files changed, 31 insertions(+)net/mptcp/pm_userspace.c +0
-0
net/mptcp/pm_userspace.c int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, · line 555
Quoted 6 lines
net/mptcp/pm_userspace.c +3
-0@@ -550,3 +550,32 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token,sock_put (sk);return ret; } + +int mptcp_userspace_pm_dump_addr (struct sk_buff *msg, +struct netlink_callback *cb)
Hi Geliang -
The entire list of entries may not fit in one skb. The cb struct is used to store context so the netlink framework can call the dump function multiple times to fill multiple skbs. This is why the original mptcp_pm_nl_get_addr_dumpit() reads and stores the id to/from cb->args[0]. That cb->args[0] context is used to skip the ids that have already been dumped.
With the function body below, if the list does not fit in one skb it will do the same thing on every call and create duplicate entries, and will never return 0 to tell the caller that it is finished.
There is also nothing in the netlink output to indicate which MPTCP connection each subflow id is associated with, or whether the entry is from a userspace-managed socket or the in-kernel pm, so the dumped information is not useful to a userspace PM.
Netlink dump commands can have attributes in the request (see netdev_nl_napi_get_dumpit()), I think it will be simpler to add a connection token to the dump request and only dump the id list for that single MPTCP connection.
- Mat
Quoted 44 lines
net/mptcp/pm_userspace.c +26
-0+{ +struct net *net =sock_net (msg->sk); +struct mptcp_pm_addr_entry *entry; +long s_slot =0 , s_num =0 ; +struct mptcp_sock *msk; + +while ((msk =mptcp_token_iter_next (net, &s_slot, &s_num)) !=NULL ) { +struct sock *sk = (struct sock *)msk; + +if (mptcp_pm_is_userspace (msk)) { +lock_sock (sk); +spin_lock_bh (&msk->pm.lock); +list_for_each_entry (entry, &msk->pm.userspace_pm_local_addr_list, list) { +if (mptcp_pm_nl_put_entry_msg (msg, cb, entry)) +break ; + } +spin_unlock_bh (&msk->pm.lock); +release_sock (sk); + } + +sock_put (sk); +cond_resched (); + } + +return msg->len; +}net/mptcp/protocol.h +2
-0@@ -1028,6 +1028,8 @@ int mptcp_pm_nl_put_entry_msg(struct sk_buff *msg,int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc);int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc);int mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc); +int mptcp_userspace_pm_dump_addr (struct sk_buff *msg, +struct netlink_callback *cb);void __init mptcp_pm_nl_init (void );void mptcp_pm_nl_work (struct mptcp_sock *msk);Signature · 1 line
2.35.3
PATCH 3/12 mptcp: dump addrs in userspace pm list
In reply to Geliang TangThis patch renames mptcp_pm_nl_get_addr_dumpit() to in-kernel netlink PM dump addrs function mptcp_pm_nl_dump_addr(), then invoke both in-kernel PM mptcp_pm_nl_dump_addr() and userspace PM mptcp_userspace_pm_dump_addr() dump addrs functions in mptcp_pm_nl_get_addr_dumpit().
--- net/mptcp/pm_netlink.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/mptcp/pm_netlink.c +9 -2
@@ -1729,8 +1729,8 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)return ret; } -int mptcp_pm_nl_get_addr_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int mptcp_pm_nl_dump_addr (struct sk_buff *msg, +struct netlink_callback *cb) {struct net *net =sock_net (msg->sk);struct mptcp_pm_addr_entry *entry;
@@ -1762,6 +1762,13 @@ int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,return msg->len; } +int mptcp_pm_nl_get_addr_dumpit (struct sk_buff *msg, +struct netlink_callback *cb) +{ +return mptcp_pm_nl_dump_addr (msg, cb) + +mptcp_userspace_pm_dump_addr (msg, cb); +} +static int parse_limit (struct genl_info *info,int id,unsigned int *limit) {struct nlattr *attr = info->attrs[id];
Signature · 1 line
2.35.3
PATCH 4/12 mptcp: check userspace pm subflow flag
In reply to Geliang TangThis patch uses mptcp_pm_parse_entry() instead of mptcp_pm_parse_addr() to get the flags of the entry. Add MPTCP_PM_ADDR_FLAG_SUBFLOW flag check in mptcp_pm_nl_subflow_create_doit().
--- net/mptcp/pm_userspace.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/mptcp/pm_userspace.c +8 -2
@@ -348,12 +348,19 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) goto create_err; } - err =mptcp_pm_parse_addr (laddr, info, &addr_l); + err =mptcp_pm_parse_entry (laddr, info, true, &local);if (err <0 ) {NL_SET_ERR_MSG_ATTR (info->extack, laddr,"error parsing local addr" ); goto create_err; } +if (!(local.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW )) { +GENL_SET_ERR_MSG (info,"invalid addr flags" ); + err = -EINVAL ; + goto create_err; + } + addr_l = local.addr; + err =mptcp_pm_parse_addr (raddr, info, &addr_r);if (err <0 ) {NL_SET_ERR_MSG_ATTR (info->extack, raddr,"error parsing remote addr" );
@@ -366,7 +373,6 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) goto create_err; } - local.addr = addr_l; err =mptcp_userspace_pm_append_new_local_addr (msk, &local);if (err <0 ) {GENL_SET_ERR_MSG (info,"did not match address and id" );
Signature · 1 line
2.35.3
PATCH 5/12 selftests: mptcp: add userspace pm subflow flag
In reply to Geliang TangThis patch adds the address flag MPTCP_PM_ADDR_FLAG_SUBFLOW in csf() in pm_nl_ctl.c when subflow is created by a userspace PM.
--- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/testing/selftests/net/mptcp/pm_nl_ctl.c +8 -0
@@ -453,6 +453,7 @@ int csf(int fd, int pm_family, int argc, char *argv[])char data[NLMSG_ALIGN (sizeof (struct nlmsghdr )) +NLMSG_ALIGN (sizeof (struct genlmsghdr )) +1024 ]; +u_int32_t flags =MPTCP_PM_ADDR_FLAG_SUBFLOW ;const char *params[5 ];struct nlmsghdr *nh;struct rtattr *addr;
@@ -558,6 +559,13 @@ int csf(int fd, int pm_family, int argc, char *argv[]) off +=NLMSG_ALIGN (rta->rta_len); } +/* addr flags */ + rta = (void *)(data + off); + rta->rta_type =MPTCP_PM_ADDR_ATTR_FLAGS ; + rta->rta_len =RTA_LENGTH (4 ); +memcpy (RTA_DATA (rta), &flags,4 ); + off +=NLMSG_ALIGN (rta->rta_len); + addr->rta_len = off - addr_start; }
Signature · 1 line
2.35.3
PATCH 6/12 selftests: mptcp: dump userspace addrs list
In reply to Geliang TangThis patch tests newly added dump command for the userspace PM. Add two new tests for userspace pm dump address and subflow. Use the helpers userspace_pm_add_addr() and userspace_pm_add_sf() to add an address and a suflow.
Similar to check() in pm_netlink.sh, add a new helper check_output() in mptcp_join.sh to check the output of the given commands. Use it to check the outputs of dump commands.
--- .../testing/selftests/net/mptcp/mptcp_join.sh | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +75 -0
@@ -21,6 +21,7 @@ cinfail="" cinsent="" tmpfile="" cout="" +check_output_err="" capout="" ns1="" ns2=""
@@ -186,6 +187,7 @@ init() { cout=$(mktemp) evts_ns1=$(mktemp) evts_ns2=$(mktemp) + check_output_err=$(mktemp) trap cleanup EXIT
@@ -199,6 +201,7 @@ cleanup() rm -f "$sin" "$sout" "$cinsent" "$cinfail" rm -f "$tmpfile" rm -rf $evts_ns1 $evts_ns2 + rm -f $check_output_err cleanup_partial }
@@ -3356,6 +3359,32 @@ userspace_pm_rm_sf() wait_rm_sf $1 "${cnt}" } +check_output() { + : "${check_output_err:?}" + : "${ret:?}" + + local cmd="$1" + local expected="$2" + local msg="$3" + local out=`$cmd 2>$check_output_err` + local cmd_ret=$? + + printf "%-42s" "$msg" + if [ $cmd_ret -ne 0 ]; then + mptcp_lib_print_err "[ FAIL ] command execution '$cmd' stderr " + cat $check_output_err + ret=${KSFT_FAIL} + return $cmd_ret + elif [ "$out" = "$expected" ]; then + mptcp_lib_print_ok "[ OK ]" + return 0 + else + mptcp_lib_print_err "[ FAIL ] expected '$expected' got '$out'" + ret=${KSFT_FAIL} + return 1 + fi +} + userspace_tests() { # userspace pm type prevents add_addr
@@ -3545,6 +3574,52 @@ userspace_tests() kill_events_pids wait $tests_pid fi + + # userspace pm dump address + if reset_with_events "userspace pm dump address" && + continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then + set_userspace_pm $ns1 + pm_nl_set_limits $ns2 1 1 + speed=5 \ + run_tests $ns1 $ns2 10.0.1.1 & + local tests_pid=$! + wait_mpj $ns1 + userspace_pm_add_addr $ns1 10.0.2.1 10 + chk_join_nr 1 1 1 + chk_add_nr 1 1 + chk_mptcp_info subflows 1 subflows 1 + chk_subflows_total 2 2 + chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 + local dump="id 10 flags signal 10.0.2.1" + [ $ip_mptcp -eq 1 ] && dump="10.0.2.1 id 10 signal " + check_output "pm_nl_show_endpoints $ns1" \ + "$dump" " dump addrs signal" + kill_events_pids + wait $tests_pid + fi + + # userspace pm dump subflow + if reset_with_events "userspace pm dump 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 + speed=5 \ + run_tests $ns1 $ns2 10.0.1.1 & + local tests_pid=$! + wait_mpj $ns2 + chk_mptcp_info subflows 0 subflows 0 + chk_subflows_total 1 1 + 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 + local dump="id 20 flags subflow 10.0.3.2" + [ $ip_mptcp -eq 1 ] && dump="10.0.3.2 id 20 subflow " + check_output "pm_nl_show_endpoints $ns2" \ + "$dump" " dump addrs subflow" + kill_events_pids + wait $tests_pid + fi } endpoint_tests()
Signature · 1 line
2.35.3
PATCH 7/12 mptcp: add userspace_pm_lookup_addr_by_id helper
In reply to Geliang TangCorresponding __lookup_addr_by_id() helper in the in-kernel netlink PM, this patch adds a new helper mptcp_userspace_pm_lookup_addr_by_id() to lookup the address entry with the given id on the userspace pm local address list.
--- net/mptcp/pm_userspace.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
net/mptcp/pm_userspace.c +16 -15
@@ -105,19 +105,26 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk,return -EINVAL ; } +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr_by_id (struct mptcp_sock *msk,unsigned int id) +{ +struct mptcp_pm_addr_entry *entry; + +list_for_each_entry (entry, &msk->pm.userspace_pm_local_addr_list, list) { +if (entry->addr.id == id) +return entry; + } +return NULL ; +} +int mptcp_userspace_pm_get_flags_and_ifindex_by_id (struct mptcp_sock *msk,unsigned int id,u8 *flags,int *ifindex) { -struct mptcp_pm_addr_entry *entry, *match =NULL ; +struct mptcp_pm_addr_entry *match;spin_lock_bh (&msk->pm.lock); -list_for_each_entry (entry, &msk->pm.userspace_pm_local_addr_list, list) { -if (id == entry->addr.id) { - match = entry; -break ; - } - } + match =mptcp_userspace_pm_lookup_addr_by_id (msk, id);spin_unlock_bh (&msk->pm.lock);if (match) { *flags = match->flags;
@@ -249,7 +256,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) {struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN ];struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID ]; -struct mptcp_pm_addr_entry *match =NULL ; +struct mptcp_pm_addr_entry *match;struct mptcp_pm_addr_entry *entry;struct mptcp_sock *msk;LIST_HEAD (free_list);
@@ -286,13 +293,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)lock_sock (sk); -list_for_each_entry (entry, &msk->pm.userspace_pm_local_addr_list, list) { -if (entry->addr.id == id_val) { - match = entry; -break ; - } - } - + match =mptcp_userspace_pm_lookup_addr_by_id (msk, id_val);if (!match) {GENL_SET_ERR_MSG (info,"address with specified id not found" );release_sock (sk);
Signature · 1 line
2.35.3
PATCH 8/12 mptcp: add mptcp_pm_nl_put_entry_info helper
In reply to Geliang TangThis patch extracts the nlmsg related code from mptcp_pm_nl_get_addr_doit() into a new helper mptcp_pm_nl_put_entry_info(). It will be used in the userspace PM get_addr().
--- net/mptcp/pm_netlink.c | 55 ++++++++++++++++++++++++------------------ net/mptcp/protocol.h | 2 ++ 2 files changed, 34 insertions(+), 23 deletions(-)
net/mptcp/pm_netlink.c +32 -23
@@ -1656,6 +1656,37 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,return -EMSGSIZE ; } +int mptcp_pm_nl_put_entry_info (struct genl_info *info, +struct mptcp_pm_addr_entry *entry) +{ +struct sk_buff *msg; +void *reply; +int ret; + + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + reply =genlmsg_put_reply (msg, info, &mptcp_genl_family,0 , + info->genlhdr->cmd); +if (!reply) { +GENL_SET_ERR_MSG (info,"not enough space in Netlink message" ); + ret = -EMSGSIZE ; + goto fail; + } + + ret =mptcp_nl_fill_addr (msg, entry); +if (ret) + goto fail; + +genlmsg_end (msg, reply); + ret =genlmsg_reply (msg, info); +return ret; +fail: +nlmsg_free (msg); +return ret; +} +int mptcp_pm_nl_put_entry_msg (struct sk_buff *msg,struct netlink_callback *cb,struct mptcp_pm_addr_entry *entry)
@@ -1684,26 +1715,12 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ];struct pm_nl_pernet *pernet =genl_info_pm_nl (info);struct mptcp_pm_addr_entry addr, *entry; -struct sk_buff *msg; -void *reply;int ret; ret =mptcp_pm_parse_entry (attr, info, false, &addr);if (ret <0 )return ret; - msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); -if (!msg) -return -ENOMEM ; - - reply =genlmsg_put_reply (msg, info, &mptcp_genl_family,0 , - info->genlhdr->cmd); -if (!reply) { -GENL_SET_ERR_MSG (info,"not enough space in Netlink message" ); - ret = -EMSGSIZE ; - goto fail; - } -spin_lock_bh (&pernet->lock); entry =__lookup_addr_by_id (pernet, addr.addr.id);if (!entry) {
@@ -1712,20 +1729,12 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) goto unlock_fail; } - ret =mptcp_nl_fill_addr (msg, entry); -if (ret) - goto unlock_fail; - -genlmsg_end (msg, reply); - ret =genlmsg_reply (msg, info); + ret =mptcp_pm_nl_put_entry_info (info, entry);spin_unlock_bh (&pernet->lock);return ret; unlock_fail:spin_unlock_bh (&pernet->lock); - -fail: -nlmsg_free (msg);return ret; }
net/mptcp/protocol.h +2 -0
@@ -1025,6 +1025,8 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,int mptcp_pm_nl_put_entry_msg (struct sk_buff *msg,struct netlink_callback *cb,struct mptcp_pm_addr_entry *entry); +int mptcp_pm_nl_put_entry_info (struct genl_info *info, +struct mptcp_pm_addr_entry *entry);int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc);int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc);int mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc);
Signature · 1 line
2.35.3
PATCH 9/12 mptcp: implement mptcp_userspace_pm_get_addr
In reply to Geliang TangThis patch implements mptcp_userspace_pm_get_addr() to get an address from userspace pm address list according the given 'token' and 'id'. Use nla_get_u32() to get the u32 value of 'token', then pass it to mptcp_token_get_sock() to get the msk. Pass 'msk' and 'id' to the helper mptcp_userspace_pm_lookup_addr_by_id() to get the address entry. Put this entry to userspace using mptcp_pm_nl_put_entry_info().
--- net/mptcp/pm_userspace.c | 24 ++++++++++++++++++++++++ net/mptcp/protocol.h | 2 ++ 2 files changed, 26 insertions(+)
net/mptcp/pm_userspace.c +24 -0
@@ -586,3 +586,27 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,return msg->len; } + +int mptcp_userspace_pm_get_addr (struct net *net,struct genl_info *info, +struct nlattr *token,u8 id) +{ +u32 token_val =nla_get_u32 (token); +struct mptcp_pm_addr_entry *entry; +struct mptcp_sock *msk; +int ret = -EINVAL ; + + msk =mptcp_token_get_sock (net, token_val); +if (!msk) +return ret; + +if (!mptcp_pm_is_userspace (msk)) +return ret; + + entry =mptcp_userspace_pm_lookup_addr_by_id (msk, id); +if (!entry) { +GENL_SET_ERR_MSG (info,"address not found" ); +return ret; + } + +return mptcp_pm_nl_put_entry_info (info, entry); +}
net/mptcp/protocol.h +2 -0
@@ -1032,6 +1032,8 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skcint mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc);int mptcp_userspace_pm_dump_addr (struct sk_buff *msg,struct netlink_callback *cb); +int mptcp_userspace_pm_get_addr (struct net *net,struct genl_info *info, +struct nlattr *token,u8 id);void __init mptcp_pm_nl_init (void );void mptcp_pm_nl_work (struct mptcp_sock *msk);
Signature · 1 line
2.35.3
PATCH 10/12 mptcp: get addr in userspace pm list
In reply to Geliang TangThis patch adds 'MPTCP_PM_ATTR_TOKEN' in mptcp_pm_get_addr_nl_policy, then token can be gotten in mptcp_pm_nl_get_addr_doit(). If token isn't null, invoke mptcp_userspace_pm_get_addr() to get addr in userspace pm list.
--- net/mptcp/mptcp_pm_gen.c | 5 +++-- net/mptcp/mptcp_pm_gen.h | 2 +- net/mptcp/pm_netlink.c | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-)
net/mptcp/mptcp_pm_gen.c +3 -2
@@ -32,8 +32,9 @@ const struct nla_policy mptcp_pm_del_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR + 1] };/* MPTCP_PM_CMD_GET_ADDR - do */ -const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR +1 ] = { +const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ATTR_TOKEN +1 ] = { [MPTCP_PM_ENDPOINT_ADDR ] =NLA_POLICY_NESTED (mptcp_pm_address_nl_policy), + [MPTCP_PM_ATTR_TOKEN ] = { .type =NLA_U32 , }, };/* MPTCP_PM_CMD_FLUSH_ADDRS - do */
@@ -110,7 +111,7 @@ const struct genl_ops mptcp_pm_nl_ops[11] = { .doit = mptcp_pm_nl_get_addr_doit, .dumpit = mptcp_pm_nl_get_addr_dumpit, .policy = mptcp_pm_get_addr_nl_policy, - .maxattr = MPTCP_PM_ENDPOINT_ADDR, + .maxattr = MPTCP_PM_ATTR_TOKEN, .flags = GENL_UNS_ADMIN_PERM, }, {
net/mptcp/mptcp_pm_gen.h +1 -1
@@ -18,7 +18,7 @@ extern const struct nla_policy mptcp_pm_add_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDextern const struct nla_policy mptcp_pm_del_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR +1 ]; -extern const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR +1 ]; +extern const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ATTR_TOKEN +1 ];extern const struct nla_policy mptcp_pm_flush_addrs_nl_policy[MPTCP_PM_ENDPOINT_ADDR +1 ];
net/mptcp/pm_netlink.c +5 -0
@@ -1713,14 +1713,19 @@ int mptcp_pm_nl_put_entry_msg(struct sk_buff *msg,int mptcp_pm_nl_get_addr_doit (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; +struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN ];struct pm_nl_pernet *pernet =genl_info_pm_nl (info);struct mptcp_pm_addr_entry addr, *entry; +struct net *net =sock_net (skb->sk);int ret; ret =mptcp_pm_parse_entry (attr, info, false, &addr);if (ret <0 )return ret; +if (token) +return mptcp_userspace_pm_get_addr (net, info, token, addr.addr.id); +spin_lock_bh (&pernet->lock); entry =__lookup_addr_by_id (pernet, addr.addr.id);if (!entry) {
Signature · 1 line
2.35.3
Mat Martineau
maintainerRe: [PATCH mptcp-next 10/12] mptcp: get addr in userspace pm list
Quoted 9 lines · Geliang Tang
This patch adds '
MPTCP_PM_ATTR_TOKEN' inmptcp_pm_get_addr_nl_policy, then token can be gotten inmptcp_pm_nl_get_addr_doit(). If token isn't null, invokemptcp_userspace_pm_get_addr()to get addr in userspace pm list.Signed-off-by Geliang Tang <[email protected]>---
net/mptcp/mptcp_pm_gen.c| 5 +++--net/mptcp/mptcp_pm_gen.h| 2 +-
Hi Geliang -
These two files should not be edited directly (check the comments at the top of the files).
Instead, modify the yaml that is used to generate them:
Documentation/netlink/specs/mptcp.yaml
(rename to mptcp_pm.yaml is happening now: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/ )
See also the commit message for aab4d8564947f391674391e5c346d7f6f1c49f89
- Mat
Quoted 69 lines
net/mptcp/pm_netlink.c| 5 +++++3 files changed, 9 insertions(+), 3 deletions(-)net/mptcp/mptcp_pm_gen.c +3
-2@@ -32,8 +32,9 @@ const struct nla_policy mptcp_pm_del_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR + 1] };/* MPTCP_PM_CMD_GET_ADDR - do */ -const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR +1 ] = { +const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ATTR_TOKEN +1 ] = { [MPTCP_PM_ENDPOINT_ADDR ] =NLA_POLICY_NESTED (mptcp_pm_address_nl_policy), + [MPTCP_PM_ATTR_TOKEN ] = { .type =NLA_U32 , }, };/* MPTCP_PM_CMD_FLUSH_ADDRS - do */ @@ -110,7 +111,7 @@ const struct genl_ops mptcp_pm_nl_ops[11] = { .doit = mptcp_pm_nl_get_addr_doit, .dumpit = mptcp_pm_nl_get_addr_dumpit, .policy = mptcp_pm_get_addr_nl_policy, - .maxattr = MPTCP_PM_ENDPOINT_ADDR, + .maxattr = MPTCP_PM_ATTR_TOKEN, .flags = GENL_UNS_ADMIN_PERM, }, {net/mptcp/mptcp_pm_gen.h +1
-1@@ -18,7 +18,7 @@ extern const struct nla_policy mptcp_pm_add_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDextern const struct nla_policy mptcp_pm_del_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR +1 ]; -extern const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR +1 ]; +extern const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ATTR_TOKEN +1 ];extern const struct nla_policy mptcp_pm_flush_addrs_nl_policy[MPTCP_PM_ENDPOINT_ADDR +1 ];net/mptcp/pm_netlink.c +5
-0@@ -1713,14 +1713,19 @@ int mptcp_pm_nl_put_entry_msg(struct sk_buff *msg,int mptcp_pm_nl_get_addr_doit (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; +struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN ];struct pm_nl_pernet *pernet =genl_info_pm_nl (info);struct mptcp_pm_addr_entry addr, *entry; +struct net *net =sock_net (skb->sk);int ret; ret =mptcp_pm_parse_entry (attr, info, false, &addr);if (ret <0 )return ret; +if (token) +return mptcp_userspace_pm_get_addr (net, info, token, addr.addr.id); +spin_lock_bh (&pernet->lock); entry =__lookup_addr_by_id (pernet, addr.addr.id);if (!entry) {Signature · 1 line
2.35.3
PATCH 11/12 selftests: mptcp: add token for get_addr
In reply to Geliang TangThe command get_addr() of pm_nl_ctl can be used like this in in-kernel PM:
pm_nl_ctl get $id
This patch adds token argument for it to support userspace PM:
pm_nl_ctl get $id token $token
If 'token $token' is passed to get_addr(), copy it into the kernel netlink.
--- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/pm_nl_ctl.c +13 -1
@@ -1087,6 +1087,7 @@ int get_addr(int fd, int pm_family, int argc, char *argv[]) 1024];struct rtattr *rta, *nest;struct nlmsghdr *nh; +u_int32_t token =0 ;int nest_start;u_int8_t id;int off =0 ;
@@ -1097,10 +1098,12 @@ int get_addr(int fd, int pm_family, int argc, char *argv[]) MPTCP_PM_VER);/* the only argument is the address id */ -if (argc !=3 ) +if (argc !=3 && argc !=5 )syntax (argv); id =atoi (argv[2 ]); +if (argc ==5 && !strcmp (argv[3 ],"token" )) + token =strtoul (argv[4 ],NULL ,10 ); nest_start = off; nest = (void *)(data + off);
@@ -1116,6 +1119,15 @@ int get_addr(int fd, int pm_family, int argc, char *argv[]) off +=NLMSG_ALIGN (rta->rta_len); nest->rta_len = off - nest_start; +/* token */ +if (token) { + rta = (void *)(data + off); + rta->rta_type =MPTCP_PM_ATTR_TOKEN ; + rta->rta_len =RTA_LENGTH (4 ); +memcpy (RTA_DATA (rta), &token,4 ); + off +=NLMSG_ALIGN (rta->rta_len); + } +print_addrs (nh, pm_family,do_nl_req (fd, nh, off,sizeof (data)));return 0 ; }
Signature · 1 line
2.35.3
PATCH 12/12 selftests: mptcp: userspace pm get addr tests
In reply to Geliang TangThis patch adds a new helper userspace_pm_get_addr() in mptcp_join.sh. In it, parse the token value from the output of 'pm_nl_ctl events', then pass it to pm_nl_ctl get_addr command. Use this helper in userspace pm dump & flush tests.
--- tools/testing/selftests/net/mptcp/mptcp_join.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +16 -0
@@ -3359,6 +3359,18 @@ userspace_pm_rm_sf() wait_rm_sf $1 "${cnt}" } +# $1: ns ; $2: id +userspace_pm_get_addr() +{ + local evts=$server_evts + local tk + + [ "$1" == "$ns2" ] && evts=$client_evts + tk=$(mptcp_lib_evts_get_info token "$evts") + + ip netns exec $1 ./pm_nl_ctl get $2 token $tk +} + check_output() { : "${check_output_err:?}" : "${ret:?}"
@@ -3591,6 +3603,8 @@ userspace_tests() chk_subflows_total 2 2 chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 local dump="id 10 flags signal 10.0.2.1" + mptcp_lib_check_output "userspace_pm_get_addr $ns1 10" \ + "$dump" " get id 10 addr" [ $ip_mptcp -eq 1 ] && dump="10.0.2.1 id 10 signal " check_output "pm_nl_show_endpoints $ns1" \ "$dump" " dump addrs signal"
@@ -3614,6 +3628,8 @@ userspace_tests() chk_mptcp_info subflows 1 subflows 1 chk_subflows_total 2 2 local dump="id 20 flags subflow 10.0.3.2" + mptcp_lib_check_output "userspace_pm_get_addr $ns2 20" \ + "$dump" " get id 20 addr" [ $ip_mptcp -eq 1 ] && dump="10.0.3.2 id 20 subflow " check_output "pm_nl_show_endpoints $ns2" \ "$dump" " dump addrs subflow"
Signature · 1 line
2.35.3
Re: selftests: mptcp: userspace pm get addr tests: Tests Results
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_fastclose 🔴:
- Task: https://cirrus-ci.com/task/6001690181107712
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6001690181107712/summary/summary.txt
- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5438740227686400
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5438740227686400/summary/summary.txt
- KVM Validation: debug (only selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_mptcp_join - Critical: 2 Call Trace(s) ❌:
- Task: https://cirrus-ci.com/task/4735052785909760
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4735052785909760/summary/summary.txt
- KVM Validation: debug (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_fastclose - Critical: 3 Call Trace(s) ❌:
- Task: https://cirrus-ci.com/task/6564640134529024
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6564640134529024/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/c6be3369e827
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-debugFor 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)