Commit 86872cb5 authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[IPv6] route: FIB6 configuration using struct fib6_config

Replaces the struct in6_rtmsg based interface orignating from
the ioctl interface with a struct fib6_config based on. Allows
changing the interface without breaking the ioctl interface
and avoids passing on tons of parameters.

The recently introduced struct nl_info is used to pass on
netlink authorship information for notifications.
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 40e22e8f
...@@ -16,14 +16,35 @@ ...@@ -16,14 +16,35 @@
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/ipv6_route.h> #include <linux/ipv6_route.h>
#include <net/dst.h>
#include <net/flow.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <net/dst.h>
#include <net/flow.h>
#include <net/netlink.h>
struct rt6_info; struct rt6_info;
struct fib6_config
{
u32 fc_table;
u32 fc_metric;
int fc_dst_len;
int fc_src_len;
int fc_ifindex;
u32 fc_flags;
u32 fc_protocol;
struct in6_addr fc_dst;
struct in6_addr fc_src;
struct in6_addr fc_gateway;
unsigned long fc_expires;
struct nlattr *fc_mx;
int fc_mx_len;
struct nl_info fc_nlinfo;
};
struct fib6_node struct fib6_node
{ {
struct fib6_node *parent; struct fib6_node *parent;
...@@ -175,18 +196,13 @@ extern void fib6_clean_all(int (*func)(struct rt6_info *, void *arg), ...@@ -175,18 +196,13 @@ extern void fib6_clean_all(int (*func)(struct rt6_info *, void *arg),
extern int fib6_add(struct fib6_node *root, extern int fib6_add(struct fib6_node *root,
struct rt6_info *rt, struct rt6_info *rt,
struct nlmsghdr *nlh, struct nl_info *info);
void *rtattr,
struct netlink_skb_parms *req);
extern int fib6_del(struct rt6_info *rt, extern int fib6_del(struct rt6_info *rt,
struct nlmsghdr *nlh, struct nl_info *info);
void *rtattr,
struct netlink_skb_parms *req);
extern void inet6_rt_notify(int event, struct rt6_info *rt, extern void inet6_rt_notify(int event, struct rt6_info *rt,
struct nlmsghdr *nlh, struct nl_info *info);
struct netlink_skb_parms *req);
extern void fib6_run_gc(unsigned long dummy); extern void fib6_run_gc(unsigned long dummy);
......
...@@ -60,11 +60,7 @@ extern void ip6_route_cleanup(void); ...@@ -60,11 +60,7 @@ extern void ip6_route_cleanup(void);
extern int ipv6_route_ioctl(unsigned int cmd, void __user *arg); extern int ipv6_route_ioctl(unsigned int cmd, void __user *arg);
extern int ip6_route_add(struct in6_rtmsg *rtmsg, extern int ip6_route_add(struct fib6_config *cfg);
struct nlmsghdr *,
void *rtattr,
struct netlink_skb_parms *req,
u32 table_id);
extern int ip6_ins_rt(struct rt6_info *); extern int ip6_ins_rt(struct rt6_info *);
extern int ip6_del_rt(struct rt6_info *); extern int ip6_del_rt(struct rt6_info *);
......
...@@ -1509,59 +1509,56 @@ static void ...@@ -1509,59 +1509,56 @@ static void
addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev, addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
unsigned long expires, u32 flags) unsigned long expires, u32 flags)
{ {
struct in6_rtmsg rtmsg; struct fib6_config cfg = {
.fc_table = RT6_TABLE_PREFIX,
.fc_metric = IP6_RT_PRIO_ADDRCONF,
.fc_ifindex = dev->ifindex,
.fc_expires = expires,
.fc_dst_len = plen,
.fc_flags = RTF_UP | flags,
};
memset(&rtmsg, 0, sizeof(rtmsg)); ipv6_addr_copy(&cfg.fc_dst, pfx);
ipv6_addr_copy(&rtmsg.rtmsg_dst, pfx);
rtmsg.rtmsg_dst_len = plen;
rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
rtmsg.rtmsg_ifindex = dev->ifindex;
rtmsg.rtmsg_info = expires;
rtmsg.rtmsg_flags = RTF_UP|flags;
rtmsg.rtmsg_type = RTMSG_NEWROUTE;
/* Prevent useless cloning on PtP SIT. /* Prevent useless cloning on PtP SIT.
This thing is done here expecting that the whole This thing is done here expecting that the whole
class of non-broadcast devices need not cloning. class of non-broadcast devices need not cloning.
*/ */
if (dev->type == ARPHRD_SIT && (dev->flags&IFF_POINTOPOINT)) if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT))
rtmsg.rtmsg_flags |= RTF_NONEXTHOP; cfg.fc_flags |= RTF_NONEXTHOP;
ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_PREFIX); ip6_route_add(&cfg);
} }
/* Create "default" multicast route to the interface */ /* Create "default" multicast route to the interface */
static void addrconf_add_mroute(struct net_device *dev) static void addrconf_add_mroute(struct net_device *dev)
{ {
struct in6_rtmsg rtmsg; struct fib6_config cfg = {
.fc_table = RT6_TABLE_LOCAL,
memset(&rtmsg, 0, sizeof(rtmsg)); .fc_metric = IP6_RT_PRIO_ADDRCONF,
ipv6_addr_set(&rtmsg.rtmsg_dst, .fc_ifindex = dev->ifindex,
htonl(0xFF000000), 0, 0, 0); .fc_dst_len = 8,
rtmsg.rtmsg_dst_len = 8; .fc_flags = RTF_UP,
rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF; };
rtmsg.rtmsg_ifindex = dev->ifindex;
rtmsg.rtmsg_flags = RTF_UP; ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
rtmsg.rtmsg_type = RTMSG_NEWROUTE;
ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_LOCAL); ip6_route_add(&cfg);
} }
static void sit_route_add(struct net_device *dev) static void sit_route_add(struct net_device *dev)
{ {
struct in6_rtmsg rtmsg; struct fib6_config cfg = {
.fc_table = RT6_TABLE_MAIN,
memset(&rtmsg, 0, sizeof(rtmsg)); .fc_metric = IP6_RT_PRIO_ADDRCONF,
.fc_ifindex = dev->ifindex,
rtmsg.rtmsg_type = RTMSG_NEWROUTE; .fc_dst_len = 96,
rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF; .fc_flags = RTF_UP | RTF_NONEXTHOP,
};
/* prefix length - 96 bits "::d.d.d.d" */ /* prefix length - 96 bits "::d.d.d.d" */
rtmsg.rtmsg_dst_len = 96; ip6_route_add(&cfg);
rtmsg.rtmsg_flags = RTF_UP|RTF_NONEXTHOP;
rtmsg.rtmsg_ifindex = dev->ifindex;
ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_MAIN);
} }
static void addrconf_add_lroute(struct net_device *dev) static void addrconf_add_lroute(struct net_device *dev)
......
...@@ -610,7 +610,7 @@ static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr, ...@@ -610,7 +610,7 @@ static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
*/ */
static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt, static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
struct nlmsghdr *nlh, struct netlink_skb_parms *req) struct nl_info *info)
{ {
struct rt6_info *iter = NULL; struct rt6_info *iter = NULL;
struct rt6_info **ins; struct rt6_info **ins;
...@@ -665,7 +665,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt, ...@@ -665,7 +665,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
*ins = rt; *ins = rt;
rt->rt6i_node = fn; rt->rt6i_node = fn;
atomic_inc(&rt->rt6i_ref); atomic_inc(&rt->rt6i_ref);
inet6_rt_notify(RTM_NEWROUTE, rt, nlh, req); inet6_rt_notify(RTM_NEWROUTE, rt, info);
rt6_stats.fib_rt_entries++; rt6_stats.fib_rt_entries++;
if ((fn->fn_flags & RTN_RTINFO) == 0) { if ((fn->fn_flags & RTN_RTINFO) == 0) {
...@@ -695,8 +695,7 @@ void fib6_force_start_gc(void) ...@@ -695,8 +695,7 @@ void fib6_force_start_gc(void)
* with source addr info in sub-trees * with source addr info in sub-trees
*/ */
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 nlmsghdr *nlh, void *_rtattr, struct netlink_skb_parms *req)
{ {
struct fib6_node *fn; struct fib6_node *fn;
int err = -ENOMEM; int err = -ENOMEM;
...@@ -769,7 +768,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, ...@@ -769,7 +768,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
} }
#endif #endif
err = fib6_add_rt2node(fn, rt, nlh, req); err = fib6_add_rt2node(fn, rt, info);
if (err == 0) { if (err == 0) {
fib6_start_gc(rt); fib6_start_gc(rt);
...@@ -1076,7 +1075,7 @@ static struct fib6_node * fib6_repair_tree(struct fib6_node *fn) ...@@ -1076,7 +1075,7 @@ static struct fib6_node * fib6_repair_tree(struct fib6_node *fn)
} }
static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp, static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
struct nlmsghdr *nlh, void *_rtattr, struct netlink_skb_parms *req) struct nl_info *info)
{ {
struct fib6_walker_t *w; struct fib6_walker_t *w;
struct rt6_info *rt = *rtp; struct rt6_info *rt = *rtp;
...@@ -1132,11 +1131,11 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp, ...@@ -1132,11 +1131,11 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
if (atomic_read(&rt->rt6i_ref) != 1) BUG(); if (atomic_read(&rt->rt6i_ref) != 1) BUG();
} }
inet6_rt_notify(RTM_DELROUTE, rt, nlh, req); inet6_rt_notify(RTM_DELROUTE, rt, info);
rt6_release(rt); rt6_release(rt);
} }
int fib6_del(struct rt6_info *rt, struct nlmsghdr *nlh, void *_rtattr, struct netlink_skb_parms *req) int fib6_del(struct rt6_info *rt, struct nl_info *info)
{ {
struct fib6_node *fn = rt->rt6i_node; struct fib6_node *fn = rt->rt6i_node;
struct rt6_info **rtp; struct rt6_info **rtp;
...@@ -1161,7 +1160,7 @@ int fib6_del(struct rt6_info *rt, struct nlmsghdr *nlh, void *_rtattr, struct ne ...@@ -1161,7 +1160,7 @@ int fib6_del(struct rt6_info *rt, struct nlmsghdr *nlh, void *_rtattr, struct ne
for (rtp = &fn->leaf; *rtp; rtp = &(*rtp)->u.next) { for (rtp = &fn->leaf; *rtp; rtp = &(*rtp)->u.next) {
if (*rtp == rt) { if (*rtp == rt) {
fib6_del_route(fn, rtp, nlh, _rtattr, req); fib6_del_route(fn, rtp, info);
return 0; return 0;
} }
} }
...@@ -1290,7 +1289,7 @@ static int fib6_clean_node(struct fib6_walker_t *w) ...@@ -1290,7 +1289,7 @@ static int fib6_clean_node(struct fib6_walker_t *w)
res = c->func(rt, c->arg); res = c->func(rt, c->arg);
if (res < 0) { if (res < 0) {
w->leaf = rt; w->leaf = rt;
res = fib6_del(rt, NULL, NULL, NULL); res = fib6_del(rt, NULL);
if (res) { if (res) {
#if RT6_DEBUG >= 2 #if RT6_DEBUG >= 2
printk(KERN_DEBUG "fib6_clean_node: del failed: rt=%p@%p err=%d\n", rt, rt->rt6i_node, res); printk(KERN_DEBUG "fib6_clean_node: del failed: rt=%p@%p err=%d\n", rt, rt->rt6i_node, res);
......
...@@ -546,15 +546,14 @@ struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr, ...@@ -546,15 +546,14 @@ struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr,
be destroyed. be destroyed.
*/ */
static int __ip6_ins_rt(struct rt6_info *rt, struct nlmsghdr *nlh, static int __ip6_ins_rt(struct rt6_info *rt, struct nl_info *info)
void *_rtattr, struct netlink_skb_parms *req)
{ {
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, nlh, _rtattr, req); err = fib6_add(&table->tb6_root, rt, info);
write_unlock_bh(&table->tb6_lock); write_unlock_bh(&table->tb6_lock);
return err; return err;
...@@ -562,7 +561,7 @@ static int __ip6_ins_rt(struct rt6_info *rt, struct nlmsghdr *nlh, ...@@ -562,7 +561,7 @@ static int __ip6_ins_rt(struct rt6_info *rt, struct nlmsghdr *nlh,
int ip6_ins_rt(struct rt6_info *rt) int ip6_ins_rt(struct rt6_info *rt)
{ {
return __ip6_ins_rt(rt, NULL, NULL, NULL); return __ip6_ins_rt(rt, NULL);
} }
static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort, struct in6_addr *daddr, static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort, struct in6_addr *daddr,
...@@ -1014,30 +1013,24 @@ int ipv6_get_hoplimit(struct net_device *dev) ...@@ -1014,30 +1013,24 @@ int ipv6_get_hoplimit(struct net_device *dev)
* *
*/ */
int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, int ip6_route_add(struct fib6_config *cfg)
void *_rtattr, struct netlink_skb_parms *req,
u32 table_id)
{ {
int err; int err;
struct rtmsg *r;
struct rtattr **rta;
struct rt6_info *rt = NULL; struct rt6_info *rt = NULL;
struct net_device *dev = NULL; struct net_device *dev = NULL;
struct inet6_dev *idev = NULL; struct inet6_dev *idev = NULL;
struct fib6_table *table; struct fib6_table *table;
int addr_type; int addr_type;
rta = (struct rtattr **) _rtattr; if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128)
if (rtmsg->rtmsg_dst_len > 128 || rtmsg->rtmsg_src_len > 128)
return -EINVAL; return -EINVAL;
#ifndef CONFIG_IPV6_SUBTREES #ifndef CONFIG_IPV6_SUBTREES
if (rtmsg->rtmsg_src_len) if (cfg->fc_src_len)
return -EINVAL; return -EINVAL;
#endif #endif
if (rtmsg->rtmsg_ifindex) { if (cfg->fc_ifindex) {
err = -ENODEV; err = -ENODEV;
dev = dev_get_by_index(rtmsg->rtmsg_ifindex); dev = dev_get_by_index(cfg->fc_ifindex);
if (!dev) if (!dev)
goto out; goto out;
idev = in6_dev_get(dev); idev = in6_dev_get(dev);
...@@ -1045,10 +1038,10 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1045,10 +1038,10 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
goto out; goto out;
} }
if (rtmsg->rtmsg_metric == 0) if (cfg->fc_metric == 0)
rtmsg->rtmsg_metric = IP6_RT_PRIO_USER; cfg->fc_metric = IP6_RT_PRIO_USER;
table = fib6_new_table(table_id); table = fib6_new_table(cfg->fc_table);
if (table == NULL) { if (table == NULL) {
err = -ENOBUFS; err = -ENOBUFS;
goto out; goto out;
...@@ -1062,14 +1055,13 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1062,14 +1055,13 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
} }
rt->u.dst.obsolete = -1; rt->u.dst.obsolete = -1;
rt->rt6i_expires = jiffies + clock_t_to_jiffies(rtmsg->rtmsg_info); rt->rt6i_expires = jiffies + clock_t_to_jiffies(cfg->fc_expires);
if (nlh && (r = NLMSG_DATA(nlh))) {
rt->rt6i_protocol = r->rtm_protocol;
} else {
rt->rt6i_protocol = RTPROT_BOOT;
}
addr_type = ipv6_addr_type(&rtmsg->rtmsg_dst); if (cfg->fc_protocol == RTPROT_UNSPEC)
cfg->fc_protocol = RTPROT_BOOT;
rt->rt6i_protocol = cfg->fc_protocol;
addr_type = ipv6_addr_type(&cfg->fc_dst);
if (addr_type & IPV6_ADDR_MULTICAST) if (addr_type & IPV6_ADDR_MULTICAST)
rt->u.dst.input = ip6_mc_input; rt->u.dst.input = ip6_mc_input;
...@@ -1078,24 +1070,22 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1078,24 +1070,22 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
rt->u.dst.output = ip6_output; rt->u.dst.output = ip6_output;
ipv6_addr_prefix(&rt->rt6i_dst.addr, ipv6_addr_prefix(&rt->rt6i_dst.addr, &cfg->fc_dst, cfg->fc_dst_len);
&rtmsg->rtmsg_dst, rtmsg->rtmsg_dst_len); rt->rt6i_dst.plen = cfg->fc_dst_len;
rt->rt6i_dst.plen = rtmsg->rtmsg_dst_len;
if (rt->rt6i_dst.plen == 128) if (rt->rt6i_dst.plen == 128)
rt->u.dst.flags = DST_HOST; rt->u.dst.flags = DST_HOST;
#ifdef CONFIG_IPV6_SUBTREES #ifdef CONFIG_IPV6_SUBTREES
ipv6_addr_prefix(&rt->rt6i_src.addr, ipv6_addr_prefix(&rt->rt6i_src.addr, &cfg->fc_src, cfg->fc_src_len);
&rtmsg->rtmsg_src, rtmsg->rtmsg_src_len); rt->rt6i_src.plen = cfg->fc_src_len;
rt->rt6i_src.plen = rtmsg->rtmsg_src_len;
#endif #endif
rt->rt6i_metric = rtmsg->rtmsg_metric; rt->rt6i_metric = cfg->fc_metric;
/* We cannot add true routes via loopback here, /* We cannot add true routes via loopback here,
they would result in kernel looping; promote them to reject routes they would result in kernel looping; promote them to reject routes
*/ */
if ((rtmsg->rtmsg_flags&RTF_REJECT) || if ((cfg->fc_flags & RTF_REJECT) ||
(dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK))) { (dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK))) {
/* hold loopback dev/idev if we haven't done so. */ /* hold loopback dev/idev if we haven't done so. */
if (dev != &loopback_dev) { if (dev != &loopback_dev) {
...@@ -1118,12 +1108,12 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1118,12 +1108,12 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
goto install_route; goto install_route;
} }
if (rtmsg->rtmsg_flags & RTF_GATEWAY) { if (cfg->fc_flags & RTF_GATEWAY) {
struct in6_addr *gw_addr; struct in6_addr *gw_addr;
int gwa_type; int gwa_type;
gw_addr = &rtmsg->rtmsg_gateway; gw_addr = &cfg->fc_gateway;
ipv6_addr_copy(&rt->rt6i_gateway, &rtmsg->rtmsg_gateway); ipv6_addr_copy(&rt->rt6i_gateway, gw_addr);
gwa_type = ipv6_addr_type(gw_addr); gwa_type = ipv6_addr_type(gw_addr);
if (gwa_type != (IPV6_ADDR_LINKLOCAL|IPV6_ADDR_UNICAST)) { if (gwa_type != (IPV6_ADDR_LINKLOCAL|IPV6_ADDR_UNICAST)) {
...@@ -1140,7 +1130,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1140,7 +1130,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
if (!(gwa_type&IPV6_ADDR_UNICAST)) if (!(gwa_type&IPV6_ADDR_UNICAST))
goto out; goto out;
grt = rt6_lookup(gw_addr, NULL, rtmsg->rtmsg_ifindex, 1); grt = rt6_lookup(gw_addr, NULL, cfg->fc_ifindex, 1);
err = -EHOSTUNREACH; err = -EHOSTUNREACH;
if (grt == NULL) if (grt == NULL)
...@@ -1172,7 +1162,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1172,7 +1162,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
if (dev == NULL) if (dev == NULL)
goto out; goto out;
if (rtmsg->rtmsg_flags & (RTF_GATEWAY|RTF_NONEXTHOP)) { if (cfg->fc_flags & (RTF_GATEWAY | RTF_NONEXTHOP)) {
rt->rt6i_nexthop = __neigh_lookup_errno(&nd_tbl, &rt->rt6i_gateway, dev); rt->rt6i_nexthop = __neigh_lookup_errno(&nd_tbl, &rt->rt6i_gateway, dev);
if (IS_ERR(rt->rt6i_nexthop)) { if (IS_ERR(rt->rt6i_nexthop)) {
err = PTR_ERR(rt->rt6i_nexthop); err = PTR_ERR(rt->rt6i_nexthop);
...@@ -1181,24 +1171,24 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1181,24 +1171,24 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
} }
} }
rt->rt6i_flags = rtmsg->rtmsg_flags; rt->rt6i_flags = cfg->fc_flags;
install_route: install_route:
if (rta && rta[RTA_METRICS-1]) { if (cfg->fc_mx) {
int attrlen = RTA_PAYLOAD(rta[RTA_METRICS-1]); struct nlattr *nla;
struct rtattr *attr = RTA_DATA(rta[RTA_METRICS-1]); int remaining;
while (RTA_OK(attr, attrlen)) { nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) {
unsigned flavor = attr->rta_type; int type = nla->nla_type;
if (flavor) {
if (flavor > RTAX_MAX) { if (type) {
if (type > RTAX_MAX) {
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
rt->u.dst.metrics[flavor-1] =
*(u32 *)RTA_DATA(attr); rt->u.dst.metrics[type - 1] = nla_get_u32(nla);
} }
attr = RTA_NEXT(attr, attrlen);
} }
} }
...@@ -1211,7 +1201,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1211,7 +1201,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
rt->u.dst.dev = dev; rt->u.dst.dev = dev;
rt->rt6i_idev = idev; rt->rt6i_idev = idev;
rt->rt6i_table = table; rt->rt6i_table = table;
return __ip6_ins_rt(rt, nlh, _rtattr, req); return __ip6_ins_rt(rt, &cfg->fc_nlinfo);
out: out:
if (dev) if (dev)
...@@ -1223,8 +1213,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, ...@@ -1223,8 +1213,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
return err; return err;
} }
static int __ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh, static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info)
void *_rtattr, struct netlink_skb_parms *req)
{ {
int err; int err;
struct fib6_table *table; struct fib6_table *table;
...@@ -1235,7 +1224,7 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh, ...@@ -1235,7 +1224,7 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh,
table = rt->rt6i_table; table = rt->rt6i_table;
write_lock_bh(&table->tb6_lock); write_lock_bh(&table->tb6_lock);
err = fib6_del(rt, nlh, _rtattr, req); err = fib6_del(rt, info);
dst_release(&rt->u.dst); dst_release(&rt->u.dst);
write_unlock_bh(&table->tb6_lock); write_unlock_bh(&table->tb6_lock);
...@@ -1245,44 +1234,41 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh, ...@@ -1245,44 +1234,41 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh,
int ip6_del_rt(struct rt6_info *rt) int ip6_del_rt(struct rt6_info *rt)
{ {
return __ip6_del_rt(rt, NULL, NULL, NULL); return __ip6_del_rt(rt, NULL);
} }
static int ip6_route_del(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, static int ip6_route_del(struct fib6_config *cfg)
void *_rtattr, struct netlink_skb_parms *req,
u32 table_id)
{ {
struct fib6_table *table; struct fib6_table *table;
struct fib6_node *fn; struct fib6_node *fn;
struct rt6_info *rt; struct rt6_info *rt;
int err = -ESRCH; int err = -ESRCH;
table = fib6_get_table(table_id); table = fib6_get_table(cfg->fc_table);
if (table == NULL) if (table == NULL)
return err; return err;
read_lock_bh(&table->tb6_lock); read_lock_bh(&table->tb6_lock);
fn = fib6_locate(&table->tb6_root, fn = fib6_locate(&table->tb6_root,
&rtmsg->rtmsg_dst, rtmsg->rtmsg_dst_len, &cfg->fc_dst, cfg->fc_dst_len,
&rtmsg->rtmsg_src, rtmsg->rtmsg_src_len); &cfg->fc_src, cfg->fc_src_len);
if (fn) { if (fn) {
for (rt = fn->leaf; rt; rt = rt->u.next) { for (rt = fn->leaf; rt; rt = rt->u.next) {
if (rtmsg->rtmsg_ifindex && if (cfg->fc_ifindex &&
(rt->rt6i_dev == NULL || (rt->rt6i_dev == NULL ||
rt->rt6i_dev->ifindex != rtmsg->rtmsg_ifindex)) rt->rt6i_dev->ifindex != cfg->fc_ifindex))
continue; continue;
if (rtmsg->rtmsg_flags&RTF_GATEWAY && if (cfg->fc_flags & RTF_GATEWAY &&
!ipv6_addr_equal(&rtmsg->rtmsg_gateway, &rt->rt6i_gateway)) !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway))
continue; continue;
if (rtmsg->rtmsg_metric && if (cfg->fc_metric && cfg->fc_metric != rt->rt6i_metric)
rtmsg->rtmsg_metric != rt->rt6i_metric)
continue; continue;
dst_hold(&rt->u.dst); dst_hold(&rt->u.dst);
read_unlock_bh(&table->tb6_lock); read_unlock_bh(&table->tb6_lock);
return __ip6_del_rt(rt, nlh, _rtattr, req); return __ip6_del_rt(rt, &cfg->fc_nlinfo);
} }
} }
read_unlock_bh(&table->tb6_lock); read_unlock_bh(&table->tb6_lock);
...@@ -1565,21 +1551,23 @@ static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixle ...@@ -1565,21 +1551,23 @@ static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixle
struct in6_addr *gwaddr, int ifindex, struct in6_addr *gwaddr, int ifindex,
unsigned pref) unsigned pref)
{ {
struct in6_rtmsg rtmsg; struct fib6_config cfg = {
.fc_table = RT6_TABLE_INFO,
.fc_metric = 1024,
.fc_ifindex = ifindex,
.fc_dst_len = prefixlen,
.fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_ROUTEINFO |
RTF_UP | RTF_PREF(pref),
};
ipv6_addr_copy(&cfg.fc_dst, prefix);
ipv6_addr_copy(&cfg.fc_gateway, gwaddr);
memset(&rtmsg, 0, sizeof(rtmsg));
rtmsg.rtmsg_type = RTMSG_NEWROUTE;
ipv6_addr_copy(&rtmsg.rtmsg_dst, prefix);
rtmsg.rtmsg_dst_len = prefixlen;
ipv6_addr_copy(&rtmsg.rtmsg_gateway, gwaddr);
rtmsg.rtmsg_metric = 1024;
rtmsg.rtmsg_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_ROUTEINFO | RTF_UP | RTF_PREF(pref);
/* We should treat it as a default route if prefix length is 0. */ /* We should treat it as a default route if prefix length is 0. */
if (!prefixlen) if (!prefixlen)
rtmsg.rtmsg_flags |= RTF_DEFAULT; cfg.fc_flags |= RTF_DEFAULT;
rtmsg.rtmsg_ifindex = ifindex;
ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_INFO); ip6_route_add(&cfg);
return rt6_get_route_info(prefix, prefixlen, gwaddr, ifindex); return rt6_get_route_info(prefix, prefixlen, gwaddr, ifindex);
} }
...@@ -1611,18 +1599,18 @@ struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr, ...@@ -1611,18 +1599,18 @@ struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr,
struct net_device *dev, struct net_device *dev,
unsigned int pref) unsigned int pref)
{ {
struct in6_rtmsg rtmsg; struct fib6_config cfg = {
.fc_table = RT6_TABLE_DFLT,
.fc_metric = 1024,
.fc_ifindex = dev->ifindex,
.fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT |
RTF_UP | RTF_EXPIRES | RTF_PREF(pref),
};
memset(&rtmsg, 0, sizeof(struct in6_rtmsg)); ipv6_addr_copy(&cfg.fc_gateway, gwaddr);
rtmsg.rtmsg_type = RTMSG_NEWROUTE;
ipv6_addr_copy(&rtmsg.rtmsg_gateway, gwaddr);
rtmsg.rtmsg_metric = 1024;
rtmsg.rtmsg_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT | RTF_UP | RTF_EXPIRES |
RTF_PREF(pref);
rtmsg.rtmsg_ifindex = dev->ifindex; ip6_route_add(&cfg);
ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_DFLT);
return rt6_get_dflt_router(gwaddr, dev); return rt6_get_dflt_router(gwaddr, dev);
} }
...@@ -1649,8 +1637,27 @@ void rt6_purge_dflt_routers(void) ...@@ -1649,8 +1637,27 @@ void rt6_purge_dflt_routers(void)
read_unlock_bh(&table->tb6_lock); read_unlock_bh(&table->tb6_lock);
} }
static void rtmsg_to_fib6_config(struct in6_rtmsg *rtmsg,
struct fib6_config *cfg)
{
memset(cfg, 0, sizeof(*cfg));
cfg->fc_table = RT6_TABLE_MAIN;
cfg->fc_ifindex = rtmsg->rtmsg_ifindex;
cfg->fc_metric = rtmsg->rtmsg_metric;
cfg->fc_expires = rtmsg->rtmsg_info;
cfg->fc_dst_len = rtmsg->rtmsg_dst_len;
cfg->fc_src_len = rtmsg->rtmsg_src_len;
cfg->fc_flags = rtmsg->rtmsg_flags;
ipv6_addr_copy(&cfg->fc_dst, &rtmsg->rtmsg_dst);
ipv6_addr_copy(&cfg->fc_src, &rtmsg->rtmsg_src);
ipv6_addr_copy(&cfg->fc_gateway, &rtmsg->rtmsg_gateway);
}
int ipv6_route_ioctl(unsigned int cmd, void __user *arg) int ipv6_route_ioctl(unsigned int cmd, void __user *arg)
{ {
struct fib6_config cfg;
struct in6_rtmsg rtmsg; struct in6_rtmsg rtmsg;
int err; int err;
...@@ -1664,15 +1671,15 @@ int ipv6_route_ioctl(unsigned int cmd, void __user *arg) ...@@ -1664,15 +1671,15 @@ int ipv6_route_ioctl(unsigned int cmd, void __user *arg)
if (err) if (err)
return -EFAULT; return -EFAULT;
rtmsg_to_fib6_config(&rtmsg, &cfg);
rtnl_lock(); rtnl_lock();
switch (cmd) { switch (cmd) {
case SIOCADDRT: case SIOCADDRT:
err = ip6_route_add(&rtmsg, NULL, NULL, NULL, err = ip6_route_add(&cfg);
RT6_TABLE_MAIN);
break; break;
case SIOCDELRT: case SIOCDELRT:
err = ip6_route_del(&rtmsg, NULL, NULL, NULL, err = ip6_route_del(&cfg);
RT6_TABLE_MAIN);
break; break;
default: default:
err = -EINVAL; err = -EINVAL;
...@@ -1823,66 +1830,104 @@ void rt6_mtu_change(struct net_device *dev, unsigned mtu) ...@@ -1823,66 +1830,104 @@ void rt6_mtu_change(struct net_device *dev, unsigned mtu)
fib6_clean_all(rt6_mtu_change_route, 0, &arg); fib6_clean_all(rt6_mtu_change_route, 0, &arg);
} }
static int inet6_rtm_to_rtmsg(struct rtmsg *r, struct rtattr **rta, static struct nla_policy rtm_ipv6_policy[RTA_MAX+1] __read_mostly = {
struct in6_rtmsg *rtmsg) [RTA_GATEWAY] = { .minlen = sizeof(struct in6_addr) },
[RTA_OIF] = { .type = NLA_U32 },
[RTA_PRIORITY] = { .type = NLA_U32 },
[RTA_METRICS] = { .type = NLA_NESTED },
};
static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
struct fib6_config *cfg)
{ {
memset(rtmsg, 0, sizeof(*rtmsg)); struct rtmsg *rtm;
struct nlattr *tb[RTA_MAX+1];
int err;
rtmsg->rtmsg_dst_len = r->rtm_dst_len; err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
rtmsg->rtmsg_src_len = r->rtm_src_len; if (err < 0)
rtmsg->rtmsg_flags = RTF_UP; goto errout;
if (r->rtm_type == RTN_UNREACHABLE)
rtmsg->rtmsg_flags |= RTF_REJECT;
if (rta[RTA_GATEWAY-1]) { err = -EINVAL;
if (rta[RTA_GATEWAY-1]->rta_len != RTA_LENGTH(16)) rtm = nlmsg_data(nlh);
return -EINVAL; memset(cfg, 0, sizeof(*cfg));
memcpy(&rtmsg->rtmsg_gateway, RTA_DATA(rta[RTA_GATEWAY-1]), 16);
rtmsg->rtmsg_flags |= RTF_GATEWAY; cfg->fc_table = rtm->rtm_table;
} cfg->fc_dst_len = rtm->rtm_dst_len;
if (rta[RTA_DST-1]) { cfg->fc_src_len = rtm->rtm_src_len;
if (RTA_PAYLOAD(rta[RTA_DST-1]) < ((r->rtm_dst_len+7)>>3)) cfg->fc_flags = RTF_UP;
return -EINVAL; cfg->fc_protocol = rtm->rtm_protocol;
memcpy(&rtmsg->rtmsg_dst, RTA_DATA(rta[RTA_DST-1]), ((r->rtm_dst_len+7)>>3));
if (rtm->rtm_type == RTN_UNREACHABLE)
cfg->fc_flags |= RTF_REJECT;
cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid;
cfg->fc_nlinfo.nlh = nlh;
if (tb[RTA_GATEWAY]) {
nla_memcpy(&cfg->fc_gateway, tb[RTA_GATEWAY], 16);
cfg->fc_flags |= RTF_GATEWAY;
} }
if (rta[RTA_SRC-1]) {
if (RTA_PAYLOAD(rta[RTA_SRC-1]) < ((r->rtm_src_len+7)>>3)) if (tb[RTA_DST]) {
return -EINVAL; int plen = (rtm->rtm_dst_len + 7) >> 3;
memcpy(&rtmsg->rtmsg_src, RTA_DATA(rta[RTA_SRC-1]), ((r->rtm_src_len+7)>>3));
if (nla_len(tb[RTA_DST]) < plen)
goto errout;
nla_memcpy(&cfg->fc_dst, tb[RTA_DST], plen);
} }
if (rta[RTA_OIF-1]) {
if (rta[RTA_OIF-1]->rta_len != RTA_LENGTH(sizeof(int))) if (tb[RTA_SRC]) {
return -EINVAL; int plen = (rtm->rtm_src_len + 7) >> 3;
memcpy(&rtmsg->rtmsg_ifindex, RTA_DATA(rta[RTA_OIF-1]), sizeof(int));
if (nla_len(tb[RTA_SRC]) < plen)
goto errout;
nla_memcpy(&cfg->fc_src, tb[RTA_SRC], plen);
} }
if (rta[RTA_PRIORITY-1]) {
if (rta[RTA_PRIORITY-1]->rta_len != RTA_LENGTH(4)) if (tb[RTA_OIF])
return -EINVAL; cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]);
memcpy(&rtmsg->rtmsg_metric, RTA_DATA(rta[RTA_PRIORITY-1]), 4);
if (tb[RTA_PRIORITY])
cfg->fc_metric = nla_get_u32(tb[RTA_PRIORITY]);
if (tb[RTA_METRICS]) {
cfg->fc_mx = nla_data(tb[RTA_METRICS]);
cfg->fc_mx_len = nla_len(tb[RTA_METRICS]);
} }
return 0;
if (tb[RTA_TABLE])
cfg->fc_table = nla_get_u32(tb[RTA_TABLE]);
err = 0;
errout:
return err;
} }
int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
{ {
struct rtmsg *r = NLMSG_DATA(nlh); struct fib6_config cfg;
struct in6_rtmsg rtmsg; int err;
if (inet6_rtm_to_rtmsg(r, arg, &rtmsg)) err = rtm_to_fib6_config(skb, nlh, &cfg);
return -EINVAL; if (err < 0)
return ip6_route_del(&rtmsg, nlh, arg, &NETLINK_CB(skb), return err;
rtm_get_table(arg, r->rtm_table));
return ip6_route_del(&cfg);
} }
int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
{ {
struct rtmsg *r = NLMSG_DATA(nlh); struct fib6_config cfg;
struct in6_rtmsg rtmsg; int err;
if (inet6_rtm_to_rtmsg(r, arg, &rtmsg)) err = rtm_to_fib6_config(skb, nlh, &cfg);
return -EINVAL; if (err < 0)
return ip6_route_add(&rtmsg, nlh, arg, &NETLINK_CB(skb), return err;
rtm_get_table(arg, r->rtm_table));
return ip6_route_add(&cfg);
} }
static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt, static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt,
...@@ -2063,15 +2108,21 @@ int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg) ...@@ -2063,15 +2108,21 @@ int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
goto out; goto out;
} }
void inet6_rt_notify(int event, struct rt6_info *rt, struct nlmsghdr *nlh, void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info)
struct netlink_skb_parms *req)
{ {
struct sk_buff *skb; struct sk_buff *skb;
u32 pid = req ? req->pid : 0; u32 pid = 0, seq = 0;
u32 seq = nlh ? nlh->nlmsg_seq : 0; struct nlmsghdr *nlh = NULL;
int payload = sizeof(struct rtmsg) + 256; int payload = sizeof(struct rtmsg) + 256;
int err = -ENOBUFS; int err = -ENOBUFS;
if (info) {
pid = info->pid;
nlh = info->nlh;
if (nlh)
seq = nlh->nlmsg_seq;
}
skb = nlmsg_new(nlmsg_total_size(payload), gfp_any()); skb = nlmsg_new(nlmsg_total_size(payload), gfp_any());
if (skb == NULL) if (skb == NULL)
goto errout; goto errout;
......
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