Skip to content

Commit 376bee6

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. v2: - keep "pernet = pm_nl_get_pernet(net);" at the beginning of mptcp_pm_nl_set_flags(). Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 0cfdd08 commit 376bee6

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

19992011
pernet = pm_nl_get_pernet(net);
20002012

2013+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
2014+
return -EINVAL;
2015+
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;
@@ -590,6 +594,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
590594
goto set_flags_err;
591595
}
592596

597+
attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
593598
ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem);
594599
if (ret < 0)
595600
goto set_flags_err;
@@ -679,20 +684,24 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
679684
int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
680685
struct genl_info *info)
681686
{
682-
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
683687
struct mptcp_pm_addr_entry addr, *entry;
684688
struct mptcp_sock *msk;
685689
struct sk_buff *msg;
690+
struct nlattr *attr;
686691
int ret = -EINVAL;
687692
struct sock *sk;
688693
void *reply;
689694

695+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
696+
return ret;
697+
690698
msk = mptcp_userspace_pm_get_sock(info);
691699
if (!msk)
692700
return ret;
693701

694702
sk = (struct sock *)msk;
695703

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

0 commit comments

Comments
 (0)