Skip to content

Commit 7fea1a8

Browse files
q2venPaolo Abeni
authored andcommitted
rtnetlink: Move simple validation from __rtnl_newlink() to rtnl_newlink().
We will push RTNL down to rtnl_newlink(). Let's move RTNL-independent validation to rtnl_newlink(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent cc47bcd commit 7fea1a8

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

net/core/rtnetlink.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,15 +3707,6 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
37073707
#ifdef CONFIG_MODULES
37083708
replay:
37093709
#endif
3710-
err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFLA_MAX,
3711-
ifla_policy, extack);
3712-
if (err < 0)
3713-
return err;
3714-
3715-
err = rtnl_ensure_unique_netns(tb, extack, false);
3716-
if (err < 0)
3717-
return err;
3718-
37193710
ifm = nlmsg_data(nlh);
37203711
if (ifm->ifi_index > 0) {
37213712
link_specified = true;
@@ -3731,16 +3722,6 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
37313722
dev = NULL;
37323723
}
37333724

3734-
if (tb[IFLA_LINKINFO]) {
3735-
err = nla_parse_nested_deprecated(linkinfo, IFLA_INFO_MAX,
3736-
tb[IFLA_LINKINFO],
3737-
ifla_info_policy, NULL);
3738-
if (err < 0)
3739-
return err;
3740-
} else {
3741-
memset(linkinfo, 0, sizeof(tbs->linkinfo));
3742-
}
3743-
37443725
if (linkinfo[IFLA_INFO_KIND]) {
37453726
nla_strscpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));
37463727
ops = rtnl_link_ops_get(kind);
@@ -3809,14 +3790,38 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
38093790
static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
38103791
struct netlink_ext_ack *extack)
38113792
{
3793+
struct nlattr **tb, **linkinfo;
38123794
struct rtnl_newlink_tbs *tbs;
38133795
int ret;
38143796

38153797
tbs = kmalloc(sizeof(*tbs), GFP_KERNEL);
38163798
if (!tbs)
38173799
return -ENOMEM;
38183800

3801+
tb = tbs->tb;
3802+
ret = nlmsg_parse_deprecated(nlh, sizeof(struct ifinfomsg), tb,
3803+
IFLA_MAX, ifla_policy, extack);
3804+
if (ret < 0)
3805+
goto free;
3806+
3807+
ret = rtnl_ensure_unique_netns(tb, extack, false);
3808+
if (ret < 0)
3809+
goto free;
3810+
3811+
linkinfo = tbs->linkinfo;
3812+
if (tb[IFLA_LINKINFO]) {
3813+
ret = nla_parse_nested_deprecated(linkinfo, IFLA_INFO_MAX,
3814+
tb[IFLA_LINKINFO],
3815+
ifla_info_policy, NULL);
3816+
if (ret < 0)
3817+
goto free;
3818+
} else {
3819+
memset(linkinfo, 0, sizeof(tbs->linkinfo));
3820+
}
3821+
38193822
ret = __rtnl_newlink(skb, nlh, tbs, extack);
3823+
3824+
free:
38203825
kfree(tbs);
38213826
return ret;
38223827
}

0 commit comments

Comments
 (0)