]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv6/route.c
[IPv6] route: FIB6 configuration using struct fib6_config
[net-next-2.6.git] / net / ipv6 / route.c
index 9ce28277f47fd91bef55c5f58891792b0b48fb0a..7bcffa6ddba371c841912395b8f5d3ae2c910c6a 100644 (file)
@@ -35,7 +35,6 @@
 #include <linux/netdevice.h>
 #include <linux/in6.h>
 #include <linux/init.h>
-#include <linux/netlink.h>
 #include <linux/if_arp.h>
 
 #ifdef         CONFIG_PROC_FS
@@ -54,6 +53,7 @@
 #include <net/dst.h>
 #include <net/xfrm.h>
 #include <net/netevent.h>
+#include <net/netlink.h>
 
 #include <asm/uaccess.h>
 
@@ -457,7 +457,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
        rt = rt6_get_route_info(prefix, rinfo->prefix_len, gwaddr, dev->ifindex);
 
        if (rt && !lifetime) {
-               ip6_del_rt(rt, NULL, NULL, NULL);
+               ip6_del_rt(rt);
                rt = NULL;
        }
 
@@ -546,20 +546,24 @@ struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr,
    be destroyed.
  */
 
-int ip6_ins_rt(struct rt6_info *rt, struct nlmsghdr *nlh,
-               void *_rtattr, struct netlink_skb_parms *req)
+static int __ip6_ins_rt(struct rt6_info *rt, struct nl_info *info)
 {
        int err;
        struct fib6_table *table;
 
        table = rt->rt6i_table;
        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);
 
        return err;
 }
 
+int ip6_ins_rt(struct rt6_info *rt)
+{
+       return __ip6_ins_rt(rt, NULL);
+}
+
 static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort, struct in6_addr *daddr,
                                      struct in6_addr *saddr)
 {
@@ -657,7 +661,7 @@ restart:
 
        dst_hold(&rt->u.dst);
        if (nrt) {
-               err = ip6_ins_rt(nrt, NULL, NULL, NULL);
+               err = ip6_ins_rt(nrt);
                if (!err)
                        goto out2;
        }
@@ -752,7 +756,7 @@ restart:
 
        dst_hold(&rt->u.dst);
        if (nrt) {
-               err = ip6_ins_rt(nrt, NULL, NULL, NULL);
+               err = ip6_ins_rt(nrt);
                if (!err)
                        goto out2;
        }
@@ -813,7 +817,7 @@ static struct dst_entry *ip6_negative_advice(struct dst_entry *dst)
 
        if (rt) {
                if (rt->rt6i_flags & RTF_CACHE)
-                       ip6_del_rt(rt, NULL, NULL, NULL);
+                       ip6_del_rt(rt);
                else
                        dst_release(dst);
        }
@@ -1009,30 +1013,24 @@ int ipv6_get_hoplimit(struct net_device *dev)
  *
  */
 
-int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh, 
-                 void *_rtattr, struct netlink_skb_parms *req,
-                 u32 table_id)
+int ip6_route_add(struct fib6_config *cfg)
 {
        int err;
-       struct rtmsg *r;
-       struct rtattr **rta;
        struct rt6_info *rt = NULL;
        struct net_device *dev = NULL;
        struct inet6_dev *idev = NULL;
        struct fib6_table *table;
        int addr_type;
 
-       rta = (struct rtattr **) _rtattr;
-
-       if (rtmsg->rtmsg_dst_len > 128 || rtmsg->rtmsg_src_len > 128)
+       if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128)
                return -EINVAL;
 #ifndef CONFIG_IPV6_SUBTREES
-       if (rtmsg->rtmsg_src_len)
+       if (cfg->fc_src_len)
                return -EINVAL;
 #endif
