netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gre: copy ToS/DiffServ bits to outer IP header
@ 2009-06-29 13:07 Andreas Jaggi
  2009-06-29 13:48 ` Patrick McHardy
  0 siblings, 1 reply; 14+ messages in thread
From: Andreas Jaggi @ 2009-06-29 13:07 UTC (permalink / raw)
  To: netdev, kuznet; +Cc: davem, kaber, linux-kernel

When tunneling IP traffic with GRE this patch makes it possible to export the ToS/DiffServ information to the outer IP header.
This is particularly useful in a scenario with ESP/AH where the inner IP header is encrypted but the packet priority/DiffServ information
should still be respected by the transporting routers (for example in an MPLS backbone network).

The feature is disabled by default and can be enabled on a per-interface basis (/proc/sys/net/ipv4/conf/ethX/gre_copy_tos).

Also does this bring Linux back in the game, as JunOS/IOS provide this for quite some time:
http://www.cisco.com/en/US/docs/ios/11_3/feature/guide/greqos.html
http://www.juniper.net/techpubs/software/junos/junos94/swconfig-services/configuring-a-gre-tunnel-to-copy-tos-bits-to-the-outer-ip-header.html

Signed-off-by: Andreas Jaggi <aj@open.ch>

diff -urN vanilla-linux-2.6.29.4/include/linux/sysctl.h gre-copy-tos/include/linux/sysctl.h
--- vanilla-linux-2.6.29.4/include/linux/sysctl.h	2009-05-19 01:52:34.000000000 +0200
+++ gre-copy-tos/include/linux/sysctl.h	2009-06-29 14:23:07.000000000 +0200
@@ -490,6 +490,7 @@
 	NET_IPV4_CONF_ARP_IGNORE=19,
 	NET_IPV4_CONF_PROMOTE_SECONDARIES=20,
 	NET_IPV4_CONF_ARP_ACCEPT=21,
+	NET_IPV4_CONF_GRE_COPY_TOS=22,
 	__NET_IPV4_CONF_MAX
 };
 
diff -urN vanilla-linux-2.6.29.4/kernel/sysctl_check.c gre-copy-tos/kernel/sysctl_check.c
--- vanilla-linux-2.6.29.4/kernel/sysctl_check.c	2009-05-19 01:52:34.000000000 +0200
+++ gre-copy-tos/kernel/sysctl_check.c	2009-06-29 14:23:07.000000000 +0200
@@ -219,6 +219,7 @@
 	{ NET_IPV4_CONF_ARP_IGNORE,		"arp_ignore" },
 	{ NET_IPV4_CONF_PROMOTE_SECONDARIES,	"promote_secondaries" },
 	{ NET_IPV4_CONF_ARP_ACCEPT,		"arp_accept" },
+	{ NET_IPV4_CONF_GRE_COPY_TOS,		"gre_copy_tos" },
 	{}
 };
 
diff -urN vanilla-linux-2.6.29.4/net/ipv4/devinet.c gre-copy-tos/net/ipv4/devinet.c
--- vanilla-linux-2.6.29.4/net/ipv4/devinet.c	2009-05-19 01:52:34.000000000 +0200
+++ gre-copy-tos/net/ipv4/devinet.c	2009-06-29 14:23:07.000000000 +0200
@@ -1439,6 +1439,7 @@
 		DEVINET_SYSCTL_RW_ENTRY(ARP_ANNOUNCE, "arp_announce"),
 		DEVINET_SYSCTL_RW_ENTRY(ARP_IGNORE, "arp_ignore"),
 		DEVINET_SYSCTL_RW_ENTRY(ARP_ACCEPT, "arp_accept"),
+		DEVINET_SYSCTL_RW_ENTRY(GRE_COPY_TOS, "gre_copy_tos"),
 
 		DEVINET_SYSCTL_FLUSHING_ENTRY(NOXFRM, "disable_xfrm"),
 		DEVINET_SYSCTL_FLUSHING_ENTRY(NOPOLICY, "disable_policy"),
diff -urN vanilla-linux-2.6.29.4/net/ipv4/ip_gre.c gre-copy-tos/net/ipv4/ip_gre.c
--- vanilla-linux-2.6.29.4/net/ipv4/ip_gre.c	2009-05-19 01:52:34.000000000 +0200
+++ gre-copy-tos/net/ipv4/ip_gre.c	2009-06-29 14:23:24.000000000 +0200
@@ -610,6 +610,7 @@
 	struct net_device_stats *stats = &tunnel->dev->stats;
 	struct iphdr  *old_iph = ip_hdr(skb);
 	struct iphdr  *tiph;
+	struct in_device *in_dev;
 	u8     tos;
 	__be16 df;
 	struct rtable *rt;     			/* Route to the other host */
@@ -677,11 +678,13 @@
 	}
 
 	tos = tiph->tos;
-	if (tos&1) {
+	in_dev = in_dev_get(dev);
+	if ((in_dev && IN_DEV_ORCONF(in_dev, GRE_COPY_TOS)) || tos&1) {
 		if (skb->protocol == htons(ETH_P_IP))
 			tos = old_iph->tos;
 		tos &= ~1;
 	}
+	in_dev_put(in_dev);
 
 	{
 		struct flowi fl = { .oif = tunnel->parms.link,

^ permalink raw reply	[flat|nested] 14+ messages in thread
* [PATCH] gre: copy ToS/DiffServ bits to outer IP header
@ 2009-07-13 13:32 Andreas Jaggi
  2009-07-13 15:33 ` Stephen Hemminger
  2009-07-13 17:44 ` David Miller
  0 siblings, 2 replies; 14+ messages in thread
From: Andreas Jaggi @ 2009-07-13 13:32 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuznet, kaber

When tunneling IP traffic with GRE this patch makes it possible to export the
ToS/DiffServ information to the outer IP header. This is particularly useful in
a scenario with ESP/AH where the inner IP header is encrypted but the packet
priority/DiffServ information should still be respected by the transporting
routers (for example in an MPLS backbone network).

The feature is disabled by default and can be enabled on per-interface basis.
The flag is stored in an unused bit of ip_tunnel_parm.o_flags, and can be
modified through the rntl_link interface.

Also does this bring Linux back in the game, as JunOS/IOS provide this for
quite some time:
http://www.cisco.com/en/US/docs/ios/11_3/feature/guide/greqos.html
http://www.juniper.net/techpubs/software/junos/junos94/swconfig-services/configuring-a-gre-tunnel-to-copy-tos-bits-to-the-outer-ip-header.html

Signed-off-by: Andreas Jaggi <aj@open.ch>

diff -urN vanilla-linux-2.6.29.4/include/linux/if_tunnel.h dev-gre/include/linux/if_tunnel.h
--- vanilla-linux-2.6.29.4/include/linux/if_tunnel.h	2009-05-19 01:52:34.000000000 +0200
+++ dev-gre/include/linux/if_tunnel.h	2009-07-13 15:15:26.000000000 +0200
@@ -24,6 +24,7 @@
 #define GRE_REC		__constant_htons(0x0700)
 #define GRE_FLAGS	__constant_htons(0x00F8)
 #define GRE_VERSION	__constant_htons(0x0007)
+#define GRE_COPY_TOS	__constant_htons(0x0008)
 
 struct ip_tunnel_parm
 {
diff -urN vanilla-linux-2.6.29.4/net/ipv4/ip_gre.c dev-gre/net/ipv4/ip_gre.c
--- vanilla-linux-2.6.29.4/net/ipv4/ip_gre.c	2009-05-19 01:52:34.000000000 +0200
+++ dev-gre/net/ipv4/ip_gre.c	2009-07-01 15:30:44.000000000 +0200
@@ -677,7 +677,7 @@
 	}
 
 	tos = tiph->tos;
-	if (tos&1) {
+	if (tunnel->parms.o_flags&GRE_COPY_TOS || tos&1) {
 		if (skb->protocol == htons(ETH_P_IP))
 			tos = old_iph->tos;
 		tos &= ~1;
@@ -804,7 +804,7 @@
 			iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
 	}
 
-	((__be16 *)(iph + 1))[0] = tunnel->parms.o_flags;
+	((__be16 *)(iph + 1))[0] = tunnel->parms.o_flags&~GRE_FLAGS;
 	((__be16 *)(iph + 1))[1] = (dev->type == ARPHRD_ETHER) ?
 				   htons(ETH_P_TEB) : skb->protocol;
 
@@ -1080,7 +1080,7 @@
 	__be16 *p = (__be16*)(iph+1);
 
 	memcpy(iph, &t->parms.iph, sizeof(struct iphdr));
-	p[0]		= t->parms.o_flags;
+	p[0]		= t->parms.o_flags&~GRE_FLAGS;
 	p[1]		= htons(type);
 
 	/*
@@ -1503,6 +1503,7 @@
 	t->parms.iph.ttl = p.iph.ttl;
 	t->parms.iph.tos = p.iph.tos;
 	t->parms.iph.frag_off = p.iph.frag_off;
+	t->parms.o_flags |= p.o_flags&GRE_COPY_TOS;
 
 	if (t->parms.link != p.link) {
 		t->parms.link = p.link;

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-07-14 16:35 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-29 13:07 [PATCH] gre: copy ToS/DiffServ bits to outer IP header Andreas Jaggi
2009-06-29 13:48 ` Patrick McHardy
2009-06-30  9:05   ` Andreas Jaggi
2009-07-01 10:28     ` Patrick McHardy
2009-06-30  9:06   ` Andreas Jaggi
  -- strict thread matches above, loose matches on Subject: below --
2009-07-13 13:32 Andreas Jaggi
2009-07-13 15:33 ` Stephen Hemminger
2009-07-13 16:01   ` Andreas Jaggi
2009-07-13 16:07     ` Stephen Hemminger
2009-07-13 16:27       ` David Miller
2009-07-13 17:44 ` David Miller
2009-07-14  7:14   ` Andreas Jaggi
2009-07-14 16:35     ` David Miller
2009-07-14 14:21   ` Andreas Jaggi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).