Commit acb5d48f authored by David S. Miller's avatar David S. Miller

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: default avatarDavid S. Miller <davem@davemloft.net>
parents 863483c9 d5d531cb
...@@ -97,6 +97,11 @@ struct netlink_ext_ack { ...@@ -97,6 +97,11 @@ struct netlink_ext_ack {
#define NL_SET_ERR_MSG_MOD(extack, msg) \ #define NL_SET_ERR_MSG_MOD(extack, msg) \
NL_SET_ERR_MSG((extack), KBUILD_MODNAME ": " 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 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);
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), ...@@ -277,7 +277,8 @@ void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
void *arg); void *arg);
int fib6_add(struct fib6_node *root, struct rt6_info *rt, 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); 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, void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info,
......
...@@ -90,7 +90,7 @@ void ip6_route_cleanup(void); ...@@ -90,7 +90,7 @@ void ip6_route_cleanup(void);
int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg); 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_ins_rt(struct rt6_info *);
int ip6_del_rt(struct rt6_info *); int ip6_del_rt(struct rt6_info *);
......
...@@ -263,7 +263,8 @@ struct fib_table { ...@@ -263,7 +263,8 @@ struct fib_table {
int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
struct fib_result *res, int fib_flags); 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_delete(struct net *, struct fib_table *, struct fib_config *);
int fib_table_dump(struct fib_table *table, struct sk_buff *skb, int fib_table_dump(struct fib_table *table, struct sk_buff *skb,
struct netlink_callback *cb); struct netlink_callback *cb);
......
...@@ -594,7 +594,8 @@ int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg) ...@@ -594,7 +594,8 @@ int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg)
} else { } else {
tb = fib_new_table(net, cfg.fc_table); tb = fib_new_table(net, cfg.fc_table);
if (tb) if (tb)
err = fib_table_insert(net, tb, &cfg); err = fib_table_insert(net, tb,
&cfg, NULL);
else else
err = -ENOBUFS; err = -ENOBUFS;
} }
...@@ -626,14 +627,15 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = { ...@@ -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, 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; struct nlattr *attr;
int err, remaining; int err, remaining;
struct rtmsg *rtm; struct rtmsg *rtm;
err = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipv4_policy, err = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipv4_policy,
NULL); extack);
if (err < 0) if (err < 0)
goto errout; goto errout;
...@@ -654,6 +656,7 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb, ...@@ -654,6 +656,7 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
cfg->fc_nlinfo.nl_net = net; cfg->fc_nlinfo.nl_net = net;
if (cfg->fc_type > RTN_MAX) { if (cfg->fc_type > RTN_MAX) {
NL_SET_ERR_MSG(extack, "Invalid route type");
err = -EINVAL; err = -EINVAL;
goto errout; goto errout;
} }
...@@ -718,12 +721,13 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -718,12 +721,13 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
struct fib_table *tb; struct fib_table *tb;
int err; int err;
err = rtm_to_fib_config(net, skb, nlh, &cfg); err = rtm_to_fib_config(net, skb, nlh, &cfg, extack);
if (err < 0) if (err < 0)
goto errout; goto errout;
tb = fib_get_table(net, cfg.fc_table); tb = fib_get_table(net, cfg.fc_table);
if (!tb) { if (!tb) {
NL_SET_ERR_MSG(extack, "FIB table does not exist");
err = -ESRCH; err = -ESRCH;
goto errout; goto errout;
} }
...@@ -741,7 +745,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -741,7 +745,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
struct fib_table *tb; struct fib_table *tb;
int err; int err;
err = rtm_to_fib_config(net, skb, nlh, &cfg); err = rtm_to_fib_config(net, skb, nlh, &cfg, extack);
if (err < 0) if (err < 0)
goto errout; goto errout;
...@@ -751,7 +755,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -751,7 +755,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
goto errout; goto errout;
} }
err = fib_table_insert(net, tb, &cfg); err = fib_table_insert(net, tb, &cfg, extack);
errout: errout:
return err; return err;
} }
...@@ -845,7 +849,7 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad ...@@ -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; cfg.fc_scope = RT_SCOPE_HOST;
if (cmd == RTM_NEWROUTE) if (cmd == RTM_NEWROUTE)
fib_table_insert(net, tb, &cfg); fib_table_insert(net, tb, &cfg, NULL);
else else
fib_table_delete(net, tb, &cfg); fib_table_delete(net, tb, &cfg);
} }
......
...@@ -28,7 +28,8 @@ static inline void fib_alias_accessed(struct fib_alias *fa) ...@@ -28,7 +28,8 @@ static inline void fib_alias_accessed(struct fib_alias *fa)
/* Exported by fib_semantics.c */ /* Exported by fib_semantics.c */
void fib_release_info(struct fib_info *); 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_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, 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, u8 type, __be32 dst, int dst_len, u8 tos, struct fib_info *fi,
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/netlink.h>
#include <net/arp.h> #include <net/arp.h>
#include <net/ip.h> #include <net/ip.h>
...@@ -454,7 +455,8 @@ static int fib_detect_death(struct fib_info *fi, int order, ...@@ -454,7 +455,8 @@ static int fib_detect_death(struct fib_info *fi, int order,
#ifdef CONFIG_IP_ROUTE_MULTIPATH #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; int nhs = 0;
...@@ -464,22 +466,35 @@ static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining) ...@@ -464,22 +466,35 @@ static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining)
} }
/* leftover implies invalid nexthop configuration, discard it */ /* 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, 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; int ret;
change_nexthops(fi) { change_nexthops(fi) {
int attrlen; 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; 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; return -EINVAL;
}
nexthop_nh->nh_flags = nexthop_nh->nh_flags =
(cfg->fc_flags & ~0xFF) | rtnh->rtnh_flags; (cfg->fc_flags & ~0xFF) | rtnh->rtnh_flags;
...@@ -505,8 +520,12 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, ...@@ -505,8 +520,12 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
nla_entype = nla_find(attrs, attrlen, nla_entype = nla_find(attrs, attrlen,
RTA_ENCAP_TYPE); 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; goto err_inval;
}
ret = lwtunnel_build_state(nla_get_u16( ret = lwtunnel_build_state(nla_get_u16(
nla_entype), nla_entype),
...@@ -714,7 +733,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi) ...@@ -714,7 +733,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
* |-> {local prefix} (terminal node) * |-> {local prefix} (terminal node)
*/ */
static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi, 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; int err = 0;
struct net *net; struct net *net;
...@@ -727,16 +746,25 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi, ...@@ -727,16 +746,25 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
if (nh->nh_flags & RTNH_F_ONLINK) { if (nh->nh_flags & RTNH_F_ONLINK) {
unsigned int addr_type; 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; return -EINVAL;
}
dev = __dev_get_by_index(net, nh->nh_oif); dev = __dev_get_by_index(net, nh->nh_oif);
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
if (!(dev->flags & IFF_UP)) if (!(dev->flags & IFF_UP)) {
NL_SET_ERR_MSG(extack,
"Nexthop device is not up");
return -ENETDOWN; return -ENETDOWN;
}
addr_type = inet_addr_type_dev_table(net, dev, nh->nh_gw); 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; return -EINVAL;
}
if (!netif_carrier_ok(dev)) if (!netif_carrier_ok(dev))
nh->nh_flags |= RTNH_F_LINKDOWN; nh->nh_flags |= RTNH_F_LINKDOWN;
nh->nh_dev = dev; nh->nh_dev = dev;
...@@ -776,18 +804,25 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi, ...@@ -776,18 +804,25 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
} }
if (err) { if (err) {
NL_SET_ERR_MSG(extack,
"Nexthop has invalid gateway");
rcu_read_unlock(); rcu_read_unlock();
return err; return err;
} }
} }
err = -EINVAL; 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; goto out;
}
nh->nh_scope = res.scope; nh->nh_scope = res.scope;
nh->nh_oif = FIB_RES_OIF(res); nh->nh_oif = FIB_RES_OIF(res);
nh->nh_dev = dev = FIB_RES_DEV(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; goto out;
}
dev_hold(dev); dev_hold(dev);
if (!netif_carrier_ok(dev)) if (!netif_carrier_ok(dev))
nh->nh_flags |= RTNH_F_LINKDOWN; nh->nh_flags |= RTNH_F_LINKDOWN;
...@@ -795,17 +830,21 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi, ...@@ -795,17 +830,21 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
} else { } else {
struct in_device *in_dev; 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; return -EINVAL;
}
rcu_read_lock(); rcu_read_lock();
err = -ENODEV; err = -ENODEV;
in_dev = inetdev_by_index(net, nh->nh_oif); in_dev = inetdev_by_index(net, nh->nh_oif);
if (!in_dev) if (!in_dev)
goto out; goto out;
err = -ENETDOWN; 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; goto out;
}
nh->nh_dev = in_dev->dev; nh->nh_dev = in_dev->dev;
dev_hold(nh->nh_dev); dev_hold(nh->nh_dev);
nh->nh_scope = RT_SCOPE_HOST; nh->nh_scope = RT_SCOPE_HOST;
...@@ -980,7 +1019,8 @@ fib_convert_metrics(struct fib_info *fi, const struct fib_config *cfg) ...@@ -980,7 +1019,8 @@ fib_convert_metrics(struct fib_info *fi, const struct fib_config *cfg)
return 0; 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; int err;
struct fib_info *fi = NULL; struct fib_info *fi = NULL;
...@@ -992,15 +1032,20 @@ struct fib_info *fib_create_info(struct fib_config *cfg) ...@@ -992,15 +1032,20 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
goto err_inval; goto err_inval;
/* Fast check to catch the most weird cases */ /* 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; 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; goto err_inval;
}
#ifdef CONFIG_IP_ROUTE_MULTIPATH #ifdef CONFIG_IP_ROUTE_MULTIPATH
if (cfg->fc_mp) { 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) if (nhs == 0)
goto err_inval; goto err_inval;
} }
...@@ -1062,18 +1107,29 @@ struct fib_info *fib_create_info(struct fib_config *cfg) ...@@ -1062,18 +1107,29 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
if (cfg->fc_mp) { if (cfg->fc_mp) {
#ifdef CONFIG_IP_ROUTE_MULTIPATH #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) if (err != 0)
goto failure; 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; 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; goto err_inval;
}
#ifdef CONFIG_IP_ROUTE_CLASSID #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; goto err_inval;
}
#endif #endif
#else #else
NL_SET_ERR_MSG(extack,
"Multipath support not enabled in kernel");
goto err_inval; goto err_inval;
#endif #endif
} else { } else {
...@@ -1082,8 +1138,11 @@ struct fib_info *fib_create_info(struct fib_config *cfg) ...@@ -1082,8 +1138,11 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
if (cfg->fc_encap) { if (cfg->fc_encap) {
struct lwtunnel_state *lwtstate; 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; goto err_inval;
}
err = lwtunnel_build_state(cfg->fc_encap_type, err = lwtunnel_build_state(cfg->fc_encap_type,
cfg->fc_encap, AF_INET, cfg, cfg->fc_encap, AF_INET, cfg,
&lwtstate); &lwtstate);
...@@ -1106,8 +1165,11 @@ struct fib_info *fib_create_info(struct fib_config *cfg) ...@@ -1106,8 +1165,11 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
} }
if (fib_props[cfg->fc_type].error) { 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 err_inval;
}
goto link_it; goto link_it;
} else { } else {
switch (cfg->fc_type) { switch (cfg->fc_type) {
...@@ -1118,19 +1180,30 @@ struct fib_info *fib_create_info(struct fib_config *cfg) ...@@ -1118,19 +1180,30 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
case RTN_MULTICAST: case RTN_MULTICAST:
break; break;
default: default:
NL_SET_ERR_MSG(extack, "Invalid route type");
goto err_inval; 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; goto err_inval;
}
if (cfg->fc_scope == RT_SCOPE_HOST) { if (cfg->fc_scope == RT_SCOPE_HOST) {
struct fib_nh *nh = fi->fib_nh; struct fib_nh *nh = fi->fib_nh;
/* Local address is added. */ /* 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; 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_scope = RT_SCOPE_NOWHERE;
nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif); nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif);
err = -ENODEV; err = -ENODEV;
...@@ -1140,7 +1213,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg) ...@@ -1140,7 +1213,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
int linkdown = 0; int linkdown = 0;
change_nexthops(fi) { change_nexthops(fi) {
err = fib_check_nh(cfg, fi, nexthop_nh); err = fib_check_nh(cfg, fi, nexthop_nh, extack);
if (err != 0) if (err != 0)
goto failure; goto failure;
if (nexthop_nh->nh_flags & RTNH_F_LINKDOWN) if (nexthop_nh->nh_flags & RTNH_F_LINKDOWN)
...@@ -1150,8 +1223,10 @@ struct fib_info *fib_create_info(struct fib_config *cfg) ...@@ -1150,8 +1223,10 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
fi->fib_flags |= RTNH_F_LINKDOWN; 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; goto err_inval;
}
change_nexthops(fi) { change_nexthops(fi) {
fib_info_update_nh_saddr(net, nexthop_nh); fib_info_update_nh_saddr(net, nexthop_nh);
......
...@@ -1101,7 +1101,7 @@ static int fib_insert_alias(struct trie *t, struct key_vector *tp, ...@@ -1101,7 +1101,7 @@ static int fib_insert_alias(struct trie *t, struct key_vector *tp,
/* Caller must hold RTNL. */ /* Caller must hold RTNL. */
int fib_table_insert(struct net *net, struct fib_table *tb, 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; enum fib_event_type event = FIB_EVENT_ENTRY_ADD;
struct trie *t = (struct trie *)tb->tb_data; struct trie *t = (struct trie *)tb->tb_data;
...@@ -1125,7 +1125,7 @@ int fib_table_insert(struct net *net, struct fib_table *tb, ...@@ -1125,7 +1125,7 @@ int fib_table_insert(struct net *net, struct fib_table *tb,
if ((plen < KEYLENGTH) && (key << plen)) if ((plen < KEYLENGTH) && (key << plen))
return -EINVAL; return -EINVAL;
fi = fib_create_info(cfg); fi = fib_create_info(cfg, extack);
if (IS_ERR(fi)) { if (IS_ERR(fi)) {
err = PTR_ERR(fi); err = PTR_ERR(fi);
goto err; goto err;
......
...@@ -2280,7 +2280,7 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev, ...@@ -2280,7 +2280,7 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
cfg.fc_flags |= RTF_NONEXTHOP; cfg.fc_flags |= RTF_NONEXTHOP;
#endif #endif
ip6_route_add(&cfg); ip6_route_add(&cfg, NULL);
} }
...@@ -2335,7 +2335,7 @@ static void addrconf_add_mroute(struct net_device *dev) ...@@ -2335,7 +2335,7 @@ static void addrconf_add_mroute(struct net_device *dev)
ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0); 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) static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
......
...@@ -473,7 +473,8 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -473,7 +473,8 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
static struct fib6_node *fib6_add_1(struct fib6_node *root, static struct fib6_node *fib6_add_1(struct fib6_node *root,
struct in6_addr *addr, int plen, struct in6_addr *addr, int plen,
int offset, int allow_create, 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 *fn, *in, *ln;
struct fib6_node *pn = NULL; struct fib6_node *pn = NULL;
...@@ -497,6 +498,8 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root, ...@@ -497,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);
} }
...@@ -543,6 +546,8 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root, ...@@ -543,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);
} }
...@@ -964,7 +969,8 @@ void fib6_force_start_gc(struct net *net) ...@@ -964,7 +969,8 @@ void fib6_force_start_gc(struct net *net)
*/ */
int fib6_add(struct fib6_node *root, struct rt6_info *rt, 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; struct fib6_node *fn, *pn = NULL;
int err = -ENOMEM; int err = -ENOMEM;
...@@ -987,7 +993,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, ...@@ -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, fn = fib6_add_1(root, &rt->rt6i_dst.addr, rt->rt6i_dst.plen,
offsetof(struct rt6_info, rt6i_dst), allow_create, offsetof(struct rt6_info, rt6i_dst), allow_create,
replace_required, sernum); replace_required, sernum, extack);
if (IS_ERR(fn)) { if (IS_ERR(fn)) {
err = PTR_ERR(fn); err = PTR_ERR(fn);
fn = NULL; fn = NULL;
...@@ -1028,7 +1034,8 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, ...@@ -1028,7 +1034,8 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
sn = fib6_add_1(sfn, &rt->rt6i_src.addr, sn = fib6_add_1(sfn, &rt->rt6i_src.addr,
rt->rt6i_src.plen, rt->rt6i_src.plen,
offsetof(struct rt6_info, rt6i_src), offsetof(struct rt6_info, rt6i_src),
allow_create, replace_required, sernum); allow_create, replace_required, sernum,
extack);
if (IS_ERR(sn)) { if (IS_ERR(sn)) {
/* If it is failed, discard just allocated /* If it is failed, discard just allocated
...@@ -1047,7 +1054,8 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, ...@@ -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, sn = fib6_add_1(fn->subtree, &rt->rt6i_src.addr,
rt->rt6i_src.plen, rt->rt6i_src.plen,
offsetof(struct rt6_info, rt6i_src), offsetof(struct rt6_info, rt6i_src),
allow_create, replace_required, sernum); allow_create, replace_required, sernum,
extack);
if (IS_ERR(sn)) { if (IS_ERR(sn)) {
err = PTR_ERR(sn); err = PTR_ERR(sn);
......
...@@ -938,14 +938,15 @@ EXPORT_SYMBOL(rt6_lookup); ...@@ -938,14 +938,15 @@ EXPORT_SYMBOL(rt6_lookup);
*/ */
static int __ip6_ins_rt(struct rt6_info *rt, struct nl_info *info, 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; int err;
struct fib6_table *table; struct fib6_table *table;
table = rt->rt6i_table; table = rt->rt6i_table;
write_lock_bh(&table->tb6_lock); 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); write_unlock_bh(&table->tb6_lock);
return err; return err;
...@@ -956,7 +957,7 @@ int ip6_ins_rt(struct rt6_info *rt) ...@@ -956,7 +957,7 @@ int ip6_ins_rt(struct rt6_info *rt)
struct nl_info info = { .nl_net = dev_net(rt->dst.dev), }; struct nl_info info = { .nl_net = dev_net(rt->dst.dev), };
struct mx6_config mxc = { .mx = NULL, }; 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, 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, ...@@ -1844,7 +1845,8 @@ static struct rt6_info *ip6_nh_lookup_table(struct net *net,
return rt; 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 net *net = cfg->fc_nlinfo.nl_net;
struct rt6_info *rt = NULL; struct rt6_info *rt = NULL;
...@@ -1855,14 +1857,25 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg) ...@@ -1855,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; goto out;
}
if (cfg->fc_src_len > 128) {
NL_SET_ERR_MSG(extack, "Invalid source address length");
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;
...@@ -2013,9 +2026,10 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg) ...@@ -2013,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)) {
...@@ -2031,8 +2045,11 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg) ...@@ -2031,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);
...@@ -2072,9 +2089,15 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg) ...@@ -2072,9 +2089,15 @@ 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;
} else if (dev->flags & IFF_LOOPBACK) {
NL_SET_ERR_MSG(extack,
"Egress device can not be loopback device for this route");
goto out; goto out;
} }
}
err = -ENODEV; err = -ENODEV;
if (!dev) if (!dev)
...@@ -2082,6 +2105,7 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg) ...@@ -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_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;
} }
...@@ -2111,13 +2135,14 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg) ...@@ -2111,13 +2135,14 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
return ERR_PTR(err); 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 mx6_config mxc = { .mx = NULL, };
struct rt6_info *rt; struct rt6_info *rt;
int err; int err;
rt = ip6_route_info_create(cfg); rt = ip6_route_info_create(cfg, extack);
if (IS_ERR(rt)) { if (IS_ERR(rt)) {
err = PTR_ERR(rt); err = PTR_ERR(rt);
rt = NULL; rt = NULL;
...@@ -2128,7 +2153,7 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -2128,7 +2153,7 @@ int ip6_route_add(struct fib6_config *cfg)
if (err) if (err)
goto out; goto out;
err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, &mxc); err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, &mxc, extack);
kfree(mxc.mx); kfree(mxc.mx);
...@@ -2222,7 +2247,8 @@ static int __ip6_del_rt_siblings(struct rt6_info *rt, struct fib6_config *cfg) ...@@ -2222,7 +2247,8 @@ static int __ip6_del_rt_siblings(struct rt6_info *rt, struct fib6_config *cfg)
return err; 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_table *table;
struct fib6_node *fn; struct fib6_node *fn;
...@@ -2230,8 +2256,10 @@ static int ip6_route_del(struct fib6_config *cfg) ...@@ -2230,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);
...@@ -2483,7 +2511,7 @@ static struct rt6_info *rt6_add_route_info(struct net *net, ...@@ -2483,7 +2511,7 @@ static struct rt6_info *rt6_add_route_info(struct net *net,
if (!prefixlen) if (!prefixlen)
cfg.fc_flags |= RTF_DEFAULT; cfg.fc_flags |= RTF_DEFAULT;
ip6_route_add(&cfg); ip6_route_add(&cfg, NULL);
return rt6_get_route_info(net, prefix, prefixlen, gwaddr, dev); 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, ...@@ -2529,7 +2557,7 @@ struct rt6_info *rt6_add_dflt_router(const struct in6_addr *gwaddr,
cfg.fc_gateway = *gwaddr; cfg.fc_gateway = *gwaddr;
if (!ip6_route_add(&cfg)) { if (!ip6_route_add(&cfg, NULL)) {
struct fib6_table *table; struct fib6_table *table;
table = fib6_get_table(dev_net(dev), cfg.fc_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) ...@@ -2622,10 +2650,10 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg)
rtnl_lock(); rtnl_lock();
switch (cmd) { switch (cmd) {
case SIOCADDRT: case SIOCADDRT:
err = ip6_route_add(&cfg); err = ip6_route_add(&cfg, NULL);
break; break;
case SIOCDELRT: case SIOCDELRT:
err = ip6_route_del(&cfg); err = ip6_route_del(&cfg, NULL);
break; break;
default: default:
err = -EINVAL; err = -EINVAL;
...@@ -2903,7 +2931,8 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = { ...@@ -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, 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 rtmsg *rtm;
struct nlattr *tb[RTA_MAX+1]; struct nlattr *tb[RTA_MAX+1];
...@@ -3097,7 +3126,8 @@ static void ip6_route_mpath_notify(struct rt6_info *rt, ...@@ -3097,7 +3126,8 @@ static void ip6_route_mpath_notify(struct rt6_info *rt,
inet6_rt_notify(RTM_NEWROUTE, rt, info, nlflags); 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 rt6_info *rt_notif = NULL, *rt_last = NULL;
struct nl_info *info = &cfg->fc_nlinfo; struct nl_info *info = &cfg->fc_nlinfo;
...@@ -3145,7 +3175,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg) ...@@ -3145,7 +3175,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg)
r_cfg.fc_encap_type = nla_get_u16(nla); 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)) { if (IS_ERR(rt)) {
err = PTR_ERR(rt); err = PTR_ERR(rt);
rt = NULL; rt = NULL;
...@@ -3170,7 +3200,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg) ...@@ -3170,7 +3200,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg)
err_nh = NULL; err_nh = NULL;
list_for_each_entry(nh, &rt6_nh_list, next) { list_for_each_entry(nh, &rt6_nh_list, next) {
rt_last = nh->rt6_info; 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 */ /* save reference to first route for notification */
if (!rt_notif && !err) if (!rt_notif && !err)
rt_notif = nh->rt6_info; rt_notif = nh->rt6_info;
...@@ -3212,7 +3242,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg) ...@@ -3212,7 +3242,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg)
list_for_each_entry(nh, &rt6_nh_list, next) { list_for_each_entry(nh, &rt6_nh_list, next) {
if (err_nh == nh) if (err_nh == nh)
break; break;
ip6_route_del(&nh->r_cfg); ip6_route_del(&nh->r_cfg, extack);
} }
cleanup: cleanup:
...@@ -3227,7 +3257,8 @@ static int ip6_route_multipath_add(struct fib6_config *cfg) ...@@ -3227,7 +3257,8 @@ static int ip6_route_multipath_add(struct fib6_config *cfg)
return err; 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 fib6_config r_cfg;
struct rtnexthop *rtnh; struct rtnexthop *rtnh;
...@@ -3254,7 +3285,7 @@ static int ip6_route_multipath_del(struct fib6_config *cfg) ...@@ -3254,7 +3285,7 @@ static int ip6_route_multipath_del(struct fib6_config *cfg)
r_cfg.fc_flags |= RTF_GATEWAY; r_cfg.fc_flags |= RTF_GATEWAY;
} }
} }
err = ip6_route_del(&r_cfg); err = ip6_route_del(&r_cfg, extack);
if (err) if (err)
last_err = err; last_err = err;
...@@ -3270,15 +3301,15 @@ static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3270,15 +3301,15 @@ static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
struct fib6_config cfg; struct fib6_config cfg;
int err; int err;
err = rtm_to_fib6_config(skb, nlh, &cfg); err = rtm_to_fib6_config(skb, nlh, &cfg, extack);
if (err < 0) if (err < 0)
return err; return err;
if (cfg.fc_mp) if (cfg.fc_mp)
return ip6_route_multipath_del(&cfg); return ip6_route_multipath_del(&cfg, extack);
else { else {
cfg.fc_delete_all_nh = 1; 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, ...@@ -3288,14 +3319,14 @@ static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
struct fib6_config cfg; struct fib6_config cfg;
int err; int err;
err = rtm_to_fib6_config(skb, nlh, &cfg); err = rtm_to_fib6_config(skb, nlh, &cfg, extack);
if (err < 0) if (err < 0)
return err; return err;
if (cfg.fc_mp) if (cfg.fc_mp)
return ip6_route_multipath_add(&cfg); return ip6_route_multipath_add(&cfg, extack);
else else
return ip6_route_add(&cfg); return ip6_route_add(&cfg, extack);
} }
static size_t rt6_nlmsg_size(struct rt6_info *rt) static size_t rt6_nlmsg_size(struct rt6_info *rt)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment