Merge branch 'for-2.6.22' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus...
[powerpc.git] / net / ipv4 / route.c
index 56d6602..cb76e3c 100644 (file)
@@ -70,7 +70,6 @@
 #include <linux/bitops.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/bootmem.h>
 #include <linux/string.h>
@@ -83,7 +82,6 @@
 #include <linux/proc_fs.h>
 #include <linux/init.h>
 #include <linux/skbuff.h>
-#include <linux/rtnetlink.h>
 #include <linux/inetdevice.h>
 #include <linux/igmp.h>
 #include <linux/pkt_sched.h>
 #include <net/xfrm.h>
 #include <net/ip_mp_alg.h>
 #include <net/netevent.h>
+#include <net/rtnetlink.h>
 #ifdef CONFIG_SYSCTL
 #include <linux/sysctl.h>
 #endif
@@ -289,7 +288,7 @@ static struct rtable *rt_cache_get_next(struct seq_file *seq, struct rtable *r)
 {
        struct rt_cache_iter_state *st = rcu_dereference(seq->private);
 
-       r = r->u.rt_next;
+       r = r->u.dst.rt_next;
        while (!r) {
                rcu_read_unlock_bh();
                if (--st->bucket < 0)
@@ -365,7 +364,7 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations rt_cache_seq_ops = {
+static const struct seq_operations rt_cache_seq_ops = {
        .start  = rt_cache_seq_start,
        .next   = rt_cache_seq_next,
        .stop   = rt_cache_seq_stop,
@@ -393,7 +392,7 @@ out_kfree:
        goto out;
 }
 
-static struct file_operations rt_cache_seq_fops = {
+static const struct file_operations rt_cache_seq_fops = {
        .owner   = THIS_MODULE,
        .open    = rt_cache_seq_open,
        .read    = seq_read,
@@ -471,7 +470,7 @@ static int rt_cpu_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations rt_cpu_seq_ops = {
+static const struct seq_operations rt_cpu_seq_ops = {
        .start  = rt_cpu_seq_start,
        .next   = rt_cpu_seq_next,
        .stop   = rt_cpu_seq_stop,
@@ -484,7 +483,7 @@ static int rt_cpu_seq_open(struct inode *inode, struct file *file)
        return seq_open(file, &rt_cpu_seq_ops);
 }
 
-static struct file_operations rt_cpu_seq_fops = {
+static const struct file_operations rt_cpu_seq_fops = {
        .owner   = THIS_MODULE,
        .open    = rt_cpu_seq_open,
        .read    = seq_read,
@@ -512,7 +511,7 @@ static __inline__ int rt_fast_clean(struct rtable *rth)
        /* Kill broadcast/multicast entries very aggresively, if they
           collide in hash table with more useful entries */
        return (rth->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) &&
-               rth->fl.iif && rth->u.rt_next;
+               rth->fl.iif && rth->u.dst.rt_next;
 }
 
 static __inline__ int rt_valuable(struct rtable *rth)
@@ -595,10 +594,10 @@ static struct rtable **rt_remove_balanced_route(struct rtable **chain_head,
                if (((*rthp)->u.dst.flags & DST_BALANCED) != 0  &&
                    compare_keys(&(*rthp)->fl, &expentry->fl)) {
                        if (*rthp == expentry) {
-                               *rthp = rth->u.rt_next;
+                               *rthp = rth->u.dst.rt_next;
                                continue;
                        } else {
-                               *rthp = rth->u.rt_next;
+                               *rthp = rth->u.dst.rt_next;
                                rt_free(rth);
                                if (removed_count)
                                        ++(*removed_count);
@@ -606,9 +605,9 @@ static struct rtable **rt_remove_balanced_route(struct rtable **chain_head,
                } else {
                        if (!((*rthp)->u.dst.flags & DST_BALANCED) &&
                            passedexpired && !nextstep)
-                               nextstep = &rth->u.rt_next;
+                               nextstep = &rth->u.dst.rt_next;
 
-                       rthp = &rth->u.rt_next;
+                       rthp = &rth->u.dst.rt_next;
                }
        }
 
@@ -649,12 +648,12 @@ static void rt_check_expire(unsigned long dummy)
                                /* Entry is expired even if it is in use */
                                if (time_before_eq(now, rth->u.dst.expires)) {
                                        tmo >>= 1;
-                                       rthp = &rth->u.rt_next;
+                                       rthp = &rth->u.dst.rt_next;
                                        continue;
                                }
                        } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout)) {
                                tmo >>= 1;
-                               rthp = &rth->u.rt_next;
+                               rthp = &rth->u.dst.rt_next;
                                continue;
                        }
 
@@ -668,11 +667,11 @@ static void rt_check_expire(unsigned long dummy)
                                if (!rthp)
                                        break;
                        } else {
-                               *rthp = rth->u.rt_next;
+                               *rthp = rth->u.dst.rt_next;
                                rt_free(rth);
                        }
 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
-                       *rthp = rth->u.rt_next;
+                       *rthp = rth->u.dst.rt_next;
                        rt_free(rth);
 #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
                }
@@ -706,7 +705,7 @@ static void rt_run_flush(unsigned long dummy)
                spin_unlock_bh(rt_hash_lock_addr(i));
 
                for (; rth; rth = next) {
-                       next = rth->u.rt_next;
+                       next = rth->u.dst.rt_next;
                        rt_free(rth);
                }
        }
@@ -840,7 +839,7 @@ static int rt_garbage_collect(void)
                        while ((rth = *rthp) != NULL) {
                                if (!rt_may_expire(rth, tmo, expire)) {
                                        tmo >>= 1;
-                                       rthp = &rth->u.rt_next;
+                                       rthp = &rth->u.dst.rt_next;
                                        continue;
                                }
 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
@@ -858,12 +857,12 @@ static int rt_garbage_collect(void)
                                        if (!rthp)
                                                break;
                                } else {
-                                       *rthp = rth->u.rt_next;
+                                       *rthp = rth->u.dst.rt_next;
                                        rt_free(rth);
                                        goal--;
                                }
 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
-                               *rthp = rth->u.rt_next;
+                               *rthp = rth->u.dst.rt_next;
                                rt_free(rth);
                                goal--;
 #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
@@ -947,13 +946,13 @@ restart:
                if (compare_keys(&rth->fl, &rt->fl)) {
 #endif
                        /* Put it first */
-                       *rthp = rth->u.rt_next;
+                       *rthp = rth->u.dst.rt_next;
                        /*
                         * Since lookup is lockfree, the deletion
                         * must be visible to another weakly ordered CPU before
                         * the insertion at the start of the hash chain.
                         */
-                       rcu_assign_pointer(rth->u.rt_next,
+                       rcu_assign_pointer(rth->u.dst.rt_next,
                                           rt_hash_table[hash].chain);
                        /*
                         * Since lookup is lockfree, the update writes
@@ -983,7 +982,7 @@ restart:
 
                chain_length++;
 
-               rthp = &rth->u.rt_next;
+               rthp = &rth->u.dst.rt_next;
        }
 
        if (cand) {
@@ -994,7 +993,7 @@ restart:
                 * only 2 entries per bucket. We will see.
                 */
                if (chain_length > ip_rt_gc_elasticity) {
-                       *candp = cand->u.rt_next;
+                       *candp = cand->u.dst.rt_next;
                        rt_free(cand);
                }
        }
@@ -1034,13 +1033,13 @@ restart:
                }
        }
 
-       rt->u.rt_next = rt_hash_table[hash].chain;
+       rt->u.dst.rt_next = rt_hash_table[hash].chain;
 #if RT_CACHE_DEBUG >= 2
-       if (rt->u.rt_next) {
+       if (rt->u.dst.rt_next) {
                struct rtable *trt;
                printk(KERN_DEBUG "rt_cache @%02x: %u.%u.%u.%u", hash,
                       NIPQUAD(rt->rt_dst));
-               for (trt = rt->u.rt_next; trt; trt = trt->u.rt_next)
+               for (trt = rt->u.dst.rt_next; trt; trt = trt->u.dst.rt_next)
                        printk(" . %u.%u.%u.%u", NIPQUAD(trt->rt_dst));
                printk("\n");
        }
@@ -1117,9 +1116,9 @@ static void rt_del(unsigned hash, struct rtable *rt)
        spin_lock_bh(rt_hash_lock_addr(hash));
        ip_rt_put(rt);
        for (rthp = &rt_hash_table[hash].chain; *rthp;
-            rthp = &(*rthp)->u.rt_next)
+            rthp = &(*rthp)->u.dst.rt_next)
                if (*rthp == rt) {
-                       *rthp = rt->u.rt_next;
+                       *rthp = rt->u.dst.rt_next;
                        rt_free(rt);
                        break;
                }
@@ -1167,7 +1166,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
                                    rth->fl.fl4_src != skeys[i] ||
                                    rth->fl.oif != ikeys[k] ||
                                    rth->fl.iif != 0) {
-                                       rthp = &rth->u.rt_next;
+                                       rthp = &rth->u.dst.rt_next;
                                        continue;
                                }
 
@@ -1416,7 +1415,7 @@ unsigned short ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mtu)
 
                rcu_read_lock();
                for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
