1 diff -Nurb linux-2.6.27-660/drivers/net/Kconfig linux-2.6.27-700/drivers/net/Kconfig
2 --- linux-2.6.27-660/drivers/net/Kconfig 2009-04-10 17:34:59.000000000 -0400
3 +++ linux-2.6.27-700/drivers/net/Kconfig 2009-04-10 17:56:31.000000000 -0400
6 Look at the iproute2 documentation directory for usage etc
9 + tristate "EGRE module for Ethernet over GRE Tunnels"
11 + This is an improvement over the GRE tunnel driver that facilitates
12 + the transport of Ethernet frames over GRE tunnels.
15 tristate "Dummy net driver support"
17 diff -Nurb linux-2.6.27-660/drivers/net/Makefile linux-2.6.27-700/drivers/net/Makefile
18 --- linux-2.6.27-660/drivers/net/Makefile 2008-10-09 18:13:53.000000000 -0400
19 +++ linux-2.6.27-700/drivers/net/Makefile 2009-04-10 17:53:47.000000000 -0400
21 # Makefile for the Linux network (ethercard) device drivers.
24 +obj-$(CONFIG_EGRE) += gre.o
25 obj-$(CONFIG_E1000) += e1000/
26 obj-$(CONFIG_E1000E) += e1000e/
27 obj-$(CONFIG_IBM_NEW_EMAC) += ibm_newemac/
28 diff -Nurb linux-2.6.27-660/drivers/net/gre.c linux-2.6.27-700/drivers/net/gre.c
29 --- linux-2.6.27-660/drivers/net/gre.c 1969-12-31 19:00:00.000000000 -0500
30 +++ linux-2.6.27-700/drivers/net/gre.c 2009-04-10 17:35:46.000000000 -0400
33 + * Linux NET3: GRE over IP protocol decoder.
35 + * Authors: Alexey Kuznetsov (kuznet@ms2.inr.ac.ru)
37 + * This program is free software; you can redistribute it and/or
38 + * modify it under the terms of the GNU General Public License
39 + * as published by the Free Software Foundation; either version
40 + * 2 of the License, or (at your option) any later version.
44 +#include <linux/capability.h>
45 +#include <linux/module.h>
46 +#include <linux/types.h>
47 +#include <linux/sched.h>
48 +#include <linux/kernel.h>
49 +#include <asm/uaccess.h>
50 +#include <linux/skbuff.h>
51 +#include <linux/netdevice.h>
52 +#include <linux/in.h>
53 +#include <linux/tcp.h>
54 +#include <linux/udp.h>
55 +#include <linux/if_arp.h>
56 +#include <linux/mroute.h>
57 +#include <linux/init.h>
58 +#include <linux/in6.h>
59 +#include <linux/inetdevice.h>
60 +#include <linux/etherdevice.h> /**XXX added XXX */
61 +#include <linux/igmp.h>
62 +#include <linux/netfilter_ipv4.h>
63 +#include <linux/if_ether.h>
65 +#include <net/sock.h>
67 +#include <net/icmp.h>
68 +#include <net/protocol.h>
69 +#include <net/ipip.h>
71 +#include <net/checksum.h>
72 +#include <net/dsfield.h>
73 +#include <net/inet_ecn.h>
74 +#include <net/xfrm.h>
77 +#include <net/ipv6.h>
78 +#include <net/ip6_fib.h>
79 +#include <net/ip6_route.h>
82 +//#define GRE_DEBUG 1
85 + Problems & solutions
86 + --------------------
88 + 1. The most important issue is detecting local dead loops.
89 + They would cause complete host lockup in transmit, which
90 + would be "resolved" by stack overflow or, if queueing is enabled,
91 + with infinite looping in net_bh.
93 + We cannot track such dead loops during route installation,
94 + it is infeasible task. The most general solutions would be
95 + to keep skb->encapsulation counter (sort of local ttl),
96 + and silently drop packet when it expires. It is the best
97 + solution, but it supposes maintaing new variable in ALL
98 + skb, even if no tunneling is used.
100 + Current solution: t->recursion lock breaks dead loops. It looks
101 + like dev->tbusy flag, but I preferred new variable, because
102 + the semantics is different. One day, when hard_start_xmit
103 + will be multithreaded we will have to use skb->encapsulation.
107 + 2. Networking dead loops would not kill routers, but would really
108 + kill network. IP hop limit plays role of "t->recursion" in this case,
109 + if we copy it from packet being encapsulated to upper header.
110 + It is very good solution, but it introduces two problems:
112 + - Routing protocols, using packets with ttl=1 (OSPF, RIP2),
113 + do not work over tunnels.
114 + - traceroute does not work. I planned to relay ICMP from tunnel,
115 + so that this problem would be solved and traceroute output
116 + would even more informative. This idea appeared to be wrong:
117 + only Linux complies to rfc1812 now (yes, guys, Linux is the only
118 + true router now :-)), all routers (at least, in neighbourhood of mine)
119 + return only 8 bytes of payload. It is the end.
121 + Hence, if we want that OSPF worked or traceroute said something reasonable,
122 + we should search for another solution.
124 + One of them is to parse packet trying to detect inner encapsulation
125 + made by our node. It is difficult or even impossible, especially,
126 + taking into account fragmentation. TO be short, tt is not solution at all.
128 + Current solution: The solution was UNEXPECTEDLY SIMPLE.
129 + We force DF flag on tunnels with preconfigured hop limit,
130 + that is ALL. :-) Well, it does not remove the problem completely,
131 + but exponential growth of network traffic is changed to linear
132 + (branches, that exceed pmtu are pruned) and tunnel mtu
133 + fastly degrades to value <68, where looping stops.
134 + Yes, it is not good if there exists a router in the loop,
135 + which does not force DF, even when encapsulating packets have DF set.
136 + But it is not our problem! Nobody could accuse us, we made
137 + all that we could make. Even if it is your gated who injected
138 + fatal route to network, even if it were you who configured
139 + fatal static route: you are innocent. :-)
143 + 3. Really, ipv4/ipip.c, ipv4/ip_gre.c and ipv6/sit.c contain
144 + practically identical code. It would be good to glue them
145 + together, but it is not very evident, how to make them modular.
146 + sit is integral part of IPv6, ipip and gre are naturally modular.
147 + We could extract common parts (hash table, ioctl etc)
148 + to a separate module (ip_tunnel.c).
153 +static int ipgre_tunnel_init(struct net_device *dev);
154 +static void ipgre_ip_tunnel_setup(struct net_device *dev);
155 +static void ipgre_eth_tunnel_setup(struct net_device *dev);
157 +/* Fallback tunnel: no source, no destination, no key, no options */
159 +static int ipgre_fb_tunnel_init(struct net_device *dev);
161 +static struct net_device *ipgre_fb_tunnel_dev;
163 +/* Tunnel hash table */
173 + We require exact key match i.e. if a key is present in packet
174 + it will match only tunnel with the same key; if it is not present,
175 + it will match only keyless tunnel.
177 + All keysless packets, if not matched configured keyless tunnels
178 + will match fallback tunnel.
181 +#define HASH_SIZE 1024
182 +#define HASH(addr) (ntohl(addr)&1023)
184 +static struct ip_tunnel *tunnels[4][HASH_SIZE];
186 +#define tunnels_r_l (tunnels[3])
187 +#define tunnels_r (tunnels[2])
188 +#define tunnels_l (tunnels[1])
189 +#define tunnels_wc (tunnels[0])
191 +static DEFINE_RWLOCK(ipgre_lock);
193 +/* Given src, dst and key, find appropriate for input tunnel. */
195 +static struct ip_tunnel * ipgre_tunnel_lookup(__be32 remote, __be32 local, __be32 key)
198 + unsigned hash_value = HASH(key);
199 + struct ip_tunnel *t;
201 + t = tunnels_r_l[hash_value];
203 + if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP)) {
207 + t = tunnels_r[hash_value];
208 + if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
211 + t = tunnels_l[hash_value];
212 + if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
214 + t = tunnels_wc[hash_value];
215 + if (t && (t->parms.i_key == key) && (t->dev->flags&IFF_UP))
217 + if (ipgre_fb_tunnel_dev->flags&IFF_UP)
218 + return netdev_priv(ipgre_fb_tunnel_dev);
222 +static struct ip_tunnel **ipgre_bucket(struct ip_tunnel *t)
224 + __be32 remote = t->parms.iph.daddr;
225 + __be32 local = t->parms.iph.saddr;
226 + __be32 key = t->parms.i_key;
227 + unsigned h = HASH(key);
232 + if (remote && !MULTICAST(remote)) {
234 + //h ^= HASH(remote);
237 + return &tunnels[prio][h];
240 +static void ipgre_tunnel_link(struct ip_tunnel *t)
242 + struct ip_tunnel **tp = ipgre_bucket(t);
245 + write_lock_bh(&ipgre_lock);
247 + write_unlock_bh(&ipgre_lock);
250 +static void ipgre_tunnel_unlink(struct ip_tunnel *t)
252 + struct ip_tunnel **tp;
254 + for (tp = ipgre_bucket(t); *tp; tp = &(*tp)->next) {
256 + write_lock_bh(&ipgre_lock);
258 + write_unlock_bh(&ipgre_lock);
264 +static struct ip_tunnel * ipgre_tunnel_locate(struct ip_tunnel_parm *parms, int create)
266 + __be32 remote = parms->iph.daddr;
267 + __be32 local = parms->iph.saddr;
268 + __be32 key = parms->i_key;
269 + __be16 proto = parms->proto_type;
270 + struct ip_tunnel *t, **tp, *nt;
271 + struct net_device *dev;
272 + unsigned h = HASH(key);
274 + char name[IFNAMSIZ];
278 + if (remote && !MULTICAST(remote)) {
280 + //h ^= HASH(remote);
282 + for (tp = &tunnels[prio][h]; (t = *tp) != NULL; tp = &t->next) {
283 + if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr) {
284 + if (key == t->parms.i_key)
291 + printk(KERN_CRIT "Adding tunnel %s with key %d\n", parms->name, ntohl(key));
293 + if (parms->name[0])
294 + strlcpy(name, parms->name, IFNAMSIZ);
297 + for (i=1; i<100; i++) {
298 + sprintf(name, "gre%d", i);
299 + if (__dev_get_by_name(&init_net, name) == NULL)
306 + /* Tunnel creation: check payload type and call appropriate
311 + dev = alloc_netdev(sizeof(*t), name, ipgre_ip_tunnel_setup);
314 + dev = alloc_netdev(sizeof(*t), name, ipgre_eth_tunnel_setup);
323 + dev->init = ipgre_tunnel_init;
324 + nt = netdev_priv(dev);
325 + nt->parms = *parms;
327 + if (register_netdevice(dev) < 0) {
333 + ipgre_tunnel_link(nt);
340 +static void ipgre_tunnel_uninit(struct net_device *dev)
342 + ipgre_tunnel_unlink(netdev_priv(dev));
347 +static void ipgre_err(struct sk_buff *skb, u32 info)
349 +#ifndef I_WISH_WORLD_WERE_PERFECT
351 +/* It is not :-( All the routers (except for Linux) return only
352 + 8 bytes of packet payload. It means, that precise relaying of
353 + ICMP in the real Internet is absolutely infeasible.
355 + Moreover, Cisco "wise men" put GRE key to the third word
356 + in GRE header. It makes impossible maintaining even soft state for keyed
357 + GRE tunnels with enabled checksum. Tell them "thank you".
359 + Well, I wonder, rfc1812 was written by Cisco employee,
360 + what the hell these idiots break standrads established
364 + struct iphdr *iph = (struct iphdr*)skb->data;
365 + __be16 *p = (__be16*)(skb->data+(iph->ihl<<2));
366 + int grehlen = (iph->ihl<<2) + 4;
367 + int type = icmp_hdr(skb)->type;
368 + int code = icmp_hdr(skb)->code;
369 + struct ip_tunnel *t;
373 + if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
374 + if (flags&(GRE_VERSION|GRE_ROUTING))
376 + if (flags&GRE_KEY) {
378 + if (flags&GRE_CSUM)
383 + /* If only 8 bytes returned, keyed message will be dropped here */
384 + if (skb_headlen(skb) < grehlen)
389 + case ICMP_PARAMETERPROB:
392 + case ICMP_DEST_UNREACH:
394 + case ICMP_SR_FAILED:
395 + case ICMP_PORT_UNREACH:
396 + /* Impossible event. */
398 + case ICMP_FRAG_NEEDED:
399 + /* Soft state for pmtu is maintained by IP core. */
402 + /* All others are translated to HOST_UNREACH.
403 + rfc2003 contains "deep thoughts" about NET_UNREACH,
404 + I believe they are just ether pollution. --ANK
409 + case ICMP_TIME_EXCEEDED:
410 + if (code != ICMP_EXC_TTL)
415 + read_lock(&ipgre_lock);
416 + t = ipgre_tunnel_lookup(iph->daddr, iph->saddr, (flags&GRE_KEY) ? *(((__be32*)p) + (grehlen>>2) - 1) : 0);
417 + if (t == NULL || t->parms.iph.daddr == 0 || MULTICAST(t->parms.iph.daddr))
420 + if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
423 + if (jiffies - t->err_time < IPTUNNEL_ERR_TIMEO)
427 + t->err_time = jiffies;
429 + read_unlock(&ipgre_lock);
432 + struct iphdr *iph = (struct iphdr*)dp;
433 + struct iphdr *eiph;
434 + __be16 *p = (__be16*)(dp+(iph->ihl<<2));
435 + int type = skb->h.icmph->type;
436 + int code = skb->h.icmph->code;
439 + __be32 rel_info = 0;
442 + int grehlen = (iph->ihl<<2) + 4;
443 + struct sk_buff *skb2;
447 + if (skb->dev->nd_net != &init_net)
450 + if (p[1] != htons(ETH_P_IP))
454 + if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
455 + if (flags&(GRE_VERSION|GRE_ROUTING))
457 + if (flags&GRE_CSUM)
464 + if (len < grehlen + sizeof(struct iphdr))
466 + eiph = (struct iphdr*)(dp + grehlen);
471 + case ICMP_PARAMETERPROB:
472 + n = ntohl(skb->h.icmph->un.gateway) >> 24;
473 + if (n < (iph->ihl<<2))
476 + /* So... This guy found something strange INSIDE encapsulated
477 + packet. Well, he is fool, but what can we do ?
479 + rel_type = ICMP_PARAMETERPROB;
481 + rel_info = htonl(n << 24);
484 + case ICMP_DEST_UNREACH:
486 + case ICMP_SR_FAILED:
487 + case ICMP_PORT_UNREACH:
488 + /* Impossible event. */
490 + case ICMP_FRAG_NEEDED:
491 + /* And it is the only really necessary thing :-) */
492 + n = ntohs(skb->h.icmph->un.frag.mtu);
493 + if (n < grehlen+68)
496 + /* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */
497 + if (n > ntohs(eiph->tot_len))
499 + rel_info = htonl(n);
502 + /* All others are translated to HOST_UNREACH.
503 + rfc2003 contains "deep thoughts" about NET_UNREACH,
504 + I believe, it is just ether pollution. --ANK
506 + rel_type = ICMP_DEST_UNREACH;
507 + rel_code = ICMP_HOST_UNREACH;
511 + case ICMP_TIME_EXCEEDED:
512 + if (code != ICMP_EXC_TTL)
517 + /* Prepare fake skb to feed it to icmp_send */
518 + skb2 = skb_clone(skb, GFP_ATOMIC);
521 + dst_release(skb2->dst);
523 + skb_pull(skb2, skb->data - (u8*)eiph);
524 + skb_reset_network_header(skb2);
526 + /* Try to guess incoming interface */
527 + memset(&fl, 0, sizeof(fl));
528 + fl.fl_net = &init_net;
529 + fl.fl4_dst = eiph->saddr;
530 + fl.fl4_tos = RT_TOS(eiph->tos);
531 + fl.proto = IPPROTO_GRE;
532 + if (ip_route_output_key(&rt, &fl)) {
536 + skb2->dev = rt->u.dst.dev;
538 + /* route "incoming" packet */
539 + if (rt->rt_flags&RTCF_LOCAL) {
542 + fl.fl4_dst = eiph->daddr;
543 + fl.fl4_src = eiph->saddr;
544 + fl.fl4_tos = eiph->tos;
545 + if (ip_route_output_key(&rt, &fl) ||
546 + rt->u.dst.dev->type != ARPHRD_IPGRE) {
553 + if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos, skb2->dev) ||
554 + skb2->dst->dev->type != ARPHRD_IPGRE) {
560 + /* change mtu on this route */
561 + if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) {
562 + if (n > dst_mtu(skb2->dst)) {
566 + skb2->dst->ops->update_pmtu(skb2->dst, n);
567 + } else if (type == ICMP_TIME_EXCEEDED) {
568 + struct ip_tunnel *t = netdev_priv(skb2->dev);
569 + if (t->parms.iph.ttl) {
570 + rel_type = ICMP_DEST_UNREACH;
571 + rel_code = ICMP_HOST_UNREACH;
575 + icmp_send(skb2, rel_type, rel_code, rel_info);
580 +static inline void ipgre_ecn_decapsulate(struct iphdr *iph, struct sk_buff *skb)
582 + if (INET_ECN_is_ce(iph->tos)) {
583 + if (skb->protocol == htons(ETH_P_IP)) {
584 + IP_ECN_set_ce(ip_hdr(skb));
585 + } else if (skb->protocol == htons(ETH_P_IPV6)) {
586 + IP6_ECN_set_ce(ipv6_hdr(skb));
592 +ipgre_ecn_encapsulate(u8 tos, struct iphdr *old_iph, struct sk_buff *skb)
595 + if (skb->protocol == htons(ETH_P_IP))
596 + inner = old_iph->tos;
597 + else if (skb->protocol == htons(ETH_P_IPV6))
598 + inner = ipv6_get_dsfield((struct ipv6hdr *)old_iph);
599 + return INET_ECN_encapsulate(tos, inner);
602 +static int ipgre_rcv(struct sk_buff *skb)
610 + struct ip_tunnel *tunnel;
614 + if (skb->dev->nd_net != &init_net) {
618 + if (!pskb_may_pull(skb, 16))
623 + flags = *(__be16*)h;
626 + printk(KERN_DEBUG "gre.c [601] src:%x dst:%x proto:%d %x", iph->saddr, iph->daddr, iph->protocol, skb->data);
628 + proto = ntohs(*(__be16*)(h+2)); /* XXX added XXX */
630 + if (flags&(GRE_CSUM|GRE_KEY|GRE_ROUTING|GRE_SEQ|GRE_VERSION)) {
631 + /* - Version must be 0.
632 + - We do not support routing headers.
634 + if (flags&(GRE_VERSION|GRE_ROUTING))
637 + if (flags&GRE_CSUM) {
638 + switch (skb->ip_summed) {
639 + case CHECKSUM_COMPLETE:
640 + csum = csum_fold(skb->csum);
644 + case CHECKSUM_NONE:
646 + csum = __skb_checksum_complete(skb);
647 + skb->ip_summed = CHECKSUM_COMPLETE;
651 + if (flags&GRE_KEY) {
652 + key = *(__be32*)(h + offset);
655 + if (flags&GRE_SEQ) {
656 + seqno = ntohl(*(__be32*)(h + offset));
661 + read_lock(&ipgre_lock);
662 + if ((tunnel = ipgre_tunnel_lookup(iph->saddr, iph->daddr, key)) != NULL) {
663 + secpath_reset(skb);
665 + skb->protocol = *(__be16*)(h + 2);
666 + /* WCCP version 1 and 2 protocol decoding.
667 + * - Change protocol to IP
668 + * - When dealing with WCCPv2, Skip extra 4 bytes in GRE header
671 + skb->protocol == htons(ETH_P_WCCP)) {
672 + skb->protocol = htons(ETH_P_IP);
673 + if ((*(h + offset) & 0xF0) != 0x40)
677 + //skb->mac.raw = skb->nh.raw;
678 + skb_reset_mac_header(skb);
679 + __pskb_pull(skb, offset);
680 + skb_reset_network_header(skb);
681 + skb_postpull_rcsum(skb, skb_transport_header(skb), offset);
682 + if(proto == ETH_P_ETH)
685 + unsigned char* tmp_hdr = skb->data;
686 + 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);
688 + skb->protocol = eth_type_trans(skb, tunnel->dev);
690 + /* XXX added these lines to make arp work? XXX */
691 + /*skb->mac.raw = skb->data;*/
692 + skb->network_header = skb->network_header + ETH_HLEN;
693 + /* XXX added these lines to make arp work? XXX */
696 + tmp_hdr = skb->data;
697 + 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);
698 + printk(KERN_ALERT "gre.c [671] received ethernet on gre %x %x\n",skb->protocol, ((skb->nh).iph)->protocol);
700 + memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
703 + skb->pkt_type = PACKET_HOST;
704 +#ifdef CONFIG_NET_IPGRE_BROADCAST
705 + if (MULTICAST(iph->daddr)) {
706 + /* Looped back packet, drop it! */
707 + if (((struct rtable*)skb->dst)->fl.iif == 0)
709 + tunnel->stat.multicast++;
710 + skb->pkt_type = PACKET_BROADCAST;
714 + if (((flags&GRE_CSUM) && csum) ||
715 + (!(flags&GRE_CSUM) && tunnel->parms.i_flags&GRE_CSUM)) {
716 + tunnel->stat.rx_crc_errors++;
717 + tunnel->stat.rx_errors++;
720 + if (tunnel->parms.i_flags&GRE_SEQ) {
721 + if (!(flags&GRE_SEQ) ||
722 + (tunnel->i_seqno && (s32)(seqno - tunnel->i_seqno) < 0)) {
723 + tunnel->stat.rx_fifo_errors++;
724 + tunnel->stat.rx_errors++;
727 + tunnel->i_seqno = seqno + 1;
729 + tunnel->stat.rx_packets++;
730 + tunnel->stat.rx_bytes += skb->len;
731 + skb->dev = tunnel->dev;
732 + dst_release(skb->dst);
735 + ipgre_ecn_decapsulate(iph, skb);
737 + read_unlock(&ipgre_lock);
740 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
743 + read_unlock(&ipgre_lock);
749 +static int ipgre_ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
751 + struct ip_tunnel *tunnel = netdev_priv(dev);
752 + struct net_device_stats *stats = &tunnel->stat;
753 + struct iphdr *old_iph = ip_hdr(skb);
754 + struct iphdr *tiph;
757 + struct rtable *rt; /* Route to the other host */
758 + struct net_device *tdev; /* Device to other host */
759 + struct iphdr *iph; /* Our new IP header */
760 + int max_headroom; /* The extra header space needed */
765 + if (tunnel->recursion++) {
766 + tunnel->stat.collisions++;
770 + if (dev->hard_header) {
772 + tiph = (struct iphdr*)skb->data;
774 + gre_hlen = tunnel->hlen;
775 + tiph = &tunnel->parms.iph;
778 + if ((dst = tiph->daddr) == 0) {
781 + if (skb->dst == NULL) {
782 + tunnel->stat.tx_fifo_errors++;
786 + if (skb->protocol == htons(ETH_P_IP)) {
787 + rt = (struct rtable*)skb->dst;
788 + if ((dst = rt->rt_gateway) == 0)
789 + goto tx_error_icmp;
792 + else if (skb->protocol == htons(ETH_P_IPV6)) {
793 + struct in6_addr *addr6;
795 + struct neighbour *neigh = skb->dst->neighbour;
800 + addr6 = (struct in6_addr*)&neigh->primary_key;
801 + addr_type = ipv6_addr_type(addr6);
803 + if (addr_type == IPV6_ADDR_ANY) {
804 + addr6 = &ipv6_hdr(skb)->daddr;
805 + addr_type = ipv6_addr_type(addr6);
808 + if ((addr_type & IPV6_ADDR_COMPATv4) == 0)
809 + goto tx_error_icmp;
819 + if (skb->protocol == htons(ETH_P_IP))
820 + tos = old_iph->tos;
825 + struct flowi fl = { .fl_net = &init_net,
826 + .oif = tunnel->parms.link,
829 + .saddr = tiph->saddr,
830 + .tos = RT_TOS(tos) } },
831 + .proto = IPPROTO_GRE };
832 + if (ip_route_output_key(&rt, &fl)) {
833 + tunnel->stat.tx_carrier_errors++;
837 + tdev = rt->u.dst.dev;
842 + tunnel->stat.collisions++;
846 + df = tiph->frag_off;
848 + mtu = dst_mtu(&rt->u.dst) - tunnel->hlen;
850 + mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
853 + skb->dst->ops->update_pmtu(skb->dst, mtu);
855 + if (skb->protocol == htons(ETH_P_IP)) {
856 + df |= (old_iph->frag_off&htons(IP_DF));
858 + if ((old_iph->frag_off&htons(IP_DF)) &&
859 + mtu < ntohs(old_iph->tot_len)) {
860 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
866 + else if (skb->protocol == htons(ETH_P_IPV6)) {
867 + struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
869 + if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) {
870 + if ((tunnel->parms.iph.daddr && !MULTICAST(tunnel->parms.iph.daddr)) ||
871 + rt6->rt6i_dst.plen == 128) {
872 + rt6->rt6i_flags |= RTF_MODIFIED;
873 + skb->dst->metrics[RTAX_MTU-1] = mtu;
877 + if (mtu >= IPV6_MIN_MTU && mtu < skb->len - tunnel->hlen + gre_hlen) {
878 + icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
885 + if (tunnel->err_count > 0) {
886 + if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
887 + tunnel->err_count--;
889 + dst_link_failure(skb);
891 + tunnel->err_count = 0;
894 + max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen;
896 + if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
897 + struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
900 + stats->tx_dropped++;
901 + dev_kfree_skb(skb);
902 + tunnel->recursion--;
906 + skb_set_owner_w(new_skb, skb->sk);
907 + dev_kfree_skb(skb);
909 + old_iph = ip_hdr(skb);
912 + skb->transport_header = skb->network_header;
913 + skb_push(skb, gre_hlen);
914 + memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
915 + IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
917 + dst_release(skb->dst);
918 + skb->dst = &rt->u.dst;
921 + * Push down and install the IPIP header.
926 + iph->ihl = sizeof(struct iphdr) >> 2;
927 + iph->frag_off = df;
928 + iph->protocol = IPPROTO_GRE;
929 + iph->tos = ipgre_ecn_encapsulate(tos, old_iph, skb);
930 + iph->daddr = rt->rt_dst;
931 + iph->saddr = rt->rt_src;
933 + if ((iph->ttl = tiph->ttl) == 0) {
934 + if (skb->protocol == htons(ETH_P_IP))
935 + iph->ttl = old_iph->ttl;
937 + else if (skb->protocol == htons(ETH_P_IPV6))
938 + iph->ttl = ((struct ipv6hdr*)old_iph)->hop_limit;
941 + iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
944 + ((__be16*)(iph+1))[0] = tunnel->parms.o_flags;
945 + ((__be16*)(iph+1))[1] = skb->protocol;
947 + if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
948 + __be32 *ptr = (__be32*)(((u8*)iph) + tunnel->hlen - 4);
950 + if (tunnel->parms.o_flags&GRE_SEQ) {
952 + *ptr = htonl(tunnel->o_seqno);
955 + if (tunnel->parms.o_flags&GRE_KEY) {
956 + *ptr = tunnel->parms.o_key;
959 + if (tunnel->parms.o_flags&GRE_CSUM) {
961 + *(__sum16*)ptr = ip_compute_csum((void*)(iph+1), skb->len - sizeof(struct iphdr));
968 + tunnel->recursion--;
972 + dst_link_failure(skb);
975 + stats->tx_errors++;
976 + dev_kfree_skb(skb);
977 + tunnel->recursion--;
981 +static int ipgre_eth_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
983 + struct ip_tunnel *tunnel = netdev_priv(dev);
984 + struct net_device_stats *stats = &tunnel->stat;
985 + struct iphdr *old_iph = ip_hdr(skb);
986 + struct iphdr *tiph = &tunnel->parms.iph;
989 + struct rtable *rt; /* Route to the other host */
990 + struct net_device *tdev; /* Device to other host */
991 + int gre_hlen = tunnel->hlen; /* XXX changed XXX*/
992 + //struct etheriphdr *ethiph;
993 + struct iphdr *iph; /* Our new IP header */
994 + int max_headroom; /* The extra header space needed */
998 + printk(KERN_ALERT "gre.c:972 Starting xmit\n");
1001 + if (tunnel->recursion++) {
1002 + stats->collisions++;
1006 + /* Need valid non-multicast daddr. */
1007 + if (tiph->daddr == 0 || MULTICAST(tiph->daddr))
1012 + if (skb->protocol == htons(ETH_P_IP))
1013 + tos = old_iph->tos;
1017 + printk(KERN_ALERT "gre.c:991 Passed tos assignment.\n");
1022 + struct flowi fl = { .fl_net = &init_net,
1023 + .oif = tunnel->parms.link,
1024 + .nl_u = { .ip4_u =
1025 + { .daddr = tiph->daddr,
1026 + .saddr = tiph->saddr,
1027 + .tos = RT_TOS(tos) } },
1028 + .proto = IPPROTO_GRE };
1029 + if (ip_route_output_key(&rt, &fl)) {
1030 + stats->tx_carrier_errors++;
1031 + goto tx_error_icmp;
1034 + tdev = rt->u.dst.dev;
1036 + printk(KERN_ALERT "gre.c:1006 Passed the route retrieval\n");
1038 + if (tdev == dev) {
1040 + stats->collisions++;
1044 + printk(KERN_ALERT "gre.c:1018 Passed tdev collision check.\n");
1047 + /* Check MTU stuff if kernel panic */
1048 + df = tiph->frag_off;
1050 + mtu = dst_mtu(&rt->u.dst) - tunnel->hlen;
1052 + mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
1055 + skb->dst->ops->update_pmtu(skb->dst, mtu);
1058 + printk(KERN_ALERT "gre.c:1032 Passed the pmtu setting.\n");
1061 + if (skb->protocol == htons(ETH_P_IP)) {
1062 + df |= (old_iph->frag_off&htons(IP_DF));
1064 + if ((old_iph->frag_off & htons(IP_DF)) &&
1065 + mtu < ntohs(old_iph->tot_len)) {
1066 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
1072 + else if (skb->protocol == htons(ETH_P_IPV6)) {
1073 + struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
1075 + if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) {
1076 + if (tiph->daddr || rt6->rt6i_dst.plen == 128) {
1077 + rt6->rt6i_flags |= RTF_MODIFIED;
1078 + skb->dst->metrics[RTAX_MTU-1] = mtu;
1082 + /* @@@ Is this correct? */
1083 + if (mtu >= IPV6_MIN_MTU && mtu < skb->len - tunnel->hlen + gre_hlen) {
1084 + icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
1091 + printk(KERN_ALERT "gre.c:1065 Passed the fragmentation check.\n");
1094 + if (tunnel->err_count > 0) {
1095 + if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
1096 + tunnel->err_count--;
1097 + dst_link_failure(skb);
1099 + tunnel->err_count = 0;
1102 + max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen;
1104 + if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
1105 + struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
1108 + stats->tx_dropped++;
1109 + dev_kfree_skb(skb);
1110 + tunnel->recursion--;
1114 + skb_set_owner_w(new_skb, skb->sk);
1115 + dev_kfree_skb(skb);
1117 + old_iph = ip_hdr(skb);
1120 + printk(KERN_ALERT "gre.c:1094 Passed the headroom calculation\n");
1124 + skb->transport_header = skb->mac_header; // Added by valas
1125 + skb_push(skb, gre_hlen);
1126 + skb_reset_network_header(skb);
1127 + memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1128 + dst_release(skb->dst);
1129 + skb->dst = &rt->u.dst;
1132 + * Push down and install the etherip header.
1135 + iph = ip_hdr(skb);
1137 + iph->ihl = sizeof(struct iphdr) >> 2;
1138 + iph->frag_off = df;
1139 + iph->protocol = IPPROTO_GRE;
1140 + iph->tos = ipgre_ecn_encapsulate(tos, old_iph, skb);
1141 + iph->daddr = rt->rt_dst;
1142 + iph->saddr = rt->rt_src;
1144 +/* ethiph->version = htons(ETHERIP_VERSION); */
1146 + printk(KERN_ALERT "gre.c:1121 Passed outer IP header construction.\n");
1149 + if ((iph->ttl = tiph->ttl) == 0) {
1150 + if (skb->protocol == htons(ETH_P_IP))
1151 + iph->ttl = old_iph->ttl;
1153 + else if (skb->protocol == htons(ETH_P_IPV6))
1154 + iph->ttl = ((struct ipv6hdr*)old_iph)->hop_limit;
1157 + iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
1160 + printk(KERN_ALERT "gre.c:1006 Passed the TTL check.\n");
1163 + ((__be16*)(iph+1))[0] = tunnel->parms.o_flags;
1164 + ((__be16*)(iph+1))[1] = htons(tunnel->parms.proto_type);
1166 + if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
1167 + __be32 *ptr = (__be32*)(((u8*)iph) + tunnel->hlen - 4);
1169 + if (tunnel->parms.o_flags&GRE_SEQ) {
1170 + ++tunnel->o_seqno;
1171 + *ptr = htonl(tunnel->o_seqno);
1174 + if (tunnel->parms.o_flags&GRE_KEY) {
1175 + *ptr = tunnel->parms.o_key;
1178 + if (tunnel->parms.o_flags&GRE_CSUM) {
1180 + *(__sum16*)ptr = ip_compute_csum((void*)(iph+1), skb->len - sizeof(struct iphdr));
1184 + printk(KERN_ALERT "gre.c:1006 Passed the tunnel transmit.\n");
1190 + tunnel->recursion--;
1194 + dst_link_failure(skb);
1197 + stats->tx_errors++;
1198 + dev_kfree_skb(skb);
1199 + tunnel->recursion--;
1205 +ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
1208 + struct ip_tunnel_parm p;
1209 + struct ip_tunnel *t;
1211 + printk(KERN_ALERT "1174 GRE: entering gre ioctl. command is: %d\n", cmd);
1214 + case SIOCGETTUNNEL:
1216 + if (dev == ipgre_fb_tunnel_dev) {
1217 + if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
1221 + t = ipgre_tunnel_locate(&p, 0);
1224 + t = netdev_priv(dev);
1225 + memcpy(&p, &t->parms, sizeof(p));
1226 + if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
1230 + case SIOCADDTUNNEL:
1231 + case SIOCCHGTUNNEL:
1233 + if (!capable(CAP_NET_ADMIN))
1237 + if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
1241 + if (p.iph.version != 4 || p.iph.protocol != IPPROTO_GRE ||
1242 + p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)) ||
1243 + ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING)))
1246 + p.iph.frag_off |= htons(IP_DF);
1248 + if (!(p.i_flags&GRE_KEY))
1250 + if (!(p.o_flags&GRE_KEY))
1253 + t = ipgre_tunnel_locate(&p, cmd == SIOCADDTUNNEL);
1254 + if (t) printk(KERN_ALERT "1174 GRE: proto %s %d\n", p.name, p.proto_type);
1255 + if (dev != ipgre_fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
1257 + if (t->dev != dev) {
1262 + unsigned nflags=0;
1264 + t = netdev_priv(dev);
1266 + if (MULTICAST(p.iph.daddr))
1267 + nflags = IFF_BROADCAST;
1268 + else if (p.iph.daddr)
1269 + nflags = IFF_POINTOPOINT;
1271 + /* XXX:Set back IFF_BROADCAST if
1272 + * transporting ethernet */
1273 + printk(KERN_ALERT "1193 GRE: proto %s %d\n", p.name, p.proto_type);
1274 + if (p.proto_type == ETH_P_ETH)
1275 + nflags = IFF_BROADCAST;
1277 + if ((dev->flags^nflags)&(IFF_POINTOPOINT|IFF_BROADCAST)) {
1281 + ipgre_tunnel_unlink(t);
1282 + t->parms.iph.saddr = p.iph.saddr;
1283 + t->parms.iph.daddr = p.iph.daddr;
1284 + t->parms.i_key = p.i_key;
1285 + t->parms.o_key = p.o_key;
1286 + /* XXX:Copy in the protocol field */
1287 + t->parms.proto_type = p.proto_type;
1288 + if (t->parms.proto_type != ETH_P_ETH)
1290 + memcpy(dev->dev_addr, &p.iph.saddr, 4);
1291 + memcpy(dev->broadcast, &p.iph.daddr, 4);
1293 + ipgre_tunnel_link(t);
1294 + netdev_state_change(dev);
1300 + if (cmd == SIOCCHGTUNNEL) {
1301 + t->parms.iph.ttl = p.iph.ttl;
1302 + t->parms.iph.tos = p.iph.tos;
1303 + t->parms.iph.frag_off = p.iph.frag_off;
1305 + if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
1308 + err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
1311 + case SIOCDELTUNNEL:
1313 + if (!capable(CAP_NET_ADMIN))
1316 + if (dev == ipgre_fb_tunnel_dev) {
1318 + if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
1321 + if ((t = ipgre_tunnel_locate(&p, 0)) == NULL)
1324 + if (t == netdev_priv(ipgre_fb_tunnel_dev))
1328 + unregister_netdevice(dev); // added by Valas
1339 +static struct net_device_stats *ipgre_tunnel_get_stats(struct net_device *dev)
1341 + return &(((struct ip_tunnel*)netdev_priv(dev))->stat);
1344 +static int ipgre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
1346 + struct ip_tunnel *tunnel = netdev_priv(dev);
1347 + if (new_mtu < 68 || new_mtu > 0xFFF8 - tunnel->hlen)
1349 + dev->mtu = new_mtu;
1353 +#ifdef CONFIG_NET_IPGRE_BROADCAST
1354 +/* Nice toy. Unfortunately, useless in real life :-)
1355 + It allows to construct virtual multiprotocol broadcast "LAN"
1356 + over the Internet, provided multicast routing is tuned.
1359 + I have no idea was this bicycle invented before me,
1360 + so that I had to set ARPHRD_IPGRE to a random value.
1361 + I have an impression, that Cisco could make something similar,
1362 + but this feature is apparently missing in IOS<=11.2(8).
1364 + I set up 10.66.66/24 and fec0:6666:6666::0/96 as virtual networks
1365 + with broadcast 224.66.66.66. If you have access to mbone, play with me :-)
1367 + ping -t 255 224.66.66.66
1369 + If nobody answers, mbone does not work.
1371 + ip tunnel add Universe mode gre remote 224.66.66.66 local <Your_real_addr> ttl 255
1372 + ip addr add 10.66.66.<somewhat>/24 dev Universe
1373 + ifconfig Universe up
1374 + ifconfig Universe add fe80::<Your_real_addr>/10
1375 + ifconfig Universe add fec0:6666:6666::<Your_real_addr>/96
1378 + ftp fec0:6666:6666::193.233.7.65
1383 +static int ipgre_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
1384 + void *daddr, void *saddr, unsigned len)
1386 + struct ip_tunnel *t = netdev_priv(dev);
1387 + struct iphdr *iph = (struct iphdr *)skb_push(skb, t->hlen);
1388 + __be16 *p = (__be16*)(iph+1);
1390 + memcpy(iph, &t->parms.iph, sizeof(struct iphdr));
1391 + p[0] = t->parms.o_flags;
1392 + p[1] = htons(type);
1395 + * Set the source hardware address.
1399 + memcpy(&iph->saddr, saddr, 4);
1402 + memcpy(&iph->daddr, daddr, 4);
1405 + if (iph->daddr && !MULTICAST(iph->daddr))
1411 +static int ipgre_open(struct net_device *dev)
1413 + struct ip_tunnel *t = netdev_priv(dev);
1415 + if (MULTICAST(t->parms.iph.daddr)) {
1416 + struct flowi fl = { .fl_net = &init_net,
1417 + .oif = t->parms.link,
1418 + .nl_u = { .ip4_u =
1419 + { .daddr = t->parms.iph.daddr,
1420 + .saddr = t->parms.iph.saddr,
1421 + .tos = RT_TOS(t->parms.iph.tos) } },
1422 + .proto = IPPROTO_GRE };
1423 + struct rtable *rt;
1424 + if (ip_route_output_key(&rt, &fl))
1425 + return -EADDRNOTAVAIL;
1426 + dev = rt->u.dst.dev;
1428 + if (__in_dev_get_rtnl(dev) == NULL)
1429 + return -EADDRNOTAVAIL;
1430 + t->mlink = dev->ifindex;
1431 + ip_mc_inc_group(__in_dev_get_rtnl(dev), t->parms.iph.daddr);
1436 +static int ipgre_close(struct net_device *dev)
1438 + struct ip_tunnel *t = netdev_priv(dev);
1439 + if (MULTICAST(t->parms.iph.daddr) && t->mlink) {
1440 + struct in_device *in_dev = inetdev_by_index(&init_net, t->mlink);
1442 + ip_mc_dec_group(in_dev, t->parms.iph.daddr);
1443 + in_dev_put(in_dev);
1451 +static void ipgre_ip_tunnel_setup(struct net_device *dev)
1453 + SET_MODULE_OWNER(dev);
1454 + dev->uninit = ipgre_tunnel_uninit;
1455 + dev->destructor = free_netdev;
1456 + dev->hard_start_xmit = ipgre_ip_tunnel_xmit;
1457 + dev->get_stats = ipgre_tunnel_get_stats;
1458 + dev->do_ioctl = ipgre_tunnel_ioctl;
1459 + dev->change_mtu = ipgre_tunnel_change_mtu;
1461 + dev->type = ARPHRD_IPGRE;
1462 + dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr) + 4;
1463 + dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 4;
1464 + dev->flags = IFF_NOARP;
1466 + dev->addr_len = 4;
1469 +/* Tunnel setup for ipgre_eth */
1470 +static void ipgre_eth_tunnel_setup(struct net_device *dev)
1472 + SET_MODULE_OWNER(dev);
1475 + dev->uninit = ipgre_tunnel_uninit;
1476 + dev->destructor = free_netdev;
1477 + dev->hard_start_xmit = ipgre_eth_tunnel_xmit;
1478 + dev->get_stats = ipgre_tunnel_get_stats;
1479 + dev->do_ioctl = ipgre_tunnel_ioctl;
1480 + dev->change_mtu = ipgre_tunnel_change_mtu;
1482 + dev->hard_header_len = ETH_HLEN + sizeof(struct iphdr) + 4;
1483 + dev->tx_queue_len = 0;
1484 + random_ether_addr(dev->dev_addr);
1487 + unsigned char* d = dev->dev_addr;
1488 + 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]);
1495 +static int ipgre_tunnel_init(struct net_device *dev)
1497 + struct net_device *tdev = NULL;
1498 + struct ip_tunnel *tunnel;
1499 + struct iphdr *iph;
1500 + int hlen = LL_MAX_HEADER;
1501 + int mtu = ETH_DATA_LEN;
1502 + int addend = sizeof(struct iphdr) + 4;
1504 + tunnel = netdev_priv(dev);
1505 + iph = &tunnel->parms.iph;
1507 + tunnel->dev = dev;
1508 + strcpy(tunnel->parms.name, dev->name);
1510 + if (tunnel->parms.proto_type != ETH_P_ETH)
1512 + memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
1513 + memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
1516 + /* Guess output device to choose reasonable mtu and hard_header_len */
1519 + struct flowi fl = { .fl_net = &init_net,
1520 + .oif = tunnel->parms.link,
1521 + .nl_u = { .ip4_u =
1522 + { .daddr = iph->daddr,
1523 + .saddr = iph->saddr,
1524 + .tos = RT_TOS(iph->tos) } },
1525 + .proto = IPPROTO_GRE };
1526 + struct rtable *rt;
1527 + if (!ip_route_output_key(&rt, &fl)) {
1528 + tdev = rt->u.dst.dev;
1532 + if (tunnel->parms.proto_type == ETH_P_ETH)
1534 + dev->flags |= IFF_BROADCAST;
1538 + dev->flags |= IFF_POINTOPOINT;
1541 +#ifdef CONFIG_NET_IPGRE_BROADCAST
1542 + if (MULTICAST(iph->daddr)) {
1545 + dev->flags = IFF_BROADCAST;
1546 + dev->hard_header = ipgre_header;
1547 + dev->open = ipgre_open;
1548 + dev->stop = ipgre_close;
1553 + if (!tdev && tunnel->parms.link)
1554 + tdev = __dev_get_by_index(&init_net, tunnel->parms.link);
1557 + hlen = tdev->hard_header_len;
1560 + dev->iflink = tunnel->parms.link;
1562 + /* Precalculate GRE options length */
1563 + if (tunnel->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) {
1564 + if (tunnel->parms.o_flags&GRE_CSUM)
1566 + if (tunnel->parms.o_flags&GRE_KEY)
1568 + if (tunnel->parms.o_flags&GRE_SEQ)
1571 + dev->hard_header_len = hlen + addend;
1572 + dev->mtu = mtu - addend;
1573 + tunnel->hlen = addend;
1577 +static int __init ipgre_fb_tunnel_init(struct net_device *dev)
1579 + struct ip_tunnel *tunnel = netdev_priv(dev);
1580 + struct iphdr *iph = &tunnel->parms.iph;
1582 + tunnel->dev = dev;
1583 + strcpy(tunnel->parms.name, dev->name);
1586 + iph->protocol = IPPROTO_GRE;
1588 + tunnel->hlen = sizeof(struct iphdr) + 4;
1591 + tunnels_wc[0] = tunnel;
1596 +static struct net_protocol ipgre_protocol = {
1597 + .handler = ipgre_rcv,
1598 + .err_handler = ipgre_err,
1603 + * And now the modules code and kernel interface.
1606 +static int __init ipgre_init(void)
1610 + printk(KERN_INFO "GRE over IPv4 tunneling driver\n");
1612 + if (inet_add_protocol(&ipgre_protocol, IPPROTO_GRE) < 0) {
1613 + printk(KERN_INFO "ipgre init: can't add protocol\n");
1617 + ipgre_fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "gre0",
1618 + ipgre_ip_tunnel_setup);
1619 + if (!ipgre_fb_tunnel_dev) {
1624 + ipgre_fb_tunnel_dev->init = ipgre_fb_tunnel_init;
1626 + if ((err = register_netdev(ipgre_fb_tunnel_dev)))
1631 + free_netdev(ipgre_fb_tunnel_dev);
1633 + inet_del_protocol(&ipgre_protocol, IPPROTO_GRE);
1637 +static void __exit ipgre_destroy_tunnels(void)
1641 + for (prio = 0; prio < 4; prio++) {
1643 + for (h = 0; h < HASH_SIZE; h++) {
1644 + struct ip_tunnel *t;
1645 + while ((t = tunnels[prio][h]) != NULL)
1646 + unregister_netdevice(t->dev);
1651 +static void __exit ipgre_fini(void)
1653 + if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0)
1654 + printk(KERN_INFO "ipgre close: can't remove protocol\n");
1657 + ipgre_destroy_tunnels();
1661 +module_init(ipgre_init);
1662 +module_exit(ipgre_fini);
1663 +MODULE_LICENSE("GPL");
1664 diff -Nurb linux-2.6.27-660/include/linux/if_ether.h linux-2.6.27-700/include/linux/if_ether.h
1665 --- linux-2.6.27-660/include/linux/if_ether.h 2008-10-09 18:13:53.000000000 -0400
1666 +++ linux-2.6.27-700/include/linux/if_ether.h 2009-04-10 17:35:46.000000000 -0400
1668 #define ETH_P_DIAG 0x6005 /* DEC Diagnostics */
1669 #define ETH_P_CUST 0x6006 /* DEC Customer use */
1670 #define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */
1671 +#define ETH_P_ETH 0x6558 /* Ethernet in Ethernet */
1672 #define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */
1673 #define ETH_P_ATALK 0x809B /* Appletalk DDP */
1674 #define ETH_P_AARP 0x80F3 /* Appletalk AARP */
1675 diff -Nurb linux-2.6.27-660/include/linux/if_tunnel.h linux-2.6.27-700/include/linux/if_tunnel.h
1676 --- linux-2.6.27-660/include/linux/if_tunnel.h 2008-10-09 18:13:53.000000000 -0400
1677 +++ linux-2.6.27-700/include/linux/if_tunnel.h 2009-04-10 17:35:46.000000000 -0400
1682 + __be16 proto_type; /*Added*/
1686 diff -Nurb linux-2.6.27-660/net/ipv4/ip_gre.c linux-2.6.27-700/net/ipv4/ip_gre.c
1687 --- linux-2.6.27-660/net/ipv4/ip_gre.c 2008-10-09 18:13:53.000000000 -0400
1688 +++ linux-2.6.27-700/net/ipv4/ip_gre.c 2009-04-10 18:20:30.000000000 -0400
1690 #include <linux/init.h>
1691 #include <linux/in6.h>
1692 #include <linux/inetdevice.h>
1693 +#include <linux/etherdevice.h> /**XXX added XXX */
1694 #include <linux/igmp.h>
1695 #include <linux/netfilter_ipv4.h>
1696 #include <linux/if_ether.h>
1698 #include <net/ip6_route.h>
1701 +//#define GRE_DEBUG 1
1704 Problems & solutions
1705 --------------------
1709 static int ipgre_tunnel_init(struct net_device *dev);
1710 -static void ipgre_tunnel_setup(struct net_device *dev);
1711 +static void ipgre_ip_tunnel_setup(struct net_device *dev);
1712 +static void ipgre_eth_tunnel_setup(struct net_device *dev);
1714 /* Fallback tunnel: no source, no destination, no key, no options */
1717 __be32 remote = parms->iph.daddr;
1718 __be32 local = parms->iph.saddr;
1719 __be32 key = parms->i_key;
1720 + __be16 proto = parms->proto_type;
1721 struct ip_tunnel *t, **tp, *nt;
1722 struct net_device *dev;
1723 char name[IFNAMSIZ];
1724 @@ -269,12 +274,28 @@
1728 + printk(KERN_CRIT "Adding tunnel %s with key %d\n", parms->name, ntohl(key));
1731 strlcpy(name, parms->name, IFNAMSIZ);
1733 sprintf(name, "gre%%d");
1735 - dev = alloc_netdev(sizeof(*t), name, ipgre_tunnel_setup);
1737 + /* Tunnel creation: check payload type and call appropriate
1742 + dev = alloc_netdev(sizeof(*t), name, ipgre_ip_tunnel_setup);
1745 + dev = alloc_netdev(sizeof(*t), name, ipgre_eth_tunnel_setup);
1756 struct ip_tunnel *tunnel;
1760 if (!pskb_may_pull(skb, 16))
1762 @@ -439,6 +461,11 @@
1764 flags = *(__be16*)h;
1767 + printk(KERN_DEBUG "gre.c [601] src:%x dst:%x proto:%d %p", iph->saddr, iph->daddr, iph->protocol, skb->data);
1769 + proto = ntohs(*(__be16*)(h+2)); /* XXX added XXX */
1771 if (flags&(GRE_CSUM|GRE_KEY|GRE_ROUTING|GRE_SEQ|GRE_VERSION)) {
1772 /* - Version must be 0.
1773 - We do not support routing headers.
1774 @@ -493,7 +520,29 @@
1775 __pskb_pull(skb, offset);
1776 skb_reset_network_header(skb);
1777 skb_postpull_rcsum(skb, skb_transport_header(skb), offset);
1778 + if(proto == ETH_P_ETH)
1781 + unsigned char* tmp_hdr = skb->data;
1782 + 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);
1784 + skb->protocol = eth_type_trans(skb, tunnel->dev);
1786 + /* XXX added these lines to make arp work? XXX */
1787 + /*skb->mac.raw = skb->data;*/
1788 + skb->network_header = skb->network_header + ETH_HLEN;
1789 + /* XXX added these lines to make arp work? XXX */
1792 + tmp_hdr = skb->data;
1793 + 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);
1794 + printk(KERN_ALERT "gre.c [671] received ethernet on gre %x\n",skb->protocol);
1796 + memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
1799 skb->pkt_type = PACKET_HOST;
1801 #ifdef CONFIG_NET_IPGRE_BROADCAST
1802 if (ipv4_is_multicast(iph->daddr)) {
1803 /* Looped back packet, drop it! */
1808 -static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
1809 +static int ipgre_ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
1811 struct ip_tunnel *tunnel = netdev_priv(dev);
1812 struct net_device_stats *stats = &tunnel->dev->stats;
1813 @@ -799,9 +848,17 @@
1814 tdev = rt->u.dst.dev;
1817 + if (tunnel->parms.proto_type == ETH_P_ETH)
1819 + dev->flags |= IFF_BROADCAST;
1823 dev->flags |= IFF_POINTOPOINT;
1828 if (!tdev && tunnel->parms.link)
1829 tdev = __dev_get_by_index(dev_net(dev), tunnel->parms.link);
1831 @@ -822,10 +879,234 @@
1833 dev->hard_header_len = hlen + addend;
1834 dev->mtu = mtu - addend;
1835 + if (tunnel->parms.proto_type == ETH_P_ETH)
1836 + dev->mtu -= ETH_HLEN;
1837 tunnel->hlen = addend;
1841 +static int ipgre_eth_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
1843 + struct ip_tunnel *tunnel = netdev_priv(dev);
1844 + struct net_device_stats *stats = &tunnel->stat;
1845 + struct iphdr *old_iph = ip_hdr(skb);
1846 + struct iphdr *tiph = &tunnel->parms.iph;
1849 + struct rtable *rt; /* Route to the other host */
1850 + struct net_device *tdev; /* Device to other host */
1851 + int gre_hlen = tunnel->hlen; /* XXX changed XXX*/
1852 + //struct etheriphdr *ethiph;
1853 + struct iphdr *iph; /* Our new IP header */
1854 + int max_headroom; /* The extra header space needed */
1858 + printk(KERN_ALERT "gre.c:972 Starting xmit\n");
1861 + if (tunnel->recursion++) {
1862 + stats->collisions++;
1866 + /* Need valid non-multicast daddr. */
1867 + if (tiph->daddr == 0 || MULTICAST(tiph->daddr))
1872 + if (skb->protocol == htons(ETH_P_IP))
1873 + tos = old_iph->tos;
1877 + printk(KERN_ALERT "gre.c:991 Passed tos assignment.\n");
1882 + struct flowi fl = { .fl_net = &init_net,
1883 + .oif = tunnel->parms.link,
1884 + .nl_u = { .ip4_u =
1885 + { .daddr = tiph->daddr,
1886 + .saddr = tiph->saddr,
1887 + .tos = RT_TOS(tos) } },
1888 + .proto = IPPROTO_GRE };
1889 + if (ip_route_output_key(&rt, &fl)) {
1890 + stats->tx_carrier_errors++;
1891 + goto tx_error_icmp;
1894 + tdev = rt->u.dst.dev;
1896 + printk(KERN_ALERT "gre.c:1006 Passed the route retrieval\n");
1898 + if (tdev == dev) {
1900 + stats->collisions++;
1904 + printk(KERN_ALERT "gre.c:1018 Passed tdev collision check.\n");
1907 + /* Check MTU stuff if kernel panic */
1908 + df = tiph->frag_off;
1910 + mtu = dst_mtu(&rt->u.dst) - tunnel->hlen;
1912 + mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
1915 + skb->dst->ops->update_pmtu(skb->dst, mtu);
1918 + printk(KERN_ALERT "gre.c:1032 Passed the pmtu setting.\n");
1921 + if (skb->protocol == htons(ETH_P_IP)) {
1922 + df |= (old_iph->frag_off&htons(IP_DF));
1924 + if ((old_iph->frag_off & htons(IP_DF)) &&
1925 + mtu < ntohs(old_iph->tot_len)) {
1926 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
1932 + else if (skb->protocol == htons(ETH_P_IPV6)) {
1933 + struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
1935 + if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) {
1936 + if (tiph->daddr || rt6->rt6i_dst.plen == 128) {
1937 + rt6->rt6i_flags |= RTF_MODIFIED;
1938 + skb->dst->metrics[RTAX_MTU-1] = mtu;
1942 + /* @@@ Is this correct? */
1943 + if (mtu >= IPV6_MIN_MTU && mtu < skb->len - tunnel->hlen + gre_hlen) {
1944 + icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
1951 + printk(KERN_ALERT "gre.c:1065 Passed the fragmentation check.\n");
1954 + if (tunnel->err_count > 0) {
1955 + if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
1956 + tunnel->err_count--;
1957 + dst_link_failure(skb);
1959 + tunnel->err_count = 0;
1962 + max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen;
1964 + if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
1965 + struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
1968 + stats->tx_dropped++;
1969 + dev_kfree_skb(skb);
1970 + tunnel->recursion--;
1974 + skb_set_owner_w(new_skb, skb->sk);
1975 + dev_kfree_skb(skb);
1977 + old_iph = ip_hdr(skb);
1980 + printk(KERN_ALERT "gre.c:1094 Passed the headroom calculation\n");
1983 + skb->transport_header = skb->data;
1984 + skb_push(skb, gre_hlen);
1985 + skb_reset_network_header(skb);
1986 + memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1987 + dst_release(skb->dst);
1988 + skb->dst = &rt->u.dst;
1991 + * Push down and install the etherip header.
1994 + iph = ip_hdr(skb);
1996 + iph->ihl = sizeof(struct iphdr) >> 2;
1997 + iph->frag_off = df;
1998 + iph->protocol = IPPROTO_GRE;
1999 + iph->tos = ipgre_ecn_encapsulate(tos, old_iph, skb);
2000 + iph->daddr = rt->rt_dst;
2001 + iph->saddr = rt->rt_src;
2003 +/* ethiph->version = htons(ETHERIP_VERSION); */
2005 + printk(KERN_ALERT "gre.c:1121 Passed outer IP header construction.\n");
2008 + if ((iph->ttl = tiph->ttl) == 0) {
2009 + if (skb->protocol == htons(ETH_P_IP))
2010 + iph->ttl = old_iph->ttl;
2012 + else if (skb->protocol == htons(ETH_P_IPV6))
2013 + iph->ttl = ((struct ipv6hdr*)old_iph)->hop_limit;
2016 + iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
2019 + printk(KERN_ALERT "gre.c:1006 Passed the TTL check.\n");
2022 + ((__be16*)(iph+1))[0] = tunnel->parms.o_flags;
2023 + ((__be16*)(iph+1))[1] = htons(tunnel->parms.proto_type);
2025 + if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
2026 + __be32 *ptr = (__be32*)(((u8*)iph) + tunnel->hlen - 4);
2028 + if (tunnel->parms.o_flags&GRE_SEQ) {
2029 + ++tunnel->o_seqno;
2030 + *ptr = htonl(tunnel->o_seqno);
2033 + if (tunnel->parms.o_flags&GRE_KEY) {
2034 + *ptr = tunnel->parms.o_key;
2037 + if (tunnel->parms.o_flags&GRE_CSUM) {
2039 + *(__sum16*)ptr = ip_compute_csum((void*)(iph+1), skb->len - sizeof(struct iphdr));
2043 + printk(KERN_ALERT "gre.c:1006 Passed the tunnel transmit.\n");
2049 + tunnel->recursion--;
2053 + dst_link_failure(skb);
2056 + stats->tx_errors++;
2057 + dev_kfree_skb(skb);
2058 + tunnel->recursion--;
2064 ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
2066 @@ -876,6 +1157,7 @@
2069 t = ipgre_tunnel_locate(net, &p, cmd == SIOCADDTUNNEL);
2070 + if (t) printk(KERN_ALERT "1174 GRE: proto %s %x\n", p.name, p.proto_type);
2072 if (dev != ign->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
2074 @@ -893,6 +1175,12 @@
2075 else if (p.iph.daddr)
2076 nflags = IFF_POINTOPOINT;
2078 + /* XXX:Set back IFF_BROADCAST if
2079 + * transporting ethernet */
2080 + printk(KERN_ALERT "1193 GRE: proto %s %d\n", p.name, p.proto_type);
2081 + if (p.proto_type == ETH_P_ETH)
2082 + nflags = IFF_BROADCAST;
2084 if ((dev->flags^nflags)&(IFF_POINTOPOINT|IFF_BROADCAST)) {
2087 @@ -902,8 +1190,13 @@
2088 t->parms.iph.daddr = p.iph.daddr;
2089 t->parms.i_key = p.i_key;
2090 t->parms.o_key = p.o_key;
2091 + /* XXX:Copy in the protocol field */
2092 + t->parms.proto_type = p.proto_type;
2093 + if (t->parms.proto_type != ETH_P_ETH) {
2094 memcpy(dev->dev_addr, &p.iph.saddr, 4);
2095 memcpy(dev->broadcast, &p.iph.daddr, 4);
2098 ipgre_tunnel_link(ign, t);
2099 netdev_state_change(dev);
2101 @@ -1076,13 +1369,13 @@
2105 -static void ipgre_tunnel_setup(struct net_device *dev)
2106 +static void ipgre_ip_tunnel_setup(struct net_device *dev)
2108 dev->uninit = ipgre_tunnel_uninit;
2109 dev->destructor = free_netdev;
2110 - dev->hard_start_xmit = ipgre_tunnel_xmit;
2111 dev->do_ioctl = ipgre_tunnel_ioctl;
2112 dev->change_mtu = ipgre_tunnel_change_mtu;
2113 + dev->hard_start_xmit = ipgre_ip_tunnel_xmit;
2115 dev->type = ARPHRD_IPGRE;
2116 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr) + 4;
2117 @@ -1093,6 +1386,35 @@
2118 dev->features |= NETIF_F_NETNS_LOCAL;
2121 +/* Tunnel setup for ipgre_eth */
2122 +static void ipgre_eth_tunnel_setup(struct net_device *dev)
2124 + SET_MODULE_OWNER(dev);
2126 + // Set default values for Ethernet device
2129 + dev->uninit = ipgre_tunnel_uninit;
2130 + dev->destructor = free_netdev;
2131 + dev->hard_start_xmit = ipgre_eth_tunnel_xmit;
2132 + dev->get_stats = ipgre_tunnel_get_stats;
2133 + dev->do_ioctl = ipgre_tunnel_ioctl;
2134 + dev->change_mtu = ipgre_tunnel_change_mtu;
2136 + dev->hard_header_len = LL_MAX_HEADER + ETH_HLEN + sizeof(struct iphdr) + 4;
2137 + dev->mtu = ETH_DATA_LEN - ETH_HLEN - sizeof(struct iphdr) - 4;
2138 + dev->tx_queue_len = 0;
2141 + random_ether_addr(dev->dev_addr);
2144 + { unsigned char* d = dev->dev_addr;
2145 + 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]); }
2150 static int ipgre_tunnel_init(struct net_device *dev)
2152 struct ip_tunnel *tunnel;
2153 @@ -1104,8 +1426,10 @@
2155 strcpy(tunnel->parms.name, dev->name);
2157 + if (tunnel->parms.proto_type != ETH_P_ETH) {
2158 memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
2159 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
2162 ipgre_tunnel_bind_dev(dev);
2164 @@ -1181,7 +1505,7 @@
2167 ign->fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "gre0",
2168 - ipgre_tunnel_setup);
2169 + ipgre_ip_tunnel_setup);
2170 if (!ign->fb_tunnel_dev) {
2173 diff -Nurb linux-2.6.27-660/rej linux-2.6.27-700/rej
2174 --- linux-2.6.27-660/rej 1969-12-31 19:00:00.000000000 -0500
2175 +++ linux-2.6.27-700/rej 2009-04-10 17:50:33.000000000 -0400
2177 +./net/ipv4/ip_gre.c.rej
2178 +./drivers/net/Makefile.rej