Skip to content

Commit d348bf5

Browse files
matttbeintel-lab-lkp
authored andcommitted
mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible
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. mptcp_userspace_pm_remove_id_zero_address() has been modified to set the missing attribute. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 169ea3f commit d348bf5

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

net/mptcp/pm_netlink.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,18 +1403,21 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
14031403
return ret;
14041404

14051405
if (addr.addr.port && !address_use_port(&addr)) {
1406-
GENL_SET_ERR_MSG(info, "flags must have signal and not subflow when using port");
1406+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
1407+
"flags must have signal and not subflow when using port");
14071408
return -EINVAL;
14081409
}
14091410

14101411
if (addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL &&
14111412
addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) {
1412-
GENL_SET_ERR_MSG(info, "flags mustn't have both signal and fullmesh");
1413+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
1414+
"flags mustn't have both signal and fullmesh");
14131415
return -EINVAL;
14141416
}
14151417

14161418
if (addr.flags & MPTCP_PM_ADDR_FLAG_IMPLICIT) {
1417-
GENL_SET_ERR_MSG(info, "can't create IMPLICIT endpoint");
1419+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
1420+
"can't create IMPLICIT endpoint");
14181421
return -EINVAL;
14191422
}
14201423

@@ -1608,7 +1611,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
16081611
spin_lock_bh(&pernet->lock);
16091612
entry = __lookup_addr_by_id(pernet, addr.addr.id);
16101613
if (!entry) {
1611-
GENL_SET_ERR_MSG(info, "address not found");
1614+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
16121615
spin_unlock_bh(&pernet->lock);
16131616
return -EINVAL;
16141617
}
@@ -1790,7 +1793,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
17901793
rcu_read_lock();
17911794
entry = __lookup_addr_by_id(pernet, addr.addr.id);
17921795
if (!entry) {
1793-
GENL_SET_ERR_MSG(info, "address not found");
1796+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
17941797
ret = -EINVAL;
17951798
goto unlock_fail;
17961799
}
@@ -1875,7 +1878,8 @@ static int parse_limit(struct genl_info *info, int id, unsigned int *limit)
18751878

18761879
*limit = nla_get_u32(attr);
18771880
if (*limit > MPTCP_PM_ADDR_MAX) {
1878-
GENL_SET_ERR_MSG(info, "limit greater than maximum");
1881+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
1882+
"limit greater than maximum");
18791883
return -EINVAL;
18801884
}
18811885
return 0;

net/mptcp/pm_userspace.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in
190190
}
191191

192192
if (!mptcp_pm_is_userspace(msk)) {
193-
GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
193+
NL_SET_ERR_MSG_ATTR(info->extack, token,
194+
"invalid request; userspace PM not selected");
194195
sock_put((struct sock *)msk);
195196
return NULL;
196197
}
@@ -237,7 +238,8 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
237238

238239
err = mptcp_userspace_pm_append_new_local_addr(msk, &addr_val, false);
239240
if (err < 0) {
240-
GENL_SET_ERR_MSG(info, "did not match address and id");
241+
NL_SET_ERR_MSG_ATTR(info->extack, addr,
242+
"did not match address and id");
241243
goto announce_err;
242244
}
243245

@@ -396,7 +398,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
396398
}
397399

398400
if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
399-
GENL_SET_ERR_MSG(info, "invalid addr flags");
401+
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "invalid addr flags");
400402
err = -EINVAL;
401403
goto create_err;
402404
}
@@ -416,7 +418,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
416418

417419
err = mptcp_userspace_pm_append_new_local_addr(msk, &entry, false);
418420
if (err < 0) {
419-
GENL_SET_ERR_MSG(info, "did not match address and id");
421+
NL_SET_ERR_MSG_ATTR(info->extack, laddr,
422+
"did not match address and id");
420423
goto create_err;
421424
}
422425

@@ -704,7 +707,7 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
704707
spin_lock_bh(&msk->pm.lock);
705708
entry = mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id);
706709
if (!entry) {
707-
GENL_SET_ERR_MSG(info, "address not found");
710+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
708711
ret = -EINVAL;
709712
goto unlock_fail;
710713
}

0 commit comments

Comments
 (0)