-                    rth = rcu_dereference(rth->u.rt_next)) {
+                    rth = rcu_dereference(rth->u.dst.rt_next)) {
                        if (rth->fl.fl4_dst == daddr &&
                            rth->fl.fl4_src == skeys[i] &&
                            rth->rt_dst  == daddr &&
@@ -1520,7 +1519,7 @@ static void ipv4_link_failure(struct sk_buff *skb)
 static int ip_rt_bug(struct sk_buff *skb)
 {
        printk(KERN_DEBUG "ip_rt_bug: %u.%u.%u.%u -> %u.%u.%u.%u, %s\n",
-               NIPQUAD(skb->nh.iph->saddr), NIPQUAD(skb->nh.iph->daddr),
+               NIPQUAD(ip_hdr(skb)->saddr), NIPQUAD(ip_hdr(skb)->daddr),
                skb->dev ? skb->dev->name : "?");
        kfree_skb(skb);
        return 0;
@@ -1699,9 +1698,9 @@ static void ip_handle_martian_source(struct net_device *dev,
                printk(KERN_WARNING "martian source %u.%u.%u.%u from "
                        "%u.%u.%u.%u, on dev %s\n",
                        NIPQUAD(daddr), NIPQUAD(saddr), dev->name);
-               if (dev->hard_header_len && skb->mac.raw) {
+               if (dev->hard_header_len && skb_mac_header_was_set(skb)) {
                        int i;
-                       unsigned char *p = skb->mac.raw;
+                       const unsigned char *p = skb_mac_header(skb);
                        printk(KERN_WARNING "ll header: ");
                        for (i = 0; i < dev->hard_header_len; i++, p++) {
                                printk("%02x", *p);
@@ -2099,7 +2098,7 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 
        rcu_read_lock();
        for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
-            rth = rcu_dereference(rth->u.rt_next)) {
+            rth = rcu_dereference(rth->u.dst.rt_next)) {
                if (rth->fl.fl4_dst == daddr &&
                    rth->fl.fl4_src == saddr &&
                    rth->fl.iif == iif &&
@@ -2135,7 +2134,7 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
                rcu_read_lock();
                if ((in_dev = __in_dev_get_rcu(dev)) != NULL) {
                        int our = ip_check_mc(in_dev, daddr, saddr,
-                               skb->nh.iph->protocol);
+                               ip_hdr(skb)->protocol);
                        if (our
 #ifdef CONFIG_IP_MROUTE
                            || (!LOCAL_MCAST(daddr) && IN_DEV_MFORWARD(in_dev))
@@ -2397,7 +2396,7 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
 
                /* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */
                dev_out = ip_dev_find(oldflp->fl4_src);
-               if (dev_out == NULL)
+               if ((dev_out == NULL) && !(sysctl_ip_nonlocal_bind))
                        goto out;
 
                /* I removed check for oif == dev_out->oif here.
@@ -2408,7 +2407,7 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
                      of another iface. --ANK
                 */
 
-               if (oldflp->oif == 0
+               if (dev_out && oldflp->oif == 0
                    && (MULTICAST(oldflp->fl4_dst) || oldflp->fl4_dst == htonl(0xFFFFFFFF))) {
                        /* Special hack: user can direct multicasts
                           and limited broadcast via necessary interface
@@ -2563,7 +2562,7 @@ int __ip_route_output_key(struct rtable **rp, const struct flowi *flp)
 
        rcu_read_lock_bh();
        for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
-               rth = rcu_dereference(rth->u.rt_next)) {
+               rth = rcu_dereference(rth->u.dst.rt_next)) {
                if (rth->fl.fl4_dst == flp->fl4_dst &&
                    rth->fl.fl4_src == flp->fl4_src &&
                    rth->fl.iif == 0 &&
@@ -2684,7 +2683,7 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
                id = rt->peer->ip_id_count;
                if (rt->peer->tcp_ts_stamp) {
                        ts = rt->peer->tcp_ts;
-                       tsage = xtime.tv_sec - rt->peer->tcp_ts_stamp;
+                       tsage = get_seconds() - rt->peer->tcp_ts_stamp;
                }
        }
 
@@ -2722,7 +2721,7 @@ nla_put_failure:
        return -EMSGSIZE;
 }
 
-int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
+static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
 {
        struct rtmsg *rtm;
        struct nlattr *tb[RTA_MAX+1];
@@ -2748,10 +2747,11 @@ int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
        /* Reserve room for dummy headers, this skb can pass
           through good chunk of routing engine.
         */
-       skb->mac.raw = skb->nh.raw = skb->data;
+       skb_reset_mac_header(skb);
+       skb_reset_network_header(skb);
 
        /* Bugfix: need to give ip_route_input enough of an IP header to not gag. */
-       skb->nh.iph->protocol = IPPROTO_ICMP;
+       ip_hdr(skb)->protocol = IPPROTO_ICMP;
        skb_reserve(skb, MAX_HEADER + sizeof(struct iphdr));
 
        src = tb[RTA_SRC] ? nla_get_be32(tb[RTA_SRC]) : 0;
@@ -2825,7 +2825,7 @@ int ip_rt_dump(struct sk_buff *skb,  struct netlink_callback *cb)
                        s_idx = 0;
                rcu_read_lock_bh();
                for (rt = rcu_dereference(rt_hash_table[h].chain), idx = 0; rt;
-                    rt = rcu_dereference(rt->u.rt_next), idx++) {
+                    rt = rcu_dereference(rt->u.dst.rt_next), idx++) {
                        if (idx < s_idx)
                                continue;
                        skb->dst = dst_clone(&rt->u.dst);
@@ -3194,6 +3194,8 @@ int __init ip_rt_init(void)
        xfrm_init();
        xfrm4_init();
 #endif
+       rtnl_register(PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL);
+
        return rc;
 }