Subject: net/openvpn DragonFly support
To: None <pkgsrc-users@netbsd.org>
From: Rumko <rumcic@gmail.com>
List: pkgsrc-users
Date: 12/11/2006 13:30:38
--Boundary-00=_v9UfFwo9Eq4ubW9
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi!

The attached patch enables openvpn to function properly under DragonFly BSD. 
The changes should not affect other OSs since they are DragonFly specific.

--Boundary-00=_v9UfFwo9Eq4ubW9
Content-Type: text/x-diff;
  charset="utf-8";
  name="openvpn.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="openvpn.patch"

Index: distinfo
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/pkgsrc/net/openvpn/distinfo,v
retrieving revision 1.9
diff -d -u -r1.9 distinfo
=2D-- distinfo	5 Jul 2006 15:50:05 -0000	1.9
+++ distinfo	11 Dec 2006 12:21:22 -0000
@@ -3,8 +3,9 @@
 SHA1 (openvpn-2.0.7.tar.gz) =3D 74a4d19e42ca226f50ab5bdba16aa4a130c5e431
 RMD160 (openvpn-2.0.7.tar.gz) =3D b89f6df5ff08326f4e07e6cd4abda633627ef9e4
 Size (openvpn-2.0.7.tar.gz) =3D 665129 bytes
=2DSHA1 (patch-ab) =3D 05c9df0a7a71cb1cfa4a2f132df02cac822ba3ba
=2DSHA1 (patch-ac) =3D 7a225a0b88dcf0039cd40f72a10564c72f41b2f1
=2DSHA1 (patch-ad) =3D ee577ad5c5621bbfa05d522e85e467e937929f6e
=2DSHA1 (patch-ae) =3D b6f8f869b5c727120df8dd433e54ffe3537e0006
=2DSHA1 (patch-af) =3D ae697790e648c4d351c8c99e21ff79a56c572ddf
+SHA1 (patch-ab) =3D 9268bca82b7b9f0f4e18b2d272e1fd0f723ca53c
+SHA1 (patch-ac) =3D dbeb3c51d86454af9c013b32270ce0604a27ebf4
+SHA1 (patch-ad) =3D edb1109d5b405345837dda9a7b5631eaff3ac6e7
+SHA1 (patch-ae) =3D 1441384d20a1361cfc8b493b74b9e24970251196
+SHA1 (patch-af) =3D 03aac9bf0eea4cca035ad9be2840d25c9b68f919
+SHA1 (patch-ag) =3D 833d46e5ad559f5a93fceee41fbdba65136b50e6
Index: patches/patch-ab
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/pkgsrc/net/openvpn/patches/patch-ab,v
retrieving revision 1.4
diff -d -u -r1.4 patch-ab
=2D-- patches/patch-ab	11 Apr 2006 20:09:52 -0000	1.4
+++ patches/patch-ab	11 Dec 2006 12:21:22 -0000
@@ -13,3 +13,32 @@
  #ifdef HAVE_NET_IF_TUN_H
  #include <net/if_tun.h>
  #endif
