提交 d5d531cb 编写于 作者: D David Ahern 提交者: David S. Miller

net: ipv6: Add extack messages for route add failures

Add messages for non-obvious errors (e.g, no need to add text for malloc
failures or ENODEV failures). This mostly covers the annoying EINVAL errors
Some message strings violate the 80-columns but searchable strings need to
trump that rule.
Signed-off-by: NDavid Ahern <dsahern@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 333c4301
...@@ -498,6 +498,8 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root, ...@@ -498,6 +498,8 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
!ipv6_prefix_equal(&key->addr, addr, fn->fn_bit)) { !ipv6_prefix_equal(&key->addr, addr, fn->fn_bit)) {
if (!allow_create) { if (!allow_create) {
if (replace_required) { if (replace_required) {
NL_SET_ERR_MSG(extack,
"Can not replace route - no match found");
pr_warn("Can't replace route, no match found\n"); pr_warn("Can't replace route, no match found\n");
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
...@@ -544,6 +546,8 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root, ...@@ -544,6 +546,8 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
* That would keep IPv6 consistent with IPv4 * That would keep IPv6 consistent with IPv4
*/ */
if (replace_required) { if (replace_required) {
NL_SET_ERR_MSG(extack,
"Can not replace route - no match found");
pr_warn("Can't replace route, no match found\n"); pr_warn("Can't replace route, no match found\n");
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
......
...@@ -1857,14 +1857,25 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg, ...@@ -1857,14 +1857,25 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
int err = -EINVAL; int err = -EINVAL;
/* RTF_PCPU is an internal flag; can not be set by userspace */ /* RTF_PCPU is an internal flag; can not be set by userspace */
if (cfg->fc_flags & RTF_PCPU) if (cfg->fc_flags & RTF_PCPU) {
NL_SET_ERR_MSG(extack, "Userspace can not set RTF_PCPU");
goto out; goto out;
}
if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128) if (cfg->fc_dst_len > 128) {
NL_SET_ERR_MSG(extack, "Invalid prefix length");
goto out;
}
if (cfg->fc_src_len > 128) {
NL_SET_ERR_MSG(extack, "Invalid source address length");
goto out; goto out;
}
#ifndef CONFIG_IPV6_SUBTREES #ifndef CONFIG_IPV6_SUBTREES
if (cfg->fc_src_len) if (cfg->fc_src_len) {
NL_SET_ERR_MSG(extack,
"Specifying source address requires IPV6_SUBTREES to be enabled");
goto out; goto out;
}
#endif #endif
if (cfg->fc_ifindex) { if (cfg->fc_ifindex) {
err = -ENODEV; err = -ENODEV;
...@@ -2015,9 +2026,10 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg, ...@@ -2015,9 +2026,10 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
err = -EINVAL; err = -EINVAL;
if (ipv6_chk_addr_and_flags(net, gw_addr, if (ipv6_chk_addr_and_flags(net, gw_addr,
gwa_type & IPV6_ADDR_LINKLOCAL ? gwa_type & IPV6_ADDR_LINKLOCAL ?
dev : NULL, 0, 0)) dev : NULL, 0, 0)) {
NL_SET_ERR_MSG(extack, "Invalid gateway address");
goto out; goto out;
}
rt->rt6i_gateway = *gw_addr; rt->rt6i_gateway = *gw_addr;
if (gwa_type != (IPV6_ADDR_LINKLOCAL|IPV6_ADDR_UNICAST)) { if (gwa_type != (IPV6_ADDR_LINKLOCAL|IPV6_ADDR_UNICAST)) {
...@@ -2033,8 +2045,11 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg, ...@@ -2033,8 +2045,11 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
addressing addressing
*/ */
if (!(gwa_type & (IPV6_ADDR_UNICAST | if (!(gwa_type & (IPV6_ADDR_UNICAST |
IPV6_ADDR_MAPPED))) IPV6_ADDR_MAPPED))) {
NL_SET_ERR_MSG(extack,
"Invalid gateway address");
goto out; goto out;
}
if (cfg->fc_table) { if (cfg->fc_table) {
grt = ip6_nh_lookup_table(net, cfg, gw_addr); grt = ip6_nh_lookup_table(net, cfg, gw_addr);
...@@ -2074,8 +2089,14 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg, ...@@ -2074,8 +2089,14 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
goto out; goto out;
} }
err = -EINVAL; err = -EINVAL;
if (!dev || (dev->flags & IFF_LOOPBACK)) if (!dev) {
NL_SET_ERR_MSG(extack, "Egress device not specified");
goto out; goto out;
} else if (dev->flags & IFF_LOOPBACK) {
NL_SET_ERR_MSG(extack,
"Egress device can not be loopback device for this route");
goto out;
}
} }
err = -ENODEV; err = -ENODEV;
...@@ -2084,6 +2105,7 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg, ...@@ -2084,6 +2105,7 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
if (!ipv6_addr_any(&cfg->fc_prefsrc)) { if (!ipv6_addr_any(&cfg->fc_prefsrc)) {
if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) { if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) {
NL_SET_ERR_MSG(extack, "Invalid source address");
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
...@@ -2234,8 +2256,10 @@ static int ip6_route_del(struct fib6_config *cfg, ...@@ -2234,8 +2256,10 @@ static int ip6_route_del(struct fib6_config *cfg,
int err = -ESRCH; int err = -ESRCH;
table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table); table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table);
if (!table) if (!table) {
NL_SET_ERR_MSG(extack, "FIB table does not exist");
return err; return err;
}
read_lock_bh(&table->tb6_lock); read_lock_bh(&table->tb6_lock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册