2 "new style" netdevice allocation patch for TUN driver (2.4.18 kernel)
4 From: Jacek Konieczny (jajcus@pld.org.pl)
5 Date: Thu Aug 01 2002 - 08:35:06 EST
7 I had a lot of problem with tun devices created with both openvpn and
8 vtund. When I wanted to shut down my system when the devices were in
9 use (eg. TCP connection established on tun0 interface), even if the
10 tunneling daemon was killed, it stopped while trying to deconfigure
11 network. And "unregister_netdevice: waiting for tun0 to become free"
12 message was displayed again and again. I tried to resolve this problem
13 using Google, but I have only found out, that this is behaviour of 2.4
14 kernels, and that it is proper. After further investigation, in kernel
15 sources, I found out, that there are "old style" and "new style" network
16 devices, and that only the "old style" devices have this problem.
17 I had similar problem with VLAN devices some time ago, so I checked VLAN
18 driver sources too. As I suspected, it was "new style" device now.
19 The patch below is my try to make tun device "new style" too. It seems
20 to work for me, but I am not sure if it is 100% proper. This is patch
21 against 2.4.18 sources.
23 Sorry, for spamming all those addresses, but I am not sure which one is
24 correct. Driver on URL given in MAINTAINERS file seems to be a bit
30 diff -ur linux-2.4.22-up/drivers/net/tun.c linux-2.4.22-tun/drivers/net/tun.c
31 --- linux-2.4.22-up/drivers/net/tun.c Sat Aug 3 02:39:44 2002
32 +++ linux-2.4.22-tun/drivers/net/tun.c Sun Sep 21 00:08:08 2003
34 * Modifications for 2.3.99-pre5 kernel.
39 + * Jacek Konieczny <jajcus@pld.org.pl>
40 + * Modifications for "new style" device allocation
41 + * (fixes "wating for tunX to become free" problem)
47 #include <linux/config.h>
52 +void tun_net_destruct(struct net_device *dev)
63 /* Character device part */
68 memcpy_fromiovec(skb_put(skb, len), iv, len);
70 - skb->dev = &tun->dev;
71 + skb->dev = tun->dev;
72 switch (tun->flags & TUN_TYPE_MASK) {
74 skb->mac.raw = skb->data;
75 skb->protocol = pi.proto;
78 - skb->protocol = eth_type_trans(skb, &tun->dev);
79 + skb->protocol = eth_type_trans(skb, tun->dev);
87 - netif_start_queue(&tun->dev);
88 + netif_start_queue(tun->dev);
90 ret = tun_put_user(tun, skb, (struct iovec *) iv, len);
93 init_waitqueue_head(&tun->read_wait);
96 - tun->dev.init = tun_net_init;
97 - tun->dev.priv = tun;
101 @@ -398,18 +415,24 @@
103 name = ifr->ifr_name;
105 - if ((err = dev_alloc_name(&tun->dev, name)) < 0)
106 + dev = dev_alloc(name, &err);
109 - if ((err = register_netdevice(&tun->dev)))
112 + dev->init = tun_net_init;
114 + dev->destructor = tun_net_destruct;
115 + dev->features |= NETIF_F_DYNALLOC;
116 + tun->name = dev->name;
118 + err=register_netdevice(dev);
124 - tun->name = tun->dev.name;
128 - DBG(KERN_INFO "%s: tun_set_iff\n", tun->name);
130 if (ifr->ifr_flags & IFF_NO_PI)
131 tun->flags |= TUN_NO_PI;
142 skb_queue_purge(&tun->readq);
144 if (!(tun->flags & TUN_PERSIST)) {
145 - dev_close(&tun->dev);
146 - unregister_netdevice(&tun->dev);
149 + dev_close(tun->dev);
150 + unregister_netdevice(tun->dev);
154 diff -ur linux-2.4.22-up/include/linux/if_tun.h linux-2.4.22-tun/include/linux/if_tun.h
155 --- linux-2.4.22-up/include/linux/if_tun.h Tue Jun 12 04:15:27 2001
156 +++ linux-2.4.22-tun/include/linux/if_tun.h Sun Sep 21 00:08:08 2003
158 wait_queue_head_t read_wait;
159 struct sk_buff_head readq;
161 - struct net_device dev;
162 + struct net_device *dev;
163 struct net_device_stats stats;
165 struct fasync_struct *fasync;