Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=8a4a50f98bc13670bee94c40b94bc169e1263cd9
Commit:     8a4a50f98bc13670bee94c40b94bc169e1263cd9
Parent:     ee34c1eb35923cc98b1c47488a615bf51a2a2afb
Author:     Michal Schmidt <[EMAIL PROTECTED]>
AuthorDate: Thu Dec 13 09:47:00 2007 -0800
Committer:  David S. Miller <[EMAIL PROTECTED]>
CommitDate: Mon Jan 28 14:57:56 2008 -0800

    [IPV6] sit: Rebinding of SIT tunnels to other interfaces
    
    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 <[EMAIL PROTECTED]>
    Signed-off-by: David S. Miller <[EMAIL PROTECTED]>
---
 net/ipv6/sit.c |   70 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index b3b8513..1c6fddb 100644
--- a/net/ipv6/sit.c
+++ b/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 *dev, struct ifreq 
*ifr, int cmd)
                        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 net_device *dev)
 
 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_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 = { .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;
 }
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to