-       if (rtmsg->rtmsg_ifindex) {
+       if (cfg->fc_ifindex) {
                err = -ENODEV;
-               dev = dev_get_by_index(rtmsg->rtmsg_ifindex);
+               dev = dev_get_by_index(cfg->fc_ifindex);
                if (!dev)
                        goto out;
                idev = in6_dev_get(dev);
@@ -1040,10 +1038,10 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
                        goto out;
        }
 
-       if (rtmsg->rtmsg_metric == 0)
-               rtmsg->rtmsg_metric = IP6_RT_PRIO_USER;
+       if (cfg->fc_metric == 0)
+               cfg->fc_metric = IP6_RT_PRIO_USER;
 
-       table = fib6_new_table(table_id);
+       table = fib6_new_table(cfg->fc_table);
        if (table == NULL) {
                err = -ENOBUFS;
                goto out;
@@ -1057,14 +1055,13 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
        }
 
        rt->u.dst.obsolete = -1;
-       rt->rt6i_expires = jiffies + clock_t_to_jiffies(rtmsg->rtmsg_info);
-       if (nlh && (r = NLMSG_DATA(nlh))) {
-               rt->rt6i_protocol = r->rtm_protocol;
-       } else {
-               rt->rt6i_protocol = RTPROT_BOOT;
-       }
+       rt->rt6i_expires = jiffies + clock_t_to_jiffies(cfg->fc_expires);
+
+       if (cfg->fc_protocol == RTPROT_UNSPEC)
+               cfg->fc_protocol = RTPROT_BOOT;
+       rt->rt6i_protocol = cfg->fc_protocol;
 
-       addr_type = ipv6_addr_type(&rtmsg->rtmsg_dst);
+       addr_type = ipv6_addr_type(&cfg->fc_dst);
 
        if (addr_type & IPV6_ADDR_MULTICAST)
                rt->u.dst.input = ip6_mc_input;
@@ -1073,24 +1070,22 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
 
        rt->u.dst.output = ip6_output;
 
-       ipv6_addr_prefix(&rt->rt6i_dst.addr, 
-                        &rtmsg->rtmsg_dst, rtmsg->rtmsg_dst_len);
-       rt->rt6i_dst.plen = rtmsg->rtmsg_dst_len;
+       ipv6_addr_prefix(&rt->rt6i_dst.addr, &cfg->fc_dst, cfg->fc_dst_len);
+       rt->rt6i_dst.plen = cfg->fc_dst_len;
        if (rt->rt6i_dst.plen == 128)
               rt->u.dst.flags = DST_HOST;
 
 #ifdef CONFIG_IPV6_SUBTREES
-       ipv6_addr_prefix(&rt->rt6i_src.addr, 
-                        &rtmsg->rtmsg_src, rtmsg->rtmsg_src_len);
-       rt->rt6i_src.plen = rtmsg->rtmsg_src_len;
+       ipv6_addr_prefix(&rt->rt6i_src.addr, &cfg->fc_src, cfg->fc_src_len);
+       rt->rt6i_src.plen = cfg->fc_src_len;
 #endif
 
-       rt->rt6i_metric = rtmsg->rtmsg_metric;
+       rt->rt6i_metric = cfg->fc_metric;
 
        /* We cannot add true routes via loopback here,
           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))) {
                /* hold loopback dev/idev if we haven't done so. */
                if (dev != &loopback_dev) {
@@ -1113,12 +1108,12 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
                goto install_route;
        }
 
-       if (rtmsg->rtmsg_flags & RTF_GATEWAY) {
+       if (cfg->fc_flags & RTF_GATEWAY) {
                struct in6_addr *gw_addr;
                int gwa_type;
 
-               gw_addr = &rtmsg->rtmsg_gateway;
-               ipv6_addr_copy(&rt->rt6i_gateway, &rtmsg->rtmsg_gateway);
+               gw_addr = &cfg->fc_gateway;
+               ipv6_addr_copy(&rt->rt6i_gateway, gw_addr);
                gwa_type = ipv6_addr_type(gw_addr);
 
                if (gwa_type != (IPV6_ADDR_LINKLOCAL|IPV6_ADDR_UNICAST)) {
@@ -1135,7 +1130,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
                        if (!(gwa_type&IPV6_ADDR_UNICAST))
                                goto out;
 
-                       grt = rt6_lookup(gw_addr, NULL, rtmsg->rtmsg_ifindex, 1);
+                       grt = rt6_lookup(gw_addr, NULL, cfg->fc_ifindex, 1);
 
                        err = -EHOSTUNREACH;
                        if (grt == NULL)
@@ -1167,7 +1162,7 @@ int ip6_route_add(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
        if (dev == NULL)
                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);
                if (IS_ERR(rt->rt6i_nexthop)) {
                        err = PTR_ERR(rt->rt6i_nexthop);
@@ -1176,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:
-       if (rta && rta[RTA_METRICS-1]) {
-               int attrlen = RTA_PAYLOAD(rta[RTA_METRICS-1]);
-               struct rtattr *attr = RTA_DATA(rta[RTA_METRICS-1]);
-
-               while (RTA_OK(attr, attrlen)) {
-                       unsigned flavor = attr->rta_type;
-                       if (flavor) {
-                               if (flavor > RTAX_MAX) {
+       if (cfg->fc_mx) {
+               struct nlattr *nla;
+               int remaining;
+
+               nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) {
+                       int type = nla->nla_type;
+
+                       if (type) {
+                               if (type > RTAX_MAX) {
                                        err = -EINVAL;
                                        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);
                }
        }
 
@@ -1206,7 +1201,7 @@ install_route:
        rt->u.dst.dev = dev;
        rt->rt6i_idev = idev;
        rt->rt6i_table = table;
-       return ip6_ins_rt(rt, nlh, _rtattr, req);
+       return __ip6_ins_rt(rt, &cfg->fc_nlinfo);
 
 out:
        if (dev)
@@ -1218,7 +1213,7 @@ out:
        return err;
 }
 
-int ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh, void *_rtattr, struct netlink_skb_parms *req)
+static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info)
 {
        int err;
        struct fib6_table *table;
@@ -1229,7 +1224,7 @@ int ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh, void *_rtattr, struct
        table = rt->rt6i_table;
        write_lock_bh(&table->tb6_lock);
 
-       err = fib6_del(rt, nlh, _rtattr, req);
+       err = fib6_del(rt, info);
        dst_release(&rt->u.dst);
 
        write_unlock_bh(&table->tb6_lock);
@@ -1237,41 +1232,43 @@ int ip6_del_rt(struct rt6_info *rt, struct nlmsghdr *nlh, void *_rtattr, struct
        return err;
 }
 
-static int ip6_route_del(struct in6_rtmsg *rtmsg, struct nlmsghdr *nlh,
-                        void *_rtattr, struct netlink_skb_parms *req,
-                        u32 table_id)
+int ip6_del_rt(struct rt6_info *rt)
+{
+       return __ip6_del_rt(rt, NULL);
+}
+
+static int ip6_route_del(struct fib6_config *cfg)
 {
        struct fib6_table *table;
        struct fib6_node *fn;
        struct rt6_info *rt;
        int err = -ESRCH;
 
-       table = fib6_get_table(table_id);
+       table = fib6_get_table(cfg->fc_table);
        if (table == NULL)
                return err;
 
        read_lock_bh(&table->tb6_lock);
 
        fn = fib6_locate(&table->tb6_root,
-                        &rtmsg->rtmsg_dst, rtmsg->rtmsg_dst_len,
-                        &rtmsg->rtmsg_src, rtmsg->rtmsg_src_len);
+                        &cfg->fc_dst, cfg->fc_dst_len,
+                        &cfg->fc_src, cfg->fc_src_len);
        
        if (fn) {
                for (rt = fn->leaf; rt; rt = rt->u.next) {
-                       if (rtmsg->rtmsg_ifindex &&
+                       if (cfg->fc_ifindex &&
                            (rt->rt6i_dev == NULL ||
-                            rt->rt6i_dev->ifindex != rtmsg->rtmsg_ifindex))
+                            rt->rt6i_dev->ifindex != cfg->fc_ifindex))
                                continue;
-                       if (rtmsg->rtmsg_flags&RTF_GATEWAY &&
-                           !ipv6_addr_equal(&rtmsg->rtmsg_gateway, &rt->rt6i_gateway))
+                       if (cfg->fc_flags & RTF_GATEWAY &&
+                           !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway))
                                continue;
-                       if (rtmsg->rtmsg_metric &&
-                           rtmsg->rtmsg_metric != rt->rt6i_metric)
+                       if (cfg->fc_metric && cfg->fc_metric != rt->rt6i_metric)
                                continue;
                        dst_hold(&rt->u.dst);
                        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);
@@ -1387,7 +1384,7 @@ restart:
        nrt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(neigh->dev);
        nrt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&nrt->u.dst));
 
-       if (ip6_ins_rt(nrt, NULL, NULL, NULL))
+       if (ip6_ins_rt(nrt))
                goto out;
 
        netevent.old = &rt->u.dst;
@@ -1395,7 +1392,7 @@ restart:
        call_netevent_notifiers(NETEVENT_REDIRECT, &netevent);
 
        if (rt->rt6i_flags&RTF_CACHE) {
-               ip6_del_rt(rt, NULL, NULL, NULL);
+               ip6_del_rt(rt);
                return;
        }
 
@@ -1477,7 +1474,7 @@ void rt6_pmtu_discovery(struct in6_addr *daddr, struct in6_addr *saddr,
                dst_set_expires(&nrt->u.dst, ip6_rt_mtu_expires);
                nrt->rt6i_flags |= RTF_DYNAMIC|RTF_EXPIRES;
 
-               ip6_ins_rt(nrt, NULL, NULL, NULL);
+               ip6_ins_rt(nrt);
        }
 out:
        dst_release(&rt->u.dst);
@@ -1554,21 +1551,23 @@ static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixle
                                           struct in6_addr *gwaddr, int ifindex,
                                           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. */
        if (!prefixlen)
-               rtmsg.rtmsg_flags |= RTF_DEFAULT;
-       rtmsg.rtmsg_ifindex = ifindex;
+               cfg.fc_flags |= RTF_DEFAULT;
 
-       ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_INFO);
+       ip6_route_add(&cfg);
 
        return rt6_get_route_info(prefix, prefixlen, gwaddr, ifindex);
 }
@@ -1600,18 +1599,18 @@ struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr,
                                     struct net_device *dev,
                                     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));
