Skip to content

Commit 47d3c02

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 3127e61 commit 47d3c02

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

net/mptcp/pm_netlink.c

Lines changed: 21 additions & 5 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;
@@ -1590,12 +1594,16 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,
15901594

15911595
int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
15921596
{
1593-
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
15941597
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
15951598
struct mptcp_pm_addr_entry addr, *entry;
15961599
unsigned int addr_max;
1600+
struct nlattr *attr;
15971601
int ret;
15981602

1603+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
1604+
return -EINVAL;
1605+
1606+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
15991607
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
16001608
if (ret < 0)
16011609
return ret;
@@ -1767,13 +1775,17 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,
17671775

17681776
int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
17691777
{
1770-
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
17711778
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
17721779
struct mptcp_pm_addr_entry addr, *entry;
17731780
struct sk_buff *msg;
1781+
struct nlattr *attr;
17741782
void *reply;
17751783
int ret;
17761784

1785+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
1786+
return -EINVAL;
1787+
1788+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
17771789
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
17781790
if (ret < 0)
17791791
return ret;
@@ -1989,18 +2001,20 @@ static int mptcp_nl_set_flags(struct net *net,
19892001
int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
19902002
{
19912003
struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
1992-
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
19932004
u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
19942005
MPTCP_PM_ADDR_FLAG_FULLMESH;
19952006
struct net *net = sock_net(skb->sk);
19962007
struct mptcp_pm_addr_entry *entry;
19972008
struct pm_nl_pernet *pernet;
2009+
struct nlattr *attr;
19982010
u8 lookup_by_id = 0;
19992011
u8 bkup = 0;
20002012
int ret;
20012013

2002-
pernet = pm_nl_get_pernet(net);
2014+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
2015+
return -EINVAL;
20032016

2017+
attr = info->attrs[MPTCP_PM_ATTR_ADDR];
20042018
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
20052019
if (ret < 0)
20062020
return ret;
@@ -2017,6 +2031,8 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
20172031
if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
20182032
bkup = 1;
20192033

2034+
pernet = pm_nl_get_pernet(net);
2035+
20202036
spin_lock_bh(&pernet->lock);
20212037
entry = lookup_by_id ? __lookup_addr_by_id(pernet, addr.addr.id) :
20222038
__lookup_addr(pernet, &addr.addr);

net/mptcp/pm_userspace.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,20 +570,24 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
570570
{
571571
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
572572
struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, };
573-
struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
574-
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
575573
struct mptcp_pm_addr_entry *entry;
574+
struct nlattr *attr, *attr_rem;
576575
struct mptcp_sock *msk;
577576
int ret = -EINVAL;
578577
struct sock *sk;
579578
u8 bkup = 0;
580579

580+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) ||
581+
GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE))
582+
return ret;
583+
581584
msk = mptcp_userspace_pm_get_sock(info);
582585
if (!msk)
583586
return ret;
584587

585588
sk = (struct sock *)msk;
586589

590+
attr = info->attrs[MPTCP_PM_ATTR_ADDR];
587591
ret = mptcp_pm_parse_entry(attr, info, false, &loc);
588592
if (ret < 0)
589593
goto set_flags_err;
@@ -595,6 +599,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
595599
goto set_flags_err;
596600
}
597601

602+
attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
598603
ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem);
599604
if (ret < 0)
600605
goto set_flags_err;
@@ -683,20 +688,24 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
683688
int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
684689
struct genl_info *info)
685690
{
686-
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
687691
struct mptcp_pm_addr_entry addr, *entry;
688692
struct mptcp_sock *msk;
689693
struct sk_buff *msg;
694+
struct nlattr *attr;
690695
int ret = -EINVAL;
691696
struct sock *sk;
692697
void *reply;
693698

699+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
700+
return ret;
701+
694702
msk = mptcp_userspace_pm_get_sock(info);
695703
if (!msk)
696704
return ret;
697705

698706
sk = (struct sock *)msk;
699707

708+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
700709
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
701710
if (ret < 0)
702711
goto out;

0 commit comments

Comments
 (0)