Merge branch 'netlink-extack-route-add-del'
David Ahern says: ==================== net: Add extack for route add/delete failures Use the extack feature to improve error messages to user on route add and delete failures. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
acb5d48f0e
|
@ -97,6 +97,11 @@ struct netlink_ext_ack {
|
|||
#define NL_SET_ERR_MSG_MOD(extack, msg) \
|
||||
NL_SET_ERR_MSG((extack), KBUILD_MODNAME ": " msg)
|
||||
|
||||
#define NL_SET_BAD_ATTR(extack, attr) do { \
|
||||
if ((extack)) \
|
||||
(extack)->bad_attr = (attr); \
|
||||
} while (0)
|
||||
|
||||
extern void netlink_kernel_release(struct sock *sk);
|
||||
extern int __netlink_change_ngroups(struct sock *sk, unsigned int groups);
|
||||
extern int netlink_change_ngroups(struct sock *sk, unsigned int groups);
|
||||
|
|
|
@ -277,7 +277,8 @@ void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
|
|||
void *arg);
|
||||
|
||||
int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
||||
struct nl_info *info, struct mx6_config *mxc);
|
||||
struct nl_info *info, struct mx6_config *mxc,
|
||||
struct netlink_ext_ack *extack);
|
||||
int fib6_del(struct rt6_info *rt, struct nl_info *info);
|
||||
|
||||
void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info,
|
||||
|
|
|
@ -90,7 +90,7 @@ void ip6_route_cleanup(void);
|
|||
|
||||
int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg);
|
||||
|
||||
int ip6_route_add(struct fib6_config *cfg);
|
||||
int ip6_route_add(struct fib6_config *cfg, struct netlink_ext_ack *extack);
|
||||
int ip6_ins_rt(struct rt6_info *);
|
||||
int ip6_del_rt(struct rt6_info *);
|
||||
|
||||
|
|
|
@ -263,7 +263,8 @@ struct fib_table {
|
|||
|
||||
int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
|
||||
struct fib_result *res, int fib_flags);
|
||||
int fib_table_insert(struct net *, struct fib_table *, struct fib_config *);
|
||||
int fib_table_insert(struct net *, struct fib_table *, struct fib_config *,
|
||||
struct netlink_ext_ack *extack);
|
||||
int fib_table_delete(struct net *, struct fib_table *, struct fib_config *);
|
||||
int fib_table_dump(struct fib_table *table, struct sk_buff *skb,
|
||||
struct netlink_callback *cb);
|
||||
|
|
|
@ -594,7 +594,8 @@ int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg)
|
|||
} else {
|
||||
tb = fib_new_table(net, cfg.fc_table);
|
||||
if (tb)
|
||||
err = fib_table_insert(net, tb, &cfg);
|
||||
err = fib_table_insert(net, tb,
|
||||
&cfg, NULL);
|
||||
else
|
||||
err = -ENOBUFS;
|
||||
}
|
||||
|
@ -626,14 +627,15 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = {
|
|||
};
|
||||
|
||||
static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
|
||||
struct nlmsghdr *nlh, struct fib_config *cfg)
|
||||
struct nlmsghdr *nlh, struct fib_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct nlattr *attr;
|
||||
int err, remaining;
|
||||
struct rtmsg *rtm;
|
||||
|
||||
err = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipv4_policy,
|
||||
NULL);
|
||||
extack);
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
|
||||
|
@ -654,6 +656,7 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
|
|||
cfg->fc_nlinfo.nl_net = net;
|
||||
|
||||
if (cfg->fc_type > RTN_MAX) {
|
||||
NL_SET_ERR_MSG(extack, "Invalid route type");
|
||||
err = -EINVAL;
|
||||
goto errout;
|
||||
}
|
||||
|
@ -718,12 +721,13 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|||
struct fib_table *tb;
|
||||
int err;
|
||||
|
||||
err = rtm_to_fib_config(net, skb, nlh, &cfg);
|
||||
err = rtm_to_fib_config(net, skb, nlh, &cfg, extack);
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
|
||||
tb = fib_get_table(net, cfg.fc_table);
|
||||
if (!tb) {
|
||||
NL_SET_ERR_MSG(extack, "FIB table does not exist");
|
||||
err = -ESRCH;
|
||||
goto errout;
|
||||
}
|
||||
|
@ -741,7 +745,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|||
struct fib_table *tb;
|
||||
int err;
|
||||
|
||||
err = rtm_to_fib_config(net, skb, nlh, &cfg);
|
||||
err = rtm_to_fib_config(net, skb, nlh, &cfg, extack);
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
|
||||
|
@ -751,7 +755,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|||
goto errout;
|
||||
}
|
||||
|
||||
err = fib_table_insert(net, tb, &cfg);
|
||||
err = fib_table_insert(net, tb, &cfg, extack);
|
||||
errout:
|
||||
return err;
|
||||
}
|
||||
|
@ -845,7 +849,7 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad
|
|||
cfg.fc_scope = RT_SCOPE_HOST;
|
||||
|
||||
if (cmd == RTM_NEWROUTE)
|
||||
fib_table_insert(net, tb, &cfg);
|
||||
fib_table_insert(net, tb, &cfg, NULL);
|
||||
else
|
||||
fib_table_delete(net, tb, &cfg);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ static inline void fib_alias_accessed(struct fib_alias *fa)
|
|||
|
||||
/* Exported by fib_semantics.c */
|
||||
void fib_release_info(struct fib_info *);
|
||||
struct fib_info *fib_create_info(struct fib_config *cfg);
|
||||
struct fib_info *fib_create_info(struct fib_config *cfg,
|
||||
struct netlink_ext_ack *extack);
|
||||
int fib_nh_match(struct fib_config *cfg, struct fib_info *fi);
|
||||
int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event, u32 tb_id,
|
||||
u8 type, __be32 dst, int dst_len, u8 tos, struct fib_info *fi,
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <linux/skbuff.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/netlink.h>
|
||||
|
||||
#include <net/arp.h>
|
||||
#include <net/ip.h>
|
||||
|
@ -454,7 +455,8 @@ static int fib_detect_death(struct fib_info *fi, int order,
|
|||
|
||||
#ifdef CONFIG_IP_ROUTE_MULTIPATH
|
||||
|
||||
static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining)
|
||||
static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
int nhs = 0;
|
||||
|
||||
|
@ -464,22 +466,35 @@ static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining)
|
|||
}
|
||||
|
||||
/* leftover implies invalid nexthop configuration, discard it */
|
||||
return remaining > 0 ? 0 : nhs;
|
||||
if (remaining > 0) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Invalid nexthop configuration - extra data after nexthops");
|
||||
nhs = 0;
|
||||
}
|
||||
|
||||
return nhs;
|
||||
}
|
||||
|
||||
static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
|
||||
int remaining, struct fib_config *cfg)
|
||||
int remaining, struct fib_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
int ret;
|
||||
|
||||
change_nexthops(fi) {
|
||||
int attrlen;
|
||||
|
||||
if (!rtnh_ok(rtnh, remaining))
|
||||
if (!rtnh_ok(rtnh, remaining)) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Invalid nexthop configuration - extra data after nexthop");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (rtnh->rtnh_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN))
|
||||
if (rtnh->rtnh_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN)) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Invalid flags for nexthop - can not contain DEAD or LINKDOWN");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
nexthop_nh->nh_flags =
|
||||
(cfg->fc_flags & ~0xFF) | rtnh->rtnh_flags;
|
||||
|
@ -505,8 +520,12 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
|
|||
|
||||
nla_entype = nla_find(attrs, attrlen,
|
||||
RTA_ENCAP_TYPE);
|
||||
if (!nla_entype)
|
||||
if (!nla_entype) {
|
||||
NL_SET_BAD_ATTR(extack, nla);
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Encap type is missing");
|
||||
goto err_inval;
|
||||
}
|
||||
|
||||
ret = lwtunnel_build_state(nla_get_u16(
|
||||
nla_entype),
|
||||
|
@ -714,7 +733,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
|
|||
* |-> {local prefix} (terminal node)
|
||||
*/
|
||||
static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
|
||||
struct fib_nh *nh)
|
||||
struct fib_nh *nh, struct netlink_ext_ack *extack)
|
||||
{
|
||||
int err = 0;
|
||||
struct net *net;
|
||||
|
@ -727,16 +746,25 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
|
|||
if (nh->nh_flags & RTNH_F_ONLINK) {
|
||||
unsigned int addr_type;
|
||||
|
||||
if (cfg->fc_scope >= RT_SCOPE_LINK)
|
||||
if (cfg->fc_scope >= RT_SCOPE_LINK) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Nexthop has invalid scope");
|
||||
return -EINVAL;
|
||||
}
|
||||
dev = __dev_get_by_index(net, nh->nh_oif);
|
||||
if (!dev)
|
||||
return -ENODEV;
|
||||
if (!(dev->flags & IFF_UP))
|
||||
if (!(dev->flags & IFF_UP)) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Nexthop device is not up");
|
||||
return -ENETDOWN;
|
||||
}
|
||||
addr_type = inet_addr_type_dev_table(net, dev, nh->nh_gw);
|
||||
if (addr_type != RTN_UNICAST)
|
||||
if (addr_type != RTN_UNICAST) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Nexthop has invalid gateway");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!netif_carrier_ok(dev))
|
||||
nh->nh_flags |= RTNH_F_LINKDOWN;
|
||||
nh->nh_dev = dev;
|
||||
|
@ -776,18 +804,25 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
|
|||
}
|
||||
|
||||
if (err) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Nexthop has invalid gateway");
|
||||
rcu_read_unlock();
|
||||
return err;
|
||||
}
|
||||
}
|
||||
err = -EINVAL;
|
||||
if (res.type != RTN_UNICAST && res.type != RTN_LOCAL)
|
||||
if (res.type != RTN_UNICAST && res.type != RTN_LOCAL) {
|
||||
NL_SET_ERR_MSG(extack, "Nexthop has invalid gateway");
|
||||
goto out;
|
||||
}
|
||||
nh->nh_scope = res.scope;
|
||||
nh->nh_oif = FIB_RES_OIF(res);
|
||||
nh->nh_dev = dev = FIB_RES_DEV(res);
|
||||
if (!dev)
|
||||
if (!dev) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"No egress device for nexthop gateway");
|
||||
goto out;
|
||||
}
|
||||
dev_hold(dev);
|
||||
if (!netif_carrier_ok(dev))
|
||||
nh->nh_flags |= RTNH_F_LINKDOWN;
|
||||
|
@ -795,17 +830,21 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
|
|||
} else {
|
||||
struct in_device *in_dev;
|
||||
|
||||
if (nh->nh_flags & (RTNH_F_PERVASIVE | RTNH_F_ONLINK))
|
||||
if (nh->nh_flags & (RTNH_F_PERVASIVE | RTNH_F_ONLINK)) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Invalid flags for nexthop - PERVASIVE and ONLINK can not be set");
|
||||
return -EINVAL;
|
||||
|
||||
}
|
||||
rcu_read_lock();
|
||||
err = -ENODEV;
|
||||
in_dev = inetdev_by_index(net, nh->nh_oif);
|
||||
if (!in_dev)
|
||||
goto out;
|
||||
err = -ENETDOWN;
|
||||
if (!(in_dev->dev->flags & IFF_UP))
|
||||
if (!(in_dev->dev->flags & IFF_UP)) {
|
||||
NL_SET_ERR_MSG(extack, "Device for nexthop is not up");
|
||||
goto out;
|
||||
}
|
||||
nh->nh_dev = in_dev->dev;
|
||||
dev_hold(nh->nh_dev);
|
||||
nh->nh_scope = RT_SCOPE_HOST;
|
||||
|
@ -980,7 +1019,8 @@ fib_convert_metrics(struct fib_info *fi, const struct fib_config *cfg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct fib_info *fib_create_info(struct fib_config *cfg)
|
||||
struct fib_info *fib_create_info(struct fib_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
int err;
|
||||
struct fib_info *fi = NULL;
|
||||
|
@ -992,15 +1032,20 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
|
|||
goto err_inval;
|
||||
|
||||
/* Fast check to catch the most weird cases */
|
||||
if (fib_props[cfg->fc_type].scope > cfg->fc_scope)
|
||||
if (fib_props[cfg->fc_type].scope > cfg->fc_scope) {
|
||||
NL_SET_ERR_MSG(extack, "Invalid scope");
|
||||
goto err_inval;
|
||||
}
|
||||
|
||||
if (cfg->fc_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN))
|
||||
if (cfg->fc_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN)) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Invalid rtm_flags - can not contain DEAD or LINKDOWN");
|
||||
goto err_inval;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IP_ROUTE_MULTIPATH
|
||||
if (cfg->fc_mp) {
|
||||
nhs = fib_count_nexthops(cfg->fc_mp, cfg->fc_mp_len);
|
||||
nhs = fib_count_nexthops(cfg->fc_mp, cfg->fc_mp_len, extack);
|
||||
if (nhs == 0)
|
||||
goto err_inval;
|
||||
}
|
||||
|
@ -1062,18 +1107,29 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
|
|||
|
||||
if (cfg->fc_mp) {
|
||||
#ifdef CONFIG_IP_ROUTE_MULTIPATH
|
||||
err = fib_get_nhs(fi, cfg->fc_mp, cfg->fc_mp_len, cfg);
|
||||
err = fib_get_nhs(fi, cfg->fc_mp, cfg->fc_mp_len, cfg, extack);
|
||||
if (err != 0)
|
||||
goto failure;
|
||||
if (cfg->fc_oif && fi->fib_nh->nh_oif != cfg->fc_oif)
|
||||
if (cfg->fc_oif && fi->fib_nh->nh_oif != cfg->fc_oif) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Nexthop device index does not match RTA_OIF");
|
||||
goto err_inval;
|
||||
if (cfg->fc_gw && fi->fib_nh->nh_gw != cfg->fc_gw)
|
||||
}
|
||||
if (cfg->fc_gw && fi->fib_nh->nh_gw != cfg->fc_gw) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Nexthop gateway does not match RTA_GATEWAY");
|
||||
goto err_inval;
|
||||
}
|
||||
#ifdef CONFIG_IP_ROUTE_CLASSID
|
||||
if (cfg->fc_flow && fi->fib_nh->nh_tclassid != cfg->fc_flow)
|
||||
if (cfg->fc_flow && fi->fib_nh->nh_tclassid != cfg->fc_flow) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Nexthop class id does not match RTA_FLOW");
|
||||
goto err_inval;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Multipath support not enabled in kernel");
|
||||
goto err_inval;
|
||||
#endif
|
||||
} else {
|
||||
|
@ -1082,8 +1138,11 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
|
|||
if (cfg->fc_encap) {
|
||||
struct lwtunnel_state *lwtstate;
|
||||
|
||||
if (cfg->fc_encap_type == LWTUNNEL_ENCAP_NONE)
|
||||
if (cfg->fc_encap_type == LWTUNNEL_ENCAP_NONE) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"LWT encap type not specified");
|
||||
goto err_inval;
|
||||
}
|
||||
err = lwtunnel_build_state(cfg->fc_encap_type,
|
||||
cfg->fc_encap, AF_INET, cfg,
|
||||
&lwtstate);
|
||||
|
@ -1106,8 +1165,11 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
|
|||
}
|
||||
|
||||
if (fib_props[cfg->fc_type].error) {
|
||||
if (cfg->fc_gw || cfg->fc_oif || cfg->fc_mp)
|
||||
if (cfg->fc_gw || cfg->fc_oif || cfg->fc_mp) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Gateway, device and multipath can not be specified for this route type");
|
||||
goto err_inval;
|
||||
}
|
||||
goto link_it;
|
||||
} else {
|
||||
switch (cfg->fc_type) {
|
||||
|
@ -1118,19 +1180,30 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
|
|||
case RTN_MULTICAST:
|
||||
break;
|
||||
default:
|
||||
NL_SET_ERR_MSG(extack, "Invalid route type");
|
||||
goto err_inval;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfg->fc_scope > RT_SCOPE_HOST)
|
||||
if (cfg->fc_scope > RT_SCOPE_HOST) {
|
||||
NL_SET_ERR_MSG(extack, "Invalid scope");
|
||||
goto err_inval;
|
||||
}
|
||||
|
||||
if (cfg->fc_scope == RT_SCOPE_HOST) {
|
||||
struct fib_nh *nh = fi->fib_nh;
|
||||
|
||||
/* Local address is added. */
|
||||
if (nhs != 1 || nh->nh_gw)
|
||||
if (nhs != 1) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Route with host scope can not have multiple nexthops");
|
||||
goto err_inval;
|
||||
}
|
||||
if (nh->nh_gw) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Route with host scope can not have a gateway");
|
||||
goto err_inval;
|
||||
}
|
||||
nh->nh_scope = RT_SCOPE_NOWHERE;
|
||||
nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif);
|
||||
err = -ENODEV;
|
||||
|
@ -1140,7 +1213,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
|
|||
int linkdown = 0;
|
||||
|
||||
change_nexthops(fi) {
|
||||
err = fib_check_nh(cfg, fi, nexthop_nh);
|
||||
err = fib_check_nh(cfg, fi, nexthop_nh, extack);
|
||||
if (err != 0)
|
||||
goto failure;
|
||||
if (nexthop_nh->nh_flags & RTNH_F_LINKDOWN)
|
||||
|
@ -1150,8 +1223,10 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
|
|||
fi->fib_flags |= RTNH_F_LINKDOWN;
|
||||
}
|
||||
|
||||
if (fi->fib_prefsrc && !fib_valid_prefsrc(cfg, fi->fib_prefsrc))
|
||||
if (fi->fib_prefsrc && !fib_valid_prefsrc(cfg, fi->fib_prefsrc)) {
|
||||
NL_SET_ERR_MSG(extack, "Invalid prefsrc address");
|
||||
goto err_inval;
|
||||
}
|
||||
|
||||
change_nexthops(fi) {
|
||||
fib_info_update_nh_saddr(net, nexthop_nh);
|
||||
|
|
|
@ -1101,7 +1101,7 @@ static int fib_insert_alias(struct trie *t, struct key_vector *tp,
|
|||
|
||||
/* Caller must hold RTNL. */
|
||||
int fib_table_insert(struct net *net, struct fib_table *tb,
|
||||
struct fib_config *cfg)
|
||||
struct fib_config *cfg, struct netlink_ext_ack *extack)
|
||||
{
|
||||
enum fib_event_type event = FIB_EVENT_ENTRY_ADD;
|
||||
struct trie *t = (struct trie *)tb->tb_data;
|
||||
|
@ -1125,7 +1125,7 @@ int fib_table_insert(struct net *net, struct fib_table *tb,
|
|||
if ((plen < KEYLENGTH) && (key << plen))
|
||||
return -EINVAL;
|
||||
|
||||
fi = fib_create_info(cfg);
|
||||
fi = fib_create_info(cfg, extack);
|
||||
if (IS_ERR(fi)) {
|
||||
err = PTR_ERR(fi);
|
||||
goto err;
|
||||
|
|
|
@ -2280,7 +2280,7 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
|
|||
cfg.fc_flags |= RTF_NONEXTHOP;
|
||||
#endif
|
||||
|
||||
ip6_route_add(&cfg);
|
||||
ip6_route_add(&cfg, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2335,7 +2335,7 @@ static void addrconf_add_mroute(struct net_device *dev)
|
|||
|
||||
ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
|
||||
|
||||
ip6_route_add(&cfg);
|
||||
ip6_route_add(&cfg, NULL);
|
||||
}
|
||||
|
||||
static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
|
||||
|
|
|
@ -473,7 +473,8 @@ out:
|
|||
static struct fib6_node *fib6_add_1(struct fib6_node *root,
|
||||
struct in6_addr *addr, int plen,
|
||||
int offset, int allow_create,
|
||||
int replace_required, int sernum)
|
||||
int replace_required, int sernum,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct fib6_node *fn, *in, *ln;
|
||||
struct fib6_node *pn = NULL;
|
||||
|
@ -497,6 +498,8 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
|
|||
!ipv6_prefix_equal(&key->addr, addr, fn->fn_bit)) {
|
||||
if (!allow_create) {
|
||||
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");
|
||||
return ERR_PTR(-ENOENT);
|
||||
}
|
||||
|
@ -543,6 +546,8 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
|
|||
* That would keep IPv6 consistent with IPv4
|
||||
*/
|
||||
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");
|
||||
return ERR_PTR(-ENOENT);
|
||||
}
|
||||
|
@ -964,7 +969,8 @@ void fib6_force_start_gc(struct net *net)
|
|||
*/
|
||||
|
||||
int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
||||
struct nl_info *info, struct mx6_config *mxc)
|
||||
struct nl_info *info, struct mx6_config *mxc,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct fib6_node *fn, *pn = NULL;
|
||||
int err = -ENOMEM;
|
||||
|
@ -987,7 +993,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|||
|
||||
fn = fib6_add_1(root, &rt->rt6i_dst.addr, rt->rt6i_dst.plen,
|
||||
offsetof(struct rt6_info, rt6i_dst), allow_create,
|
||||
replace_required, sernum);
|
||||
replace_required, sernum, extack);
|
||||
if (IS_ERR(fn)) {
|
||||
err = PTR_ERR(fn);
|
||||
fn = NULL;
|
||||
|
@ -1028,7 +1034,8 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|||
sn = fib6_add_1(sfn, &rt->rt6i_src.addr,
|
||||
rt->rt6i_src.plen,
|
||||
offsetof(struct rt6_info, rt6i_src),
|
||||
allow_create, replace_required, sernum);
|
||||
allow_create, replace_required, sernum,
|
||||
extack);
|
||||
|
||||
if (IS_ERR(sn)) {
|
||||
/* If it is failed, discard just allocated
|
||||
|
@ -1047,7 +1054,8 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|||
sn = fib6_add_1(fn->subtree, &rt->rt6i_src.addr,
|
||||
rt->rt6i_src.plen,
|
||||
offsetof(struct rt6_info, rt6i_src),
|
||||
allow_create, replace_required, sernum);
|
||||
allow_create, replace_required, sernum,
|
||||
extack);
|
||||
|
||||
if (IS_ERR(sn)) {
|
||||
err = PTR_ERR(sn);
|
||||
|
|
|
@ -938,14 +938,15 @@ EXPORT_SYMBOL(rt6_lookup);
|
|||
*/
|
||||
|
||||
static int __ip6_ins_rt(struct rt6_info *rt, struct nl_info *info,
|
||||
struct mx6_config *mxc)
|
||||
struct mx6_config *mxc,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
int err;
|
||||
struct fib6_table *table;
|
||||
|
||||
table = rt->rt6i_table;
|
||||
write_lock_bh(&table->tb6_lock);
|
||||
err = fib6_add(&table->tb6_root, rt, info, mxc);
|
||||
err = fib6_add(&table->tb6_root, rt, info, mxc, extack);
|
||||
write_unlock_bh(&table->tb6_lock);
|
||||
|
||||
return err;
|
||||
|
@ -956,7 +957,7 @@ int ip6_ins_rt(struct rt6_info *rt)
|
|||
struct nl_info info = { .nl_net = dev_net(rt->dst.dev), };
|
||||
struct mx6_config mxc = { .mx = NULL, };
|
||||
|
||||
return __ip6_ins_rt(rt, &info, &mxc);
|
||||
return __ip6_ins_rt(rt, &info, &mxc, NULL);
|
||||
}
|
||||
|
||||
static struct rt6_info *ip6_rt_cache_alloc(struct rt6_info *ort,
|
||||
|
@ -1844,7 +1845,8 @@ static struct rt6_info *ip6_nh_lookup_table(struct net *net,
|
|||
return rt;
|
||||
}
|
||||
|
||||
static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
|
||||
static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct net *net = cfg->fc_nlinfo.nl_net;
|
||||
struct rt6_info *rt = NULL;
|
||||
|
@ -1855,14 +1857,25 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
|
|||
int err = -EINVAL;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
#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;
|
||||
}
|
||||
#endif
|
||||
if (cfg->fc_ifindex) {
|
||||
err = -ENODEV;
|
||||
|
@ -2013,9 +2026,10 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
|
|||
err = -EINVAL;
|
||||
if (ipv6_chk_addr_and_flags(net, gw_addr,
|
||||
gwa_type & IPV6_ADDR_LINKLOCAL ?
|
||||
dev : NULL, 0, 0))
|
||||
dev : NULL, 0, 0)) {
|
||||
NL_SET_ERR_MSG(extack, "Invalid gateway address");
|
||||
goto out;
|
||||
|
||||
}
|
||||
rt->rt6i_gateway = *gw_addr;
|
||||
|
||||
if (gwa_type != (IPV6_ADDR_LINKLOCAL|IPV6_ADDR_UNICAST)) {
|
||||
|
@ -2031,8 +2045,11 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
|
|||
addressing
|
||||
*/
|
||||
if (!(gwa_type & (IPV6_ADDR_UNICAST |
|
||||
IPV6_ADDR_MAPPED)))
|
||||
IPV6_ADDR_MAPPED))) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
"Invalid gateway address");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (cfg->fc_table) {
|
||||
grt = ip6_nh_lookup_table(net, cfg, gw_addr);
|
||||
|
@ -2072,8 +2089,14 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
|
|||
goto out;
|
||||
}
|
||||
err = -EINVAL;
|
||||
if (!dev || (dev->flags & IFF_LOOPBACK))
|
||||
if (!dev) {
|
||||
NL_SET_ERR_MSG(extack, "Egress device not specified");
|
||||
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;
|
||||
|
@ -2082,6 +2105,7 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
|
|||
|
||||
if (!ipv6_addr_any(&cfg->fc_prefsrc)) {
|
||||
if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) {
|
||||
NL_SET_ERR_MSG(extack, "Invalid source address");
|
||||
err = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
@ -2111,13 +2135,14 @@ out:
|
|||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
int ip6_route_add(struct fib6_config *cfg)
|
||||
int ip6_route_add(struct fib6_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mx6_config mxc = { .mx = NULL, };
|
||||
struct rt6_info *rt;
|
||||
int err;
|
||||
|
||||
rt = ip6_route_info_create(cfg);
|
||||
rt = ip6_route_info_create(cfg, extack);
|
||||
if (IS_ERR(rt)) {
|
||||
err = PTR_ERR(rt);
|
||||
rt = NULL;
|
||||
|
@ -2128,7 +2153,7 @@ int ip6_route_add(struct fib6_config *cfg)
|
|||
if (err)
|
||||
goto out;
|
||||
|
||||
err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, &mxc);
|
||||
err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, &mxc, extack);
|
||||
|
||||
kfree(mxc.mx);
|
||||
|
||||
|
@ -2222,7 +2247,8 @@ out_put:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int ip6_route_del(struct fib6_config *cfg)
|
||||
static int ip6_route_del(struct fib6_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct fib6_table *table;
|
||||
struct fib6_node *fn;
|
||||
|
@ -2230,8 +2256,10 @@ static int ip6_route_del(struct fib6_config *cfg)
|
|||
int err = -ESRCH;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
read_lock_bh(&table->tb6_lock);
|
||||
|
||||
|
@ -2483,7 +2511,7 @@ static struct rt6_info *rt6_add_route_info(struct net *net,
|
|||
if (!prefixlen)
|
||||
cfg.fc_flags |= RTF_DEFAULT;
|
||||
|
||||
ip6_route_add(&cfg);
|
||||
ip6_route_add(&cfg, NULL);
|
||||
|
||||
return rt6_get_route_info(net, prefix, prefixlen, gwaddr, dev);
|
||||
}
|
||||
|
@ -2529,7 +2557,7 @@ struct rt6_info *rt6_add_dflt_router(const struct in6_addr *gwaddr,
|
|||
|
||||
cfg.fc_gateway = *gwaddr;
|
||||
|
||||
if (!ip6_route_add(&cfg)) {
|
||||
if (!ip6_route_add(&cfg, NULL)) {
|
||||
struct fib6_table *table;
|
||||
|
||||
table = fib6_get_table(dev_net(dev), cfg.fc_table);
|
||||
|
@ -2622,10 +2650,10 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg)
|
|||
rtnl_lock();
|
||||
switch (cmd) {
|
||||
case SIOCADDRT:
|
||||
err = ip6_route_add(&cfg);
|
||||
err = ip6_route_add(&cfg, NULL);
|
||||
break;
|
||||
case SIOCDELRT:
|
||||
err = ip6_route_del(&cfg);
|
||||
err = ip6_route_del(&cfg, NULL);
|
||||
break;
|
||||
default:
|
||||
err = -EINVAL;
|
||||
|
@ -2903,7 +2931,8 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
|
|||
};
|
||||
|
||||
static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||
struct fib6_config *cfg)
|
||||
struct fib6_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct rtmsg *rtm;
|
||||
struct nlattr *tb[RTA_MAX+1];
|
||||
|
@ -3097,7 +3126,8 @@ static void ip6_route_mpath_notify(struct rt6_info *rt,
|
|||
inet6_rt_notify(RTM_NEWROUTE, rt, info, nlflags);
|
||||
}
|
||||
|
||||
static int ip6_route_multipath_add(struct fib6_config *cfg)
|
||||
static int ip6_route_multipath_add(struct fib6_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct rt6_info *rt_notif = NULL, *rt_last = NULL;
|
||||
struct nl_info *info = &cfg->fc_nlinfo;
|
||||
|
@ -3145,7 +3175,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg)
|
|||
r_cfg.fc_encap_type = nla_get_u16(nla);
|
||||
}
|
||||
|
||||
rt = ip6_route_info_create(&r_cfg);
|
||||
rt = ip6_route_info_create(&r_cfg, extack);
|
||||
if (IS_ERR(rt)) {
|
||||
err = PTR_ERR(rt);
|
||||
rt = NULL;
|
||||
|
@ -3170,7 +3200,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg)
|
|||
err_nh = NULL;
|
||||
list_for_each_entry(nh, &rt6_nh_list, next) {
|
||||
rt_last = nh->rt6_info;
|
||||
err = __ip6_ins_rt(nh->rt6_info, info, &nh->mxc);
|
||||
err = __ip6_ins_rt(nh->rt6_info, info, &nh->mxc, extack);
|
||||
/* save reference to first route for notification */
|
||||
if (!rt_notif && !err)
|
||||
rt_notif = nh->rt6_info;
|
||||
|
@ -3212,7 +3242,7 @@ add_errout:
|
|||
list_for_each_entry(nh, &rt6_nh_list, next) {
|
||||
if (err_nh == nh)
|
||||
break;
|
||||
ip6_route_del(&nh->r_cfg);
|
||||
ip6_route_del(&nh->r_cfg, extack);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
@ -3227,7 +3257,8 @@ cleanup:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int ip6_route_multipath_del(struct fib6_config *cfg)
|
||||
static int ip6_route_multipath_del(struct fib6_config *cfg,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct fib6_config r_cfg;
|
||||
struct rtnexthop *rtnh;
|
||||
|
@ -3254,7 +3285,7 @@ static int ip6_route_multipath_del(struct fib6_config *cfg)
|
|||
r_cfg.fc_flags |= RTF_GATEWAY;
|
||||
}
|
||||
}
|
||||
err = ip6_route_del(&r_cfg);
|
||||
err = ip6_route_del(&r_cfg, extack);
|
||||
if (err)
|
||||
last_err = err;
|
||||
|
||||
|
@ -3270,15 +3301,15 @@ static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|||
struct fib6_config cfg;
|
||||
int err;
|
||||
|
||||
err = rtm_to_fib6_config(skb, nlh, &cfg);
|
||||
err = rtm_to_fib6_config(skb, nlh, &cfg, extack);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (cfg.fc_mp)
|
||||
return ip6_route_multipath_del(&cfg);
|
||||
return ip6_route_multipath_del(&cfg, extack);
|
||||
else {
|
||||
cfg.fc_delete_all_nh = 1;
|
||||
return ip6_route_del(&cfg);
|
||||
return ip6_route_del(&cfg, extack);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3288,14 +3319,14 @@ static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|||
struct fib6_config cfg;
|
||||
int err;
|
||||
|
||||
err = rtm_to_fib6_config(skb, nlh, &cfg);
|
||||
err = rtm_to_fib6_config(skb, nlh, &cfg, extack);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (cfg.fc_mp)
|
||||
return ip6_route_multipath_add(&cfg);
|
||||
return ip6_route_multipath_add(&cfg, extack);
|
||||
else
|
||||
return ip6_route_add(&cfg);
|
||||
return ip6_route_add(&cfg, extack);
|
||||
}
|
||||
|
||||
static size_t rt6_nlmsg_size(struct rt6_info *rt)
|
||||
|
|
Loading…
Reference in New Issue