-       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);
+       ipv6_addr_copy(&cfg.fc_gateway, gwaddr);
 
-       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);
 }
 
@@ -1631,15 +1630,34 @@ restart:
                if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) {
                        dst_hold(&rt->u.dst);
                        read_unlock_bh(&table->tb6_lock);
-                       ip6_del_rt(rt, NULL, NULL, NULL);
+                       ip6_del_rt(rt);
                        goto restart;
                }
        }
        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)
 {
+       struct fib6_config cfg;
        struct in6_rtmsg rtmsg;
        int err;
 
@@ -1652,16 +1670,16 @@ int ipv6_route_ioctl(unsigned int cmd, void __user *arg)
                                     sizeof(struct in6_rtmsg));
                if (err)
                        return -EFAULT;
-                       
+
+               rtmsg_to_fib6_config(&rtmsg, &cfg);
+
                rtnl_lock();
                switch (cmd) {
                case SIOCADDRT:
-                       err = ip6_route_add(&rtmsg, NULL, NULL, NULL,
-                                           RT6_TABLE_MAIN);
+                       err = ip6_route_add(&cfg);
                        break;
                case SIOCDELRT:
-                       err = ip6_route_del(&rtmsg, NULL, NULL, NULL,
-                                           RT6_TABLE_MAIN);
+                       err = ip6_route_del(&cfg);
                        break;
                default:
                        err = -EINVAL;
@@ -1812,66 +1830,104 @@ void rt6_mtu_change(struct net_device *dev, unsigned mtu)
        fib6_clean_all(rt6_mtu_change_route, 0, &arg);
 }
 
