netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 0/2] rebinding tunnels to interfaces
@ 2007-12-13 13:37 mschmidt
  2007-12-13 13:37 ` [patch 1/2] ip_gre: Rebinding of GRE tunnels to other interfaces mschmidt
  2007-12-13 13:37 ` [patch 2/2] ipv6/sit: Rebinding of SIT " mschmidt
  0 siblings, 2 replies; 5+ messages in thread
From: mschmidt @ 2007-12-13 13:37 UTC (permalink / raw)
  To: netdev; +Cc: davem, kaber, mmaslano

These two patches allow rebinding of GRE and SIT tunnels to interfaces using
ip tun change <tunnel> dev <iface>
A similar change was already done for IPIP tunnels.

Michal
-- 

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

* [patch 1/2] ip_gre: Rebinding of GRE tunnels to other interfaces
  2007-12-13 13:37 [patch 0/2] rebinding tunnels to interfaces mschmidt
@ 2007-12-13 13:37 ` mschmidt
  2007-12-13 17:47   ` David Miller
  2007-12-13 13:37 ` [patch 2/2] ipv6/sit: Rebinding of SIT " mschmidt
  1 sibling, 1 reply; 5+ messages in thread
From: mschmidt @ 2007-12-13 13:37 UTC (permalink / raw)
  To: netdev; +Cc: davem, kaber, mmaslano

[-- Attachment #1: ip_gre-chgtunnel.patch --]
[-- Type: text/plain, Size: 4605 bytes --]

This is similar to the change already done for IPIP tunnels.

Once created, a GRE tunnel can't be bound to another device.
To reproduce:

# create a tunnel:
ip tunnel add tunneltest0 mode gre remote 10.0.0.1 dev eth0
# try to change the bounding device from eth0 to eth1:
ip tunnel change tunneltest0 dev eth1
# show the result:
ip tunnel show tunneltest0

tunneltest0: gre/ip  remote 10.0.0.1  local any  dev eth0  ttl inherit

Notice the bound device has not changed from eth0 to eth1.

This patch fixes it. When changing the binding, it also recalculates the
MTU according to the new bound device's MTU.

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>

Index: linus-kernel.git/net/ipv4/ip_gre.c
===================================================================
--- linus-kernel.git.orig/net/ipv4/ip_gre.c
+++ linus-kernel.git/net/ipv4/ip_gre.c
@@ -896,6 +896,59 @@ tx_error:
 	return 0;
 }
 
+static void ipgre_tunnel_bind_dev(struct net_device *dev)
+{
+	struct net_device *tdev = NULL;
+	struct ip_tunnel *tunnel;
+	struct iphdr *iph;
+	int hlen = LL_MAX_HEADER;
+	int mtu = ETH_DATA_LEN;
+	int addend = sizeof(struct iphdr) + 4;
+
+	tunnel = netdev_priv(dev);
+	iph = &tunnel->parms.iph;
+
+	/* Guess output device to choose reasonable mtu and hard_header_len */
+
+	if (iph->daddr) {
+		struct flowi fl = { .oif = tunnel->parms.link,
+				    .nl_u = { .ip4_u =
+					      { .daddr = iph->daddr,
+						.saddr = iph->saddr,
+						.tos = RT_TOS(iph->tos) } },
+				    .proto = IPPROTO_GRE };
+		struct rtable *rt;
+		if (!ip_route_output_key(&rt, &fl)) {
+			tdev = rt->u.dst.dev;
+			ip_rt_put(rt);
+		}
+		dev->flags |= IFF_POINTOPOINT;
+	}
+
+	if (!tdev && tunnel->parms.link)
+		tdev = __dev_get_by_index(&init_net, tunnel->parms.link);
+
+	if (tdev) {
+		hlen = tdev->hard_header_len;
+		mtu = tdev->mtu;
+	}
+	dev->iflink = tunnel->parms.link;
+
+	/* Precalculate GRE options length */
+	if (tunnel->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) {
+		if (tunnel->parms.o_flags&GRE_CSUM)
+			addend += 4;
+		if (tunnel->parms.o_flags&GRE_KEY)
+			addend += 4;
+		if (tunnel->parms.o_flags&GRE_SEQ)
+			addend += 4;
+	}
+	dev->hard_header_len = hlen + addend;
+	dev->mtu = mtu - addend;
+	tunnel->hlen = addend;
+
+}
+
 static int
 ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
 {
@@ -983,6 +1036,11 @@ ipgre_tunnel_ioctl (struct net_device *d
 				t->parms.iph.ttl = p.iph.ttl;
 				t->parms.iph.tos = p.iph.tos;
 				t->parms.iph.frag_off = p.iph.frag_off;
+				if (t->parms.link != p.link) {
+					t->parms.link = p.link;
+					ipgre_tunnel_bind_dev(dev);
+					netdev_state_change(dev);
+				}
 			}
 			if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
 				err = -EFAULT;
@@ -1162,12 +1220,8 @@ static void ipgre_tunnel_setup(struct ne
 
 static int ipgre_tunnel_init(struct net_device *dev)
 {
-	struct net_device *tdev = NULL;
 	struct ip_tunnel *tunnel;
 	struct iphdr *iph;
-	int hlen = LL_MAX_HEADER;
-	int mtu = ETH_DATA_LEN;
-	int addend = sizeof(struct iphdr) + 4;
 
 	tunnel = netdev_priv(dev);
 	iph = &tunnel->parms.iph;
@@ -1178,23 +1232,9 @@ static int ipgre_tunnel_init(struct net_
 	memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
 	memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
 
-	/* Guess output device to choose reasonable mtu and hard_header_len */
+	ipgre_tunnel_bind_dev(dev);
 
 	if (iph->daddr) {
-		struct flowi fl = { .oif = tunnel->parms.link,
-				    .nl_u = { .ip4_u =
-					      { .daddr = iph->daddr,
-						.saddr = iph->saddr,
-						.tos = RT_TOS(iph->tos) } },
-				    .proto = IPPROTO_GRE };
-		struct rtable *rt;
-		if (!ip_route_output_key(&rt, &fl)) {
-			tdev = rt->u.dst.dev;
-			ip_rt_put(rt);
-		}
-
-		dev->flags |= IFF_POINTOPOINT;
-
 #ifdef CONFIG_NET_IPGRE_BROADCAST
 		if (MULTICAST(iph->daddr)) {
 			if (!iph->saddr)
@@ -1205,31 +1245,9 @@ static int ipgre_tunnel_init(struct net_
 			dev->stop = ipgre_close;
 		}
 #endif
-	} else {
+	} else
 		dev->header_ops = &ipgre_header_ops;
-	}
-
-	if (!tdev && tunnel->parms.link)
-		tdev = __dev_get_by_index(&init_net, tunnel->parms.link);
-
-	if (tdev) {
-		hlen = tdev->hard_header_len;
-		mtu = tdev->mtu;
-	}
-	dev->iflink = tunnel->parms.link;
 
-	/* Precalculate GRE options length */
-	if (tunnel->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) {
-		if (tunnel->parms.o_flags&GRE_CSUM)
-			addend += 4;
-		if (tunnel->parms.o_flags&GRE_KEY)
-			addend += 4;
-		if (tunnel->parms.o_flags&GRE_SEQ)
-			addend += 4;
-	}
-	dev->hard_header_len = hlen + addend;
-	dev->mtu = mtu - addend;
-	tunnel->hlen = addend;
 	return 0;
 }
 

-- 

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

* [patch 2/2] ipv6/sit: Rebinding of SIT tunnels to other interfaces
  2007-12-13 13:37 [patch 0/2] rebinding tunnels to interfaces mschmidt
  2007-12-13 13:37 ` [patch 1/2] ip_gre: Rebinding of GRE tunnels to other interfaces mschmidt
