Hello, The code in tinc for BSD device has no way to handle the fact that several tun devices are already used., since it always try to open the specified device which might already be in use. The following patch makes it try to open the various available tun devices before giving up. Hope that helps, -- Ga?l Roualland -+- gael.roualland@oleane.net -------------- next part -------------- diff -ru tinc-1.0.4/src/bsd/device.c tinc-1.0.4.gr/src/bsd/device.c --- tinc-1.0.4/src/bsd/device.c Wed May 4 18:57:55 2005 +++ tinc-1.0.4.gr/src/bsd/device.c Wed May 17 22:47:27 2006 @@ -38,6 +38,10 @@ int device_fd = -1; char *device; + +static char device_buf[256]; +#define DEVICE_TRIES_MAX 255 + char *iface; char *device_info; static int device_total_in = 0; @@ -60,8 +64,31 @@ iface = rindex(device, '/') ? rindex(device, '/') + 1 : device; if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) { - logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno)); - return false; + int device_nr; + + /* if device terminates by a number and is of reasonable size, + try any following numbered device */ + if (strlen(device) > 1 && strlen(device) < sizeof(device_buf) - 3) { + char *nr = device + strlen(device) - 1; + while (nr > device && *nr >= '0' && *nr <= '9') + nr--; + if (nr > device && nr < device + strlen(device) - 1) { + nr++; + device_nr = atoi(nr); + *nr = 0; + do { + device_nr++; + sprintf(device_buf, "%s%d", device, device_nr); + device_fd = open(device_buf, O_RDWR | O_NONBLOCK); + } while (device_fd < 0 && device_nr < DEVICE_TRIES_MAX); + if (device_fd >= 0) + device = device_buf; + } + } + if (device_fd < 0) { + logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno)); + return false; + } } if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
On Thu, May 18, 2006 at 12:38:01AM +0200, Ga?l Roualland wrote:> The code in tinc for BSD device has no way to handle the fact that > several tun devices are already used., since it always try to open the > specified device which might already be in use. > > The following patch makes it try to open the various available tun > devices before giving up.[...] Why not just change your Device entry in tinc.conf to point to a free tun device? -- Met vriendelijke groet / with kind regards, Guus Sliepen <guus@sliepen.eu.org> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://brouwer.uvt.nl/pipermail/tinc-devel/attachments/20060601/267e0c1e/attachment.pgp
Hello,>> The code in tinc for BSD device has no way to handle the fact that >> several tun devices are already used., since it always try to open the >> specified device which might already be in use. >> >> The following patch makes it try to open the various available tun >> devices before giving up. > [...] > > Why not just change your Device entry in tinc.conf to point to a free > tun device?I tried that indeed, buf for some reason, some devices stay busy after being used (eg if tinc crashes, cf my other report). I have not investigated this a great length (could be a freebsd bug instead perhaps) but I found it usefull that tinc could try to find an inetrface on its own, just like it does on Linux for instance. (eg, this allows one to run several instances of tinc without specific configuration). I can understand however that it might not be wanted on setups where tinc has to bind to a very specific interface, so maybe there needs to be a way to turn it on or off ? -- Ga?l Roualland -+- gael.roualland@dial.oleane.com
Reasonably Related Threads
- Random crashes after sighup
- [RFC] vhost: introduce mdev based hardware vhost backend
- [RFC] vhost: introduce mdev based hardware vhost backend
- [RFC v2] vhost: introduce mdev based hardware vhost backend
- [RFC v4 3/3] vhost: introduce mdev based hardware backend