+--- syshead.h.orig	2006-12-11 10:32:08.000000000 +0100
++++ syshead.h	2006-12-11 10:37:17.000000000 +0100
+@@ -252,6 +252,26 @@
+=20
+ #endif /* TARGET_FREEBSD */
+=20
++#ifdef TARGET_DRAGONFLY
++
++#ifdef HAVE_SYS_UIO_H
++#include <sys/uio.h>
++#endif
++
++#ifdef HAVE_NETINET_IN_SYSTM_H
++#include <netinet/in_systm.h>
++#endif
++
++#ifdef HAVE_NETINET_IP_H
++#include <netinet/ip.h>
++#endif
++
++#ifdef HAVE_NET_TUN_IF_TUN_H
++#include <net/tun/if_tun.h>
++#endif
++
++#endif /* TARGET_DRAGONFLY */
++
+ #ifdef TARGET_NETBSD
+=20
+ #ifdef HAVE_NET_IF_TAP_H
Index: patches/patch-ac
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/pkgsrc/net/openvpn/patches/patch-ac,v
retrieving revision 1.3
diff -d -u -r1.3 patch-ac
=2D-- patches/patch-ac	11 Apr 2006 20:09:52 -0000	1.3
+++ patches/patch-ac	11 Dec 2006 12:21:22 -0000
@@ -41,3 +41,126 @@
  		{
  		  openvpn_snprintf (tunname, sizeof (tunname),
  				    "/dev/%s%d", dev, i);
+--- tun.c.orig	2006-12-11 10:38:09.000000000 +0100
++++ tun.c	2006-12-11 10:41:24.000000000 +0100
+@@ -767,6 +767,30 @@
+       system_check (command_line, es, S_FATAL, "FreeBSD ifconfig failed");
+       tt->did_ifconfig =3D true;
+=20
++#elif defined(TARGET_DRAGONFLY)
++
++      /* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.25=
5.255.255 up */
++      if (tun)
++        openvpn_snprintf (command_line, sizeof (command_line),
++                          IFCONFIG_PATH " %s %s %s mtu %d netmask 255.255=
=2E255.255 up",
++                          actual,
++                          ifconfig_local,
++                          ifconfig_remote_netmask,
++                          tun_mtu
++                          );
++      else
++        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, "FreeBSD ifconfig failed");
++      tt->did_ifconfig =3D true;
++
+ #elif defined (WIN32)
+       {
+ 	const char *netmask;
+@@ -1641,6 +1665,89 @@
+     return read (tt->fd, buf, len);
+ }
+=20
++#elif defined(TARGET_DRAGONFLY)
++
++static inline int
++freebsd_modify_read_write_return (int len)
++{
++  if (len > 0)
++    return len > sizeof (u_int32_t) ? len - sizeof (u_int32_t) : 0;
++  else
++    return len;
++}
++
++void
++open_tun (const char *dev, const char *dev_type, const char *dev_node, bo=
ol ipv6, struct tuntap *tt)
++{
++  open_tun_generic (dev, dev_type, dev_node, ipv6, true, true, tt);
++
++  if (tt->fd >=3D 0)
++    {
++      int i =3D 0;
++
++      /* Disable extended modes */
++      ioctl (tt->fd, TUNSLMODE, &i);
++      i =3D 1;
++      ioctl (tt->fd, TUNSIFHEAD, &i);
++    }
++}
++
++void
++close_tun (struct tuntap *tt)
++{
++  if (tt)
++    {
++      close_tun_generic (tt);
++      free (tt);
++    }
++}
++
++int
++write_tun (struct tuntap* tt, uint8_t *buf, int len)
++{
++  if (tt->type =3D=3D DEV_TYPE_TUN)
++    {
++      u_int32_t type;
++      struct iovec iv[2];
++      struct ip *iph;
++
++      iph =3D (struct ip *) buf;
++
++      if (tt->ipv6 && iph->ip_v =3D=3D 6)
++        type =3D htonl (AF_INET6);
++      else
++        type =3D htonl (AF_INET);
++
++      iv[0].iov_base =3D (char *)&type;
++      iv[0].iov_len =3D sizeof (type);
++      iv[1].iov_base =3D buf;
++      iv[1].iov_len =3D len;
++
++      return freebsd_modify_read_write_return (writev (tt->fd, iv, 2));
++    }
++  else
++    return write (tt->fd, buf, len);
++}
++
++int
++read_tun (struct tuntap* tt, uint8_t *buf, int len)
++{
++  if (tt->type =3D=3D DEV_TYPE_TUN)
++    {
++      u_int32_t type;
++      struct iovec iv[2];
++
++      iv[0].iov_base =3D (char *)&type;
++      iv[0].iov_len =3D sizeof (type);
++      iv[1].iov_base =3D buf;
++      iv[1].iov_len =3D len;
++
++      return freebsd_modify_read_write_return (readv (tt->fd, iv, 2));
++    }
++  else
++    return read (tt->fd, buf, len);
++}
++
+ #elif defined(WIN32)
+=20
+ int
Index: patches/patch-ad
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/pkgsrc/net/openvpn/patches/patch-ad,v
retrieving revision 1.1
diff -d -u -r1.1 patch-ad
=2D-- patches/patch-ad	11 Apr 2006 20:09:52 -0000	1.1
+++ patches/patch-ad	11 Dec 2006 12:21:22 -0000
@@ -12,3 +12,27 @@
  /* Define to 1 if you have the <net/if_tun.h> header file. */
  #undef HAVE_NET_IF_TUN_H
 =20
+--- config.h.in.orig	2006-12-11 11:15:42.000000000 +0100
++++ config.h.in	2006-12-11 11:16:11.000000000 +0100
+@@ -433,6 +433,9 @@
+ /* Are we running on FreeBSD? */
+ #undef TARGET_FREEBSD
+=20
++/* Are we running on DragonFly */
++#undef TARGET_DRAGONFLY
++
+ /* Are we running on Linux? */
+ #undef TARGET_LINUX
+=20
+--- config.h.in.orig	2006-12-11 13:08:09.000000000 +0100
++++ config.h.in	2006-12-11 13:04:35.000000000 +0100
+@@ -207,6 +207,9 @@
+ /* Define to 1 if you have the <net/if_tun.h> header file. */
+ #undef HAVE_NET_IF_TUN_H
+=20
++/* Define to 1 if you have the <net/tun/if_tun.h> header file. */
++#undef HAVE_NET_TUN_IF_TUN_H
++
+ /* Define to 1 if you have the `nice' function. */
+ #undef HAVE_NICE
+=20
Index: patches/patch-ae
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/pkgsrc/net/openvpn/patches/patch-ae,v
retrieving revision 1.1
diff -d -u -r1.1 patch-ae
=2D-- patches/patch-ae	11 Apr 2006 20:09:52 -0000	1.1
+++ patches/patch-ae	11 Dec 2006 12:21:22 -0000
@@ -7,7 +7,19 @@
  		 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