-static int inet6_rtm_to_rtmsg(struct rtmsg *r, struct rtattr **rta,
-                             struct in6_rtmsg *rtmsg)
+static struct nla_policy rtm_ipv6_policy[RTA_MAX+1] __read_mostly = {
+       [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;
-       rtmsg->rtmsg_src_len = r->rtm_src_len;
-       rtmsg->rtmsg_flags = RTF_UP;
-       if (r->rtm_type == RTN_UNREACHABLE)
-               rtmsg->rtmsg_flags |= RTF_REJECT;
+       err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
+       if (err < 0)
+               goto errout;
 
-       if (rta[RTA_GATEWAY-1]) {
-               if (rta[RTA_GATEWAY-1]->rta_len != RTA_LENGTH(16))
-                       return -EINVAL;
-               memcpy(&rtmsg->rtmsg_gateway, RTA_DATA(rta[RTA_GATEWAY-1]), 16);
-               rtmsg->rtmsg_flags |= RTF_GATEWAY;
-       }
-       if (rta[RTA_DST-1]) {
-               if (RTA_PAYLOAD(rta[RTA_DST-1]) < ((r->rtm_dst_len+7)>>3))
-                       return -EINVAL;
-               memcpy(&rtmsg->rtmsg_dst, RTA_DATA(rta[RTA_DST-1]), ((r->rtm_dst_len+7)>>3));
+       err = -EINVAL;
+       rtm = nlmsg_data(nlh);
+       memset(cfg, 0, sizeof(*cfg));
+
+       cfg->fc_table = rtm->rtm_table;
+       cfg->fc_dst_len = rtm->rtm_dst_len;
+       cfg->fc_src_len = rtm->rtm_src_len;
+       cfg->fc_flags = RTF_UP;
+       cfg->fc_protocol = rtm->rtm_protocol;
+
+       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))
-                       return -EINVAL;
-               memcpy(&rtmsg->rtmsg_src, RTA_DATA(rta[RTA_SRC-1]), ((r->rtm_src_len+7)>>3));
+
+       if (tb[RTA_DST]) {
+               int plen = (rtm->rtm_dst_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)))
-                       return -EINVAL;
-               memcpy(&rtmsg->rtmsg_ifindex, RTA_DATA(rta[RTA_OIF-1]), sizeof(int));
+
+       if (tb[RTA_SRC]) {
+               int plen = (rtm->rtm_src_len + 7) >> 3;
+
+               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))
-                       return -EINVAL;
-               memcpy(&rtmsg->rtmsg_metric, RTA_DATA(rta[RTA_PRIORITY-1]), 4);
+
+       if (tb[RTA_OIF])
+               cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]);
+
+       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)
 {
-       struct rtmsg *r = NLMSG_DATA(nlh);
-       struct in6_rtmsg rtmsg;
+       struct fib6_config cfg;
+       int err;
 
-       if (inet6_rtm_to_rtmsg(r, arg, &rtmsg))
-               return -EINVAL;
-       return ip6_route_del(&rtmsg, nlh, arg, &NETLINK_CB(skb),
-                            rtm_get_table(arg, r->rtm_table));
+       err = rtm_to_fib6_config(skb, nlh, &cfg);
+       if (err < 0)
+               return err;
+
+       return ip6_route_del(&cfg);
 }
 
 int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 {
-       struct rtmsg *r = NLMSG_DATA(nlh);
-       struct in6_rtmsg rtmsg;
+       struct fib6_config cfg;
+       int err;
 
-       if (inet6_rtm_to_rtmsg(r, arg, &rtmsg))
-               return -EINVAL;
-       return ip6_route_add(&rtmsg, nlh, arg, &NETLINK_CB(skb),
-                            rtm_get_table(arg, r->rtm_table));
+       err = rtm_to_fib6_config(skb, nlh, &cfg);
+       if (err < 0)
+               return err;
+
+       return ip6_route_add(&cfg);
 }
 
 static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt,
