* [PATCH] IPIP: Allow rebinding the tunnel to another interface
@ 2007-12-12 15:34 Michal Schmidt
2007-12-12 16:00 ` Patrick McHardy
0 siblings, 1 reply; 5+ messages in thread
From: Michal Schmidt @ 2007-12-12 15:34 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Marcela Maslanova
Hello,
Once created, an IP tunnel can't be bound to another device.
(reported as https://bugzilla.redhat.com/show_bug.cgi?id=419671)
To reproduce:
# create a tunnel:
ip tunnel add tunneltest0 mode ipip 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: ip/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.
If the change is acceptable, I'll do the same for GRE and SIT tunnels.
Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 8c2b2b0..05b267b 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -651,6 +651,40 @@ tx_error:
return 0;
}
+static void ipip_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 = { .oif = tunnel->parms.link,
+ .nl_u = { .ip4_u =
+ { .daddr = iph->daddr,
+ .saddr = iph->saddr,
+ .tos = RT_TOS(iph->tos) } },
+ .proto = IPPROTO_IPIP };
+ 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);
+ }
+ dev->iflink = tunnel->parms.link;
+}
+
static int
ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
{
@@ -723,6 +757,10 @@ ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
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;
+ ipip_tunnel_bind_dev(dev);
+ }
}
if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
err = -EFAULT;
@@ -791,12 +829,9 @@ static void ipip_tunnel_setup(struct net_device *dev)
static int ipip_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);
@@ -804,29 +839,7 @@ static int ipip_tunnel_init(struct net_device *dev)
memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
- 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_IPIP };
- 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);
- }
- dev->iflink = tunnel->parms.link;
+ ipip_tunnel_bind_dev(dev);
return 0;
}
--
1.5.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] IPIP: Allow rebinding the tunnel to another interface
2007-12-12 15:34 [PATCH] IPIP: Allow rebinding the tunnel to another interface Michal Schmidt
@ 2007-12-12 16:00 ` Patrick McHardy
2007-12-12 16:29 ` Michal Schmidt
0 siblings, 1 reply; 5+ messages in thread
From: Patrick McHardy @ 2007-12-12 16:00 UTC (permalink / raw)
To: Michal Schmidt; +Cc: netdev, David S. Miller, Marcela Maslanova
Michal Schmidt wrote:
> +static void ipip_tunnel_bind_dev(struct net_device *dev)
> +{
...
> + dev->iflink = tunnel->parms.link;
> +}
> +
> static int
> ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
> {
> @@ -723,6 +757,10 @@ ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
> 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;
> + ipip_tunnel_bind_dev(dev);
> + }
If you change dev->iflink this should trigger a rtnetlink
notification.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] IPIP: Allow rebinding the tunnel to another interface
2007-12-12 16:00 ` Patrick McHardy
@ 2007-12-12 16:29 ` Michal Schmidt
2007-12-12 16:33 ` Patrick McHardy
2007-12-12 19:02 ` David Miller
0 siblings, 2 replies; 5+ messages in thread
From: Michal Schmidt @ 2007-12-12 16:29 UTC (permalink / raw)
To: Patrick McHardy; +Cc: netdev, David S. Miller, Marcela Maslanova
On Wed, 12 Dec 2007 17:00:14 +0100
Patrick McHardy <kaber@trash.net> wrote:
> If you change dev->iflink this should trigger a rtnetlink
> notification.
OK, I've added netdev_state_change(dev). Here's the new patch.
Once created, an IP tunnel can't be bound to another device.
(reported as https://bugzilla.redhat.com/show_bug.cgi?id=419671)
To reproduce:
# create a tunnel:
ip tunnel add tunneltest0 mode ipip 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: ip/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.
If the change is acceptable, I'll do the same for GRE and SIT tunnels.
Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 8c2b2b0..160535b 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -651,6 +651,40 @@ tx_error:
return 0;
}
+static void ipip_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 = { .oif = tunnel->parms.link,
+ .nl_u = { .ip4_u =
+ { .daddr = iph->daddr,
+ .saddr = iph->saddr,
+ .tos = RT_TOS(iph->tos) } },
+ .proto = IPPROTO_IPIP };
+ 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);
+ }
+ dev->iflink = tunnel->parms.link;
+}
+
static int
ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
{
@@ -723,6 +757,11 @@ ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
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;
+ ipip_tunnel_bind_dev(dev);
+ netdev_state_change(dev);
+ }
}
if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
err = -EFAULT;
@@ -791,12 +830,9 @@ static void ipip_tunnel_setup(struct net_device *dev)
static int ipip_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);
@@ -804,29 +840,7 @@ static int ipip_tunnel_init(struct net_device *dev)
memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
- 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_IPIP };
- 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);
- }
- dev->iflink = tunnel->parms.link;
+ ipip_tunnel_bind_dev(dev);
return 0;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] IPIP: Allow rebinding the tunnel to another interface
2007-12-12 16:29 ` Michal Schmidt
@ 2007-12-12 16:33 ` Patrick McHardy
2007-12-12 19:02 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: Patrick McHardy @ 2007-12-12 16:33 UTC (permalink / raw)
To: Michal Schmidt; +Cc: netdev, David S. Miller, Marcela Maslanova
Michal Schmidt wrote:
> On Wed, 12 Dec 2007 17:00:14 +0100
> Patrick McHardy <kaber@trash.net> wrote:
>
>> If you change dev->iflink this should trigger a rtnetlink
>> notification.
>
> OK, I've added netdev_state_change(dev). Here's the new patch.
Looks good to me, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] IPIP: Allow rebinding the tunnel to another interface
2007-12-12 16:29 ` Michal Schmidt
2007-12-12 16:33 ` Patrick McHardy
@ 2007-12-12 19:02 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2007-12-12 19:02 UTC (permalink / raw)
To: mschmidt; +Cc: kaber, netdev, mmaslano
From: Michal Schmidt <mschmidt@redhat.com>
Date: Wed, 12 Dec 2007 17:29:33 +0100
> On Wed, 12 Dec 2007 17:00:14 +0100
> Patrick McHardy <kaber@trash.net> wrote:
>
> > If you change dev->iflink this should trigger a rtnetlink
> > notification.
>
> OK, I've added netdev_state_change(dev). Here's the new patch.
Applied to net-2.6.25, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-12-12 19:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-12 15:34 [PATCH] IPIP: Allow rebinding the tunnel to another interface Michal Schmidt
2007-12-12 16:00 ` Patrick McHardy
2007-12-12 16:29 ` Michal Schmidt
2007-12-12 16:33 ` Patrick McHardy
2007-12-12 19:02 ` 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).