=2D+		 net/if_tap.h net/if_tun.h net/if.h stropts.h sys/sockio.h dnl
++		 net/if_tap.h net/if_tun.h net/tun/if_tun.h net/if.h stropts.h sys/sock=
io.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
+--- configure.ac.orig	2006-12-11 10:26:42.000000000 +0100
++++ configure.ac	2006-12-11 10:27:14.000000000 +0100
+@@ -222,6 +222,9 @@
+ *freebsd*)
+ 	AC_DEFINE(TARGET_FREEBSD, 1, [Are we running on FreeBSD?])
+ 	;;
++*dragonfly*)
++        AC_DEFINE(TARGET_DRAGONFLY, 1, [Are we running on DragonFly?])
++        ;;
+ *netbsd*)
+ 	AC_DEFINE(TARGET_NETBSD, 1, [Are we running NetBSD?])
+ 	;;
Index: patches/patch-af
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/pkgsrc/net/openvpn/patches/patch-af,v
retrieving revision 1.1
diff -d -u -r1.1 patch-af
=2D-- patches/patch-af	11 Apr 2006 20:09:52 -0000	1.1
+++ patches/patch-af	11 Dec 2006 12:21:22 -0000
@@ -7,7 +7,23 @@
 =20
 =20
 -for ac_header in sys/time.h sys/socket.h sys/ioctl.h sys/stat.h 		 sys/mm=
an.h fcntl.h sys/file.h stdlib.h stdint.h 		 stdarg.h unistd.h signal.h std=
io.h string.h 		 strings.h ctype.h errno.h syslog.h pwd.h grp.h 		 net/if_t=
un.h net/if.h stropts.h sys/sockio.h 		 netinet/in.h netinet/in_systm.h net=
inet/ip.h 		 netinet/if_ether.h netinet/tcp.h resolv.h arpa/inet.h 		 netdb=
=2Eh sys/uio.h linux/if_tun.h linux/sockios.h 		 linux/types.h sys/poll.h s=
ys/epoll.h
=2D+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 s=
tdio.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
++for ac_header in sys/time.h sys/socket.h sys/ioctl.h sys/stat.h 		 sys/mm=
an.h fcntl.h sys/file.h stdlib.h stdint.h 		 stdarg.h unistd.h signal.h std=
io.h string.h 		 strings.h ctype.h errno.h syslog.h pwd.h grp.h 		 net/if_t=
ap.h net/if_tun.h net/tun/if_tun.h net/if.h stropts.h sys/sockio.h 		 netin=
et/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=3D`echo "ac_cv_header_$ac_header" | $as_tr_sh`
  if eval "test \"\${$as_ac_Header+set}\" =3D set"; then
+--- configure.orig	2006-12-11 10:56:40.000000000 +0100
++++ configure	2006-12-11 10:57:02.000000000 +0100
+@@ -2282,6 +2282,13 @@
+ _ACEOF
+=20
+ 	;;
++*dragonfly*)
++
++cat >>confdefs.h <<\_ACEOF
++#define TARGET_DRAGONFLY 1
++_ACEOF
++
++        ;;
+ *netbsd*)
+=20
+ cat >>confdefs.h <<\_ACEOF
=2D-- /dev/null	2006-12-11 13:20:28.000000000 +0100
+++ patches/patch-ag	2006-12-11 10:54:26.000000000 +0100
@@ -0,0 +1,46 @@
+--- route.c.orig	2006-12-11 10:43:59.000000000 +0100
++++ route.c	2006-12-11 10:49:45.000000000 +0100
+@@ -759,6 +759,17 @@
+   msg (D_ROUTE, "%s", BSTR (&buf));
+   status =3D system_check (BSTR (&buf), es, 0, "ERROR: FreeBSD route add =
command failed");
+=20
++#elif defined(TARGET_DRAGONFLY)
++
++  buf_printf (&buf, ROUTE_PATH " add");
++  buf_printf (&buf, " -net %s %s %s",
++              network,
++              gateway,
++              netmask);
++
++  msg (D_ROUTE, "%s", BSTR (&buf));
++  status =3D system_check (BSTR (&buf), es, 0, "ERROR: DragonFly route ad=
d command failed");
++
+ #elif defined(TARGET_DARWIN)
+=20
+   buf_printf (&buf, ROUTE_PATH " add");
+@@ -882,6 +893,16 @@
+   msg (D_ROUTE, "%s", BSTR (&buf));
+   system_check (BSTR (&buf), es, 0, "ERROR: FreeBSD route delete command =
failed");
+=20
++#elif defined(TARGET_DRAGONFLY)
++
++  buf_printf (&buf, ROUTE_PATH " delete -net %s %s %s",
++              network,
++              gateway,
++              netmask);
++
++  msg (D_ROUTE, "%s", BSTR (&buf));
++  system_check (BSTR (&buf), es, 0, "ERROR: DragonFly route delete comman=
d failed");
++
+ #elif defined(TARGET_DARWIN)
+=20
+   buf_printf (&buf, ROUTE_PATH " delete -net %s %s %s",
+@@ -1308,7 +1329,7 @@
+   return ret;
+ }
+=20
+-#elif defined(TARGET_FREEBSD)
++#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
+=20
+ #include <sys/types.h>
+ #include <sys/socket.h>

--Boundary-00=_v9UfFwo9Eq4ubW9--