1 diff -Nurp linux-2.6.22-592/include/linux/if_ether.h linux-2.6.22-593/include/linux/if_ether.h
2 --- linux-2.6.22-592/include/linux/if_ether.h 2007-07-08 19:32:17.000000000 -0400
3 +++ linux-2.6.22-593/include/linux/if_ether.h 2008-02-11 14:01:45.000000000 -0500
5 #define ETH_P_DIAG 0x6005 /* DEC Diagnostics */
6 #define ETH_P_CUST 0x6006 /* DEC Customer use */
7 #define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */
8 +#define ETH_P_ETH 0x6558 /* Ethernet encapsulation (GRE) */
9 #define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */
10 #define ETH_P_ATALK 0x809B /* Appletalk DDP */
11 #define ETH_P_AARP 0x80F3 /* Appletalk AARP */
12 diff -Nurp linux-2.6.22-592/net/ethernet/gre.c linux-2.6.22-593/net/ethernet/gre.c
13 --- linux-2.6.22-592/net/ethernet/gre.c 1969-12-31 19:00:00.000000000 -0500
14 +++ linux-2.6.22-593/net/ethernet/gre.c 2008-02-11 13:43:02.000000000 -0500
17 + * Linux NET3: GRE over IP protocol decoder.
19 + * Authors: Alexey Kuznetsov (kuznet@ms2.inr.ac.ru)
21 + * This program is free software; you can redistribute it and/or
22 + * modify it under the terms of the GNU General Public License
23 + * as published by the Free Software Foundation; either version
24 + * 2 of the License, or (at your option) any later version.
28 +#include <linux/capability.h>
29 +#include <linux/module.h>
30 +#include <linux/types.h>
31 +#include <linux/sched.h>
32 +#include <linux/kernel.h>
33 +#include <asm/uaccess.h>
34 +#include <linux/skbuff.h>
35 +#include <linux/netdevice.h>
36 +#include <linux/in.h>
37 +#include <linux/tcp.h>
38 +#include <linux/udp.h>
39 +#include <linux/if_arp.h>
40 +#include <linux/mroute.h>
41 +#include <linux/init.h>
42 +#include <linux/in6.h>
43 +#include <linux/inetdevice.h>
44 +#include <linux/etherdevice.h> /**XXX added XXX */
45 +#include <linux/igmp.h>
46 +#include <linux/netfilter_ipv4.h>
47 +#include <linux/if_ether.h>
49 +#include <net/sock.h>
51 +#include <net/icmp.h>
52 +#include <net/protocol.h>
53 +#include <net/ipip.h>
55 +#include <net/checksum.h>
56 +#include <net/dsfield.h>
57 +#include <net/inet_ecn.h>
58 +#include <net/xfrm.h>
61 +#include <net/ipv6.h>
62 +#include <net/ip6_fib.h>
63 +#include <net/ip6_route.h>
66 +//#define GRE_DEBUG 1
69 + Problems & solutions
70 + --------------------
72 + 1. The most important issue is detecting local dead loops.
73 + They would cause complete host lockup in transmit, which
74 + would be "resolved" by stack overflow or, if queueing is enabled,
75 + with infinite looping in net_bh.
77 + We cannot track such dead loops during route installation,
78 + it is infeasible task. The most general solutions would be
79 + to keep skb->encapsulation counter (sort of local ttl),
80 + and silently drop packet when it expires. It is the best
81 + solution, but it supposes maintaing new variable in ALL
82 + skb, even if no tunneling is used.
84 + Current solution: t->recursion lock breaks dead loops. It looks
85 + like dev->tbusy flag, but I preferred new variable, because
86 + the semantics is different. One day, when hard_start_xmit
87 + will be multithreaded we will have to use skb->encapsulation.
91 + 2. Networking dead loops would not kill routers, but would really
92 + kill network. IP hop limit plays role of "t->recursion" in this case,
93 + if we copy it from packet being encapsulated to upper header.
94 + It is very good solution, but it introduces two problems:
96 + - Routing protocols, using packets with ttl=1 (OSPF, RIP2),
97 + do not work over tunnels.
98 + - traceroute does not work. I planned to relay ICMP from tunnel,
99 + so that this problem would be solved and traceroute output
100 + would even more informative. This idea appeared to be wrong:
101 + only Linux complies to rfc1812 now (yes, guys, Linux is the only
102 + true router now :-)), all routers (at least, in neighbourhood of mine)
103 + return only 8 bytes of payload. It is the end.
105 + Hence, if we want that OSPF worked or traceroute said something reasonable,
106 + we should search for another solution.
108 + One of them is to parse packet trying to detect inner encapsulation
109 + made by our node. It is difficult or even impossible, especially,
110 + taking into account fragmentation. TO be short, tt is not solution at all.
112 + Current solution: The solution was UNEXPECTEDLY SIMPLE.
113 + We force DF flag on tunnels with preconfigured hop limit,
114 + that is ALL. :-) Well, it does not remove the problem completely,
115 + but exponential growth of network traffic is changed to linear
116 + (branches, that exceed pmtu are pruned) and tunnel mtu
117 + fastly degrades to value <68, where looping stops.
118 + Yes, it is not good if there exists a router in the loop,
119 + which does not force DF, even when encapsulating packets have DF set.
120 + But it is not our problem! Nobody could accuse us, we made
121 + all that we could make. Even if it is your gated who injected
122 + fatal route to network, even if it were you who configured
123 + fatal static route: you are innocent. :-)
127 + 3. Really, ipv4/ipip.c, ipv4/ip_gre.c and ipv6/sit.c contain
128 + practically identical code. It would be good to glue them
129 + together, but it is not very evident, how to make them modular.
130 + sit is integral part of IPv6, ipip and gre are naturally modular.
131 + We could extract common parts (hash table, ioctl etc)
132 + to a separate module (ip_tunnel.c).
137 +static int ipgre_tunnel_init(struct net_device *dev);
138 +static void ipgre_ip_tunnel_setup(struct net_device *dev);
139 +static void ipgre_eth_tunnel_setup(struct net_device *dev);
141 +/* Fallback tunnel: no source, no destination, no key, no options */
143 +static int ipgre_fb_tunnel_init(struct net_device *dev);
145 +static struct net_device *ipgre_fb_tunnel_dev;
147 +/* Tunnel hash table */
157 + We require exact key match i.e. if a key is present in packet
158 + it will match only tunnel with the same key; if it is not present,
159 + it will match only keyless tunnel.
161 + All keysless packets, if not matched configured keyless tunnels
162 + will match fallback tunnel.
165 +#define HASH_SIZE 16
166 +#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
168 +static struct ip_tunnel *tunnels[4][HASH_SIZE];
170 +#define tunnels_r_l (tunnels[3])
171 +#define tunnels_r (tunnels[2])
172 +#define tunnels_l (tunnels[1])
173 +#define tunnels_wc (tunnels[0])
175 +static DEFINE_RWLOCK(ipgre_lock);
177 +/* Given src, dst and key, find appropriate for input tunnel. */
179 +static struct ip_tunnel * ipgre_tunnel_lookup(__be32 remote, __be32 local, __be32 key)
181 + unsigned h0 = HASH(remote);
182 + unsigned h1 = HASH(key);
183 + struct ip_tunnel *t;
185 + for (t = tunnels_r_l[h0^h1]; t; t = t->next) {
186 + if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr) {
187 + if (t->parms.i_key == key && (t->dev->flags&IFF_UP))
191 + for (t = tunnels_r[h0^h1]; t; t = t->next) {
192 + if (remote == t->parms.iph.daddr) {
193 + if (t->parms.i_key == key && (t->dev->flags&IFF_UP))
197 + for (t = tunnels_l[h1]; t; t = t->next) {
198 + if (local == t->parms.iph.saddr ||
199 + (local == t->parms.iph.daddr && MULTICAST(local))) {
200 + if (t->parms.i_key == key && (t->dev->flags&IFF_UP))
204 + for (t = tunnels_wc[h1]; t; t = t->next) {
205 + if (t->parms.i_key == key && (t->dev->flags&IFF_UP))
209 + if (ipgre_fb_tunnel_dev->flags&IFF_UP)
210 + return netdev_priv(ipgre_fb_tunnel_dev);
214 +static struct ip_tunnel **ipgre_bucket(struct ip_tunnel *t)
216 + __be32 remote = t->parms.iph.daddr;
217 + __be32 local = t->parms.iph.saddr;
218 + __be32 key = t->parms.i_key;
219 + unsigned h = HASH(key);
224 + if (remote && !MULTICAST(remote)) {
229 + return &tunnels[prio][h];
232 +static void ipgre_tunnel_link(struct ip_tunnel *t)
234 + struct ip_tunnel **tp = ipgre_bucket(t);
237 + write_lock_bh(&ipgre_lock);
239 + write_unlock_bh(&ipgre_lock);
242 +static void ipgre_tunnel_unlink(struct ip_tunnel *t)
244 + struct ip_tunnel **tp;
246 + for (tp = ipgre_bucket(t); *tp; tp = &(*tp)->next) {
248 + write_lock_bh(&ipgre_lock);
250 + write_unlock_bh(&ipgre_lock);
256 +static struct ip_tunnel * ipgre_tunnel_locate(struct ip_tunnel_parm *parms, int create)
258 + __be32 remote = parms->iph.daddr;
259 + __be32 local = parms->iph.saddr;
260 + __be32 key = parms->i_key;
261 + __be16 proto = parms->proto_type;
262 + struct ip_tunnel *t, **tp, *nt;
263 + struct net_device *dev;
264 + unsigned h = HASH(key);
266 + char name[IFNAMSIZ];
270 + if (remote && !MULTICAST(remote)) {
274 + for (tp = &tunnels[prio][h]; (t = *tp) != NULL; tp = &t->next) {
275 + if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr) {
276 + if (key == t->parms.i_key)
283 + if (parms->name[0])
284 + strlcpy(name, parms->name, IFNAMSIZ);
287 + for (i=1; i<100; i++) {
288 + sprintf(name, "gre%d", i);
289 + if (__dev_get_by_name(init_net(), name) == NULL)
296 + /* Tunnel creation: check payload type and call appropriate
301 + dev = alloc_netdev(sizeof(*t), name, ipgre_ip_tunnel_setup);
304 + dev = alloc_netdev(sizeof(*t), name, ipgre_eth_tunnel_setup);
313 + dev->init = ipgre_tunnel_init;
314 + nt = netdev_priv(dev);
315 + nt->parms = *parms;
317 + if (register_netdevice(dev) < 0) {
323 + ipgre_tunnel_link(nt);
330 +static void ipgre_tunnel_uninit(struct net_device *dev)
332 + ipgre_tunnel_unlink(netdev_priv(dev));
337 +static void ipgre_err(struct sk_buff *skb, u32 info)
339 +#ifndef I_WISH_WORLD_WERE_PERFECT
341 +/* It is not :-( All the routers (except for Linux) return only
342 + 8 bytes of packet payload. It means, that precise relaying of
343 + ICMP in the real Internet is absolutely infeasible.
345 + Moreover, Cisco "wise men" put GRE key to the third word
346 + in GRE header. It makes impossible maintaining even soft state for keyed
347 + GRE tunnels with enabled checksum. Tell them "thank you".
349 + Well, I wonder, rfc1812 was written by Cisco employee,
350 + what the hell these idiots break standrads established
354 + struct iphdr *iph = (struct iphdr*)skb->data;
355 + __be16 *p = (__be16*)(skb->data+(iph->ihl<<2));
356 + int grehlen = (iph->ihl<<2) + 4;
357 + int type = skb->h.icmph->type;
358 + int code = skb->h.icmph->code;
359 + struct ip_tunnel *t;
363 + if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
364 + if (flags&(GRE_VERSION|GRE_ROUTING))
366 + if (flags&GRE_KEY) {
368 + if (flags&GRE_CSUM)
373 + /* If only 8 bytes returned, keyed message will be dropped here */
374 + if (skb_headlen(skb) < grehlen)
379 + case ICMP_PARAMETERPROB:
382 + case ICMP_DEST_UNREACH:
384 + case ICMP_SR_FAILED:
385 + case ICMP_PORT_UNREACH:
386 + /* Impossible event. */
388 + case ICMP_FRAG_NEEDED:
389 + /* Soft state for pmtu is maintained by IP core. */
392 + /* All others are translated to HOST_UNREACH.
393 + rfc2003 contains "deep thoughts" about NET_UNREACH,
394 + I believe they are just ether pollution. --ANK
399 + case ICMP_TIME_EXCEEDED:
400 + if (code != ICMP_EXC_TTL)
405 + read_lock(&ipgre_lock);
406 + t = ipgre_tunnel_lookup(iph->daddr, iph->saddr, (flags&GRE_KEY) ? *(((__be32*)p) + (grehlen>>2) - 1) : 0);
407 + if (t == NULL || t->parms.iph.daddr == 0 || MULTICAST(t->parms.iph.daddr))
410 + if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
413 + if (jiffies - t->err_time < IPTUNNEL_ERR_TIMEO)
417 + t->err_time = jiffies;
419 + read_unlock(&ipgre_lock);
422 + struct iphdr *iph = (struct iphdr*)dp;
423 + struct iphdr *eiph;
424 + __be16 *p = (__be16*)(dp+(iph->ihl<<2));
425 + int type = skb->h.icmph->type;
426 + int code = skb->h.icmph->code;
429 + __be32 rel_info = 0;
432 + int grehlen = (iph->ihl<<2) + 4;
433 + struct sk_buff *skb2;
437 + if (!net_eq(skb->dev->nd_net, init_net()))
440 + if (p[1] != htons(ETH_P_IP))
444 + if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
445 + if (flags&(GRE_VERSION|GRE_ROUTING))
447 + if (flags&GRE_CSUM)
454 + if (len < grehlen + sizeof(struct iphdr))
456 + eiph = (struct iphdr*)(dp + grehlen);
461 + case ICMP_PARAMETERPROB:
462 + n = ntohl(skb->h.icmph->un.gateway) >> 24;
463 + if (n < (iph->ihl<<2))
466 + /* So... This guy found something strange INSIDE encapsulated
467 + packet. Well, he is fool, but what can we do ?
469 + rel_type = ICMP_PARAMETERPROB;
471 + rel_info = htonl(n << 24);
474 + case ICMP_DEST_UNREACH:
476 + case ICMP_SR_FAILED:
477 + case ICMP_PORT_UNREACH:
478 + /* Impossible event. */
480 + case ICMP_FRAG_NEEDED:
481 + /* And it is the only really necessary thing :-) */
482 + n = ntohs(skb->h.icmph->un.frag.mtu);
483 + if (n < grehlen+68)
486 + /* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */
487 + if (n > ntohs(eiph->tot_len))
489 + rel_info = htonl(n);
492 + /* All others are translated to HOST_UNREACH.
493 + rfc2003 contains "deep thoughts" about NET_UNREACH,
494 + I believe, it is just ether pollution. --ANK
496 + rel_type = ICMP_DEST_UNREACH;
497 + rel_code = ICMP_HOST_UNREACH;
501 + case ICMP_TIME_EXCEEDED:
502 + if (code != ICMP_EXC_TTL)
507 + /* Prepare fake skb to feed it to icmp_send */
508 + skb2 = skb_clone(skb, GFP_ATOMIC);
511 + dst_release(skb2->dst);
513 + skb_pull(skb2, skb->data - (u8*)eiph);
514 + skb2->nh.raw = skb2->data;
516 + /* Try to guess incoming interface */
517 + memset(&fl, 0, sizeof(fl));
518 + fl.fl_net = init_net();
519 + fl.fl4_dst = eiph->saddr;
520 + fl.fl4_tos = RT_TOS(eiph->tos);
521 + fl.proto = IPPROTO_GRE;
522 + if (ip_route_output_key(&rt, &fl)) {
526 + skb2->dev = rt->u.dst.dev;
528 + /* route "incoming" packet */
529 + if (rt->rt_flags&RTCF_LOCAL) {
532 + fl.fl4_dst = eiph->daddr;
533 + fl.fl4_src = eiph->saddr;
534 + fl.fl4_tos = eiph->tos;
535 + if (ip_route_output_key(&rt, &fl) ||
536 + rt->u.dst.dev->type != ARPHRD_IPGRE) {
543 + if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos, skb2->dev) ||
544 + skb2->dst->dev->type != ARPHRD_IPGRE) {
550 + /* change mtu on this route */
551 + if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) {
552 + if (n > dst_mtu(skb2->dst)) {
556 + skb2->dst->ops->update_pmtu(skb2->dst, n);
557 + } else if (type == ICMP_TIME_EXCEEDED) {
558 + struct ip_tunnel *t = netdev_priv(skb2->dev);
559 + if (t->parms.iph.ttl) {
560 + rel_type = ICMP_DEST_UNREACH;
561 + rel_code = ICMP_HOST_UNREACH;
565 + icmp_send(skb2, rel_type, rel_code, rel_info);
570 +static inline void ipgre_ecn_decapsulate(struct iphdr *iph, struct sk_buff *skb)
572 + if (INET_ECN_is_ce(iph->tos)) {
573 + if (skb->protocol == htons(ETH_P_IP)) {
574 + IP_ECN_set_ce(skb->nh.iph);
575 + } else if (skb->protocol == htons(ETH_P_IPV6)) {
576 + IP6_ECN_set_ce(skb->nh.ipv6h);
582 +ipgre_ecn_encapsulate(u8 tos, struct iphdr *old_iph, struct sk_buff *skb)
585 + if (skb->protocol == htons(ETH_P_IP))
586 + inner = old_iph->tos;
587 + else if (skb->protocol == htons(ETH_P_IPV6))
588 + inner = ipv6_get_dsfield((struct ipv6hdr *)old_iph);
589 + return INET_ECN_encapsulate(tos, inner);
592 +static int ipgre_rcv(struct sk_buff *skb)
600 + struct ip_tunnel *tunnel;
604 + if (!net_eq(skb->dev->nd_net, init_net())) {
608 + if (!pskb_may_pull(skb, 16))
613 + flags = *(__be16*)h;
616 + printk(KERN_DEBUG "gre.c [601] src:%x dst:%x proto:%d %x", iph->saddr, iph->daddr, iph->protocol, skb->data);
618 + proto = ntohs(*(__be16*)(h+2)); /* XXX added XXX */
620 + if (flags&(GRE_CSUM|GRE_KEY|GRE_ROUTING|GRE_SEQ|GRE_VERSION)) {
621 + /* - Version must be 0.
622 + - We do not support routing headers.
624 + if (flags&(GRE_VERSION|GRE_ROUTING))
627 + if (flags&GRE_CSUM) {
628 + switch (skb->ip_summed) {
629 + case CHECKSUM_COMPLETE:
630 + csum = csum_fold(skb->csum);
634 + case CHECKSUM_NONE:
636 + csum = __skb_checksum_complete(skb);
637 + skb->ip_summed = CHECKSUM_COMPLETE;
641 + if (flags&GRE_KEY) {
642 + key = *(__be32*)(h + offset);
645 + if (flags&GRE_SEQ) {
646 + seqno = ntohl(*(__be32*)(h + offset));
651 + read_lock(&ipgre_lock);
652 + if ((tunnel = ipgre_tunnel_lookup(iph->saddr, iph->daddr, key)) != NULL) {
653 + secpath_reset(skb);
655 + skb->protocol = *(__be16*)(h + 2);
656 + /* WCCP version 1 and 2 protocol decoding.
657 + * - Change protocol to IP
658 + * - When dealing with WCCPv2, Skip extra 4 bytes in GRE header
661 + skb->protocol == htons(ETH_P_WCCP)) {
662 + skb->protocol = htons(ETH_P_IP);
663 + if ((*(h + offset) & 0xF0) != 0x40)
667 + skb->mac.raw = skb->nh.raw;
668 + skb->nh.raw = __pskb_pull(skb, offset);
669 + skb_postpull_rcsum(skb, skb->h.raw, offset);
670 + if(proto == ETH_P_ETH)
673 + unsigned char* tmp_hdr = skb->data;
674 + printk(KERN_DEBUG "gre.c [658] %x %x %x %x %x %x\tskb %x\n", tmp_hdr[0], tmp_hdr[1], tmp_hdr[2], tmp_hdr[3], tmp_hdr[4], tmp_hdr[5], skb->data);
676 + skb->protocol = eth_type_trans(skb, tunnel->dev);
678 + /* XXX added these lines to make arp work? XXX */
679 + /*skb->mac.raw = skb->data;*/
680 + skb->nh.raw = skb->nh.raw + ETH_HLEN;
681 + /* XXX added these lines to make arp work? XXX */
684 + tmp_hdr = skb->data;
685 + printk(KERN_DEBUG "gre.c [669] %x %x %x %x %x %x\tskb %x\n", tmp_hdr[0], tmp_hdr[1], tmp_hdr[2], tmp_hdr[3], tmp_hdr[4], tmp_hdr[5], skb->data);
686 + printk(KERN_ALERT "gre.c [671] received ethernet on gre %x %x\n",skb->protocol, ((skb->nh).iph)->protocol);
688 + memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
691 + skb->pkt_type = PACKET_HOST;
692 +#ifdef CONFIG_NET_IPGRE_BROADCAST
693 + if (MULTICAST(iph->daddr)) {
694 + /* Looped back packet, drop it! */
695 + if (((struct rtable*)skb->dst)->fl.iif == 0)
697 + tunnel->stat.multicast++;
698 + skb->pkt_type = PACKET_BROADCAST;
702 + if (((flags&GRE_CSUM) && csum) ||
703 + (!(flags&GRE_CSUM) && tunnel->parms.i_flags&GRE_CSUM)) {
704 + tunnel->stat.rx_crc_errors++;
705 + tunnel->stat.rx_errors++;
708 + if (tunnel->parms.i_flags&GRE_SEQ) {
709 + if (!(flags&GRE_SEQ) ||
710 + (tunnel->i_seqno && (s32)(seqno - tunnel->i_seqno) < 0)) {
711 + tunnel->stat.rx_fifo_errors++;
712 + tunnel->stat.rx_errors++;
715 + tunnel->i_seqno = seqno + 1;
717 + tunnel->stat.rx_packets++;
718 + tunnel->stat.rx_bytes += skb->len;
719 + skb->dev = tunnel->dev;
720 + dst_release(skb->dst);
723 + ipgre_ecn_decapsulate(iph, skb);
725 + read_unlock(&ipgre_lock);
728 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
731 + read_unlock(&ipgre_lock);
737 +static int ipgre_ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
739 + struct ip_tunnel *tunnel = netdev_priv(dev);
740 + struct net_device_stats *stats = &tunnel->stat;
741 + struct iphdr *old_iph = skb->nh.iph;
742 + struct iphdr *tiph;
745 + struct rtable *rt; /* Route to the other host */
746 + struct net_device *tdev; /* Device to other host */
747 + struct iphdr *iph; /* Our new IP header */
748 + int max_headroom; /* The extra header space needed */
753 + if (tunnel->recursion++) {
754 + tunnel->stat.collisions++;
758 + if (dev->hard_header) {
760 + tiph = (struct iphdr*)skb->data;
762 + gre_hlen = tunnel->hlen;
763 + tiph = &tunnel->parms.iph;
766 + if ((dst = tiph->daddr) == 0) {
769 + if (skb->dst == NULL) {
770 + tunnel->stat.tx_fifo_errors++;
774 + if (skb->protocol == htons(ETH_P_IP)) {
775 + rt = (struct rtable*)skb->dst;
776 + if ((dst = rt->rt_gateway) == 0)
777 + goto tx_error_icmp;
780 + else if (skb->protocol == htons(ETH_P_IPV6)) {
781 + struct in6_addr *addr6;
783 + struct neighbour *neigh = skb->dst->neighbour;
788 + addr6 = (struct in6_addr*)&neigh->primary_key;
789 + addr_type = ipv6_addr_type(addr6);
791 + if (addr_type == IPV6_ADDR_ANY) {
792 + addr6 = &skb->nh.ipv6h->daddr;
793 + addr_type = ipv6_addr_type(addr6);
796 + if ((addr_type & IPV6_ADDR_COMPATv4) == 0)
797 + goto tx_error_icmp;
799 + dst = addr6->s6_addr32[3];
808 + if (skb->protocol == htons(ETH_P_IP))
809 + tos = old_iph->tos;
814 + struct flowi fl = { .fl_net = init_net(),
815 + .oif = tunnel->parms.link,
818 + .saddr = tiph->saddr,
819 + .tos = RT_TOS(tos) } },
820 + .proto = IPPROTO_GRE };
821 + if (ip_route_output_key(&rt, &fl)) {
822 + tunnel->stat.tx_carrier_errors++;
826 + tdev = rt->u.dst.dev;
831 + tunnel->stat.collisions++;
835 + df = tiph->frag_off;
837 + mtu = dst_mtu(&rt->u.dst) - tunnel->hlen;
839 + mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
842 + skb->dst->ops->update_pmtu(skb->dst, mtu);
844 + if (skb->protocol == htons(ETH_P_IP)) {
845 + df |= (old_iph->frag_off&htons(IP_DF));
847 + if ((old_iph->frag_off&htons(IP_DF)) &&
848 + mtu < ntohs(old_iph->tot_len)) {
849 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
855 + else if (skb->protocol == htons(ETH_P_IPV6)) {
856 + struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
858 + if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) {
859 + if ((tunnel->parms.iph.daddr && !MULTICAST(tunnel->parms.iph.daddr)) ||
860 + rt6->rt6i_dst.plen == 128) {
861 + rt6->rt6i_flags |= RTF_MODIFIED;
862 + skb->dst->metrics[RTAX_MTU-1] = mtu;
866 + if (mtu >= IPV6_MIN_MTU && mtu < skb->len - tunnel->hlen + gre_hlen) {
867 + icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
874 + if (tunnel->err_count > 0) {
875 + if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
876 + tunnel->err_count--;
878 + dst_link_failure(skb);
880 + tunnel->err_count = 0;
883 + max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen;
885 + if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
886 + struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
889 + stats->tx_dropped++;
890 + dev_kfree_skb(skb);
891 + tunnel->recursion--;
895 + skb_set_owner_w(new_skb, skb->sk);
896 + dev_kfree_skb(skb);
898 + old_iph = skb->nh.iph;
901 + skb->h.raw = skb->nh.raw;
902 + skb->nh.raw = skb_push(skb, gre_hlen);
903 + memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
904 + IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
906 + dst_release(skb->dst);
907 + skb->dst = &rt->u.dst;
910 + * Push down and install the IPIP header.
915 + iph->ihl = sizeof(struct iphdr) >> 2;
916 + iph->frag_off = df;
917 + iph->protocol = IPPROTO_GRE;
918 + iph->tos = ipgre_ecn_encapsulate(tos, old_iph, skb);
919 + iph->daddr = rt->rt_dst;
920 + iph->saddr = rt->rt_src;
922 + if ((iph->ttl = tiph->ttl) == 0) {
923 + if (skb->protocol == htons(ETH_P_IP))
924 + iph->ttl = old_iph->ttl;
926 + else if (skb->protocol == htons(ETH_P_IPV6))
927 + iph->ttl = ((struct ipv6hdr*)old_iph)->hop_limit;
930 + iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
933 + ((__be16*)(iph+1))[0] = tunnel->parms.o_flags;
934 + ((__be16*)(iph+1))[1] = skb->protocol;
936 + if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
937 + __be32 *ptr = (__be32*)(((u8*)iph) + tunnel->hlen - 4);
939 + if (tunnel->parms.o_flags&GRE_SEQ) {
941 + *ptr = htonl(tunnel->o_seqno);
944 + if (tunnel->parms.o_flags&GRE_KEY) {
945 + *ptr = tunnel->parms.o_key;
948 + if (tunnel->parms.o_flags&GRE_CSUM) {
950 + *(__sum16*)ptr = ip_compute_csum((void*)(iph+1), skb->len - sizeof(struct iphdr));
957 + tunnel->recursion--;
961 + dst_link_failure(skb);
964 + stats->tx_errors++;
965 + dev_kfree_skb(skb);
966 + tunnel->recursion--;
970 +static int ipgre_eth_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
972 + struct ip_tunnel *tunnel = netdev_priv(dev);
973 + struct net_device_stats *stats = &tunnel->stat;
974 + struct iphdr *old_iph = skb->nh.iph;
975 + struct iphdr *tiph = &tunnel->parms.iph;
978 + struct rtable *rt; /* Route to the other host */
979 + struct net_device *tdev; /* Device to other host */
980 + int gre_hlen = tunnel->hlen; /* XXX changed XXX*/
981 + //struct etheriphdr *ethiph;
982 + struct iphdr *iph; /* Our new IP header */
983 + int max_headroom; /* The extra header space needed */
987 + printk(KERN_ALERT "gre.c:972 Starting xmit\n");
990 + if (tunnel->recursion++) {
991 + stats->collisions++;
995 + /* Need valid non-multicast daddr. */
996 + if (tiph->daddr == 0 || MULTICAST(tiph->daddr))
1001 + if (skb->protocol == htons(ETH_P_IP))
1002 + tos = old_iph->tos;
1006 + printk(KERN_ALERT "gre.c:991 Passed tos assignment.\n");
1011 + struct flowi fl = { .fl_net = init_net(),
1012 + .oif = tunnel->parms.link,
1013 + .nl_u = { .ip4_u =
1014 + { .daddr = tiph->daddr,
1015 + .saddr = tiph->saddr,
1016 + .tos = RT_TOS(tos) } },
1017 + .proto = IPPROTO_GRE };
1018 + if (ip_route_output_key(&rt, &fl)) {
1019 + stats->tx_carrier_errors++;
1020 + goto tx_error_icmp;
1023 + tdev = rt->u.dst.dev;
1025 + printk(KERN_ALERT "gre.c:1006 Passed the route retrieval\n");
1027 + if (tdev == dev) {
1029 + stats->collisions++;
1033 + printk(KERN_ALERT "gre.c:1018 Passed tdev collision check.\n");
1036 + /* Check MTU stuff if kernel panic */
1037 + df = tiph->frag_off;
1039 + mtu = dst_mtu(&rt->u.dst) - tunnel->hlen;
1041 + mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
1044 + skb->dst->ops->update_pmtu(skb->dst, mtu);
1047 + printk(KERN_ALERT "gre.c:1032 Passed the pmtu setting.\n");
1050 + if (skb->protocol == htons(ETH_P_IP)) {
1051 + df |= (old_iph->frag_off&htons(IP_DF));
1053 + if ((old_iph->frag_off & htons(IP_DF)) &&
1054 + mtu < ntohs(old_iph->tot_len)) {
1055 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
1061 + else if (skb->protocol == htons(ETH_P_IPV6)) {
1062 + struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
1064 + if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) {
1065 + if (tiph->daddr || rt6->rt6i_dst.plen == 128) {
1066 + rt6->rt6i_flags |= RTF_MODIFIED;
1067 + skb->dst->metrics[RTAX_MTU-1] = mtu;
1071 + /* @@@ Is this correct? */
1072 + if (mtu >= IPV6_MIN_MTU && mtu < skb->len - tunnel->hlen + gre_hlen) {
1073 + icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
1080 + printk(KERN_ALERT "gre.c:1065 Passed the fragmentation check.\n");
1083 + if (tunnel->err_count > 0) {
1084 + if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
1085 + tunnel->err_count--;
1086 + dst_link_failure(skb);
1088 + tunnel->err_count = 0;
1091 + max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen;
1093 + if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
1094 + struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
1097 + stats->tx_dropped++;
1098 + dev_kfree_skb(skb);
1099 + tunnel->recursion--;
1103 + skb_set_owner_w(new_skb, skb->sk);
1104 + dev_kfree_skb(skb);
1106 + old_iph = skb->nh.iph;
1109 + printk(KERN_ALERT "gre.c:1094 Passed the headroom calculation\n");
1113 +/* XXX skb->h.raw = skb->nh.raw; XXX */
1114 + skb->h.raw = skb->mac.raw;
1116 + skb->nh.raw = skb_push(skb, gre_hlen);
1117 + memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1118 + dst_release(skb->dst);
1119 + skb->dst = &rt->u.dst;
1122 + * Push down and install the etherip header.
1125 + iph = skb->nh.iph;
1127 + iph->ihl = sizeof(struct iphdr) >> 2;
1128 + iph->frag_off = df;
1129 + iph->protocol = IPPROTO_GRE;
1130 + iph->tos = ipgre_ecn_encapsulate(tos, old_iph, skb);
1131 + iph->daddr = rt->rt_dst;
1132 + iph->saddr = rt->rt_src;
1134 +/* ethiph->version = htons(ETHERIP_VERSION); */
1136 + printk(KERN_ALERT "gre.c:1121 Passed outer IP header construction.\n");
1139 + if ((iph->ttl = tiph->ttl) == 0) {
1140 + if (skb->protocol == htons(ETH_P_IP))
1141 + iph->ttl = old_iph->ttl;
1143 + else if (skb->protocol == htons(ETH_P_IPV6))
1144 + iph->ttl = ((struct ipv6hdr*)old_iph)->hop_limit;
1147 + iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
1150 + printk(KERN_ALERT "gre.c:1006 Passed the TTL check.\n");
1153 + ((__be16*)(iph+1))[0] = tunnel->parms.o_flags;
1154 + ((__be16*)(iph+1))[1] = htons(tunnel->parms.proto_type);
1156 + if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
1157 + __be32 *ptr = (__be32*)(((u8*)iph) + tunnel->hlen - 4);
1159 + if (tunnel->parms.o_flags&GRE_SEQ) {
1160 + ++tunnel->o_seqno;
1161 + *ptr = htonl(tunnel->o_seqno);
1164 + if (tunnel->parms.o_flags&GRE_KEY) {
1165 + *ptr = tunnel->parms.o_key;
1168 + if (tunnel->parms.o_flags&GRE_CSUM) {
1170 + *(__sum16*)ptr = ip_compute_csum((void*)(iph+1), skb->len - sizeof(struct iphdr));
1174 + printk(KERN_ALERT "gre.c:1006 Passed the tunnel transmit.\n");
1180 + tunnel->recursion--;
1184 + dst_link_failure(skb);
1187 + stats->tx_errors++;
1188 + dev_kfree_skb(skb);
1189 + tunnel->recursion--;
1195 +ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
1198 + struct ip_tunnel_parm p;
1199 + struct ip_tunnel *t;
1201 + printk(KERN_ALERT "1174 GRE: entering gre ioctl. command is: %d\n", cmd);
1204 + case SIOCGETTUNNEL:
1206 + if (dev == ipgre_fb_tunnel_dev) {
1207 + if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
1211 + t = ipgre_tunnel_locate(&p, 0);
1214 + t = netdev_priv(dev);
1215 + memcpy(&p, &t->parms, sizeof(p));
1216 + if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
1220 + case SIOCADDTUNNEL:
1221 + case SIOCCHGTUNNEL:
1223 + if (!capable(CAP_NET_ADMIN))
1227 + if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
1231 + if (p.iph.version != 4 || p.iph.protocol != IPPROTO_GRE ||
1232 + p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)) ||
1233 + ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING)))
1236 + p.iph.frag_off |= htons(IP_DF);
1238 + if (!(p.i_flags&GRE_KEY))
1240 + if (!(p.o_flags&GRE_KEY))
1243 + t = ipgre_tunnel_locate(&p, cmd == SIOCADDTUNNEL);
1244 + printk(KERN_ALERT "1174 GRE: proto %s %d\n", p.name, p.proto_type);
1245 + if (dev != ipgre_fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
1247 + if (t->dev != dev) {
1252 + unsigned nflags=0;
1254 + t = netdev_priv(dev);
1256 + if (MULTICAST(p.iph.daddr))
1257 + nflags = IFF_BROADCAST;
1258 + else if (p.iph.daddr)
1259 + nflags = IFF_POINTOPOINT;
1261 + /* XXX:Set back IFF_BROADCAST if
1262 + * transporting ethernet */
1263 + printk(KERN_ALERT "1193 GRE: proto %s %d\n", p.name, p.proto_type);
1264 + if (p.proto_type == ETH_P_ETH)
1265 + nflags = IFF_BROADCAST;
1267 + if ((dev->flags^nflags)&(IFF_POINTOPOINT|IFF_BROADCAST)) {
1271 + ipgre_tunnel_unlink(t);
1272 + t->parms.iph.saddr = p.iph.saddr;
1273 + t->parms.iph.daddr = p.iph.daddr;
1274 + t->parms.i_key = p.i_key;
1275 + t->parms.o_key = p.o_key;
1276 + /* XXX:Copy in the protocol field */
1277 + t->parms.proto_type = p.proto_type;
1278 + if (t->parms.proto_type != ETH_P_ETH)
1280 + memcpy(dev->dev_addr, &p.iph.saddr, 4);
1281 + memcpy(dev->broadcast, &p.iph.daddr, 4);
1283 + ipgre_tunnel_link(t);
1284 + netdev_state_change(dev);
1290 + if (cmd == SIOCCHGTUNNEL) {
1291 + t->parms.iph.ttl = p.iph.ttl;
1292 + t->parms.iph.tos = p.iph.tos;
1293 + t->parms.iph.frag_off = p.iph.frag_off;
1295 + if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
1298 + err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
1301 + case SIOCDELTUNNEL:
1303 + if (!capable(CAP_NET_ADMIN))
1306 + if (dev == ipgre_fb_tunnel_dev) {
1308 + if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
1311 + if ((t = ipgre_tunnel_locate(&p, 0)) == NULL)
1314 + if (t == netdev_priv(ipgre_fb_tunnel_dev))
1318 + err = unregister_netdevice(dev);
1329 +static struct net_device_stats *ipgre_tunnel_get_stats(struct net_device *dev)
1331 + return &(((struct ip_tunnel*)netdev_priv(dev))->stat);
1334 +static int ipgre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
1336 + struct ip_tunnel *tunnel = netdev_priv(dev);
1337 + if (new_mtu < 68 || new_mtu > 0xFFF8 - tunnel->hlen)
1339 + dev->mtu = new_mtu;
1343 +#ifdef CONFIG_NET_IPGRE_BROADCAST
1344 +/* Nice toy. Unfortunately, useless in real life :-)
1345 + It allows to construct virtual multiprotocol broadcast "LAN"
1346 + over the Internet, provided multicast routing is tuned.
1349 + I have no idea was this bicycle invented before me,
1350 + so that I had to set ARPHRD_IPGRE to a random value.
1351 + I have an impression, that Cisco could make something similar,
1352 + but this feature is apparently missing in IOS<=11.2(8).
1354 + I set up 10.66.66/24 and fec0:6666:6666::0/96 as virtual networks
1355 + with broadcast 224.66.66.66. If you have access to mbone, play with me :-)
1357 + ping -t 255 224.66.66.66
1359 + If nobody answers, mbone does not work.
1361 + ip tunnel add Universe mode gre remote 224.66.66.66 local <Your_real_addr> ttl 255
1362 + ip addr add 10.66.66.<somewhat>/24 dev Universe
1363 + ifconfig Universe up
1364 + ifconfig Universe add fe80::<Your_real_addr>/10
1365 + ifconfig Universe add fec0:6666:6666::<Your_real_addr>/96
1368 + ftp fec0:6666:6666::193.233.7.65
1373 +static int ipgre_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
1374 + void *daddr, void *saddr, unsigned len)
1376 + struct ip_tunnel *t = netdev_priv(dev);
1377 + struct iphdr *iph = (struct iphdr *)skb_push(skb, t->hlen);
1378 + __be16 *p = (__be16*)(iph+1);
1380 + memcpy(iph, &t->parms.iph, sizeof(struct iphdr));
1381 + p[0] = t->parms.o_flags;
1382 + p[1] = htons(type);
1385 + * Set the source hardware address.
1389 + memcpy(&iph->saddr, saddr, 4);
1392 + memcpy(&iph->daddr, daddr, 4);
1395 + if (iph->daddr && !MULTICAST(iph->daddr))
1401 +static int ipgre_open(struct net_device *dev)
1403 + struct ip_tunnel *t = netdev_priv(dev);
1405 + if (MULTICAST(t->parms.iph.daddr)) {
1406 + struct flowi fl = { .fl_net = init_net(),
1407 + .oif = t->parms.link,
1408 + .nl_u = { .ip4_u =
1409 + { .daddr = t->parms.iph.daddr,
1410 + .saddr = t->parms.iph.saddr,
1411 + .tos = RT_TOS(t->parms.iph.tos) } },
1412 + .proto = IPPROTO_GRE };
1413 + struct rtable *rt;
1414 + if (ip_route_output_key(&rt, &fl))
1415 + return -EADDRNOTAVAIL;
1416 + dev = rt->u.dst.dev;
1418 + if (__in_dev_get_rtnl(dev) == NULL)
1419 + return -EADDRNOTAVAIL;
1420 + t->mlink = dev->ifindex;
1421 + ip_mc_inc_group(__in_dev_get_rtnl(dev), t->parms.iph.daddr);
1426 +static int ipgre_close(struct net_device *dev)
1428 + struct ip_tunnel *t = netdev_priv(dev);
1429 + if (MULTICAST(t->parms.iph.daddr) && t->mlink) {
1430 + struct in_device *in_dev = inetdev_by_index(init_net(), t->mlink);
1432 + ip_mc_dec_group(in_dev, t->parms.iph.daddr);
1433 + in_dev_put(in_dev);
1441 +static void ipgre_ip_tunnel_setup(struct net_device *dev)
1443 + SET_MODULE_OWNER(dev);
1444 + dev->uninit = ipgre_tunnel_uninit;
1445 + dev->destructor = free_netdev;
1446 + dev->hard_start_xmit = ipgre_ip_tunnel_xmit;
1447 + dev->get_stats = ipgre_tunnel_get_stats;
1448 + dev->do_ioctl = ipgre_tunnel_ioctl;
1449 + dev->change_mtu = ipgre_tunnel_change_mtu;
1451 + dev->type = ARPHRD_IPGRE;
1452 + dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr) + 4;
1453 + dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 4;
1454 + dev->flags = IFF_NOARP;
1456 + dev->addr_len = 4;
1459 +/* Tunnel setup for ipgre_eth */
1460 +static void ipgre_eth_tunnel_setup(struct net_device *dev)
1462 + SET_MODULE_OWNER(dev);
1465 + dev->uninit = ipgre_tunnel_uninit;
1466 + dev->destructor = free_netdev;
1467 + dev->hard_start_xmit = ipgre_eth_tunnel_xmit;
1468 + dev->get_stats = ipgre_tunnel_get_stats;
1469 + dev->do_ioctl = ipgre_tunnel_ioctl;
1470 + dev->change_mtu = ipgre_tunnel_change_mtu;
1472 + dev->hard_header_len = ETH_HLEN + sizeof(struct iphdr) + 4;
1473 + dev->tx_queue_len = 0;
1474 + random_ether_addr(dev->dev_addr);
1477 + unsigned char* d = dev->dev_addr;
1478 + 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]);
1485 +static int ipgre_tunnel_init(struct net_device *dev)
1487 + struct net_device *tdev = NULL;
1488 + struct ip_tunnel *tunnel;
1489 + struct iphdr *iph;
1490 + int hlen = LL_MAX_HEADER;
1491 + int mtu = ETH_DATA_LEN;
1492 + int addend = sizeof(struct iphdr) + 4;
1494 + tunnel = netdev_priv(dev);
1495 + iph = &tunnel->parms.iph;
1497 + tunnel->dev = dev;
1498 + strcpy(tunnel->parms.name, dev->name);
1500 + if (tunnel->parms.proto_type != ETH_P_ETH)
1502 + memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
1503 + memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
1506 + /* Guess output device to choose reasonable mtu and hard_header_len */
1509 + struct flowi fl = { .fl_net = init_net(),
1510 + .oif = tunnel->parms.link,
1511 + .nl_u = { .ip4_u =
1512 + { .daddr = iph->daddr,
1513 + .saddr = iph->saddr,
1514 + .tos = RT_TOS(iph->tos) } },
1515 + .proto = IPPROTO_GRE };
1516 + struct rtable *rt;
1517 + if (!ip_route_output_key(&rt, &fl)) {
1518 + tdev = rt->u.dst.dev;
1522 + if (tunnel->parms.proto_type == ETH_P_ETH)
1524 + dev->flags |= IFF_BROADCAST;
1528 + dev->flags |= IFF_POINTOPOINT;
1531 +#ifdef CONFIG_NET_IPGRE_BROADCAST
1532 + if (MULTICAST(iph->daddr)) {
1535 + dev->flags = IFF_BROADCAST;
1536 + dev->hard_header = ipgre_header;
1537 + dev->open = ipgre_open;
1538 + dev->stop = ipgre_close;
1543 + if (!tdev && tunnel->parms.link)
1544 + tdev = __dev_get_by_index(init_net(), tunnel->parms.link);
1547 + hlen = tdev->hard_header_len;
1550 + dev->iflink = tunnel->parms.link;
1552 + /* Precalculate GRE options length */
1553 + if (tunnel->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) {
1554 + if (tunnel->parms.o_flags&GRE_CSUM)
1556 + if (tunnel->parms.o_flags&GRE_KEY)
1558 + if (tunnel->parms.o_flags&GRE_SEQ)
1561 + dev->hard_header_len = hlen + addend;
1562 + dev->mtu = mtu - addend;
1563 + tunnel->hlen = addend;
1567 +static int __init ipgre_fb_tunnel_init(struct net_device *dev)
1569 + struct ip_tunnel *tunnel = netdev_priv(dev);
1570 + struct iphdr *iph = &tunnel->parms.iph;
1572 + tunnel->dev = dev;
1573 + strcpy(tunnel->parms.name, dev->name);
1576 + iph->protocol = IPPROTO_GRE;
1578 + tunnel->hlen = sizeof(struct iphdr) + 4;
1581 + tunnels_wc[0] = tunnel;
1586 +static struct net_protocol ipgre_protocol = {
1587 + .handler = ipgre_rcv,
1588 + .err_handler = ipgre_err,
1593 + * And now the modules code and kernel interface.
1596 +static int __init ipgre_init(void)
1600 + printk(KERN_INFO "GRE over IPv4 tunneling driver\n");
1602 + if (inet_add_protocol(&ipgre_protocol, IPPROTO_GRE) < 0) {
1603 + printk(KERN_INFO "ipgre init: can't add protocol\n");
1607 + ipgre_fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "gre0",
1608 + ipgre_ip_tunnel_setup);
1609 + if (!ipgre_fb_tunnel_dev) {
1614 + ipgre_fb_tunnel_dev->init = ipgre_fb_tunnel_init;
1616 + if ((err = register_netdev(ipgre_fb_tunnel_dev)))
1621 + free_netdev(ipgre_fb_tunnel_dev);
1623 + inet_del_protocol(&ipgre_protocol, IPPROTO_GRE);
1627 +static void __exit ipgre_destroy_tunnels(void)
1631 + for (prio = 0; prio < 4; prio++) {
1633 + for (h = 0; h < HASH_SIZE; h++) {
1634 + struct ip_tunnel *t;
1635 + while ((t = tunnels[prio][h]) != NULL)
1636 + unregister_netdevice(t->dev);
1641 +static void __exit ipgre_fini(void)
1643 + if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0)
1644 + printk(KERN_INFO "ipgre close: can't remove protocol\n");
1647 + ipgre_destroy_tunnels();
1651 +module_init(ipgre_init);
1652 +module_exit(ipgre_fini);
1653 +MODULE_LICENSE("GPL");
1654 diff -Nurp linux-2.6.22-592/net/ethernet/Makefile linux-2.6.22-593/net/ethernet/Makefile
1655 --- linux-2.6.22-592/net/ethernet/Makefile 2007-07-08 19:32:17.000000000 -0400
1656 +++ linux-2.6.22-593/net/ethernet/Makefile 2008-02-11 13:58:47.000000000 -0500
1659 obj-$(subst m,y,$(CONFIG_IPX)) += pe2.o
1660 obj-$(subst m,y,$(CONFIG_ATALK)) += pe2.o