1 diff -Nurp linux-2.6.22-592/drivers/net/gre.c linux-2.6.22-593/drivers/net/gre.c
2 --- linux-2.6.22-592/drivers/net/gre.c 1969-12-31 19:00:00.000000000 -0500
3 +++ linux-2.6.22-593/drivers/net/gre.c 2008-03-18 16:10:13.000000000 -0400
6 + * Linux NET3: GRE over IP protocol decoder.
8 + * Authors: Alexey Kuznetsov (kuznet@ms2.inr.ac.ru)
10 + * This program is free software; you can redistribute it and/or
11 + * modify it under the terms of the GNU General Public License
12 + * as published by the Free Software Foundation; either version
13 + * 2 of the License, or (at your option) any later version.
17 +#include <linux/capability.h>
18 +#include <linux/module.h>
19 +#include <linux/types.h>
20 +#include <linux/sched.h>
21 +#include <linux/kernel.h>
22 +#include <asm/uaccess.h>
23 +#include <linux/skbuff.h>
24 +#include <linux/netdevice.h>
25 +#include <linux/in.h>
26 +#include <linux/tcp.h>
27 +#include <linux/udp.h>
28 +#include <linux/if_arp.h>
29 +#include <linux/mroute.h>
30 +#include <linux/init.h>
31 +#include <linux/in6.h>
32 +#include <linux/inetdevice.h>
33 +#include <linux/etherdevice.h> /**XXX added XXX */
34 +#include <linux/igmp.h>
35 +#include <linux/netfilter_ipv4.h>
36 +#include <linux/if_ether.h>
38 +#include <net/sock.h>
40 +#include <net/icmp.h>
41 +#include <net/protocol.h>
42 +#include <net/ipip.h>
44 +#include <net/checksum.h>
45 +#include <net/dsfield.h>
46 +#include <net/inet_ecn.h>
47 +#include <net/xfrm.h>
50 +#include <net/ipv6.h>
51 +#include <net/ip6_fib.h>
52 +#include <net/ip6_route.h>
55 +//#define GRE_DEBUG 1
58 + Problems & solutions
59 + --------------------
61 + 1. The most important issue is detecting local dead loops.
62 + They would cause complete host lockup in transmit, which
63 + would be "resolved" by stack overflow or, if queueing is enabled,
64 + with infinite looping in net_bh.
66 + We cannot track such dead loops during route installation,
67 + it is infeasible task. The most general solutions would be
68 + to keep skb->encapsulation counter (sort of local ttl),
69 + and silently drop packet when it expires. It is the best
70 + solution, but it supposes maintaing new variable in ALL
71 + skb, even if no tunneling is used.
73 + Current solution: t->recursion lock breaks dead loops. It looks
74 + like dev->tbusy flag, but I preferred new variable, because
75 + the semantics is different. One day, when hard_start_xmit
76 + will be multithreaded we will have to use skb->encapsulation.
80 + 2. Networking dead loops would not kill routers, but would really
81 + kill network. IP hop limit plays role of "t->recursion" in this case,
82 + if we copy it from packet being encapsulated to upper header.
83 + It is very good solution, but it introduces two problems:
85 + - Routing protocols, using packets with ttl=1 (OSPF, RIP2),
86 + do not work over tunnels.
87 + - traceroute does not work. I planned to relay ICMP from tunnel,
88 + so that this problem would be solved and traceroute output
89 + would even more informative. This idea appeared to be wrong:
90 + only Linux complies to rfc1812 now (yes, guys, Linux is the only
91 + true router now :-)), all routers (at least, in neighbourhood of mine)
92 + return only 8 bytes of payload. It is the end.
94 + Hence, if we want that OSPF worked or traceroute said something reasonable,
95 + we should search for another solution.
97 + One of them is to parse packet trying to detect inner encapsulation
98 + made by our node. It is difficult or even impossible, especially,
99 + taking into account fragmentation. TO be short, tt is not solution at all.
101 + Current solution: The solution was UNEXPECTEDLY SIMPLE.
102 + We force DF flag on tunnels with preconfigured hop limit,
103 + that is ALL. :-) Well, it does not remove the problem completely,
104 + but exponential growth of network traffic is changed to linear
105 + (branches, that exceed pmtu are pruned) and tunnel mtu
106 + fastly degrades to value <68, where looping stops.
107 + Yes, it is not good if there exists a router in the loop,
108 + which does not force DF, even when encapsulating packets have DF set.
109 + But it is not our problem! Nobody could accuse us, we made
110 + all that we could make. Even if it is your gated who injected
111 + fatal route to network, even if it were you who configured
112 + fatal static route: you are innocent. :-)
116 + 3. Really, ipv4/ipip.c, ipv4/ip_gre.c and ipv6/sit.c contain
117 + practically identical code. It would be good to glue them
118 + together, but it is not very evident, how to make them modular.
119 + sit is integral part of IPv6, ipip and gre are naturally modular.
120 + We could extract common parts (hash table, ioctl etc)
121 + to a separate module (ip_tunnel.c).
126 +static int ipgre_tunnel_init(struct net_device *dev);
127 +static void ipgre_ip_tunnel_setup(struct net_device *dev);
128 +static void ipgre_eth_tunnel_setup(struct net_device *dev);
130 +/* Fallback tunnel: no source, no destination, no key, no options */
132 +static int ipgre_fb_tunnel_init(struct net_device *dev);
134 +static struct net_device *ipgre_fb_tunnel_dev;
136 +/* Tunnel hash table */
146 + We require exact key match i.e. if a key is present in packet
147 + it will match only tunnel with the same key; if it is not present,
148 + it will match only keyless tunnel.
150 + All keysless packets, if not matched configured keyless tunnels
151 + will match fallback tunnel.
154 +#define HASH_SIZE 1024
155 +#define HASH(addr) (ntohl(addr)&1023)
157 +static struct ip_tunnel *tunnels[4][HASH_SIZE];
159 +#define tunnels_r_l (tunnels[3])
160 +#define tunnels_r (tunnels[2])
161 +#define tunnels_l (tunnels[1])
162 +#define tunnels_wc (tunnels[0])
164 +static DEFINE_RWLOCK(ipgre_lock);
166 +/* Given src, dst and key, find appropriate for input tunnel. */
168 +static struct ip_tunnel * ipgre_tunnel_lookup(__be32 remote, __be32 local, __be32 key)
171 + unsigned hash_value = HASH(key);
172 + struct ip_tunnel *t;
174 + t = tunnels_r_l[hash_value];
176 + if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP)) {
180 + t = tunnels_r[hash_value];
181 + if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
184 + t = tunnels_l[hash_value];
185 + if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
187 + t = tunnels_wc[hash_value];
188 + if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
190 + if (ipgre_fb_tunnel_dev->flags&IFF_UP)
191 + return netdev_priv(ipgre_fb_tunnel_dev);
195 +static struct ip_tunnel **ipgre_bucket(struct ip_tunnel *t)
197 + __be32 remote = t->parms.iph.daddr;
198 + __be32 local = t->parms.iph.saddr;
199 + __be32 key = t->parms.i_key;
200 + unsigned h = HASH(key);
205 + if (remote && !MULTICAST(remote)) {
207 + //h ^= HASH(remote);
210 + return &tunnels[prio][h];
213 +static void ipgre_tunnel_link(struct ip_tunnel *t)
215 + struct ip_tunnel **tp = ipgre_bucket(t);
218 + write_lock_bh(&ipgre_lock);
220 + write_unlock_bh(&ipgre_lock);
223 +static void ipgre_tunnel_unlink(struct ip_tunnel *t)
225 + struct ip_tunnel **tp;
227 + for (tp = ipgre_bucket(t); *tp; tp = &(*tp)->next) {
229 + write_lock_bh(&ipgre_lock);
231 + write_unlock_bh(&ipgre_lock);
237 +static struct ip_tunnel * ipgre_tunnel_locate(struct ip_tunnel_parm *parms, int create)
239 + __be32 remote = parms->iph.daddr;
240 + __be32 local = parms->iph.saddr;
241 + __be32 key = parms->i_key;
242 + __be16 proto = parms->proto_type;
243 + struct ip_tunnel *t, **tp, *nt;
244 + struct net_device *dev;
245 + unsigned h = HASH(key);
247 + char name[IFNAMSIZ];
251 + if (remote && !MULTICAST(remote)) {
253 + //h ^= HASH(remote);
255 + for (tp = &tunnels[prio][h]; (t = *tp) != NULL; tp = &t->next) {
256 + if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr) {
257 + if (key == t->parms.i_key)
264 + printk(KERN_CRIT "Adding tunnel %s with key %d\n", parms->name, ntohl(key));
266 + if (parms->name[0])
267 + strlcpy(name, parms->name, IFNAMSIZ);
270 + for (i=1; i<100; i++) {
271 + sprintf(name, "gre%d", i);
272 + if (__dev_get_by_name(&init_net, name) == NULL)
279 + /* Tunnel creation: check payload type and call appropriate
284 + dev = alloc_netdev(sizeof(*t), name, ipgre_ip_tunnel_setup);
287 + dev = alloc_netdev(sizeof(*t), name, ipgre_eth_tunnel_setup);
296 + dev->init = ipgre_tunnel_init;
297 + nt = netdev_priv(dev);
298 + nt->parms = *parms;
300 + if (register_netdevice(dev) < 0) {
306 + ipgre_tunnel_link(nt);
313 +static void ipgre_tunnel_uninit(struct net_device *dev)
315 + ipgre_tunnel_unlink(netdev_priv(dev));
320 +static void ipgre_err(struct sk_buff *skb, u32 info)
322 +#ifndef I_WISH_WORLD_WERE_PERFECT
324 +/* It is not :-( All the routers (except for Linux) return only
325 + 8 bytes of packet payload. It means, that precise relaying of
326 + ICMP in the real Internet is absolutely infeasible.
328 + Moreover, Cisco "wise men" put GRE key to the third word
329 + in GRE header. It makes impossible maintaining even soft state for keyed
330 + GRE tunnels with enabled checksum. Tell them "thank you".
332 + Well, I wonder, rfc1812 was written by Cisco employee,
333 + what the hell these idiots break standrads established
337 + struct iphdr *iph = (struct iphdr*)skb->data;
338 + __be16 *p = (__be16*)(skb->data+(iph->ihl<<2));
339 + int grehlen = (iph->ihl<<2) + 4;
340 + int type = icmp_hdr(skb)->type;
341 + int code = icmp_hdr(skb)->code;
342 + struct ip_tunnel *t;
346 + if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
347 + if (flags&(GRE_VERSION|GRE_ROUTING))
349 + if (flags&GRE_KEY) {
351 + if (flags&GRE_CSUM)
356 + /* If only 8 bytes returned, keyed message will be dropped here */
357 + if (skb_headlen(skb) < grehlen)
362 + case ICMP_PARAMETERPROB:
365 + case ICMP_DEST_UNREACH:
367 + case ICMP_SR_FAILED:
368 + case ICMP_PORT_UNREACH:
369 + /* Impossible event. */
371 + case ICMP_FRAG_NEEDED:
372 + /* Soft state for pmtu is maintained by IP core. */
375 + /* All others are translated to HOST_UNREACH.
376 + rfc2003 contains "deep thoughts" about NET_UNREACH,
377 + I believe they are just ether pollution. --ANK
382 + case ICMP_TIME_EXCEEDED:
383 + if (code != ICMP_EXC_TTL)
388 + read_lock(&ipgre_lock);
389 + t = ipgre_tunnel_lookup(iph->daddr, iph->saddr, (flags&GRE_KEY) ? *(((__be32*)p) + (grehlen>>2) - 1) : 0);
390 + if (t == NULL || t->parms.iph.daddr == 0 || MULTICAST(t->parms.iph.daddr))
393 + if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
396 + if (jiffies - t->err_time < IPTUNNEL_ERR_TIMEO)
400 + t->err_time = jiffies;
402 + read_unlock(&ipgre_lock);
405 + struct iphdr *iph = (struct iphdr*)dp;
406 + struct iphdr *eiph;
407 + __be16 *p = (__be16*)(dp+(iph->ihl<<2));
408 + int type = skb->h.icmph->type;
409 + int code = skb->h.icmph->code;
412 + __be32 rel_info = 0;
415 + int grehlen = (iph->ihl<<2) + 4;
416 + struct sk_buff *skb2;
420 + if (skb->dev->nd_net != &init_net)
423 + if (p[1] != htons(ETH_P_IP))
427 + if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
428 + if (flags&(GRE_VERSION|GRE_ROUTING))
430 + if (flags&GRE_CSUM)
437 + if (len < grehlen + sizeof(struct iphdr))
439 + eiph = (struct iphdr*)(dp + grehlen);
444 + case ICMP_PARAMETERPROB:
445 + n = ntohl(skb->h.icmph->un.gateway) >> 24;
446 + if (n < (iph->ihl<<2))
449 + /* So... This guy found something strange INSIDE encapsulated
450 + packet. Well, he is fool, but what can we do ?
452 + rel_type = ICMP_PARAMETERPROB;
454 + rel_info = htonl(n << 24);
457 + case ICMP_DEST_UNREACH:
459 + case ICMP_SR_FAILED:
460 + case ICMP_PORT_UNREACH:
461 + /* Impossible event. */
463 + case ICMP_FRAG_NEEDED:
464 + /* And it is the only really necessary thing :-) */
465 + n = ntohs(skb->h.icmph->un.frag.mtu);
466 + if (n < grehlen+68)
469 + /* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */
470 + if (n > ntohs(eiph->tot_len))
472 + rel_info = htonl(n);
475 + /* All others are translated to HOST_UNREACH.
476 + rfc2003 contains "deep thoughts" about NET_UNREACH,
477 + I believe, it is just ether pollution. --ANK
479 + rel_type = ICMP_DEST_UNREACH;
480 + rel_code = ICMP_HOST_UNREACH;
484 + case ICMP_TIME_EXCEEDED:
485 + if (code != ICMP_EXC_TTL)
490 + /* Prepare fake skb to feed it to icmp_send */
491 + skb2 = skb_clone(skb, GFP_ATOMIC);
494 + dst_release(skb2->dst);
496 + skb_pull(skb2, skb->data - (u8*)eiph);
497 + skb_reset_network_header(skb2);
499 + /* Try to guess incoming interface */
500 + memset(&fl, 0, sizeof(fl));
501 --- trellis20/include/linux/if_tunnel.h.orig 2009-02-26 01:10:20.000000000 -0500
502 +++ trellis20/include/linux/if_tunnel.h 2009-02-26 00:19:32.000000000 -0500
507 + __be16 proto_type; /*Added*/
511 --- trellis20/include/linux/if_ether.h.orig 2009-02-26 01:10:06.000000000 -0500
512 +++ trellis20/include/linux/if_ether.h 2009-02-26 00:19:32.000000000 -0500
514 #define ETH_P_DIAG 0x6005 /* DEC Diagnostics */
515 #define ETH_P_CUST 0x6006 /* DEC Customer use */
516 #define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */
517 +#define ETH_P_ETH 0x6558 /* Ethernet in Ethernet */
518 #define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */
519 #define ETH_P_ATALK 0x809B /* Appletalk DDP */
520 #define ETH_P_AARP 0x80F3 /* Appletalk AARP */
521 --- trellis20/net/ipv4/ip_gre.c.orig 2009-02-26 01:09:40.000000000 -0500
522 +++ trellis20/net/ipv4/ip_gre.c 2009-02-26 00:54:20.000000000 -0500
524 #include <linux/init.h>
525 #include <linux/in6.h>
526 #include <linux/inetdevice.h>
527 +#include <linux/etherdevice.h> /**XXX added XXX */
528 #include <linux/igmp.h>
529 #include <linux/netfilter_ipv4.h>
530 #include <linux/if_ether.h>
532 #include <net/ip6_route.h>
535 +//#define GRE_DEBUG 1
543 static int ipgre_tunnel_init(struct net_device *dev);
544 -static void ipgre_tunnel_setup(struct net_device *dev);
545 +static void ipgre_ip_tunnel_setup(struct net_device *dev);
546 +static void ipgre_eth_tunnel_setup(struct net_device *dev);
548 /* Fallback tunnel: no source, no destination, no key, no options */
551 __be32 remote = parms->iph.daddr;
552 __be32 local = parms->iph.saddr;
553 __be32 key = parms->i_key;
554 + __be16 proto = parms->proto_type;
555 struct ip_tunnel *t, **tp, *nt;
556 struct net_device *dev;
558 @@ -269,12 +274,29 @@
562 + printk(KERN_CRIT "Adding tunnel %s with key %d\n", parms->name, ntohl(key));
565 strlcpy(name, parms->name, IFNAMSIZ);
567 sprintf(name, "gre%%d");
569 dev = alloc_netdev(sizeof(*t), name, ipgre_tunnel_setup);
571 + /* Tunnel creation: check payload type and call appropriate
576 + dev = alloc_netdev(sizeof(*t), name, ipgre_ip_tunnel_setup);
579 + dev = alloc_netdev(sizeof(*t), name, ipgre_eth_tunnel_setup);
590 struct ip_tunnel *tunnel;
594 if (!pskb_may_pull(skb, 16))
601 + printk(KERN_DEBUG "gre.c [601] src:%x dst:%x proto:%d %p", iph->saddr, iph->daddr, iph->protocol, skb->data);
603 + proto = ntohs(*(__be16*)(h+2)); /* XXX added XXX */
605 if (flags&(GRE_CSUM|GRE_KEY|GRE_ROUTING|GRE_SEQ|GRE_VERSION)) {
606 /* - Version must be 0.
607 - We do not support routing headers.
609 __pskb_pull(skb, offset);
610 skb_reset_network_header(skb);
611 skb_postpull_rcsum(skb, skb_transport_header(skb), offset);
612 - skb->pkt_type = PACKET_HOST;
613 + if(proto == ETH_P_ETH)
616 + unsigned char* tmp_hdr = skb->data;
617 + printk(KERN_DEBUG "gre.c [658] %x %x %x %x %x %x\tskb %p\n", tmp_hdr[0], tmp_hdr[1], tmp_hdr[2], tmp_hdr[3], tmp_hdr[4], tmp_hdr[5], skb->data);
619 + skb->protocol = eth_type_trans(skb, tunnel->dev);
621 + /* XXX added these lines to make arp work? XXX */
622 + /*skb->mac.raw = skb->data;*/
623 + skb->network_header = skb->network_header + ETH_HLEN;
624 + /* XXX added these lines to make arp work? XXX */
627 + tmp_hdr = skb->data;
628 + printk(KERN_DEBUG "gre.c [669] %x %x %x %x %x %x\tskb %p\n", tmp_hdr[0], tmp_hdr[1], tmp_hdr[2], tmp_hdr[3], tmp_hdr[4], tmp_hdr[5], skb->data);
629 + printk(KERN_ALERT "gre.c [671] received ethernet on gre %x\n",skb->protocol);
631 + memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
634 + skb->pkt_type = PACKET_HOST;
635 #ifdef CONFIG_NET_IPGRE_BROADCAST
636 if (ipv4_is_multicast(iph->daddr)) {
637 /* Looped back packet, drop it! */
642 -static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
643 +static int ipgre_ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
645 struct ip_tunnel *tunnel = netdev_priv(dev);
646 struct net_device_stats *stats = &tunnel->dev->stats;
648 tdev = rt->u.dst.dev;
651 - dev->flags |= IFF_POINTOPOINT;
652 + if (tunnel->parms.proto_type == ETH_P_ETH)
654 + dev->flags |= IFF_BROADCAST;
658 + dev->flags |= IFF_POINTOPOINT;
663 if (!tdev && tunnel->parms.link)
664 @@ -822,10 +879,235 @@
666 dev->hard_header_len = hlen + addend;
667 dev->mtu = mtu - addend;
668 + if (tunnel->parms.proto_type == ETH_P_ETH)
669 + dev->mtu -= ETH_HLEN;
671 tunnel->hlen = addend;
675 +static int ipgre_eth_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
677 + struct ip_tunnel *tunnel = netdev_priv(dev);
678 + struct net_device_stats *stats = &tunnel->stat;
679 + struct iphdr *old_iph = ip_hdr(skb);
680 + struct iphdr *tiph = &tunnel->parms.iph;
683 + struct rtable *rt; /* Route to the other host */
684 + struct net_device *tdev; /* Device to other host */
685 + int gre_hlen = tunnel->hlen; /* XXX changed XXX*/
686 + //struct etheriphdr *ethiph;
687 + struct iphdr *iph; /* Our new IP header */
688 + int max_headroom; /* The extra header space needed */
692 + printk(KERN_ALERT "gre.c:972 Starting xmit\n");
695 + if (tunnel->recursion++) {
696 + stats->collisions++;
700 + /* Need valid non-multicast daddr. */
701 + if (tiph->daddr == 0 || MULTICAST(tiph->daddr))
706 + if (skb->protocol == htons(ETH_P_IP))
707 + tos = old_iph->tos;
711 + printk(KERN_ALERT "gre.c:991 Passed tos assignment.\n");
716 + struct flowi fl = { .fl_net = &init_net,
717 + .oif = tunnel->parms.link,
719 + { .daddr = tiph->daddr,
720 + .saddr = tiph->saddr,
721 + .tos = RT_TOS(tos) } },
722 + .proto = IPPROTO_GRE };
723 + if (ip_route_output_key(&rt, &fl)) {
724 + stats->tx_carrier_errors++;
725 + goto tx_error_icmp;
728 + tdev = rt->u.dst.dev;
730 + printk(KERN_ALERT "gre.c:1006 Passed the route retrieval\n");
734 + stats->collisions++;
738 + printk(KERN_ALERT "gre.c:1018 Passed tdev collision check.\n");
741 + /* Check MTU stuff if kernel panic */
742 + df = tiph->frag_off;
744 + mtu = dst_mtu(&rt->u.dst) - tunnel->hlen;
746 + mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
749 + skb->dst->ops->update_pmtu(skb->dst, mtu);
752 + printk(KERN_ALERT "gre.c:1032 Passed the pmtu setting.\n");
755 + if (skb->protocol == htons(ETH_P_IP)) {
756 + df |= (old_iph->frag_off&htons(IP_DF));
758 + if ((old_iph->frag_off & htons(IP_DF)) &&
759 + mtu < ntohs(old_iph->tot_len)) {
760 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
766 + else if (skb->protocol == htons(ETH_P_IPV6)) {
767 + struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
769 + if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) {
770 + if (tiph->daddr || rt6->rt6i_dst.plen == 128) {
771 + rt6->rt6i_flags |= RTF_MODIFIED;
772 + skb->dst->metrics[RTAX_MTU-1] = mtu;
776 + /* @@@ Is this correct? */
777 + if (mtu >= IPV6_MIN_MTU && mtu < skb->len - tunnel->hlen + gre_hlen) {
778 + icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
785 + printk(KERN_ALERT "gre.c:1065 Passed the fragmentation check.\n");
788 + if (tunnel->err_count > 0) {
789 + if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
790 + tunnel->err_count--;
791 + dst_link_failure(skb);
793 + tunnel->err_count = 0;
796 + max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen;
798 + if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
799 + struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
802 + stats->tx_dropped++;
803 + dev_kfree_skb(skb);
804 + tunnel->recursion--;
808 + skb_set_owner_w(new_skb, skb->sk);
809 + dev_kfree_skb(skb);
811 + old_iph = ip_hdr(skb);
814 + printk(KERN_ALERT "gre.c:1094 Passed the headroom calculation\n");
817 + skb->transport_header = skb->data;
818 + skb_push(skb, gre_hlen);
819 + skb_reset_network_header(skb);
820 + memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
821 + dst_release(skb->dst);
822 + skb->dst = &rt->u.dst;
825 + * Push down and install the etherip header.
830 + iph->ihl = sizeof(struct iphdr) >> 2;
831 + iph->frag_off = df;
832 + iph->protocol = IPPROTO_GRE;
833 + iph->tos = ipgre_ecn_encapsulate(tos, old_iph, skb);
834 + iph->daddr = rt->rt_dst;
835 + iph->saddr = rt->rt_src;
837 +/* ethiph->version = htons(ETHERIP_VERSION); */
839 + printk(KERN_ALERT "gre.c:1121 Passed outer IP header construction.\n");
842 + if ((iph->ttl = tiph->ttl) == 0) {
843 + if (skb->protocol == htons(ETH_P_IP))
844 + iph->ttl = old_iph->ttl;
846 + else if (skb->protocol == htons(ETH_P_IPV6))
847 + iph->ttl = ((struct ipv6hdr*)old_iph)->hop_limit;
850 + iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
853 + printk(KERN_ALERT "gre.c:1006 Passed the TTL check.\n");
856 + ((__be16*)(iph+1))[0] = tunnel->parms.o_flags;
857 + ((__be16*)(iph+1))[1] = htons(tunnel->parms.proto_type);
859 + if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
860 + __be32 *ptr = (__be32*)(((u8*)iph) + tunnel->hlen - 4);
862 + if (tunnel->parms.o_flags&GRE_SEQ) {
864 + *ptr = htonl(tunnel->o_seqno);
867 + if (tunnel->parms.o_flags&GRE_KEY) {
868 + *ptr = tunnel->parms.o_key;
871 + if (tunnel->parms.o_flags&GRE_CSUM) {
873 + *(__sum16*)ptr = ip_compute_csum((void*)(iph+1), skb->len - sizeof(struct iphdr));
877 + printk(KERN_ALERT "gre.c:1006 Passed the tunnel transmit.\n");
883 + tunnel->recursion--;
887 + dst_link_failure(skb);
890 + stats->tx_errors++;
891 + dev_kfree_skb(skb);
892 + tunnel->recursion--;
898 ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
901 struct net *net = dev_net(dev);
902 struct ipgre_net *ign = net_generic(net, ipgre_net_id);
904 + printk(KERN_ALERT "1174 GRE: entering gre ioctl. command is: %d\n", cmd);
912 t = ipgre_tunnel_locate(net, &p, cmd == SIOCADDTUNNEL);
913 + if (t) printk(KERN_ALERT "1174 GRE: proto %s %x\n", p.name, p.proto_type);
915 if (dev != ign->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
917 @@ -892,6 +1177,12 @@
918 nflags = IFF_BROADCAST;
919 else if (p.iph.daddr)
920 nflags = IFF_POINTOPOINT;
922 + /* XXX:Set back IFF_BROADCAST if
923 + * transporting ethernet */
924 + printk(KERN_ALERT "1193 GRE: proto %s %d\n", p.name, p.proto_type);
925 + if (p.proto_type == ETH_P_ETH)
926 + nflags = IFF_BROADCAST;
928 if ((dev->flags^nflags)&(IFF_POINTOPOINT|IFF_BROADCAST)) {
930 @@ -902,8 +1193,13 @@
931 t->parms.iph.daddr = p.iph.daddr;
932 t->parms.i_key = p.i_key;
933 t->parms.o_key = p.o_key;
934 - memcpy(dev->dev_addr, &p.iph.saddr, 4);
935 - memcpy(dev->broadcast, &p.iph.daddr, 4);
936 + /* XXX:Copy in the protocol field */
937 + t->parms.proto_type = p.proto_type;
938 + if (t->parms.proto_type != ETH_P_ETH) {
939 + memcpy(dev->dev_addr, &p.iph.saddr, 4);
940 + memcpy(dev->broadcast, &p.iph.daddr, 4);
943 ipgre_tunnel_link(ign, t);
944 netdev_state_change(dev);
946 @@ -1076,11 +1372,11 @@
950 -static void ipgre_tunnel_setup(struct net_device *dev)
951 +static void ipgre_ip_tunnel_setup(struct net_device *dev)
953 dev->uninit = ipgre_tunnel_uninit;
954 dev->destructor = free_netdev;
955 - dev->hard_start_xmit = ipgre_tunnel_xmit;
956 + dev->hard_start_xmit = ipgre_ip_tunnel_xmit;
957 dev->do_ioctl = ipgre_tunnel_ioctl;
958 dev->change_mtu = ipgre_tunnel_change_mtu;
960 @@ -1093,6 +1389,35 @@
961 dev->features |= NETIF_F_NETNS_LOCAL;
964 +/* Tunnel setup for ipgre_eth */
965 +static void ipgre_eth_tunnel_setup(struct net_device *dev)
967 + SET_MODULE_OWNER(dev);
969 + // Set default values for Ethernet device
972 + dev->uninit = ipgre_tunnel_uninit;
973 + dev->destructor = free_netdev;
974 + dev->hard_start_xmit = ipgre_eth_tunnel_xmit;
975 + dev->get_stats = ipgre_tunnel_get_stats;
976 + dev->do_ioctl = ipgre_tunnel_ioctl;
977 + dev->change_mtu = ipgre_tunnel_change_mtu;
979 + dev->hard_header_len = LL_MAX_HEADER + ETH_HLEN + sizeof(struct iphdr) + 4;
980 + dev->mtu = ETH_DATA_LEN - ETH_HLEN - sizeof(struct iphdr) - 4;
981 + dev->tx_queue_len = 0;
984 + random_ether_addr(dev->dev_addr);
987 + { unsigned char* d = dev->dev_addr;
988 + printk(KERN_ALERT "Here is the address we got:%x%x%x%x%x%x\n",d[0],d[1],d[2],d[3],d[4],d[5]); }
993 static int ipgre_tunnel_init(struct net_device *dev)
995 struct ip_tunnel *tunnel;
996 @@ -1104,8 +1429,10 @@
998 strcpy(tunnel->parms.name, dev->name);
1000 - memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
1001 - memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
1002 + if (tunnel->parms.proto_type != ETH_P_ETH) {
1003 + memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
1004 + memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
1007 ipgre_tunnel_bind_dev(dev);
1009 @@ -1181,7 +1508,7 @@
1012 ign->fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "gre0",
1013 - ipgre_tunnel_setup);
1014 + ipgre_ip_tunnel_setup);
1015 if (!ign->fb_tunnel_dev) {
1018 --- trellis20/drivers/net/Makefile.orig 2009-02-26 01:10:33.000000000 -0500
1019 +++ trellis20/drivers/net/Makefile 2009-02-26 00:20:33.000000000 -0500
1021 # Makefile for the Linux network (ethercard) device drivers.
1025 obj-$(CONFIG_E1000) += e1000/
1026 obj-$(CONFIG_E1000E) += e1000e/
1027 obj-$(CONFIG_IBM_NEW_EMAC) += ibm_newemac/