patch-1.3.73 linux/drivers/net/new_tunnel.c

Next file: linux/drivers/pci/pci.c
Previous file: linux/drivers/net/lance.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.72/linux/drivers/net/new_tunnel.c linux/drivers/net/new_tunnel.c
@@ -18,7 +18,8 @@
 		-Alan Cox	(Alan.Cox@linux.org) 21 March 95
 
 	Reworked:
-		Changed to tunnel to destination gateway instead of pointopoint
+		Changed to tunnel to destination gateway in addition to the
+			tunnel's pointopoint address
 		Almost completely rewritten
 		Note:  There is currently no firewall or ICMP handling done.
 
@@ -81,7 +82,7 @@
  *	[36 bytes]
  */
  
-#define TUNL_HLEN	(((ETH_HLEN+15)&~15)+tunl_hlen)
+#define TUNL_HLEN	(((ETH_HLEN+15)&~15)+tunnel_hlen)
 
 
 #ifdef MODULE
@@ -168,15 +169,22 @@
 		/* No route to host */
 		/* Where did the packet come from? */
 		/*icmp_send(skb, ICMP_DEST_UNREACH, ICMP_NET_UNREACH, 0, dev);*/
-		printk ( KERN_INFO "%s: Packet with no route!\n", dev->name );
+		printk ( KERN_INFO "%s: Packet with no route!\n", dev->name);
 		dev->tbusy=0;
 		stats->tx_errors++;
 		return(1);
 	}
 
-	if (!(rt->rt_flags & RTF_GATEWAY))
-	{ 
-		/* No gateway to tunnel through? */
+	/*
+	 * Get the target address (other end of IP tunnel)
+	 */
+	if (rt->rt_flags & RTF_GATEWAY)
+		target = rt->rt_gateway;
+	else
+		target = dev->pa_dstaddr;
+
+	if ( ! target )
+	{	/* No gateway to tunnel through? */
 		/* Where did the packet come from? */
 		/*icmp_send(skb, ICMP_DEST_UNREACH, ICMP_NET_UNREACH, 0, dev);*/
 		printk ( KERN_INFO "%s: Packet with no target gateway!\n", dev->name);
@@ -185,7 +193,6 @@
 		stats->tx_errors++;
 		return(1);
 	}
-	target = rt->rt_gateway;
 	ip_rt_put(rt);
 
 	if ((rt = ip_rt_route(target, 0)) == NULL)
@@ -203,7 +210,7 @@
 	if (tdev == dev)
 	{ 
 		/* Tunnel to ourselves?  -- I don't think so. */
-		printk ( KERN_INFO "%s: Packet targetted at myself!\n" ,dev->name);
+		printk ( KERN_INFO "%s: Packet targetted at myself!\n" , dev->name);
 		ip_rt_put(rt);
 		dev->tbusy=0;
 		stats->tx_errors++;
@@ -218,7 +225,7 @@
 	/*
 	 * Okay, now see if we can stuff it in the buffer as-is.
 	 */
-	max_headroom = ((tunnel_hlen+tdev->hard_header_len+15)&~15);
+	max_headroom = (((tdev->hard_header_len+15)&~15)+tunnel_hlen);
 #ifdef TUNNEL_DEBUG
 printk("Room left at head: %d\n", skb_headroom(skb));
 printk("Room left at tail: %d\n", skb_tailroom(skb));
@@ -241,13 +248,13 @@
 		new_skb->free = 1;
 
 		/*
-		 * Reserve space for our header
+		 * Reserve space for our header and the lower device header
 		 */
-		skb_reserve(new_skb, tunnel_hlen);
-		new_skb->h.iph = (struct iphdr *) skb_push(new_skb, tunnel_hlen);
+		skb_reserve(new_skb, max_headroom);
+
 		/*
 		 * Copy the old packet to the new buffer.
-		 * Note that new_skb->h.iph is our (tunnel driver's) header
+		 * Note that new_skb->h.iph will be our (tunnel driver's) header
 		 * and new_skb->ip_hdr is the IP header of the old packet.
 		 */
 		new_skb->ip_hdr = (struct iphdr *) skb_put(new_skb, skb->len);
@@ -255,6 +262,9 @@
 		/* Is this necessary? */
 		memcpy(new_skb->proto_priv, skb->proto_priv, sizeof(skb->proto_priv));
 
+		/* Tack on our header */
+		new_skb->h.iph = (struct iphdr *) skb_push(new_skb, tunnel_hlen);
+
 		/* Free the old packet, we no longer need it */
 		kfree_skb(skb, FREE_WRITE);
 		skb = new_skb;
@@ -353,12 +363,10 @@
 	dev->header_cache_update= NULL;
 
 	dev->type				= ARPHRD_TUNNEL;
-	dev->hard_header_len 	= (tunnel_hlen+ETH_HLEN);
+	dev->hard_header_len 	= TUNL_HLEN;
 	dev->mtu		= 1500-tunnel_hlen; 	/* eth_mtu */
 	dev->addr_len		= 0;		/* Is this only for ARP? */
 	dev->tx_queue_len	= 2;		/* Small queue */
-
-	/* it should all run through */
 	memset(dev->broadcast,0xFF, ETH_ALEN);
 
 	/* New-style flags. */
@@ -417,11 +425,4 @@
 	dev_tunnel.priv=NULL;
 }
 #endif /* MODULE */
-
-
-
-
- 
-
-
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this