Skip to content

Commit 3583a4e

Browse files
shemmingerdavem330
authored andcommitted
ipv6: report errors for iftoken via netlink extack
Setting iftoken can fail for several different reasons but there and there was no report to user as to the cause. Add netlink extended errors to the processing of the request. This requires adding additional argument through rtnl_af_ops set_link_af callback. Reported-by: Hongren Zheng <[email protected]> Signed-off-by: Stephen Hemminger <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f2fbd0a commit 3583a4e

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

include/net/rtnetlink.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ struct rtnl_af_ops {
147147
int (*validate_link_af)(const struct net_device *dev,
148148
const struct nlattr *attr);
149149
int (*set_link_af)(struct net_device *dev,
150-
const struct nlattr *attr);
151-
150+
const struct nlattr *attr,
151+
struct netlink_ext_ack *extack);
152152
int (*fill_stats_af)(struct sk_buff *skb,
153153
const struct net_device *dev);
154154
size_t (*get_stats_af_size)(const struct net_device *dev);

net/core/rtnetlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,7 @@ static int do_setlink(const struct sk_buff *skb,
28632863

28642864
BUG_ON(!(af_ops = rtnl_af_lookup(nla_type(af))));
28652865

2866-
err = af_ops->set_link_af(dev, af);
2866+
err = af_ops->set_link_af(dev, af, extack);
28672867
if (err < 0) {
28682868
rcu_read_unlock();
28692869
goto errout;

net/ipv4/devinet.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,8 @@ static int inet_validate_link_af(const struct net_device *dev,
19781978
return 0;
19791979
}
19801980

1981-
static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla)
1981+
static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla,
1982+
struct netlink_ext_ack *extack)
19821983
{
19831984
struct in_device *in_dev = __in_dev_get_rcu(dev);
19841985
struct nlattr *a, *tb[IFLA_INET_MAX+1];

net/ipv6/addrconf.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5669,7 +5669,8 @@ static int inet6_fill_link_af(struct sk_buff *skb, const struct net_device *dev,
56695669
return 0;
56705670
}
56715671

5672-
static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
5672+
static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token,
5673+
struct netlink_ext_ack *extack)
56735674
{
56745675
struct inet6_ifaddr *ifp;
56755676
struct net_device *dev = idev->dev;
@@ -5680,12 +5681,29 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
56805681

56815682
if (!token)
56825683
return -EINVAL;
5683-
if (dev->flags & (IFF_LOOPBACK | IFF_NOARP))
5684+
5685+
if (dev->flags & IFF_LOOPBACK) {
5686+
NL_SET_ERR_MSG_MOD(extack, "Device is loopback");
56845687
return -EINVAL;
5685-
if (!ipv6_accept_ra(idev))
5688+
}
5689+
5690+
if (dev->flags & IFF_NOARP) {
5691+
NL_SET_ERR_MSG_MOD(extack,
5692+
"Device does not do neighbour discovery");
5693+
return -EINVAL;
5694+
}
5695+
5696+
if (!ipv6_accept_ra(idev)) {
5697+
NL_SET_ERR_MSG_MOD(extack,
5698+
"Router advertisement is disabled on device");
56865699
return -EINVAL;
5687-
if (idev->cnf.rtr_solicits == 0)
5700+
}
5701+
5702+
if (idev->cnf.rtr_solicits == 0) {
5703+
NL_SET_ERR_MSG(extack,
5704+
"Router solicitation is disabled on device");
56885705
return -EINVAL;
5706+
}
56895707

56905708
write_lock_bh(&idev->lock);
56915709

@@ -5793,7 +5811,8 @@ static int inet6_validate_link_af(const struct net_device *dev,
57935811
return 0;
57945812
}
57955813

5796-
static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
5814+
static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla,
5815+
struct netlink_ext_ack *extack)
57975816
{
57985817
struct inet6_dev *idev = __in6_dev_get(dev);
57995818
struct nlattr *tb[IFLA_INET6_MAX + 1];
@@ -5806,7 +5825,8 @@ static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
58065825
BUG();
58075826

58085827
if (tb[IFLA_INET6_TOKEN]) {
5809-
err = inet6_set_iftoken(idev, nla_data(tb[IFLA_INET6_TOKEN]));
5828+
err = inet6_set_iftoken(idev, nla_data(tb[IFLA_INET6_TOKEN]),
5829+
extack);
58105830
if (err)
58115831
return err;
58125832
}

0 commit comments

Comments
 (0)