use GENL_REQ_ATTR_CHECK in userspace pm
Subsystems (2)
Geliang Tang
reviewerv9 cover use GENL_REQ_ATTR_CHECK in userspace pm
From: Geliang Tang <[email protected]>
v9:
patch 3, move the code using NL_SET_ERR_MSG_ATTR into patch 8. patch 7, adjust the location of "pernet = pm_nl_get_pernet(net);".
v8:
- move the set_flags() patches out of this set.
- differences from v6:
- adjust the order of the patches.
- keep "pernet = pm_nl_get_pernet(net);" at the beginning of
mptcp_pm_nl_set_flags().
- not use NL_SET_ERR_MSG_ATTR in mptcp_pm_nl_set_flags(), since 'attr' will be removed in the commit "mptcp: add local & remote parameters for set_flags".
- update the code related mptcp_userspace_pm_remove_id_zero_address() since a new patch to drop "info" parameter of this patch is added.
- add a comment "mptcp_pm_nl_mp_prio_send_ack() only fails in one case" in mptcp_userspace_pm_set_flags().
v7:
- update set_flags() interface.
- drop 'info' parameter of userspace_pm_remove_id_zero_address().
- rebase v6 on top of these changes.
This is a newer version of the series started by Geliang, now making them more uniform on how the NL errors are set, and giving more hints to the userspace about what's wrong.
Geliang Tang (2):
mptcp: drop info of userspace_pm_remove_id_zero_address
mptcp: pm: userspace: use GENL_REQ_ATTR_CHECK
Matthieu Baerts (NGI0) (6):
mptcp: pm: userspace: flags: clearer msg if no remote addr
mptcp: pm: more precise error messages
mptcp: pm: improve error messages
mptcp: pm: remove duplicated error messages
mptcp: pm: mark missing address attributes
mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible
net/mptcp/pm_netlink.c | 43 +++++++++--- net/mptcp/pm_userspace.c | 148 +++++++++++++++++++++++---------------- 2 files changed, 118 insertions(+), 73 deletions(-)
Signature · 1 line
2.45.2
Geliang Tang
reviewerPATCH v9 1/8 mptcp: drop info of userspace_pm_remove_id_zero_address
From: Geliang Tang <[email protected]>
The only use of 'info' parameter of userspace_pm_remove_id_zero_address() is to set an error message into it.
Plus, this helper will only fail when it cannot find any subflows with a local address ID 0.
This patch drops this parameter and sets the error message where this function is called in mptcp_pm_nl_remove_doit().
--- net/mptcp/pm_userspace.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
net/mptcp/pm_userspace.c +8 -7
@@ -253,8 +253,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)return err; } -static int mptcp_userspace_pm_remove_id_zero_address (struct mptcp_sock *msk, -struct genl_info *info) +static int mptcp_userspace_pm_remove_id_zero_address (struct mptcp_sock *msk) {struct mptcp_rm_list list = { .nr =0 };struct mptcp_subflow_context *subflow;
@@ -269,10 +268,8 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk,break ; } } -if (!has_id_0) { -GENL_SET_ERR_MSG (info,"address with id 0 not found" ); +if (!has_id_0) goto remove_err; - } list.ids[list.nr++] =0 ;
@@ -330,7 +327,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk;if (id_val ==0 ) { - err =mptcp_userspace_pm_remove_id_zero_address (msk, info); + err =mptcp_userspace_pm_remove_id_zero_address (msk); goto out; }
@@ -339,7 +336,6 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)spin_lock_bh (&msk->pm.lock); match =mptcp_userspace_pm_lookup_addr_by_id (msk, id_val);if (!match) { -GENL_SET_ERR_MSG (info,"address with specified id not found" );spin_unlock_bh (&msk->pm.lock);release_sock (sk); goto out;
@@ -356,6 +352,11 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) err =0 ; out: +if (err) +GENL_SET_ERR_MSG_FMT (info, +"address with id %u not found" , + id_val); +sock_put (sk);return err; }
Signature · 1 line
2.45.2
Geliang Tang
reviewerPATCH v9 2/8 mptcp: pm: userspace: flags: clearer msg if no remote addr
In reply to Geliang TangFrom: "Matthieu Baerts (NGI0)" <[email protected]>
Since its introduction in commit 892f396c8e68 ("mptcp: netlink: issue MP_PRIO signals from userspace PMs"), it was mandatory to specify the remote address, because of the 'if (rem->addr.family == AF_UNSPEC)' check done later one.
In theory, this attribute can be optional, but it sounds better to be precise to avoid sending the MP_PRIO on the wrong subflow, e.g. if there are multiple subflows attached to the same local ID. This can be relaxed later on if there is a need to act on multiple subflows with one command.
For the moment, the check to see if attr_rem is NULL can be removed, because mptcp_pm_parse_entry() will do this check as well, no need to do that differently here.
--- net/mptcp/pm_userspace.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/mptcp/pm_userspace.c +3 -5
@@ -580,11 +580,9 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)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; - } + 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 ) {
Signature · 1 line
2.45.2
Geliang Tang
reviewerPATCH v9 3/8 mptcp: pm: more precise error messages
In reply to Geliang TangFrom: "Matthieu Baerts (NGI0)" <[email protected]>
Some errors reported by the userspace PM were vague: "this or that is invalid".
It is easier for the userspace to know which part is wrong, instead of having to guess that.
While at it, in mptcp_userspace_pm_set_flags() move the parsing after the check linked to the local attribute.
---
v2:
- move the code using NL_SET_ERR_MSG_ATTR into patch 8.
--- net/mptcp/pm_userspace.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
net/mptcp/pm_userspace.c +24 -7
@@ -223,8 +223,14 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) goto announce_err; } -if (addr_val.addr.id ==0 || !(addr_val.flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) { -GENL_SET_ERR_MSG (info,"invalid addr id or flags" ); +if (addr_val.addr.id ==0 ) { +GENL_SET_ERR_MSG (info,"invalid addr id" ); + err = -EINVAL ; + goto announce_err; + } + +if (!(addr_val.flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) { +GENL_SET_ERR_MSG (info,"invalid addr flags" ); err = -EINVAL ; goto announce_err; }
@@ -531,8 +537,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info goto destroy_err; } -if (!addr_l.addr.port || !addr_r.port) { -GENL_SET_ERR_MSG (info,"missing local or remote port" ); +if (!addr_l.addr.port) { +GENL_SET_ERR_MSG (info,"missing local port" ); + err = -EINVAL ; + goto destroy_err; + } + +if (!addr_r.port) { +GENL_SET_ERR_MSG (info,"missing remote port" ); err = -EINVAL ; goto destroy_err; }
@@ -580,13 +592,18 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)if (ret <0 ) goto set_flags_err; +if (loc.addr.family ==AF_UNSPEC ) { +GENL_SET_ERR_MSG (info,"invalid local address family" ); + ret = -EINVAL ; + goto set_flags_err; + } + 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 ) { -GENL_SET_ERR_MSG (info,"invalid address families" ); +if (rem.addr.family ==AF_UNSPEC ) { +GENL_SET_ERR_MSG (info,"invalid remote address family" ); ret = -EINVAL ; goto set_flags_err; }
Signature · 1 line
2.45.2
Geliang Tang
reviewerPATCH v9 4/8 mptcp: pm: improve error messages
In reply to Geliang TangFrom: "Matthieu Baerts (NGI0)" <[email protected]>
Some error messages were:
- too generic: "missing input", "invalid request"
- not precise enough: "limit greater than maximum" but what's the max?
- missing: subflow not found, or connect error.
This can be easily improved by being more precise, or adding new error messages.
---
v2: add a comment in mptcp_userspace_pm_set_flags().
--- net/mptcp/pm_netlink.c | 6 ++++-- net/mptcp/pm_userspace.c | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-)
net/mptcp/pm_netlink.c +4 -2
@@ -1875,7 +1875,9 @@ static int parse_limit(struct genl_info *info, int id, unsigned int *limit) *limit =nla_get_u32 (attr);if (*limit >MPTCP_PM_ADDR_MAX ) { -GENL_SET_ERR_MSG (info,"limit greater than maximum" ); +NL_SET_ERR_MSG_ATTR_FMT (info->extack, attr, +"limit greater than maximum (%u)" , +MPTCP_PM_ADDR_MAX );return -EINVAL ; }return 0 ;
@@ -2003,7 +2005,7 @@ 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) { -GENL_SET_ERR_MSG (info,"missing required inputs" ); +GENL_SET_ERR_MSG (info,"missing address ID" );return -EOPNOTSUPP ; } }
net/mptcp/pm_userspace.c +9 -1
@@ -190,7 +190,7 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in }if (!mptcp_pm_is_userspace (msk)) { -GENL_SET_ERR_MSG (info,"invalid request; userspace PM not selected" ); +GENL_SET_ERR_MSG (info,"userspace PM not selected" );sock_put ((struct sock *)msk);return NULL ; }
@@ -428,6 +428,9 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) err =__mptcp_subflow_connect (sk, &local, &addr_r);release_sock (sk); +if (err) +GENL_SET_ERR_MSG_FMT (info,"connect error: %d" , err); +spin_lock_bh (&msk->pm.lock);if (err)mptcp_userspace_pm_delete_local_addr (msk, &entry);
@@ -552,6 +555,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *infolock_sock (sk); ssk =mptcp_nl_find_ssk (msk, &addr_l.addr, &addr_r);if (!ssk) { +GENL_SET_ERR_MSG (info,"subflow not found" ); err = -ESRCH ; goto release_sock; }
@@ -625,6 +629,10 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) ret =mptcp_pm_nl_mp_prio_send_ack (msk, &loc.addr, &rem.addr, bkup);release_sock (sk); +/* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */ +if (ret <0 ) +GENL_SET_ERR_MSG (info,"subflow not found" ); + set_flags_err:sock_put (sk);return ret;
Signature · 1 line
2.45.2
Geliang Tang
reviewerPATCH v9 5/8 mptcp: pm: userspace: use GENL_REQ_ATTR_CHECK
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
A more general way to check if MPTCP_PM_ATTR_* exists in 'info' is to use GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_*) instead of directly reading info->attrs[MPTCP_PM_ATTR_*] and then checking if it's NULL.
So this patch uses GENL_REQ_ATTR_CHECK() for userspace PM in mptcp_pm_nl_announce_doit(), mptcp_pm_nl_remove_doit(), mptcp_pm_nl_subflow_create_doit(), mptcp_pm_nl_subflow_destroy_doit() and mptcp_userspace_pm_get_sock().
"Suggested-by: Jakub Kicinski <[email protected]>"
--- net/mptcp/pm_userspace.c | 41 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-)
net/mptcp/pm_userspace.c +19 -22
@@ -175,14 +175,13 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk,static struct mptcp_sock *mptcp_userspace_pm_get_sock (const struct genl_info *info) { -struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN ];struct mptcp_sock *msk; +struct nlattr *token; -if (!token) { -GENL_SET_ERR_MSG (info,"missing required token" ); +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_TOKEN ))return NULL ; - } + token = info->attrs[MPTCP_PM_ATTR_TOKEN ]; msk =mptcp_token_get_sock (genl_info_net (info),nla_get_u32 (token));if (!msk) {NL_SET_ERR_MSG_ATTR (info->extack, token,"invalid token" );
@@ -200,16 +199,14 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *inint mptcp_pm_nl_announce_doit (struct sk_buff *skb,struct genl_info *info) { -struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR ];struct mptcp_pm_addr_entry addr_val;struct mptcp_sock *msk; +struct nlattr *addr;int err = -EINVAL ;struct sock *sk; -if (!addr) { -GENL_SET_ERR_MSG (info,"missing required address" ); +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR ))return err; - } msk =mptcp_userspace_pm_get_sock (info);if (!msk)
@@ -217,6 +214,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; + addr = info->attrs[MPTCP_PM_ATTR_ADDR ]; err =mptcp_pm_parse_entry (addr, info, true, &addr_val);if (err <0 ) {GENL_SET_ERR_MSG (info,"error parsing local address" );
@@ -312,18 +310,17 @@ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk,int mptcp_pm_nl_remove_doit (struct sk_buff *skb,struct genl_info *info) { -struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID ];struct mptcp_pm_addr_entry *match;struct mptcp_sock *msk; +struct nlattr *id;int err = -EINVAL ;struct sock *sk;u8 id_val; -if (!id) { -GENL_SET_ERR_MSG (info,"missing required ID" ); +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_LOC_ID ))return err; - } + id = info->attrs[MPTCP_PM_ATTR_LOC_ID ]; id_val =nla_get_u8 (id); msk =mptcp_userspace_pm_get_sock (info);
@@ -369,19 +366,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)int mptcp_pm_nl_subflow_create_doit (struct sk_buff *skb,struct genl_info *info) { -struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; -struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR ];struct mptcp_pm_addr_entry entry = {0 };struct mptcp_addr_info addr_r; +struct nlattr *raddr, *laddr;struct mptcp_pm_local local;struct mptcp_sock *msk;int err = -EINVAL ;struct sock *sk; -if (!laddr || !raddr) { -GENL_SET_ERR_MSG (info,"missing required address(es)" ); +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR ) || +GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR_REMOTE ))return err; - } msk =mptcp_userspace_pm_get_sock (info);if (!msk)
@@ -389,6 +384,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; + laddr = info->attrs[MPTCP_PM_ATTR_ADDR ]; err =mptcp_pm_parse_entry (laddr, info, true, &entry);if (err <0 ) {NL_SET_ERR_MSG_ATTR (info->extack, laddr,"error parsing local addr" );
@@ -402,6 +398,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) } entry.flags |=MPTCP_PM_ADDR_FLAG_SUBFLOW ; + raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; err =mptcp_pm_parse_addr (raddr, info, &addr_r);if (err <0 ) {NL_SET_ERR_MSG_ATTR (info->extack, raddr,"error parsing remote addr" );
@@ -493,18 +490,16 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk,int mptcp_pm_nl_subflow_destroy_doit (struct sk_buff *skb,struct genl_info *info) { -struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; -struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR ];struct mptcp_pm_addr_entry addr_l;struct mptcp_addr_info addr_r; +struct nlattr *raddr, *laddr;struct mptcp_sock *msk;struct sock *sk, *ssk;int err = -EINVAL ; -if (!laddr || !raddr) { -GENL_SET_ERR_MSG (info,"missing required address(es)" ); +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR ) || +GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR_REMOTE ))return err; - } msk =mptcp_userspace_pm_get_sock (info);if (!msk)
@@ -512,12 +507,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info sk = (struct sock *)msk; + laddr = info->attrs[MPTCP_PM_ATTR_ADDR ]; err =mptcp_pm_parse_entry (laddr, info, true, &addr_l);if (err <0 ) {NL_SET_ERR_MSG_ATTR (info->extack, laddr,"error parsing local addr" ); goto destroy_err; } + raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; err =mptcp_pm_parse_addr (raddr, info, &addr_r);if (err <0 ) {NL_SET_ERR_MSG_ATTR (info->extack, raddr,"error parsing remote addr" );
Signature · 1 line
2.45.2
Geliang Tang
reviewerPATCH v9 6/8 mptcp: pm: remove duplicated error messages
In reply to Geliang TangFrom: "Matthieu Baerts (NGI0)" <[email protected]>
mptcp_pm_parse_entry() and mptcp_pm_parse_addr() will already set a error message in case of parsing issue.
Then, no need to override this error message with another less precise
one: "error parsing address".
--- net/mptcp/pm_userspace.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
net/mptcp/pm_userspace.c +5 -15
@@ -216,10 +216,8 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) addr = info->attrs[MPTCP_PM_ATTR_ADDR ]; err =mptcp_pm_parse_entry (addr, info, true, &addr_val); -if (err <0 ) { -GENL_SET_ERR_MSG (info,"error parsing local address" ); +if (err <0 ) goto announce_err; - }if (addr_val.addr.id ==0 ) {GENL_SET_ERR_MSG (info,"invalid addr id" );
@@ -386,10 +384,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) laddr = info->attrs[MPTCP_PM_ATTR_ADDR ]; err =mptcp_pm_parse_entry (laddr, info, true, &entry); -if (err <0 ) { -NL_SET_ERR_MSG_ATTR (info->extack, laddr,"error parsing local addr" ); +if (err <0 ) goto create_err; - }if (entry.flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) {GENL_SET_ERR_MSG (info,"invalid addr flags" );
@@ -400,10 +396,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; err =mptcp_pm_parse_addr (raddr, info, &addr_r); -if (err <0 ) { -NL_SET_ERR_MSG_ATTR (info->extack, raddr,"error parsing remote addr" ); +if (err <0 ) goto create_err; - }if (!mptcp_pm_addr_families_match (sk, &entry.addr, &addr_r)) {GENL_SET_ERR_MSG (info,"families mismatch" );
@@ -509,17 +503,13 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info laddr = info->attrs[MPTCP_PM_ATTR_ADDR ]; err =mptcp_pm_parse_entry (laddr, info, true, &addr_l); -if (err <0 ) { -NL_SET_ERR_MSG_ATTR (info->extack, laddr,"error parsing local addr" ); +if (err <0 ) goto destroy_err; - } raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; err =mptcp_pm_parse_addr (raddr, info, &addr_r); -if (err <0 ) { -NL_SET_ERR_MSG_ATTR (info->extack, raddr,"error parsing remote addr" ); +if (err <0 ) goto destroy_err; - }#if IS_ENABLED (CONFIG_MPTCP_IPV6 )if (addr_l.addr.family ==AF_INET &&ipv6_addr_v4mapped (&addr_r.addr6)) {
Signature · 1 line
2.45.2
Geliang Tang
reviewerPATCH v9 7/8 mptcp: pm: mark missing address attributes
In reply to Geliang TangFrom: "Matthieu Baerts (NGI0)" <[email protected]>
mptcp_pm_parse_entry() will check if the given attribute is defined. If not, it will return a generic error: "missing address info".
It might then not be clear for the userspace developer which attribute is missing, especially when the command takes multiple addresses.
By using GENL_REQ_ATTR_CHECK(), the userspace will get a hint about which attribute is missing, making thing clearer. Note that this is what was already done for most of the other MPTCP NL commands, this patch simply adds the missing ones.
---
v3:
- adjust the location of "pernet = pm_nl_get_pernet(net);".
v2:
- keep "pernet = pm_nl_get_pernet(net);" at the beginning ofmptcp_pm_nl_set_flags().
--- net/mptcp/pm_netlink.c | 24 ++++++++++++++++++++---- net/mptcp/pm_userspace.c | 15 ++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-)
net/mptcp/pm_netlink.c +20 -4
@@ -1393,11 +1393,15 @@ static bool mptcp_pm_has_addr_attr_id(const struct nlattr *attr,int mptcp_pm_nl_add_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 nlattr *attr;int ret; +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ENDPOINT_ADDR )) +return -EINVAL ; + + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; ret =mptcp_pm_parse_entry (attr, info, true, &addr);if (ret <0 )return ret;
@@ -1587,12 +1591,16 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,int mptcp_pm_nl_del_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;unsigned int addr_max; +struct nlattr *attr;int ret; +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ENDPOINT_ADDR )) +return -EINVAL ; + + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; ret =mptcp_pm_parse_entry (attr, info, false, &addr);if (ret <0 )return ret;
@@ -1764,13 +1772,17 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,int mptcp_pm_nl_get_addr (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; +struct nlattr *attr;void *reply;int ret; +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ENDPOINT_ADDR )) +return -EINVAL ; + + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; ret =mptcp_pm_parse_entry (attr, info, false, &addr);if (ret <0 )return ret;
@@ -1986,18 +1998,22 @@ static int mptcp_nl_set_flags(struct net *net,int mptcp_pm_nl_set_flags (struct sk_buff *skb,struct genl_info *info) {struct mptcp_pm_addr_entry addr = { .addr = { .family =AF_UNSPEC }, }; -struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];u8 changed, mask =MPTCP_PM_ADDR_FLAG_BACKUP |MPTCP_PM_ADDR_FLAG_FULLMESH ;struct net *net =sock_net (skb->sk);struct mptcp_pm_addr_entry *entry;struct pm_nl_pernet *pernet; +struct nlattr *attr;u8 lookup_by_id =0 ;u8 bkup =0 ;int ret; +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR )) +return -EINVAL ; + pernet =pm_nl_get_pernet (net); + attr = info->attrs[MPTCP_PM_ATTR_ADDR ]; ret =mptcp_pm_parse_entry (attr, info, false, &addr);if (ret <0 )return ret;
net/mptcp/pm_userspace.c +12 -3
@@ -565,20 +565,24 @@ 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 *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];struct mptcp_pm_addr_entry *entry; +struct nlattr *attr, *attr_rem;struct mptcp_sock *msk;int ret = -EINVAL ;struct sock *sk;u8 bkup =0 ; +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR ) || +GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR_REMOTE )) +return ret; + msk =mptcp_userspace_pm_get_sock (info);if (!msk)return ret; sk = (struct sock *)msk; + attr = info->attrs[MPTCP_PM_ATTR_ADDR ]; ret =mptcp_pm_parse_entry (attr, info, false, &loc);if (ret <0 ) goto set_flags_err;
@@ -589,6 +593,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) goto set_flags_err; } + attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; ret =mptcp_pm_parse_entry (attr_rem, info, false, &rem);if (ret <0 ) goto set_flags_err;
@@ -677,20 +682,24 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,int mptcp_userspace_pm_get_addr (struct sk_buff *skb,struct genl_info *info) { -struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ];struct mptcp_pm_addr_entry addr, *entry;struct mptcp_sock *msk;struct sk_buff *msg; +struct nlattr *attr;int ret = -EINVAL ;struct sock *sk;void *reply; +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ENDPOINT_ADDR )) +return ret; + msk =mptcp_userspace_pm_get_sock (info);if (!msk)return ret; sk = (struct sock *)msk; + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; ret =mptcp_pm_parse_entry (attr, info, false, &addr);if (ret <0 ) goto out;
Signature · 1 line
2.45.2
Geliang Tang
reviewerPATCH v9 8/8 mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible
In reply to Geliang TangFrom: "Matthieu Baerts (NGI0)" <[email protected]>
Instead of only returning a text message with GENL_SET_ERR_MSG(), NL_SET_ERR_MSG_ATTR() can help the userspace developers by also reporting which attribute is faulty.
When the error is specific to an attribute, NL_SET_ERR_MSG_ATTR() is now used. The error messages have not been modified in this commit.
---
v2:
- update the code related mptcp_userspace_pm_remove_id_zero_address() since a new patch to drop "info" parameter of this patch is added.
v3:
- not use NL_SET_ERR_MSG_ATTR in mptcp_pm_nl_set_flags(), since 'attr' will be removed in the commit "mptcp: add local & remote parameters for set_flags".
--- net/mptcp/pm_netlink.c | 13 ++++++++----- net/mptcp/pm_userspace.c | 24 ++++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-)
net/mptcp/pm_netlink.c +8 -5
@@ -1407,18 +1407,21 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)return ret;if (addr.addr.port && !address_use_port (&addr)) { -GENL_SET_ERR_MSG (info,"flags must have signal and not subflow when using port" ); +NL_SET_ERR_MSG_ATTR (info->extack, attr, +"flags must have signal and not subflow when using port" );return -EINVAL ; }if (addr.flags &MPTCP_PM_ADDR_FLAG_SIGNAL && addr.flags &MPTCP_PM_ADDR_FLAG_FULLMESH ) { -GENL_SET_ERR_MSG (info,"flags mustn't have both signal and fullmesh" ); +NL_SET_ERR_MSG_ATTR (info->extack, attr, +"flags mustn't have both signal and fullmesh" );return -EINVAL ; }if (addr.flags &MPTCP_PM_ADDR_FLAG_IMPLICIT ) { -GENL_SET_ERR_MSG (info,"can't create IMPLICIT endpoint" ); +NL_SET_ERR_MSG_ATTR (info->extack, attr, +"can't create IMPLICIT endpoint" );return -EINVAL ; }
@@ -1616,7 +1619,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)spin_lock_bh (&pernet->lock); entry =__lookup_addr_by_id (pernet, addr.addr.id);if (!entry) { -GENL_SET_ERR_MSG (info,"address not found" ); +NL_SET_ERR_MSG_ATTR (info->extack, attr,"address not found" );spin_unlock_bh (&pernet->lock);return -EINVAL ; }
@@ -1802,7 +1805,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)rcu_read_lock (); entry =__lookup_addr_by_id (pernet, addr.addr.id);if (!entry) { -GENL_SET_ERR_MSG (info,"address not found" ); +NL_SET_ERR_MSG_ATTR (info->extack, attr,"address not found" ); ret = -EINVAL ; goto unlock_fail; }
net/mptcp/pm_userspace.c +14 -10
@@ -189,7 +189,8 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in }if (!mptcp_pm_is_userspace (msk)) { -GENL_SET_ERR_MSG (info,"userspace PM not selected" ); +NL_SET_ERR_MSG_ATTR (info->extack, token, +"userspace PM not selected" );sock_put ((struct sock *)msk);return NULL ; }
@@ -220,20 +221,21 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) goto announce_err;if (addr_val.addr.id ==0 ) { -GENL_SET_ERR_MSG (info,"invalid addr id" ); +NL_SET_ERR_MSG_ATTR (info->extack, addr,"invalid addr id" ); err = -EINVAL ; goto announce_err; }if (!(addr_val.flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) { -GENL_SET_ERR_MSG (info,"invalid addr flags" ); +NL_SET_ERR_MSG_ATTR (info->extack, addr,"invalid addr flags" ); err = -EINVAL ; goto announce_err; } err =mptcp_userspace_pm_append_new_local_addr (msk, &addr_val, false);if (err <0 ) { -GENL_SET_ERR_MSG (info,"did not match address and id" ); +NL_SET_ERR_MSG_ATTR (info->extack, addr, +"did not match address and id" ); goto announce_err; }
@@ -388,7 +390,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) goto create_err;if (entry.flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { -GENL_SET_ERR_MSG (info,"invalid addr flags" ); +NL_SET_ERR_MSG_ATTR (info->extack, laddr,"invalid addr flags" ); err = -EINVAL ; goto create_err; }
@@ -407,7 +409,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) err =mptcp_userspace_pm_append_new_local_addr (msk, &entry, false);if (err <0 ) { -GENL_SET_ERR_MSG (info,"did not match address and id" ); +NL_SET_ERR_MSG_ATTR (info->extack, laddr, +"did not match address and id" ); goto create_err; }
@@ -528,13 +531,13 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info }if (!addr_l.addr.port) { -GENL_SET_ERR_MSG (info,"missing local port" ); +NL_SET_ERR_MSG_ATTR (info->extack, laddr,"missing local port" ); err = -EINVAL ; goto destroy_err; }if (!addr_r.port) { -GENL_SET_ERR_MSG (info,"missing remote port" ); +NL_SET_ERR_MSG_ATTR (info->extack, raddr,"missing remote port" ); err = -EINVAL ; goto destroy_err; }
@@ -599,7 +602,8 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) goto set_flags_err;if (rem.addr.family ==AF_UNSPEC ) { -GENL_SET_ERR_MSG (info,"invalid remote address family" ); +NL_SET_ERR_MSG_ATTR (info->extack, attr_rem, +"invalid remote address family" ); ret = -EINVAL ; goto set_flags_err; }
@@ -722,7 +726,7 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb,spin_lock_bh (&msk->pm.lock); entry =mptcp_userspace_pm_lookup_addr_by_id (msk, addr.addr.id);if (!entry) { -GENL_SET_ERR_MSG (info,"address not found" ); +NL_SET_ERR_MSG_ATTR (info->extack, attr,"address not found" ); ret = -EINVAL ; goto unlock_fail; }
Signature · 1 line
2.45.2
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v9 8/8] mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible
Hi Geliang,
Thank you for the new version!
Quoted 15 lines · Geliang Tang
From: "Matthieu Baerts (NGI0)" <[email protected]>
Instead of only returning a text message with
GENL_SET_ERR_MSG(),NL_SET_ERR_MSG_ATTR()can help the userspace developers by also reporting which attribute is faulty.When the error is specific to an attribute,
NL_SET_ERR_MSG_ATTR()is now used. The error messages have not been modified in this commit.Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
v2:
- update the code relatedmptcp_userspace_pm_remove_id_zero_address()since a new patch to drop "info" parameter of this patch is added.
Quoted 4 lines
v3:
- not useNL_SET_ERR_MSG_ATTRinmptcp_pm_nl_set_flags(), since 'attr' will be removed in the commit "mptcp: add local & remote parameters forset_flags".
It could still be set here, and removed in the other series (or we could also use it in the other series, to uniform the errors, the helper has access to 'info'), but OK, we had enough versions here.
Note that in mptcp_pm_nl_remove_doit(), there is one GENL_SET_ERR_MSG_FMT() left: NL_SET_ERR_MSG_ATTR_FMT() can be used instead. I can fix that when applying the patch if that's OK for you.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Hi Matthieu,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Unstable: 1 failed test(s): bpftest_test_progs-no_alu32_mptcp 🔴
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/12705350996
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/d5de4a4eab65
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=924037
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
maintainerHi Geliang,
Quoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v9:
patch 3, move the code usingNL_SET_ERR_MSG_ATTRinto patch 8. patch 7, adjust the location of "pernet =pm_nl_get_pernet(net);".
Thank you for the new version.
I have one small request in patch 8/8, but I can fix that when applying the patches if that's OK with you.
I can also do the modifications in set_flags(), and fix the conflicts when applying "BPF path manager, part 2" (if it is ready)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Hi Geliang,
Quoted 9 lines · Matthieu Baerts
Hi Geliang,
Quoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v9:
patch 3, move the code usingNL_SET_ERR_MSG_ATTRinto patch 8. patch 7, adjust the location of "pernet =pm_nl_get_pernet(net);".
Quoted 7 lines
Thank you for the new version.
I have one small request in patch 8/8, but I can fix that when applying the patches if that's OK with you.
I can also do the modifications in
set_flags(), and fix the conflicts when applying "BPF path manager, part 2" (if it is ready)
As discussed on the "BPF path manager, part 2" thread, I will apply patches from these 2 series with the suggested modifications.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerHi Geliang,
Quoted 17 lines · Matthieu Baerts
Hi Geliang,
Quoted 14 lines · Matthieu Baerts
Hi Geliang,
Quoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v9:
patch 3, move the code usingNL_SET_ERR_MSG_ATTRinto patch 8. patch 7, adjust the location of "pernet =pm_nl_get_pernet(net);".Thank you for the new version.
I have one small request in patch 8/8, but I can fix that when applying the patches if that's OK with you.
Quoted 7 lines
Quoted 2 lines
I can also do the modifications in
set_flags(), and fix the conflicts when applying "BPF path manager, part 2" (if it is ready)As discussed on the "BPF path manager, part 2" thread, I will apply patches from these 2 series with the suggested modifications.
Reviewed-by Matthieu Baerts (NGI0) <[email protected]>
Now in our tree (feat. for net-next) with my/your RvB tag:
New patches for t/upstream:
- 5e429e15a686: mptcp: drop info of userspace_pm_remove_id_zero_address
- 81e5a669e7d9: mptcp: pm: userspace: flags: clearer msg if no remote addr
- 677a8abf8d6c: mptcp: pm: more precise error messages
- b4609c1a21bc: mptcp: pm: improve error messages
- b8f41c31bdfc: mptcp: pm: userspace: use GENL_REQ_ATTR_CHECK
- 59b41cafd64c: mptcp: pm: remove duplicated error messages
- 94f4c18c1bd8: mptcp: pm: mark missing address attributes
- 04606ffe7837: mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible
- Results: 632bb7330ffe..472c88326ee3 (export)
Tests are now in progress:
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.