]> Pileus Git - ~andy/linux/blobdiff - net/ipv6/route.c
[NETNS][IPV6] ip6_fib - make it per network namespace
[~andy/linux] / net / ipv6 / route.c
index 6e7b56ef44499c0bf5bf48af941f8b77181131df..09206f7ba525ee0c71769e73d6c22108f43eea08 100644 (file)
@@ -571,7 +571,7 @@ struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr,
                flags |= RT6_LOOKUP_F_HAS_SADDR;
        }
 
-       dst = fib6_rule_lookup(&fl, flags, ip6_pol_route_lookup);
+       dst = fib6_rule_lookup(&init_net, &fl, flags, ip6_pol_route_lookup);
        if (dst->error == 0)
                return (struct rt6_info *) dst;
 
@@ -758,7 +758,7 @@ void ip6_route_input(struct sk_buff *skb)
        if (rt6_need_strict(&iph->daddr))
                flags |= RT6_LOOKUP_F_IFACE;
 
-       skb->dst = fib6_rule_lookup(&fl, flags, ip6_pol_route_input);
+       skb->dst = fib6_rule_lookup(&init_net, &fl, flags, ip6_pol_route_input);
 }
 
 static struct rt6_info *ip6_pol_route_output(struct fib6_table *table,
@@ -777,7 +777,7 @@ struct dst_entry * ip6_route_output(struct sock *sk, struct flowi *fl)
        if (!ipv6_addr_any(&fl->fl6_src))
                flags |= RT6_LOOKUP_F_HAS_SADDR;
 
-       return fib6_rule_lookup(fl, flags, ip6_pol_route_output);
+       return fib6_rule_lookup(&init_net, fl, flags, ip6_pol_route_output);
 }
 
 EXPORT_SYMBOL(ip6_route_output);
@@ -904,13 +904,12 @@ static inline unsigned int ipv6_advmss(unsigned int mtu)
        return mtu;
 }
 
-static struct dst_entry *ndisc_dst_gc_list;
-static DEFINE_SPINLOCK(ndisc_lock);
+static struct dst_entry *icmp6_dst_gc_list;
+static DEFINE_SPINLOCK(icmp6_dst_lock);
 
-struct dst_entry *ndisc_dst_alloc(struct net_device *dev,
+struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
                                  struct neighbour *neigh,
-                                 struct in6_addr *addr,
-                                 int (*output)(struct sk_buff *))
+                                 struct in6_addr *addr)
 {
        struct rt6_info *rt;
        struct inet6_dev *idev = in6_dev_get(dev);
@@ -937,7 +936,7 @@ struct dst_entry *ndisc_dst_alloc(struct net_device *dev,
        rt->u.dst.metrics[RTAX_HOPLIMIT-1] = 255;
        rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(rt->rt6i_dev);
        rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&rt->u.dst));
-       rt->u.dst.output  = output;
+       rt->u.dst.output  = ip6_output;
 
 #if 0  /* there's no chance to use these for ndisc */
        rt->u.dst.flags   = ipv6_addr_type(addr) & IPV6_ADDR_UNICAST
@@ -947,10 +946,10 @@ struct dst_entry *ndisc_dst_alloc(struct net_device *dev,
        rt->rt6i_dst.plen = 128;
 #endif
 
-       spin_lock_bh(&ndisc_lock);
-       rt->u.dst.next = ndisc_dst_gc_list;
-       ndisc_dst_gc_list = &rt->u.dst;
-       spin_unlock_bh(&ndisc_lock);
+       spin_lock_bh(&icmp6_dst_lock);
+       rt->u.dst.next = icmp6_dst_gc_list;
+       icmp6_dst_gc_list = &rt->u.dst;
+       spin_unlock_bh(&icmp6_dst_lock);
 
        fib6_force_start_gc();
 
@@ -958,7 +957,7 @@ out:
        return &rt->u.dst;
 }
 
-int ndisc_dst_gc(int *more)
+int icmp6_dst_gc(int *more)
 {
        struct dst_entry *dst, *next, **pprev;
        int freed;
@@ -966,8 +965,8 @@ int ndisc_dst_gc(int *more)
        next = NULL;
        freed = 0;
 
-       spin_lock_bh(&ndisc_lock);
-       pprev = &ndisc_dst_gc_list;
+       spin_lock_bh(&icmp6_dst_lock);
+       pprev = &icmp6_dst_gc_list;
 
        while ((dst = *pprev) != NULL) {
                if (!atomic_read(&dst->__refcnt)) {
@@ -980,7 +979,7 @@ int ndisc_dst_gc(int *more)
                }
        }
 
-       spin_unlock_bh(&ndisc_lock);
+       spin_unlock_bh(&icmp6_dst_lock);
 
        return freed;
 }