@@ -2044,9 +2100,7 @@ int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
                goto out_free;
        }
 
-       err = netlink_unicast(rtnl, skb, NETLINK_CB(in_skb).pid, MSG_DONTWAIT);
-       if (err > 0)
-               err = 0;
+       err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
 out:
        return err;
 out_free:
@@ -2054,31 +2108,35 @@ out_free:
        goto out;       
 }
 
-void inet6_rt_notify(int event, struct rt6_info *rt, struct nlmsghdr *nlh, 
-                       struct netlink_skb_parms *req)
+void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info)
 {
        struct sk_buff *skb;
-       int size = NLMSG_SPACE(sizeof(struct rtmsg)+256);
-       u32 pid = current->pid;
-       u32 seq = 0;
-
-       if (req)
-               pid = req->pid;
-       if (nlh)
-               seq = nlh->nlmsg_seq;
-       
-       skb = alloc_skb(size, gfp_any());
-       if (!skb) {
-               netlink_set_err(rtnl, 0, RTNLGRP_IPV6_ROUTE, ENOBUFS);
-               return;
+       u32 pid = 0, seq = 0;
+       struct nlmsghdr *nlh = NULL;
+       int payload = sizeof(struct rtmsg) + 256;
+       int err = -ENOBUFS;
+
+       if (info) {
+               pid = info->pid;
+               nlh = info->nlh;
+               if (nlh)
+                       seq = nlh->nlmsg_seq;
        }
-       if (rt6_fill_node(skb, rt, NULL, NULL, 0, event, pid, seq, 0, 0) < 0) {
+
+       skb = nlmsg_new(nlmsg_total_size(payload), gfp_any());
+       if (skb == NULL)
+               goto errout;
+
+       err = rt6_fill_node(skb, rt, NULL, NULL, 0, event, pid, seq, 0, 0);
+       if (err < 0) {
                kfree_skb(skb);
-               netlink_set_err(rtnl, 0, RTNLGRP_IPV6_ROUTE, EINVAL);
-               return;
+               goto errout;
        }
-       NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_ROUTE;
-       netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_ROUTE, gfp_any());
+
+       err = rtnl_notify(skb, pid, RTNLGRP_IPV6_ROUTE, nlh, gfp_any());
+errout:
+       if (err < 0)
+               rtnl_set_sk_err(RTNLGRP_IPV6_ROUTE, err);
 }
 
 /*