Skip to content

Commit 0d3008d

Browse files
q2venPaolo Abeni
authored andcommitted
rtnetlink: Move ops->validate to rtnl_newlink().
ops->validate() does not require RTNL. Let's move it 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 331fe31 commit 0d3008d

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

net/core/rtnetlink.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,16 +3692,14 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm,
36923692
static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
36933693
const struct rtnl_link_ops *ops,
36943694
struct rtnl_newlink_tbs *tbs,
3695+
struct nlattr **data,
36953696
struct netlink_ext_ack *extack)
36963697
{
3697-
struct nlattr ** const linkinfo = tbs->linkinfo;
36983698
struct nlattr ** const tb = tbs->tb;
36993699
struct net *net = sock_net(skb->sk);
37003700
struct net_device *dev;
37013701
struct ifinfomsg *ifm;
3702-
struct nlattr **data;
37033702
bool link_specified;
3704-
int err;
37053703

37063704
ifm = nlmsg_data(nlh);
37073705
if (ifm->ifi_index > 0) {
@@ -3718,26 +3716,6 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
37183716
dev = NULL;
37193717
}
37203718

3721-
data = NULL;
3722-
if (ops) {
3723-
if (ops->maxtype > RTNL_MAX_TYPE)
3724-
return -EINVAL;
3725-
3726-
if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
3727-
err = nla_parse_nested_deprecated(tbs->attr, ops->maxtype,
3728-
linkinfo[IFLA_INFO_DATA],
3729-
ops->policy, extack);
3730-
if (err < 0)
3731-
return err;
3732-
data = tbs->attr;
3733-
}
3734-
if (ops->validate) {
3735-
err = ops->validate(tb, data, extack);
3736-
if (err < 0)
3737-
return err;
3738-
}
3739-
}
3740-
37413719
if (dev)
37423720
return rtnl_changelink(skb, nlh, ops, dev, tbs, data, extack);
37433721

@@ -3768,8 +3746,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
37683746
static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
37693747
struct netlink_ext_ack *extack)
37703748
{
3749+
struct nlattr **tb, **linkinfo, **data = NULL;
37713750
const struct rtnl_link_ops *ops = NULL;
3772-
struct nlattr **tb, **linkinfo;
37733751
struct rtnl_newlink_tbs *tbs;
37743752
int ret;
37753753

@@ -3813,7 +3791,28 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
38133791
#endif
38143792
}
38153793

3816-
ret = __rtnl_newlink(skb, nlh, ops, tbs, extack);
3794+
if (ops) {
3795+
if (ops->maxtype > RTNL_MAX_TYPE)
3796+
return -EINVAL;
3797+
3798+
if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
3799+
ret = nla_parse_nested_deprecated(tbs->attr, ops->maxtype,
3800+
linkinfo[IFLA_INFO_DATA],
3801+
ops->policy, extack);
3802+
if (ret < 0)
3803+
goto free;
3804+
3805+
data = tbs->attr;
3806+
}
3807+
3808+
if (ops->validate) {
3809+
ret = ops->validate(tb, data, extack);
3810+
if (ret < 0)
3811+
goto free;
3812+
}
3813+
}
3814+
3815+
ret = __rtnl_newlink(skb, nlh, ops, tbs, data, extack);
38173816

38183817
free:
38193818
kfree(tbs);

0 commit comments

Comments
 (0)