Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / net / ipv4 / ip_gre.c
index 8848355..ab99beb 100644 (file)
@@ -10,6 +10,7 @@
  *
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
@@ -28,6 +29,7 @@
 #include <linux/inetdevice.h>
 #include <linux/igmp.h>
 #include <linux/netfilter_ipv4.h>
+#include <linux/if_ether.h>
 
 #include <net/sock.h>
 #include <net/ip.h>
@@ -187,7 +189,7 @@ static struct ip_tunnel * ipgre_tunnel_lookup(u32 remote, u32 local, u32 key)
        }
 
        if (ipgre_fb_tunnel_dev->flags&IFF_UP)
-               return ipgre_fb_tunnel_dev->priv;
+               return netdev_priv(ipgre_fb_tunnel_dev);
        return NULL;
 }
 
@@ -277,7 +279,7 @@ static struct ip_tunnel * ipgre_tunnel_locate(struct ip_tunnel_parm *parms, int
          return NULL;
 
        dev->init = ipgre_tunnel_init;
-       nt = dev->priv;
+       nt = netdev_priv(dev);
        nt->parms = *parms;
 
        if (register_netdevice(dev) < 0) {
@@ -285,12 +287,8 @@ static struct ip_tunnel * ipgre_tunnel_locate(struct ip_tunnel_parm *parms, int
                goto failed;
        }
 
-       nt = dev->priv;
-       nt->parms = *parms;
-
        dev_hold(dev);
        ipgre_tunnel_link(nt);
-       /* Do not decrement MOD_USE_COUNT here. */
        return nt;
 
 failed:
@@ -299,7 +297,7 @@ failed:
 
 static void ipgre_tunnel_uninit(struct net_device *dev)
 {
-       ipgre_tunnel_unlink((struct ip_tunnel*)dev->priv);
+       ipgre_tunnel_unlink(netdev_priv(dev));
        dev_put(dev);
 }
 
@@ -518,7 +516,7 @@ out:
                skb2->dst->ops->update_pmtu(skb2->dst, rel_info);
                rel_info = htonl(rel_info);
        } else if (type == ICMP_TIME_EXCEEDED) {
-               struct ip_tunnel *t = (struct ip_tunnel*)skb2->dev->priv;
+               struct ip_tunnel *t = netdev_priv(skb2->dev);
                if (t->parms.iph.ttl) {
                        rel_type = ICMP_DEST_UNREACH;
                        rel_code = ICMP_HOST_UNREACH;
@@ -578,15 +576,16 @@ static int ipgre_rcv(struct sk_buff *skb)
                        goto drop_nolock;
 
                if (flags&GRE_CSUM) {
-                       if (skb->ip_summed == CHECKSUM_HW) {
+                       switch (skb->ip_summed) {
+                       case CHECKSUM_HW:
                                csum = (u16)csum_fold(skb->csum);
-                               if (csum)
-                                       skb->ip_summed = CHECKSUM_NONE;
-                       }
-                       if (skb->ip_summed == CHECKSUM_NONE) {
-                               skb->csum = skb_checksum(skb, 0, skb->len, 0);
+                               if (!csum)
+                                       break;
+                               /* fall through */
+                       case CHECKSUM_NONE:
+                               skb->csum = 0;
+                               csum = __skb_checksum_complete(skb);
                                skb->ip_summed = CHECKSUM_HW;
-                               csum = (u16)csum_fold(skb->csum);
                        }
                        offset += 4;
                }
@@ -618,7 +617,7 @@ static int ipgre_rcv(struct sk_buff *skb)
 
                skb->mac.raw = skb->nh.raw;
                skb->nh.raw = __pskb_pull(skb, offset);
-               skb_postpull_rcsum(skb, skb->mac.raw, offset);
+               skb_postpull_rcsum(skb, skb->h.raw, offset);
                memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
                skb->pkt_type = PACKET_HOST;
 #ifdef CONFIG_NET_IPGRE_BROADCAST
@@ -657,7 +656,7 @@ static int ipgre_rcv(struct sk_buff *skb)
                read_unlock(&ipgre_lock);
                return(0);
        }
-       icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PROT_UNREACH, 0);
+       icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
 
 drop:
        read_unlock(&ipgre_lock);
@@ -668,7 +667,7 @@ drop_nolock:
 
 static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       struct ip_tunnel *tunnel = (struct ip_tunnel*)dev->priv;
+       struct ip_tunnel *tunnel = netdev_priv(dev);
        struct net_device_stats *stats = &tunnel->stat;
        struct iphdr  *old_iph = skb->nh.iph;
        struct iphdr  *tiph;
@@ -831,6 +830,8 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
        skb->h.raw = skb->nh.raw;
        skb->nh.raw = skb_push(skb, gre_hlen);
        memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
+       IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
+                             IPSKB_REROUTED);
        dst_release(skb->dst);
        skb->dst = &rt->u.dst;
 
@@ -913,7 +914,7 @@ ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
                        t = ipgre_tunnel_locate(&p, 0);
                }
                if (t == NULL)
-                       t = (struct ip_tunnel*)dev->priv;
+                       t = netdev_priv(dev);
                memcpy(&p, &t->parms, sizeof(p));
                if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
                        err = -EFAULT;