@ 2007-12-13 13:37 ` mschmidt
  2007-12-13 17:47   ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: mschmidt @ 2007-12-13 13:37 UTC (permalink / raw)
  To: netdev; +Cc: davem, kaber, mmaslano

[-- Attachment #1: ipv6-sit-chgtunnel.patch --]
[-- Type: text/plain, Size: 3577 bytes --]

This is similar to the change already done for IPIP tunnels.

Once created, a SIT tunnel can't be bound to another device.
To reproduce:

# create a tunnel:
ip tunnel add tunneltest0 mode sit remote 10.0.0.1 dev eth0
# try to change the bounding device from eth0 to eth1:
ip tunnel change tunneltest0 dev eth1
# show the result:
ip tunnel show tunneltest0

tunneltest0: ipv6/ip  remote 10.0.0.1  local any  dev eth0  ttl inherit

Notice the bound device has not changed from eth0 to eth1.

This patch fixes it. When changing the binding, it also recalculates the
MTU according to the new bound device's MTU.

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>

Index: linus-kernel.git/net/ipv6/sit.c
===================================================================
--- linus-kernel.git.orig/net/ipv6/sit.c
+++ linus-kernel.git/net/ipv6/sit.c
@@ -669,6 +669,42 @@ tx_error:
 	return 0;
 }
 
+static void ipip6_tunnel_bind_dev(struct net_device *dev)
+{
+	struct net_device *tdev = NULL;
+	struct ip_tunnel *tunnel;
+	struct iphdr *iph;
+
+	tunnel = netdev_priv(dev);
+	iph = &tunnel->parms.iph;
+
+	if (iph->daddr) {
+		struct flowi fl = { .nl_u = { .ip4_u =
+					      { .daddr = iph->daddr,
+						.saddr = iph->saddr,
+						.tos = RT_TOS(iph->tos) } },
+				    .oif = tunnel->parms.link,
+				    .proto = IPPROTO_IPV6 };
+		struct rtable *rt;
+		if (!ip_route_output_key(&rt, &fl)) {
+			tdev = rt->u.dst.dev;
+			ip_rt_put(rt);
+		}
+		dev->flags |= IFF_POINTOPOINT;
+	}
+
+	if (!tdev && tunnel->parms.link)
+		tdev = __dev_get_by_index(&init_net, tunnel->parms.link);
+
+	if (tdev) {
+		dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr);
+		dev->mtu = tdev->mtu - sizeof(struct iphdr);
+		if (dev->mtu < IPV6_MIN_MTU)
+			dev->mtu = IPV6_MIN_MTU;
+	}
+	dev->iflink = tunnel->parms.link;
+}
+
 static int
 ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
 {
@@ -740,6 +776,11 @@ ipip6_tunnel_ioctl (struct net_device *d
 			if (cmd == SIOCCHGTUNNEL) {
 				t->parms.iph.ttl = p.iph.ttl;
 				t->parms.iph.tos = p.iph.tos;
+				if (t->parms.link != p.link) {
+					t->parms.link = p.link;
+					ipip6_tunnel_bind_dev(dev);
+					netdev_state_change(dev);
+				}
 			}
 			if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
 				err = -EFAULT;
@@ -808,12 +849,9 @@ static void ipip6_tunnel_setup(struct ne
 
 static int ipip6_tunnel_init(struct net_device *dev)
 {
-	struct net_device *tdev = NULL;
 	struct ip_tunnel *tunnel;
-	struct iphdr *iph;
 
 	tunnel = netdev_priv(dev);
-	iph = &tunnel->parms.iph;
 
 	tunnel->dev = dev;
 	strcpy(tunnel->parms.name, dev->name);
@@ -821,31 +859,7 @@ static int ipip6_tunnel_init(struct net_
 	memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
 	memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
 
-	if (iph->daddr) {
-		struct flowi fl = { .nl_u = { .ip4_u =
-					      { .daddr = iph->daddr,
-						.saddr = iph->saddr,
-						.tos = RT_TOS(iph->tos) } },
-				    .oif = tunnel->parms.link,
-				    .proto = IPPROTO_IPV6 };
-		struct rtable *rt;
-		if (!ip_route_output_key(&rt, &fl)) {
-			tdev = rt->u.dst.dev;
-			ip_rt_put(rt);
-		}
-		dev->flags |= IFF_POINTOPOINT;
-	}
-
-	if (!tdev && tunnel->parms.link)
-		tdev = __dev_get_by_index(&init_net, tunnel->parms.link);
-
-	if (tdev) {
-		dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr);
-		dev->mtu = tdev->mtu - sizeof(struct iphdr);
-		if (dev->mtu < IPV6_MIN_MTU)
-			dev->mtu = IPV6_MIN_MTU;
-	}
-	dev->iflink = tunnel->parms.link;
+	ipip6_tunnel_bind_dev(dev);
 
 	return 0;
 }

-- 

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

* Re: [patch 1/2] ip_gre: Rebinding of GRE tunnels to other interfaces
  2007-12-13 13:37 ` [patch 1/2] ip_gre: Rebinding of GRE tunnels to other interfaces mschmidt
