Get rid of .orig
[linux-2.6.git] / linux-2.6-720-egre.patch
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
4 @@ -0,0 +1,1632 @@
5 +/*
6 + *     Linux NET3:     GRE over IP protocol decoder.
7 + *
8 + *     Authors: Alexey Kuznetsov (kuznet@ms2.inr.ac.ru)
9 + *
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.
14 + *
15 + */
16 +
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>
37 +
38 +#include <net/sock.h>
39 +#include <net/ip.h>
40 +#include <net/icmp.h>
41 +#include <net/protocol.h>
42 +#include <net/ipip.h>
43 +#include <net/arp.h>
44 +#include <net/checksum.h>
45 +#include <net/dsfield.h>
46 +#include <net/inet_ecn.h>
47 +#include <net/xfrm.h>
48 +
49 +#ifdef CONFIG_IPV6
50 +#include <net/ipv6.h>
51 +#include <net/ip6_fib.h>
52 +#include <net/ip6_route.h>
53 +#endif
54 +
55 +//#define GRE_DEBUG 1
56 +
57 +/*
58 +   Problems & solutions
59 +   --------------------
60 +
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.
65 +
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.
72 +
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.
77 +
78 +
79 +
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:
84 +
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.
93 +
94 +   Hence, if we want that OSPF worked or traceroute said something reasonable,
95 +   we should search for another solution.
96 +
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.
100 +
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. :-)
113 +
114 +
115 +
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).
122 +
123 +   Alexey Kuznetsov.
124 + */
125 +
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);
129 +
130 +/* Fallback tunnel: no source, no destination, no key, no options */
131 +
132 +static int ipgre_fb_tunnel_init(struct net_device *dev);
133 +
134 +static struct net_device *ipgre_fb_tunnel_dev;
135 +
136 +/* Tunnel hash table */
137 +
138 +/*
139 +   4 hash tables:
140 +
141 +   3: (remote,local)
142 +   2: (remote,*)
143 +   1: (*,local)
144 +   0: (*,*)
145 +
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.
149 +
150 +   All keysless packets, if not matched configured keyless tunnels
151 +   will match fallback tunnel.
152 + */
153 +
154 +#define HASH_SIZE  1024
155 +#define HASH(addr) (ntohl(addr)&1023)
156 +
157 +static struct ip_tunnel *tunnels[4][HASH_SIZE];
158 +
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])
163 +
164 +static DEFINE_RWLOCK(ipgre_lock);
165 +
166 +/* Given src, dst and key, find appropriate for input tunnel. */
167 +
168 +static struct ip_tunnel * ipgre_tunnel_lookup(__be32 remote, __be32 local, __be32 key)
169 +{
170 +       /* HACK */
171 +       unsigned hash_value = HASH(key);
172 +       struct ip_tunnel *t;
173 +
174 +       t = tunnels_r_l[hash_value];
175 +
176 +       if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP)) {
177 +               return t;
178 +       }
179 +
180 +       t = tunnels_r[hash_value];
181 +                       if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
182 +                               return t;
183 +
184 +       t = tunnels_l[hash_value];
185 +                       if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
186 +                               return t;
187 +       t = tunnels_wc[hash_value];
188 +               if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
189 +                       return t;
190 +       if (ipgre_fb_tunnel_dev->flags&IFF_UP)
191 +               return netdev_priv(ipgre_fb_tunnel_dev);
192 +       return NULL;
193 +}
194 +
195 +static struct ip_tunnel **ipgre_bucket(struct ip_tunnel *t)
196 +{
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);
201 +       int prio = 0;
202 +
203 +       if (local)
204 +               prio |= 1;
205 +       if (remote && !MULTICAST(remote)) {
206 +               prio |= 2;
207 +               //h ^= HASH(remote);
208 +       }
209 +
210 +       return &tunnels[prio][h];
211 +}
212 +
213 +static void ipgre_tunnel_link(struct ip_tunnel *t)
214 +{
215 +       struct ip_tunnel **tp = ipgre_bucket(t);
216 +
217 +       t->next = *tp;
218 +       write_lock_bh(&ipgre_lock);
219 +       *tp = t;
220 +       write_unlock_bh(&ipgre_lock);
221 +}
222 +
223 +static void ipgre_tunnel_unlink(struct ip_tunnel *t)
224 +{
225 +       struct ip_tunnel **tp;
226 +
227 +       for (tp = ipgre_bucket(t); *tp; tp = &(*tp)->next) {
228 +               if (t == *tp) {
229 +                       write_lock_bh(&ipgre_lock);
230 +                       *tp = t->next;
231 +                       write_unlock_bh(&ipgre_lock);
232 +                       break;
233 +               }
234 +       }
235 +}
236 +
237 +static struct ip_tunnel * ipgre_tunnel_locate(struct ip_tunnel_parm *parms, int create)
238 +{
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);
246 +       int prio = 0;
247 +       char name[IFNAMSIZ];
248 +
249 +       if (local)
250 +               prio |= 1;
251 +       if (remote && !MULTICAST(remote)) {
252 +               prio |= 2;
253 +               //h ^= HASH(remote);
254 +       }
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)
258 +                               return t;
259 +               }
260 +       }
261 +       if (!create)
262 +               return NULL;
263 +
264 +       printk(KERN_CRIT "Adding tunnel %s with key %d\n", parms->name, ntohl(key));
265 +
266 +       if (parms->name[0])
267 +               strlcpy(name, parms->name, IFNAMSIZ);
268 +       else {
269 +               int i;
270 +               for (i=1; i<100; i++) {
271 +                       sprintf(name, "gre%d", i);
272 +                       if (__dev_get_by_name(&init_net, name) == NULL)
273 +                               break;
274 +               }
275 +               if (i==100)
276 +                       goto failed;
277 +       }
278 +       
279 +       /* Tunnel creation: check payload type and call appropriate
280 +        * function */
281 +       switch (proto)
282 +       {
283 +           case ETH_P_IP:
284 +               dev = alloc_netdev(sizeof(*t), name, ipgre_ip_tunnel_setup);
285 +               break;
286 +           case ETH_P_ETH:
287 +               dev = alloc_netdev(sizeof(*t), name, ipgre_eth_tunnel_setup);
288 +               break;
289 +           default:
290 +               return NULL;
291 +       }
292 +
293 +       if (!dev)
294 +         return NULL;
295 +
296 +       dev->init = ipgre_tunnel_init;
297 +       nt = netdev_priv(dev);
298 +       nt->parms = *parms;
299 +
300 +       if (register_netdevice(dev) < 0) {
301 +               free_netdev(dev);
302 +               goto failed;
303 +       }
304 +
305 +       dev_hold(dev);
306 +       ipgre_tunnel_link(nt);
307 +       return nt;
308 +
309 +failed:
310 +       return NULL;
311 +}
312 +
313 +static void ipgre_tunnel_uninit(struct net_device *dev)
314 +{
315 +       ipgre_tunnel_unlink(netdev_priv(dev));
316 +       dev_put(dev);
317 +}
318 +
319 +
320 +static void ipgre_err(struct sk_buff *skb, u32 info)
321 +{
322 +#ifndef I_WISH_WORLD_WERE_PERFECT
323 +
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.
327 +
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".
331 +
332 +   Well, I wonder, rfc1812 was written by Cisco employee,
333 +   what the hell these idiots break standrads established
334 +   by themself???
335 + */
336 +
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;
343 +       __be16 flags;
344 +
345 +       flags = p[0];
346 +       if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
347 +               if (flags&(GRE_VERSION|GRE_ROUTING))
348 +                       return;
349 +               if (flags&GRE_KEY) {
350 +                       grehlen += 4;
351 +                       if (flags&GRE_CSUM)
352 +                               grehlen += 4;
353 +               }
354 +       }
355 +
356 +       /* If only 8 bytes returned, keyed message will be dropped here */
357 +       if (skb_headlen(skb) < grehlen)
358 +               return;
359 +
360 +       switch (type) {
361 +       default:
362 +       case ICMP_PARAMETERPROB:
363 +               return;
364 +
365 +       case ICMP_DEST_UNREACH:
366 +               switch (code) {
367 +               case ICMP_SR_FAILED:
368 +               case ICMP_PORT_UNREACH:
369 +                       /* Impossible event. */
370 +                       return;
371 +               case ICMP_FRAG_NEEDED:
372 +                       /* Soft state for pmtu is maintained by IP core. */
373 +                       return;
374 +               default:
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
378 +                        */
379 +                       break;
380 +               }
381 +               break;
382 +       case ICMP_TIME_EXCEEDED:
383 +               if (code != ICMP_EXC_TTL)
384 +                       return;
385 +               break;
386 +       }
387 +
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))
391 +               goto out;
392 +
393 +       if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
394 +               goto out;
395 +
396 +       if (jiffies - t->err_time < IPTUNNEL_ERR_TIMEO)
397 +               t->err_count++;
398 +       else
399 +               t->err_count = 1;
400 +       t->err_time = jiffies;
401 +out:
402 +       read_unlock(&ipgre_lock);
403 +       return;
404 +#else
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;
410 +       int rel_type = 0;
411 +       int rel_code = 0;
412 +       __be32 rel_info = 0;
413 +       __u32 n = 0;
414 +       __be16 flags;
415 +       int grehlen = (iph->ihl<<2) + 4;
416 +       struct sk_buff *skb2;
417 +       struct flowi fl;
418 +       struct rtable *rt;
419 +
420 +       if (skb->dev->nd_net != &init_net)
421 +               return;
422 +
423 +       if (p[1] != htons(ETH_P_IP))
424 +               return;
425 +
426 +       flags = p[0];
427 +       if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
428 +               if (flags&(GRE_VERSION|GRE_ROUTING))
429 +                       return;
430 +               if (flags&GRE_CSUM)
431 +                       grehlen += 4;
432 +               if (flags&GRE_KEY)
433 +                       grehlen += 4;
434 +               if (flags&GRE_SEQ)
435 +                       grehlen += 4;
436 +       }
437 +       if (len < grehlen + sizeof(struct iphdr))
438 +               return;
439 +       eiph = (struct iphdr*)(dp + grehlen);
440 +
441 +       switch (type) {
442 +       default:
443 +               return;
444 +       case ICMP_PARAMETERPROB:
445 +               n = ntohl(skb->h.icmph->un.gateway) >> 24;
446 +               if (n < (iph->ihl<<2))
447 +                       return;
448 +
449 +               /* So... This guy found something strange INSIDE encapsulated
450 +                  packet. Well, he is fool, but what can we do ?
451 +                */
452 +               rel_type = ICMP_PARAMETERPROB;
453 +               n -= grehlen;
454 +               rel_info = htonl(n << 24);
455 +               break;
456 +
457 +       case ICMP_DEST_UNREACH:
458 +               switch (code) {
459 +               case ICMP_SR_FAILED:
460 +               case ICMP_PORT_UNREACH:
461 +                       /* Impossible event. */
462 +                       return;
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)
467 +                               return;
468 +                       n -= grehlen;
469 +                       /* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */
470 +                       if (n > ntohs(eiph->tot_len))
471 +                               return;
472 +                       rel_info = htonl(n);
473 +                       break;
474 +               default:
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
478 +                        */
479 +                       rel_type = ICMP_DEST_UNREACH;
480 +                       rel_code = ICMP_HOST_UNREACH;
481 +                       break;
482 +               }
483 +               break;
484 +       case ICMP_TIME_EXCEEDED:
485 +               if (code != ICMP_EXC_TTL)
486 +                       return;
487 +               break;
488 +       }
489 +
490 +       /* Prepare fake skb to feed it to icmp_send */
491 +       skb2 = skb_clone(skb, GFP_ATOMIC);
492 +       if (skb2 == NULL)
493 +               return;
494 +       dst_release(skb2->dst);
495 +       skb2->dst = NULL;
496 +       skb_pull(skb2, skb->data - (u8*)eiph);
497 +       skb_reset_network_header(skb2);
498 +
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
503 @@ -29,6 +29,7 @@
504         __be16                  o_flags;
505         __be32                  i_key;
506         __be32                  o_key;
507 +        __be16                  proto_type;   /*Added*/
508         struct iphdr            iph;
509  };
510  
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
513 @@ -56,6 +56,7 @@
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
523 @@ -25,6 +25,7 @@
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>
531 @@ -48,6 +49,8 @@
532  #include <net/ip6_route.h>
533  #endif
534  
535 +//#define GRE_DEBUG 1
536 +
537  /*
538     Problems & solutions
539     --------------------
540 @@ -118,7 +121,8 @@
541   */
542  
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);
547  
548  /* Fallback tunnel: no source, no destination, no key, no options */
549  
550 @@ -255,6 +259,7 @@
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;
557         char name[IFNAMSIZ];
558 @@ -269,12 +274,29 @@
559         if (!create)
560                 return NULL;
561  
562 +       printk(KERN_CRIT "Adding tunnel %s with key %d\n", parms->name, ntohl(key));
563 +
564         if (parms->name[0])
565                 strlcpy(name, parms->name, IFNAMSIZ);
566         else
567                 sprintf(name, "gre%%d");
568  
569         dev = alloc_netdev(sizeof(*t), name, ipgre_tunnel_setup);
570 +       
571 +       /* Tunnel creation: check payload type and call appropriate
572 +        * function */
573 +       switch (proto)
574 +       {
575 +           case ETH_P_IP:
576 +               dev = alloc_netdev(sizeof(*t), name, ipgre_ip_tunnel_setup);
577 +               break;
578 +           case ETH_P_ETH:
579 +               dev = alloc_netdev(sizeof(*t), name, ipgre_eth_tunnel_setup);
580 +               break;
581 +           default:
582 +               return NULL;
583 +       }
584 +
585         if (!dev)
586           return NULL;
587  
588 @@ -431,6 +453,7 @@
589         u32    seqno = 0;
590         struct ip_tunnel *tunnel;
591         int    offset = 4;
592 +       __be16 proto;
593  
594         if (!pskb_may_pull(skb, 16))
595                 goto drop_nolock;
596 @@ -439,6 +462,11 @@
597         h = skb->data;
598         flags = *(__be16*)h;
599  
600 +#ifdef GRE_DEBUG
601 +       printk(KERN_DEBUG "gre.c [601] src:%x dst:%x  proto:%d %p", iph->saddr, iph->daddr, iph->protocol, skb->data);
602 +#endif 
603 +       proto = ntohs(*(__be16*)(h+2)); /* XXX added XXX */
604 +       
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.
608 @@ -493,7 +521,28 @@
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)
614 +                 {
615 +#ifdef GRE_DEBUG
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);
618 +#endif             
619 +                   skb->protocol = eth_type_trans(skb, tunnel->dev);
620 +
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 */
625 +
626 +#ifdef GRE_DEBUG
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); 
630 +#endif
631 +                   memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
632 +                 }
633 +               else
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! */
638 @@ -539,7 +588,7 @@
639         return(0);
640  }
641  
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)
644  {
645         struct ip_tunnel *tunnel = netdev_priv(dev);
646         struct net_device_stats *stats = &tunnel->dev->stats;
647 @@ -799,7 +848,15 @@
648                         tdev = rt->u.dst.dev;
649                         ip_rt_put(rt);
650                 }
651 -               dev->flags |= IFF_POINTOPOINT;
652 +               if (tunnel->parms.proto_type == ETH_P_ETH)
653 +               {
654 +                   dev->flags |= IFF_BROADCAST;
655 +               }
656 +               else
657 +               {
658 +                       dev->flags |= IFF_POINTOPOINT;
659 +               }
660 +
661         }
662  
663         if (!tdev && tunnel->parms.link)
664 @@ -822,10 +879,235 @@
665         }
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;
670 +
671         tunnel->hlen = addend;
672  
673  }
674  
675 +static int ipgre_eth_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
676 +{
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;
681 +       u8     tos;
682 +       __be16 df;
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 */
689 +       int    mtu;
690 +
691 +#ifdef GRE_DEBUG
692 +       printk(KERN_ALERT "gre.c:972 Starting xmit\n");
693 +#endif
694 +
695 +       if (tunnel->recursion++) {
696 +               stats->collisions++;
697 +               goto tx_error;
698 +       }
699 +
700 +       /* Need valid non-multicast daddr.  */
701 +       if (tiph->daddr == 0 || MULTICAST(tiph->daddr))
702 +               goto tx_error;
703 +
704 +       tos = tiph->tos;
705 +       if (tos&1) {
706 +               if (skb->protocol == htons(ETH_P_IP))
707 +                       tos = old_iph->tos;
708 +               tos &= ~1;
709 +       }
710 +#ifdef GRE_DEBUG
711 +       printk(KERN_ALERT "gre.c:991 Passed tos assignment.\n");
712 +#endif
713 +
714 +
715 +       {
716 +               struct flowi fl = { .fl_net = &init_net,
717 +                                   .oif = tunnel->parms.link,
718 +                                   .nl_u = { .ip4_u =
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;
726 +               }
727 +       }
728 +       tdev = rt->u.dst.dev;
729 +#ifdef GRE_DEBUG
730 +       printk(KERN_ALERT "gre.c:1006 Passed the route retrieval\n");
731 +#endif
732 +       if (tdev == dev) {
733 +               ip_rt_put(rt);
734 +               stats->collisions++;
735 +               goto tx_error;
736 +       }
737 +#ifdef GRE_DEBUG
738 +       printk(KERN_ALERT "gre.c:1018 Passed tdev collision check.\n");
739 +#endif
740 +
741 +       /* Check MTU stuff if kernel panic */
742 +       df = tiph->frag_off;
743 +       if (df)
744 +               mtu = dst_mtu(&rt->u.dst) - tunnel->hlen;
745 +       else
746 +               mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
747 +/*
748 +       if (skb->dst)
749 +               skb->dst->ops->update_pmtu(skb->dst, mtu);
750 +        XXX */
751 +#ifdef GRE_DEBUG
752 +       printk(KERN_ALERT "gre.c:1032 Passed the pmtu setting.\n");
753 +#endif
754 +
755 +       if (skb->protocol == htons(ETH_P_IP)) {
756 +               df |= (old_iph->frag_off&htons(IP_DF));
757 +
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));
761 +                       ip_rt_put(rt);
762 +                       goto tx_error;
763 +               }
764 +       }
765 +#ifdef CONFIG_IPV6
766 +       else if (skb->protocol == htons(ETH_P_IPV6)) {
767 +               struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
768 +
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;
773 +                       }
774 +               }
775 +
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);
779 +                       ip_rt_put(rt);
780 +                       goto tx_error;
781 +               }
782 +       }
783 +#endif
784 +#ifdef GRE_DEBUG
785 +       printk(KERN_ALERT "gre.c:1065 Passed the fragmentation check.\n");
786 +#endif
787 +
788 +       if (tunnel->err_count > 0) {
789 +               if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
790 +                       tunnel->err_count--;
791 +                       dst_link_failure(skb);
792 +               } else
793 +                       tunnel->err_count = 0;
794 +       }
795 +
796 +       max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen;
797 +
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);
800 +               if (!new_skb) {
801 +                       ip_rt_put(rt);
802 +                       stats->tx_dropped++;
803 +                       dev_kfree_skb(skb);
804 +                       tunnel->recursion--;
805 +                       return 0;
806 +               }
807 +               if (skb->sk)
808 +                       skb_set_owner_w(new_skb, skb->sk);
809 +               dev_kfree_skb(skb);
810 +               skb = new_skb;
811 +               old_iph = ip_hdr(skb);
812 +       }
813 +#ifdef GRE_DEBUG
814 +       printk(KERN_ALERT "gre.c:1094 Passed the headroom calculation\n");
815 +#endif
816 +
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;
823 +
824 +       /*
825 +        *      Push down and install the etherip header.
826 +        */
827 +
828 +       iph                     =       ip_hdr(skb);
829 +       iph->version            =       4;
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;
836 +
837 +/*     ethiph->version         =       htons(ETHERIP_VERSION); */
838 +#ifdef GRE_DEBUG
839 +       printk(KERN_ALERT "gre.c:1121 Passed outer IP header construction.\n");
840 +#endif
841 +
842 +       if ((iph->ttl = tiph->ttl) == 0) {
843 +               if (skb->protocol == htons(ETH_P_IP))
844 +                       iph->ttl = old_iph->ttl;
845 +#ifdef CONFIG_IPV6
846 +               else if (skb->protocol == htons(ETH_P_IPV6))
847 +                       iph->ttl = ((struct ipv6hdr*)old_iph)->hop_limit;
848 +#endif
849 +               else
850 +                       iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
851 +       }
852 +#ifdef GRE_DEBUG
853 +       printk(KERN_ALERT "gre.c:1006 Passed the TTL check.\n");
854 +#endif
855 +
856 +       ((__be16*)(iph+1))[0] = tunnel->parms.o_flags;
857 +       ((__be16*)(iph+1))[1] = htons(tunnel->parms.proto_type);
858 +
859 +       if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
860 +               __be32 *ptr = (__be32*)(((u8*)iph) + tunnel->hlen - 4);
861 +
862 +               if (tunnel->parms.o_flags&GRE_SEQ) {
863 +                       ++tunnel->o_seqno;
864 +                       *ptr = htonl(tunnel->o_seqno);
865 +                       ptr--;
866 +               }
867 +               if (tunnel->parms.o_flags&GRE_KEY) {
868 +                       *ptr = tunnel->parms.o_key;
869 +                       ptr--;
870 +               }
871 +               if (tunnel->parms.o_flags&GRE_CSUM) {
872 +                       *ptr = 0;
873 +                       *(__sum16*)ptr = ip_compute_csum((void*)(iph+1), skb->len - sizeof(struct iphdr));
874 +               }
875 +       }
876 +#ifdef GRE_DEBUG
877 +       printk(KERN_ALERT "gre.c:1006 Passed the tunnel transmit.\n");
878 +#endif
879 +
880 +       nf_reset(skb);
881 +
882 +       IPTUNNEL_XMIT();
883 +       tunnel->recursion--;
884 +       return 0;
885 +
886 +tx_error_icmp:
887 +       dst_link_failure(skb);
888 +
889 +tx_error:
890 +       stats->tx_errors++;
891 +       dev_kfree_skb(skb);
892 +       tunnel->recursion--;
893 +       return 0;
894 +}
895 +
896 +
897  static int
898  ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
899  {
900 @@ -835,6 +1117,8 @@
901         struct net *net = dev_net(dev);
902         struct ipgre_net *ign = net_generic(net, ipgre_net_id);
903  
904 +        printk(KERN_ALERT "1174 GRE: entering gre ioctl. command is: %d\n", cmd);
905 +
906         switch (cmd) {
907         case SIOCGETTUNNEL:
908                 t = NULL;
909 @@ -876,6 +1160,7 @@
910                         p.o_key = 0;
911  
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);
914  
915                 if (dev != ign->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
916                         if (t != NULL) {
917 @@ -892,6 +1177,12 @@
918                                         nflags = IFF_BROADCAST;
919                                 else if (p.iph.daddr)
920                                         nflags = IFF_POINTOPOINT;
921 +                               
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;
927  
928                                 if ((dev->flags^nflags)&(IFF_POINTOPOINT|IFF_BROADCAST)) {
929                                         err = -EINVAL;
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);
941 +                               }
942 +
943                                 ipgre_tunnel_link(ign, t);
944                                 netdev_state_change(dev);
945                         }
946 @@ -1076,11 +1372,11 @@
947  
948  #endif
949  
950 -static void ipgre_tunnel_setup(struct net_device *dev)
951 +static void ipgre_ip_tunnel_setup(struct net_device *dev)
952  {
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;
959  
960 @@ -1093,6 +1389,35 @@
961         dev->features           |= NETIF_F_NETNS_LOCAL;
962  }
963  
964 +/* Tunnel setup for ipgre_eth */
965 +static void ipgre_eth_tunnel_setup(struct net_device *dev)
966 +{
967 +       SET_MODULE_OWNER(dev);
968 +
969 +       // Set default values for Ethernet device
970 +       ether_setup(dev);
971 +
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;
978 +
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;
982 +       dev->iflink             = 0;
983 +
984 +       random_ether_addr(dev->dev_addr);
985 +
986 +#ifdef GRE_DEBUG
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]); }
989 +#endif 
990 +}
991 +
992 +
993  static int ipgre_tunnel_init(struct net_device *dev)
994  {
995         struct ip_tunnel *tunnel;
996 @@ -1104,8 +1429,10 @@
997         tunnel->dev = dev;
998         strcpy(tunnel->parms.name, dev->name);
999  
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);
1005 +       } 
1006  
1007         ipgre_tunnel_bind_dev(dev);
1008  
1009 @@ -1181,7 +1508,7 @@
1010                 goto err_assign;
1011  
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) {
1016                 err = -ENOMEM;
1017                 goto err_alloc_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
1020 @@ -2,6 +2,7 @@
1021  # Makefile for the Linux network (ethercard) device drivers.
1022  #
1023  
1024 +obj-m +=gre.o
1025  obj-$(CONFIG_E1000) += e1000/
1026  obj-$(CONFIG_E1000E) += e1000e/
1027  obj-$(CONFIG_IBM_NEW_EMAC) += ibm_newemac/