@@ -953,7 +954,7 @@ ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
                        } else {
                                unsigned nflags=0;
 
-                               t = (struct ip_tunnel*)dev->priv;
+                               t = netdev_priv(dev);
 
                                if (MULTICAST(p.iph.daddr))
                                        nflags = IFF_BROADCAST;
@@ -1002,7 +1003,7 @@ ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
                        if ((t = ipgre_tunnel_locate(&p, 0)) == NULL)
                                goto done;
                        err = -EPERM;
-                       if (t == ipgre_fb_tunnel_dev->priv)
+                       if (t == netdev_priv(ipgre_fb_tunnel_dev))
                                goto done;
                        dev = t->dev;
                }
@@ -1019,12 +1020,12 @@ done:
 
 static struct net_device_stats *ipgre_tunnel_get_stats(struct net_device *dev)
 {
-       return &(((struct ip_tunnel*)dev->priv)->stat);
+       return &(((struct ip_tunnel*)netdev_priv(dev))->stat);
 }
 
 static int ipgre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
 {
-       struct ip_tunnel *tunnel = (struct ip_tunnel*)dev->priv;
+       struct ip_tunnel *tunnel = netdev_priv(dev);
        if (new_mtu < 68 || new_mtu > 0xFFF8 - tunnel->hlen)
                return -EINVAL;
        dev->mtu = new_mtu;
@@ -1064,7 +1065,7 @@ static int ipgre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
 static int ipgre_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
                        void *daddr, void *saddr, unsigned len)
 {
-       struct ip_tunnel *t = (struct ip_tunnel*)dev->priv;
+       struct ip_tunnel *t = netdev_priv(dev);
        struct iphdr *iph = (struct iphdr *)skb_push(skb, t->hlen);
        u16 *p = (u16*)(iph+1);
 
@@ -1091,7 +1092,7 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev, unsigned sh
 
 static int ipgre_open(struct net_device *dev)
 {
-       struct ip_tunnel *t = (struct ip_tunnel*)dev->priv;
+       struct ip_tunnel *t = netdev_priv(dev);
 
        if (MULTICAST(t->parms.iph.daddr)) {
                struct flowi fl = { .oif = t->parms.link,
@@ -1105,17 +1106,17 @@ static int ipgre_open(struct net_device *dev)
                        return -EADDRNOTAVAIL;
                dev = rt->u.dst.dev;
                ip_rt_put(rt);
-               if (__in_dev_get(dev) == NULL)
+               if (__in_dev_get_rtnl(dev) == NULL)
                        return -EADDRNOTAVAIL;
                t->mlink = dev->ifindex;
-               ip_mc_inc_group(__in_dev_get(dev), t->parms.iph.daddr);
+               ip_mc_inc_group(__in_dev_get_rtnl(dev), t->parms.iph.daddr);
        }
        return 0;
 }
 
 static int ipgre_close(struct net_device *dev)
 {
-       struct ip_tunnel *t = (struct ip_tunnel*)dev->priv;
+       struct ip_tunnel *t = netdev_priv(dev);
        if (MULTICAST(t->parms.iph.daddr) && t->mlink) {
                struct in_device *in_dev = inetdev_by_index(t->mlink);
                if (in_dev) {
@@ -1140,7 +1141,7 @@ static void ipgre_tunnel_setup(struct net_device *dev)
 
        dev->type               = ARPHRD_IPGRE;
        dev->hard_header_len    = LL_MAX_HEADER + sizeof(struct iphdr) + 4;
-       dev->mtu                = 1500 - sizeof(struct iphdr) - 4;
+       dev->mtu                = ETH_DATA_LEN - sizeof(struct iphdr) - 4;
        dev->flags              = IFF_NOARP;
        dev->iflink             = 0;
        dev->addr_len           = 4;
@@ -1152,10 +1153,10 @@ static int ipgre_tunnel_init(struct net_device *dev)
        struct ip_tunnel *tunnel;
        struct iphdr *iph;
        int hlen = LL_MAX_HEADER;
-       int mtu = 1500;
+       int mtu = ETH_DATA_LEN;
        int addend = sizeof(struct iphdr) + 4;
 
-       tunnel = (struct ip_tunnel*)dev->priv;
+       tunnel = netdev_priv(dev);
        iph = &tunnel->parms.iph;
 
        tunnel->dev = dev;
@@ -1217,9 +1218,9 @@ static int ipgre_tunnel_init(struct net_device *dev)
        return 0;
 }
 
-int __init ipgre_fb_tunnel_init(struct net_device *dev)
+static int __init ipgre_fb_tunnel_init(struct net_device *dev)
 {
-       struct ip_tunnel *tunnel = (struct ip_tunnel*)dev->priv;
+       struct ip_tunnel *tunnel = netdev_priv(dev);
        struct iphdr *iph = &tunnel->parms.iph;
 
        tunnel->dev = dev;
@@ -1277,12 +1278,28 @@ err1:
        goto out;
 }
 
-static void ipgre_fini(void)
+static void __exit ipgre_destroy_tunnels(void)
+{
+       int prio;
+
+       for (prio = 0; prio < 4; prio++) {
+               int h;
+               for (h = 0; h < HASH_SIZE; h++) {
+                       struct ip_tunnel *t;
+                       while ((t = tunnels[prio][h]) != NULL)
+                               unregister_netdevice(t->dev);
+               }
+       }
+}
+
+static void __exit ipgre_fini(void)
 {
        if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0)
                printk(KERN_INFO "ipgre close: can't remove protocol\n");
 
-       unregister_netdev(ipgre_fb_tunnel_dev);
+       rtnl_lock();
+       ipgre_destroy_tunnels();
+       rtnl_unlock();
 }
 
 module_init(ipgre_init);