Skip to contentSkip to conversation

Now it works far better on/against BSD.

Openvpn-devel Janne Johansson 2 participants 2 messages Apr 4, 2002

lore
Share & tools
lore
#0 lore raw

Ok, this is tested in cleartext tunnel mode, and ssl-with-preshared-key.

Both methods work if the Linux side has "--remote-bsd" on the command line, and they do not work without it.
(Given that the remote IS bsd of course =)
Both machines were little-endian, I haven't tested BE machines yet. (I have a BSD sparc that I can test with later)

I haven't tested lzo yet, nor certificate-based encryption, but I don't think they will cause more problems now that SSL works.

It compiles cleanly on Linux2.4 and with 2 warnings on OpenBSD3.0.
==============================================
gcc -g -O2 -I/usr/local/include -c openvpn.c
openvpn.c: In function `openvpn':
openvpn.c:777: warning: passing arg 5 of `tls_multi_process' from incompatible pointer type
openvpn.c:780: warning: passing arg 3 of `interval_set_timeout' from incompatible pointer type
=========================
Weird.

Also, I'm not sure if the frame-extension stuff (+sizeof(u_int32_t) bytes if remote is bsd)
is 100% correct for all cases but at least pings work. =) Please look over that part.

The line I used on Linux was: (got 10.0.0.2 for its address) prompt> ./openvpn --local 1.2.3.4 --remote 2.3.4.5 --dev tun --remote-bsd&
prompt> ifconfig tun0 10.0.0.2 pointopoint 10.0.0.1 mtu 1450 up

On BSD: (Which got 10.0.0.1 as the local tun-ip-address) prompt> ./openvpn --local 2.3.4.5 --remote 1.2.3.4 --dev tun0 & prompt> ifconfig tun0 10.0.0.1 10.0.0.2 mtu 1450 up
...
prompt> ifconfig tun0 delete

On BSD, the tun device is always refered to by number (tun0) and it will not be brought down on openvpn exits like on Linux. Apart from that, it's quite straightforward.

It should be easy(er) to make a Net/FreeBSD/Solaris port now if anyone wants.

This patch is against a clean 1.0.3 and incorporates the NULL-fix, and the de/encrypt() -> openvpn_de/encrypt() rename.

====================cut here============

basic.h +2 -0
diff -ru openvpn-1.0.3/basic.h obsd-openvpn-1.0.3/basic.h
@@ -37,6 +37,8 @@
 /* clear an object */
 #define CLEAR(x) memset(&(x), 0, sizeof(x))
 
+#ifndef NULL
 #define NULL ((void *)0)
+#endif /* NULL */
 
 #endif
crypto.c +2 -2
diff -ru openvpn-1.0.3/crypto.c obsd-openvpn-1.0.3/crypto.c
@@ -79,7 +79,7 @@
   do { msg (D_CRYPT_ERRORS, "%s: " format, error_prefix, args); goto error_exit; } while (false)
 
 void
-encrypt (struct buffer *buf, struct buffer work,
+openvpn_encrypt (struct buffer *buf, struct buffer work,
 	 const struct crypto_options *opt,
 	 const struct frame* frame,
 	 const time_t current)
@@ -186,7 +186,7 @@
 }
 
 void
-decrypt (struct buffer *buf, struct buffer work,
+openvpn_decrypt (struct buffer *buf, struct buffer work,
 	 const struct crypto_options *opt,
 	 const struct frame* frame,
 	 const time_t current)
crypto.h +2 -2
diff -ru openvpn-1.0.3/crypto.h obsd-openvpn-1.0.3/crypto.h
@@ -97,12 +97,12 @@
 void init_key_ctx (struct key_ctx *key_ctx, struct key *key,
 		   const struct key_type *kt, const char *prefix);
 
-void encrypt (struct buffer *buf, struct buffer work,
+void openvpn_encrypt (struct buffer *buf, struct buffer work,
 	      const struct crypto_options *opt,
 	      const struct frame* frame,
 	      const time_t current);
 
-void decrypt (struct buffer *buf, struct buffer work,
+void openvpn_decrypt (struct buffer *buf, struct buffer work,
 	      const struct crypto_options *opt,
 	      const struct frame* frame,
 	      const time_t current);
openvpn.c +41 -2

115 lines not on this page · raw message

openvpn.h +1 -0
diff -ru openvpn-1.0.3/openvpn.h obsd-openvpn-1.0.3/openvpn.h
@@ -53,6 +53,7 @@
   int nice;
   int verbosity;
   bool gremlin;
+  bool remotebsd;
 
 #ifdef USE_LZO
   bool comp_lzo;

Only in obsd-openvpn-1.0.3: out

socket.c +7 -1
diff -ru openvpn-1.0.3/socket.c obsd-openvpn-1.0.3/socket.c
@@ -27,7 +27,13 @@
 
 #include <netdb.h>		/* gethostbyname */
 #include <netinet/in.h>		/* struct sockaddr_in */
-#include <linux/if.h>		/* inet stuff */
+
+#ifdef __OpenBSD__
+#include <net/if_tun.h>		/* inet stuff */
+#else
+#include <linux/if_tun.h>
+#endif /* OBSD */
+
 #include <stdlib.h>		/* system() */
 
 #include "socket.h"
socket.h +3 -0
diff -ru openvpn-1.0.3/socket.h obsd-openvpn-1.0.3/socket.h
@@ -26,7 +26,10 @@
 #ifndef SOCKET_H
 #define SOCKET_H
 
+#include <netinet/in.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
+
 #include "buffer.h"
 #include "common.h"
 
ssl.c +2 -2
diff -ru openvpn-1.0.3/ssl.c obsd-openvpn-1.0.3/ssl.c
@@ -943,7 +943,7 @@
   *header = ks->key_id | (opcode << P_OPCODE_SHIFT);
   if (session->tls_auth.key_ctx_bi->encrypt.hmac_defined)
     {
-      encrypt (buf, null, &session->tls_auth, NULL, current); /* no encryption, only write hmac */
+      openvpn_encrypt (buf, null, &session->tls_auth, NULL, current); /* no encryption, only write hmac */
       ASSERT (swap_hmac (buf, &session->tls_auth, false));
     }
   *to_udp_addr = ks->remote_addr;
@@ -970,7 +970,7 @@
 
       /* authenticate only (no decrypt) and remove the hmac record
          from the head of the buffer */
-      decrypt (buf, null, co, NULL, current);
+      openvpn_decrypt (buf, null, co, NULL, current);
       if (!buf->len)
 	{
 	  msg (D_TLS_ERRORS,
ssl.h +1 -0
diff -ru openvpn-1.0.3/ssl.h obsd-openvpn-1.0.3/ssl.h
@@ -28,6 +28,7 @@
 #include <openssl/ssl.h>
 #include <openssl/bio.h>
 #include <openssl/rand.h>
+#include <netinet/in.h>
 #include "basic.h"
 #include "crypto.h"
 #include "packet_id.h"
tun.c +2 -2
diff -ru openvpn-1.0.3/tun.c obsd-openvpn-1.0.3/tun.c
@@ -25,12 +25,12 @@
 
 #include "config.h"
 
-#include <sys/socket.h>
 #include <sys/ioctl.h>
-#include <linux/if.h>
 #include <fcntl.h>
 
 #ifndef OLD_TUN_TAP
+#include <sys/socket.h>
+#include <linux/if.h>
 #include <linux/if_tun.h>
 #endif /* OLD_TUN_TAP */
 

=========cut here==========

Signature · 5 lines
Janne Johansson
[email protected]...
BioMat Systems AB
Klarabergsg 37 3tr
111 21 Stockholm
#1 lore raw

Janne,

On BSD, is there any way to ioctl away the leading AF_INET, or is it necessary to have the linux side conform to the BSD side with --remote-bsd?

Quoted 1 line

It compiles cleanly on Linux2.4 and with 2 warnings on OpenBSD3.0.

==============================================
gcc -g -O2 -I/usr/local/include -c openvpn.c
openvpn.c: In function `openvpn':
openvpn.c:777: warning: passing arg 5 of `tls_multi_process' from incompatible pointer type
openvpn.c:780: warning: passing arg 3 of `interval_set_timeout' from incompatible pointer type
=========================
Weird.

What's the type of the tv_sec member of struct timeval on BSD? On linux it's time_t. It's probably something else on BSD, hence the warning.

Jim