@ 2007-12-13 17:47   ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2007-12-13 17:47 UTC (permalink / raw)
  To: mschmidt; +Cc: netdev, kaber, mmaslano

From: mschmidt@redhat.com
Date: Thu, 13 Dec 2007 14:37:49 +0100

> This is similar to the change already done for IPIP tunnels.
> 
> Once created, a GRE tunnel can't be bound to another device.
> To reproduce:
> 
> # create a tunnel:
> ip tunnel add tunneltest0 mode gre remote 10.0.0.1 dev eth0
> # try to change the bounding device from eth0 to eth1:
> ip tunnel change tunneltest0 dev eth1
> # show the result:
> ip tunnel show tunneltest0
> 
> tunneltest0: gre/ip  remote 10.0.0.1  local any  dev eth0  ttl inherit
> 
> Notice the bound device has not changed from eth0 to eth1.
> 
> This patch fixes it. When changing the binding, it also recalculates the
> MTU according to the new bound device's MTU.
> 
> Signed-off-by: Michal Schmidt <mschmidt@redhat.com>

Applied to net-2.6.25, thanks.

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

* Re: [patch 2/2] ipv6/sit: Rebinding of SIT tunnels to other interfaces
  2007-12-13 13:37 ` [patch 2/2] ipv6/sit: Rebinding of SIT " mschmidt
@ 2007-12-13 17:47   ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2007-12-13 17:47 UTC (permalink / raw)
  To: mschmidt; +Cc: netdev, kaber, mmaslano

From: mschmidt@redhat.com
Date: Thu, 13 Dec 2007 14:37:50 +0100

> This is similar to the change already done for IPIP tunnels.
> 
> Once created, a SIT tunnel can't be bound to another device.
> To reproduce:
> 
> # create a tunnel:
> ip tunnel add tunneltest0 mode sit remote 10.0.0.1 dev eth0
> # try to change the bounding device from eth0 to eth1:
> ip tunnel change tunneltest0 dev eth1
> # show the result:
> ip tunnel show tunneltest0
> 
> tunneltest0: ipv6/ip  remote 10.0.0.1  local any  dev eth0  ttl inherit
> 
> Notice the bound device has not changed from eth0 to eth1.
> 
> This patch fixes it. When changing the binding, it also recalculates the
> MTU according to the new bound device's MTU.
> 
> Signed-off-by: Michal Schmidt <mschmidt@redhat.com>

Also applied, thanks.

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

end of thread, other threads:[~2007-12-13 17:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-13 13:37 [patch 0/2] rebinding tunnels to interfaces mschmidt
2007-12-13 13:37 ` [patch 1/2] ip_gre: Rebinding of GRE tunnels to other interfaces mschmidt
2007-12-13 17:47   ` David Miller
2007-12-13 13:37 ` [patch 2/2] ipv6/sit: Rebinding of SIT " mschmidt
2007-12-13 17:47   ` David Miller

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).