Subject: pkg/32929: net/openvpn fails to work with tap device
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: Alan Barrett <apb@cequrux.com>
List: pkgsrc-bugs
Date: 02/25/2006 16:25:01
>Number:         32929
>Category:       pkg
>Synopsis:       net/openvpn fails to work with tap device
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 25 16:25:01 +0000 2006
>Originator:     Alan Barrett
>Release:        NetBSD 3.99.15
>Organization:
	Not much
>Environment:
System: NetBSD 3.99.15
Architecture: i386
Machine: i386
openvpn-2.05 from pkgsrc as of 2006-02-25
>Description:
	The net/openvpn package needs to be patched to support
	NetBSD's cloning tap device.
>How-To-Repeat:
	install openvpn-2.05.
	Configure it with "dev tap".
	Watch it fail.
>Fix:
	Apply appended patch.  Also bump PKGREVISION.

Index: pkgsrc/net/openvpn/distinfo
==================================================================
--- distinfo
+++ distinfo
@@ -3,3 +3,8 @@
 SHA1 (openvpn-2.0.5.tar.gz) = ba65a29e528e8e5f0978e89ef766c43d1d2a25aa
 RMD160 (openvpn-2.0.5.tar.gz) = add5c84c56b8a95d18e70ffa072bf9c42166074d
 Size (openvpn-2.0.5.tar.gz) = 662647 bytes
+SHA1 (patch-aa) = 2595a9d00549ce7950a9743e56100ffbbac2c47f
+SHA1 (patch-ab) = 74b4347f0321e0386a23c29b16892e1bca4bd851
+SHA1 (patch-ac) = 1c3d9694bd19cb49a08cde90cb657da4b940986a
+SHA1 (patch-ad) = 3f4f756fb2d1c1946b6a475d96bcaff613b14bf0
+SHA1 (patch-ae) = e9c35c0cec4293f6939170a9d3b9a1151eedf85d
Index: pkgsrc/net/openvpn/patches/patch-ab
==================================================================
--- patches/patch-ab
+++ patches/patch-ab
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- configure.ac.orig	2005-11-03 08:39:53.000000000 +0200
++++ configure.ac
+@@ -266,7 +266,7 @@ AC_CHECK_HEADERS(sys/time.h sys/socket.h
+ 		 sys/mman.h fcntl.h sys/file.h stdlib.h stdint.h dnl
+ 		 stdarg.h unistd.h signal.h stdio.h string.h dnl
+ 		 strings.h ctype.h errno.h syslog.h pwd.h grp.h dnl
+-		 net/if_tun.h net/if.h stropts.h sys/sockio.h dnl
++		 net/if_tap.h net/if_tun.h net/if.h stropts.h sys/sockio.h dnl
+ 		 netinet/in.h netinet/in_systm.h netinet/ip.h dnl
+ 		 netinet/if_ether.h netinet/tcp.h resolv.h arpa/inet.h dnl
+ 		 netdb.h sys/uio.h linux/if_tun.h linux/sockios.h dnl
Index: pkgsrc/net/openvpn/patches/patch-ac
==================================================================
--- /dev/null
+++ patches/patch-ac
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- configure.orig	2005-11-03 08:40:00.000000000 +0200
++++ configure
+@@ -4881,7 +4881,7 @@ fi
+ 
+ 
+ 
+-for ac_header in sys/time.h sys/socket.h sys/ioctl.h sys/stat.h 		 sys/mman.h fcntl.h sys/file.h stdlib.h stdint.h 		 stdarg.h unistd.h signal.h stdio.h string.h 		 strings.h ctype.h errno.h syslog.h pwd.h grp.h 		 net/if_tun.h net/if.h stropts.h sys/sockio.h 		 netinet/in.h netinet/in_systm.h netinet/ip.h 		 netinet/if_ether.h netinet/tcp.h resolv.h arpa/inet.h 		 netdb.h sys/uio.h linux/if_tun.h linux/sockios.h 		 linux/types.h sys/poll.h sys/epoll.h
++for ac_header in sys/time.h sys/socket.h sys/ioctl.h sys/stat.h 		 sys/mman.h fcntl.h sys/file.h stdlib.h stdint.h 		 stdarg.h unistd.h signal.h stdio.h string.h 		 strings.h ctype.h errno.h syslog.h pwd.h grp.h 		 net/if_tap.h net/if_tun.h net/if.h stropts.h sys/sockio.h 		 netinet/in.h netinet/in_systm.h netinet/ip.h 		 netinet/if_ether.h netinet/tcp.h resolv.h arpa/inet.h 		 netdb.h sys/uio.h linux/if_tun.h linux/sockios.h 		 linux/types.h sys/poll.h sys/epoll.h
+ do
+ as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ if eval "test \"\${$as_ac_Header+set}\" = set"; then
Index: pkgsrc/net/openvpn/patches/patch-ad
==================================================================
--- /dev/null
+++ patches/patch-ad
@@ -0,0 +1,15 @@
+$NetBSD$
+
+--- syshead.h.orig	2005-11-01 13:06:11.000000000 +0200
++++ syshead.h
+@@ -254,6 +254,10 @@
+ 
+ #ifdef TARGET_NETBSD
+ 
++#ifdef HAVE_NET_IF_TAP_H
++#include <net/if_tap.h>
++#endif
++
+ #ifdef HAVE_NET_IF_TUN_H
+ #include <net/if_tun.h>
+ #endif
Index: pkgsrc/net/openvpn/patches/patch-ae
==================================================================
--- /dev/null
+++ patches/patch-ae
@@ -0,0 +1,59 @@
+$NetBSD$
+
+--- tun.c.orig	2005-11-01 13:06:10.000000000 +0200
++++ tun.c
+@@ -690,7 +690,13 @@ do_ifconfig (struct tuntap *tt,
+ 			  tun_mtu
+ 			  );
+       else
+-	no_tap_ifconfig ();
++	openvpn_snprintf (command_line, sizeof (command_line),
++			  IFCONFIG_PATH " %s %s netmask %s mtu %d up",
++			  actual,
++			  ifconfig_local,
++			  ifconfig_remote_netmask,
++			  tun_mtu
++			  );
+       msg (M_INFO, "%s", command_line);
+       system_check (command_line, es, S_FATAL, "NetBSD ifconfig failed");
+       tt->did_ifconfig = true;
+@@ -865,7 +871,38 @@ open_tun_generic (const char *dev, const
+ 	  if (dynamic && !has_digit(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 /* SIOCGIFNAME */
++	      for (i = 0; i < 256 && !dynamic_opened; ++i)
+ 		{
+ 		  openvpn_snprintf (tunname, sizeof (tunname),
+ 				    "/dev/%s%d", dev, i);
Index: pkgsrc/net/openvpn/patches/patch-aa
==================================================================
--- /dev/null
+++ patches/patch-aa
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- config.h.in.orig	2005-11-03 08:40:01.000000000 +0200
++++ config.h.in
+@@ -201,6 +201,9 @@
+ /* Define to 1 if you have the <net/if.h> header file. */
+ #undef HAVE_NET_IF_H
+ 
++/* Define to 1 if you have the <net/if_tap.h> header file. */
++#undef HAVE_NET_IF_TAP_H
++
+ /* Define to 1 if you have the <net/if_tun.h> header file. */
+ #undef HAVE_NET_IF_TUN_H
+