[patch 2/3] vfs: dcache cleanups
[safe/jmp/linux-2.6] / net / ipv4 / fib_frontend.c
index e787d21..0b2ac6a 100644 (file)
@@ -116,6 +116,21 @@ struct fib_table *fib_get_table(struct net *net, u32 id)
 }
 #endif /* CONFIG_IP_MULTIPLE_TABLES */
 
+void fib_select_default(struct net *net,
+                       const struct flowi *flp, struct fib_result *res)
+{
+       struct fib_table *tb;
+       int table = RT_TABLE_MAIN;
+#ifdef CONFIG_IP_MULTIPLE_TABLES
+       if (res->r == NULL || res->r->action != FR_ACT_TO_TBL)
+               return;
+       table = res->r->table;
+#endif
+       tb = fib_get_table(net, table);
+       if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
+               tb->tb_select_default(tb, flp, res);
+}
+
 static void fib_flush(struct net *net)
 {
        int flushed = 0;
@@ -138,7 +153,7 @@ static void fib_flush(struct net *net)
  *     Find the first device with a given source address.
  */
 
-struct net_device * ip_dev_find(__be32 addr)
+struct net_device * ip_dev_find(struct net *net, __be32 addr)
 {
        struct flowi fl = { .nl_u = { .ip4_u = { .daddr = addr } } };
        struct fib_result res;
@@ -149,7 +164,7 @@ struct net_device * ip_dev_find(__be32 addr)
        res.r = NULL;
 #endif
 
-       local_table = fib_get_table(&init_net, RT_TABLE_LOCAL);
+       local_table = fib_get_table(net, RT_TABLE_LOCAL);
        if (!local_table || local_table->tb_lookup(local_table, &fl, &res))
                return NULL;
        if (res.type != RTN_LOCAL)
@@ -176,7 +191,7 @@ static inline unsigned __inet_dev_addr_type(struct net *net,
        unsigned ret = RTN_BROADCAST;
        struct fib_table *local_table;
 
-       if (ipv4_is_zeronet(addr) || ipv4_is_badclass(addr))
+       if (ipv4_is_zeronet(addr) || ipv4_is_lbcast(addr))
                return RTN_BROADCAST;
        if (ipv4_is_multicast(addr))
                return RTN_MULTICAST;
@@ -228,6 +243,7 @@ int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
        struct fib_result res;
        int no_addr, rpf;
        int ret;
+       struct net *net;
 
        no_addr = rpf = 0;
        rcu_read_lock();
@@ -241,7 +257,8 @@ int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
        if (in_dev == NULL)
                goto e_inval;
 
-       if (fib_lookup(&fl, &res))
+       net = dev_net(dev);
+       if (fib_lookup(net, &fl, &res))
                goto last_resort;
        if (res.type != RTN_UNICAST)
                goto e_inval_res;
@@ -265,7 +282,7 @@ int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
        fl.oif = dev->ifindex;
 
        ret = 0;
-       if (fib_lookup(&fl, &res) == 0) {
+       if (fib_lookup(net, &fl, &res) == 0) {
                if (res.type == RTN_UNICAST) {
                        *spec_dst = FIB_RES_PREFSRC(res);
                        ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST;
@@ -489,7 +506,6 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX+1] = {
        [RTA_PREFSRC]           = { .type = NLA_U32 },
        [RTA_METRICS]           = { .type = NLA_NESTED },
        [RTA_MULTIPATH]         = { .len = sizeof(struct rtnexthop) },
-       [RTA_PROTOINFO]         = { .type = NLA_U32 },
        [RTA_FLOW]              = { .type = NLA_U32 },
 };
 
@@ -566,7 +582,7 @@ errout:
 
 static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 {
-       struct net *net = skb->sk->sk_net;
+       struct net *net = sock_net(skb->sk);
        struct fib_config cfg;
        struct fib_table *tb;
        int err;
@@ -588,7 +604,7 @@ errout:
 
 static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 {
-       struct net *net = skb->sk->sk_net;
+       struct net *net = sock_net(skb->sk);
        struct fib_config cfg;
        struct fib_table *tb;
        int err;
@@ -610,7 +626,7 @@ errout:
 
 static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
 {
-       struct net *net = skb->sk->sk_net;
+       struct net *net = sock_net(skb->sk);
        unsigned int h, s_h;
        unsigned int e = 0, s_e;
        struct fib_table *tb;
@@ -657,7 +673,7 @@ out:
 
 static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifaddr *ifa)
 {
-       struct net *net = ifa->ifa_dev->dev->nd_net;
+       struct net *net = dev_net(ifa->ifa_dev->dev);
        struct fib_table *tb;
        struct fib_config cfg = {
                .fc_protocol = RTPROT_KERNEL,
@@ -784,15 +800,15 @@ static void fib_del_ifaddr(struct in_ifaddr *ifa)
                fib_magic(RTM_DELROUTE, RTN_LOCAL, ifa->ifa_local, 32, prim);
 
                /* Check, that this local address finally disappeared. */
-               if (inet_addr_type(dev->nd_net, ifa->ifa_local) != RTN_LOCAL) {
+               if (inet_addr_type(dev_net(dev), ifa->ifa_local) != RTN_LOCAL) {
                        /* And the last, but not the least thing.
                           We must flush stray FIB entries.
 
                           First of all, we scan fib_info list searching
                           for stray nexthop entries, then ignite fib_flush.
                        */
-                       if (fib_sync_down(ifa->ifa_local, NULL, 0))
-                               fib_flush(dev->nd_net);
+                       if (fib_sync_down_addr(dev_net(dev), ifa->ifa_local))
+                               fib_flush(dev_net(dev));
                }
        }
 #undef LOCAL_OK
@@ -840,7 +856,7 @@ static void nl_fib_input(struct sk_buff *skb)
        struct fib_table *tb;
        u32 pid;
 
-       net = skb->sk->sk_net;
+       net = sock_net(skb->sk);
        nlh = nlmsg_hdr(skb);
        if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
            nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn)))
@@ -869,25 +885,20 @@ static int nl_fib_lookup_init(struct net *net)
                                   nl_fib_input, NULL, THIS_MODULE);
        if (sk == NULL)
                return -EAFNOSUPPORT;
-       /* Don't hold an extra reference on the namespace */
-       put_net(sk->sk_net);
        net->ipv4.fibnl = sk;
        return 0;
 }
 
 static void nl_fib_lookup_exit(struct net *net)
 {
-       /* At the last minute lie and say this is a socket for the
-        * initial network namespace. So the socket will  be safe to free.
-        */
-       net->ipv4.fibnl->sk_net = get_net(&init_net);
        netlink_kernel_release(net->ipv4.fibnl);
+       net->ipv4.fibnl = NULL;
 }
 
 static void fib_disable_ip(struct net_device *dev, int force)
 {
-       if (fib_sync_down(0, dev, force))
-               fib_flush(dev->nd_net);
+       if (fib_sync_down_dev(dev, force))
+               fib_flush(dev_net(dev));
        rt_cache_flush(0);
        arp_ifdown(dev);
 }
@@ -963,6 +974,7 @@ static struct notifier_block fib_netdev_notifier = {
 
 static int __net_init ip_fib_net_init(struct net *net)
 {
+       int err;
        unsigned int i;
 
        net->ipv4.fib_table_hash = kzalloc(
@@ -973,7 +985,14 @@ static int __net_init ip_fib_net_init(struct net *net)
        for (i = 0; i < FIB_TABLE_HASHSZ; i++)
                INIT_HLIST_HEAD(&net->ipv4.fib_table_hash[i]);
 
-       return fib4_rules_init(net);
+       err = fib4_rules_init(net);
+       if (err < 0)
+               goto fail;
+       return 0;
+
+fail:
+       kfree(net->ipv4.fib_table_hash);
+       return err;
 }
 
 static void __net_exit ip_fib_net_exit(struct net *net)