@@ -1070,7 +1069,7 @@ int ip6_route_add(struct fib6_config *cfg)
        if (cfg->fc_metric == 0)
                cfg->fc_metric = IP6_RT_PRIO_USER;
 
-       table = fib6_new_table(cfg->fc_table);
+       table = fib6_new_table(&init_net, cfg->fc_table);
        if (table == NULL) {
                err = -ENOBUFS;
                goto out;
@@ -1276,7 +1275,7 @@ static int ip6_route_del(struct fib6_config *cfg)
        struct rt6_info *rt;
        int err = -ESRCH;
 
-       table = fib6_get_table(cfg->fc_table);
+       table = fib6_get_table(&init_net, cfg->fc_table);
        if (table == NULL)
                return err;
 
@@ -1391,7 +1390,9 @@ static struct rt6_info *ip6_route_redirect(struct in6_addr *dest,
        if (rt6_need_strict(dest))
                flags |= RT6_LOOKUP_F_IFACE;
 
-       return (struct rt6_info *)fib6_rule_lookup((struct flowi *)&rdfl, flags, __ip6_route_redirect);
+       return (struct rt6_info *)fib6_rule_lookup(&init_net,
+                                                  (struct flowi *)&rdfl,
+                                                  flags, __ip6_route_redirect);
 }
 
 void rt6_redirect(struct in6_addr *dest, struct in6_addr *src,
@@ -1590,7 +1591,7 @@ static struct rt6_info *rt6_get_route_info(struct in6_addr *prefix, int prefixle
        struct rt6_info *rt = NULL;
        struct fib6_table *table;
 
-       table = fib6_get_table(RT6_TABLE_INFO);
+       table = fib6_get_table(&init_net, RT6_TABLE_INFO);
        if (table == NULL)
                return NULL;
 
@@ -1645,7 +1646,7 @@ struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *d
        struct rt6_info *rt;
        struct fib6_table *table;
 
-       table = fib6_get_table(RT6_TABLE_DFLT);
+       table = fib6_get_table(&init_net, RT6_TABLE_DFLT);
        if (table == NULL)
                return NULL;
 
@@ -1689,7 +1690,7 @@ void rt6_purge_dflt_routers(void)
        struct fib6_table *table;
 
        /* NOTE: Keep consistent with rt6_get_dflt_router */
-       table = fib6_get_table(RT6_TABLE_DFLT);
+       table = fib6_get_table(&init_net, RT6_TABLE_DFLT);
        if (table == NULL)
                return;
 
@@ -1719,6 +1720,8 @@ static void rtmsg_to_fib6_config(struct in6_rtmsg *rtmsg,
        cfg->fc_src_len = rtmsg->rtmsg_src_len;
        cfg->fc_flags = rtmsg->rtmsg_flags;
 
+       cfg->fc_nlinfo.nl_net = &init_net;
+
        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);
@@ -1850,7 +1853,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
 
        ipv6_addr_copy(&rt->rt6i_dst.addr, addr);
        rt->rt6i_dst.plen = 128;
-       rt->rt6i_table = fib6_get_table(RT6_TABLE_LOCAL);
+       rt->rt6i_table = fib6_get_table(&init_net, RT6_TABLE_LOCAL);
 
        atomic_set(&rt->u.dst.__refcnt, 1);
 
@@ -2120,7 +2123,8 @@ static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt,
                NLA_PUT_U32(skb, RTA_IIF, iif);
        else if (dst) {
                struct in6_addr saddr_buf;
-               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0)
+               if (ipv6_dev_get_saddr(ip6_dst_idev(&rt->u.dst)->dev,
+                                      dst, &saddr_buf) == 0)
                        NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
        }
 
@@ -2503,6 +2507,20 @@ struct ctl_table *ipv6_route_sysctl_init(struct net *net)
        table = kmemdup(ipv6_route_table_template,
                        sizeof(ipv6_route_table_template),
                        GFP_KERNEL);
+
+       if (table) {
+               table[0].data = &net->ipv6.sysctl.flush_delay;
+               /* table[1].data will be handled when we have
+                  routes per namespace */
+               table[2].data = &net->ipv6.sysctl.ip6_rt_max_size;
+               table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval;
+               table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout;
+               table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval;
+               table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity;
+               table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires;
+               table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss;
+       }
+
        return table;
 }
 #endif