]> 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 4004c5f0b8d78eec1ad2ae6fbd2a3494645dac5c..09206f7ba525ee0c71769e73d6c22108f43eea08 100644 (file)
@@ -107,6 +107,7 @@ static struct dst_ops ip6_dst_ops = {
        .update_pmtu            =       ip6_rt_update_pmtu,
        .local_out              =       ip6_local_out,
        .entry_size             =       sizeof(struct rt6_info),
+       .entries                =       ATOMIC_INIT(0),
 };
 
 static void ip6_rt_blackhole_update_pmtu(struct dst_entry *dst, u32 mtu)
@@ -120,6 +121,7 @@ static struct dst_ops ip6_dst_blackhole_ops = {
        .check                  =       ip6_dst_check,
        .update_pmtu            =       ip6_rt_blackhole_update_pmtu,
        .entry_size             =       sizeof(struct rt6_info),
+       .entries                =       ATOMIC_INIT(0),
 };
 
 struct rt6_info ip6_null_entry = {
@@ -569,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;
 
@@ -756,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,
@@ -775,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);
@@ -902,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);
@@ -935,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
@@ -945,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();
 
@@ -956,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;
@@ -964,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)) {
@@ -978,7 +979,7 @@ int ndisc_dst_gc(int *more)
                }
        }
 
-       spin_unlock_bh(&ndisc_lock);
+       spin_unlock_bh(&icmp6_dst_lock);
 
        return freed;
 }
@@ -1068,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;
@@ -1274,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;
 
@@ -1389,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,
@@ -1588,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;
 
@@ -1618,7 +1621,7 @@ static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixle
 {
        struct fib6_config cfg = {
                .fc_table       = RT6_TABLE_INFO,
-               .fc_metric      = 1024,
+               .fc_metric      = IP6_RT_PRIO_USER,
                .fc_ifindex     = ifindex,
                .fc_dst_len     = prefixlen,
                .fc_flags       = RTF_GATEWAY | RTF_ADDRCONF | RTF_ROUTEINFO |
@@ -1643,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;
 
@@ -1668,7 +1671,7 @@ struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr,
 {
        struct fib6_config cfg = {
                .fc_table       = RT6_TABLE_DFLT,
-               .fc_metric      = 1024,
+               .fc_metric      = IP6_RT_PRIO_USER,
                .fc_ifindex     = dev->ifindex,
                .fc_flags       = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT |
                                  RTF_UP | RTF_EXPIRES | RTF_PREF(pref),
@@ -1687,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;
 
@@ -1717,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);
@@ -1848,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);
 
@@ -1907,7 +1912,7 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
         */
        if (rt->rt6i_dev == arg->dev &&
            !dst_metric_locked(&rt->u.dst, RTAX_MTU) &&
-           (dst_mtu(&rt->u.dst) > arg->mtu ||
+           (dst_mtu(&rt->u.dst) >= arg->mtu ||
             (dst_mtu(&rt->u.dst) < arg->mtu &&
              dst_mtu(&rt->u.dst) == idev->cnf.mtu6))) {
                rt->u.dst.metrics[RTAX_MTU-1] = arg->mtu;
@@ -1960,6 +1965,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
 
        cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid;
        cfg->fc_nlinfo.nlh = nlh;
+       cfg->fc_nlinfo.nl_net = skb->sk->sk_net;
 
        if (tb[RTA_GATEWAY]) {
                nla_memcpy(&cfg->fc_gateway, tb[RTA_GATEWAY], 16);
@@ -2117,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);
        }
 
@@ -2500,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