Skip to content

Commit c250de5

Browse files
matttbeintel-lab-lkp
authored andcommitted
mptcp: pm: mark missing address attributes
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. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 5dfd4e0 commit c250de5

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

net/mptcp/pm_netlink.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,11 +1393,15 @@ static bool mptcp_pm_has_addr_attr_id(const struct nlattr *attr,
13931393

13941394
int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
13951395
{
1396-
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
13971396
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
13981397
struct mptcp_pm_addr_entry addr, *entry;
1398+
struct nlattr *attr;
13991399
int ret;
14001400

1401+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
1402+
return -EINVAL;
1403+
1404+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
14011405
ret = mptcp_pm_parse_entry(attr, info, true, &addr);
14021406
if (ret < 0)
14031407
return ret;
@@ -1587,12 +1591,16 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,
15871591

15881592
int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
15891593
{
1590-
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
15911594
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
15921595
struct mptcp_pm_addr_entry addr, *entry;
15931596
unsigned int addr_max;
1597+
struct nlattr *attr;
15941598
int ret;
15951599

1600+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
1601+
return -EINVAL;
1602+
1603+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
15961604
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
15971605
if (ret < 0)
15981606
return ret;
@@ -1764,13 +1772,17 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,
17641772

17651773
int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
17661774
{
1767-
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
17681775
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
17691776
struct mptcp_pm_addr_entry addr, *entry;
17701777
struct sk_buff *msg;
1778+
struct nlattr *attr;
17711779
void *reply;
17721780
int ret;
17731781

1782+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
1783+
return -EINVAL;
1784+
1785+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
17741786
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
17751787
if (ret < 0)
17761788
return ret;
@@ -1986,18 +1998,22 @@ static int mptcp_nl_set_flags(struct net *net,
19861998
int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
19871999
{
19882000
struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
1989-
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
19902001
u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
19912002
MPTCP_PM_ADDR_FLAG_FULLMESH;
19922003
struct net *net = sock_net(skb->sk);
19932004
struct mptcp_pm_addr_entry *entry;
19942005
struct pm_nl_pernet *pernet;
2006+
struct nlattr *attr;
19952007
u8 lookup_by_id = 0;
19962008
u8 bkup = 0;
19972009
int ret;
19982010

2011+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
2012+
return -EINVAL;
2013+
19992014
pernet = pm_nl_get_pernet(net);
20002015

2016+
attr = info->attrs[MPTCP_PM_ATTR_ADDR];
20012017
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
20022018
if (ret < 0)
20032019
return ret;

net/mptcp/pm_userspace.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,20 +565,24 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
565565
{
566566
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
567567
struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, };
568-
struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
569-
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
570568
struct mptcp_pm_addr_entry *entry;
569+
struct nlattr *attr, *attr_rem;
571570
struct mptcp_sock *msk;
572571
int ret = -EINVAL;
573572
struct sock *sk;
574573
u8 bkup = 0;
575574

575+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) ||
576+
GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE))
577+
return ret;
578+
576579
msk = mptcp_userspace_pm_get_sock(info);
577580
if (!msk)
578581
return ret;
579582

580583
sk = (struct sock *)msk;
581584

585+
attr = info->attrs[MPTCP_PM_ATTR_ADDR];
582586
ret = mptcp_pm_parse_entry(attr, info, false, &loc);
583587
if (ret < 0)
584588
goto set_flags_err;
@@ -589,6 +593,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
589593
goto set_flags_err;
590594
}
591595

596+
attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
592597
ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem);
593598
if (ret < 0)
594599
goto set_flags_err;
@@ -677,20 +682,24 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
677682
int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
678683
struct genl_info *info)
679684
{
680-
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
681685
struct mptcp_pm_addr_entry addr, *entry;
682686
struct mptcp_sock *msk;
683687
struct sk_buff *msg;
688+
struct nlattr *attr;
684689
int ret = -EINVAL;
685690
struct sock *sk;
686691
void *reply;
687692

693+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
694+
return ret;
695+
688696
msk = mptcp_userspace_pm_get_sock(info);
689697
if (!msk)
690698
return ret;
691699

692700
sk = (struct sock *)msk;
693701

702+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
694703
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
695704
if (ret < 0)
696705
goto out;

0 commit comments

Comments
 (0)