$NetBSD: patch-ac,v 1.9 2011/04/28 07:27:25 adam Exp $ --- tun.c.orig 2011-04-06 16:05:52.000000000 +0000 +++ tun.c @@ -805,15 +805,15 @@ do_ifconfig (struct tuntap *tt, * NetBSD has distinct tun and tap devices * so we don't need the "link0" extra parameter to specify we want to do * tunneling at the ethernet level + * NB: The tun driver has no broadcast capability. */ argv_printf (&argv, - "%s %s %s netmask %s mtu %d broadcast %s", + "%s %s %s netmask %s mtu %d", IFCONFIG_PATH, actual, ifconfig_local, ifconfig_remote_netmask, - tun_mtu, - ifconfig_broadcast + tun_mtu ); argv_msg (M_INFO, &argv); openvpn_execve_check (&argv, es, S_FATAL, "NetBSD ifconfig failed"); @@ -1023,7 +1023,37 @@ open_tun_generic (const char *dev, const if (dynamic && !has_digit((unsigned char *)dev)) { int i; - for (i = 0; i < 256; ++i) +#if defined(TAPGIFNAME) + /* + * Perhaps we have a cloning device. Try opening + * the device without any appended digits, + * and use ioctl(,TAPGIFNAME,) to get the resulting + * interface name. + */ + openvpn_snprintf (tunname, sizeof (tunname), "/dev/%s", dev); + if ((tt->fd = open (tunname, O_RDWR)) > 0) + { + struct ifreq ifr; + if (ioctl (tt->fd, TAPGIFNAME, (void*)&ifr) < 0) + { + msg (D_READ_WRITE | M_ERRNO, + "ioctl(,TAPGIFNAME,) failed for %s", tunname); + close(tt->fd); + } + else + { + strlcpy (dynamic_name, ifr.ifr_name, + sizeof (dynamic_name)); + dynamic_opened = true; + msg (M_INFO, "TUN/TAP dynamic interface %s opened", + dynamic_name); + } + } + if (!dynamic_opened) + msg (D_READ_WRITE | M_ERRNO, "Tried opening %s (failed)", + tunname); +#endif /* TAPGIFNAME */ + for (i = 0; i < 256 && !dynamic_opened; ++i) { openvpn_snprintf (tunname, sizeof (tunname), "/dev/%s%d", dev, i);