-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

As it is openvpn has no way to allow the kernel to dynamically choose
a source port for it's connections. If you have two openvpn client
processes on the same machine both you have to configure lport to
different ports manually. This patch allows you to specify '--lport 0'
and get the behaviour of normal programs, where the source port is
dynamically chosen.

Not sure if this is an issue for others, but here's the patch in
case anyone has run into the same issue.

Cheers,
Nate Nielsen

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDhqR2e/sRCNknZa8RAkxcAKCLOrVEiVp0NZ3cBr0XQuemmGMkZQCdFbWl
hgFOINIEwoZnYcs2noCM8ik=
=2H3u
-----END PGP SIGNATURE-----
diff -rU 3 ../openvpn-2.0/options.c ./options.c
--- ../openvpn-2.0/options.c	2005-04-16 16:03:15.000000000 -0600
+++ ./options.c	2005-07-22 12:54:12.722483296 -0600
@@ -3189,7 +3189,7 @@
       ++i;
       VERIFY_PERMISSION (OPT_P_GENERAL);
       port = atoi (p[1]);
-      if (!legal_ipv4_port (port))
+      if (port != 0 && !legal_ipv4_port (port))
 	{
 	  msg (msglevel, "Bad local port number: %s", p[1]);
 	  goto err;
diff -rU 3 ../openvpn-2.0/socket.c ./socket.c
--- ../openvpn-2.0/socket.c	2005-04-10 21:43:58.000000000 -0600
+++ ./socket.c	2005-07-22 12:53:42.908015784 -0600
@@ -737,7 +737,20 @@
 	       print_sockaddr (&sock->info.lsa->local, &gc),
 	       strerror_ts (errnum, &gc));
 	}
+
+      /* If the local port was '0' look it up again */
+      if (sock->local_port == 0)
+	{
+	  socklen_t l = sizeof(sock->info.lsa->local);
+	  if (getsockname (sock->sd, (struct sockaddr *)&sock->info.lsa->local, &l) < 0)
+	    {
+	      const int errnum = openvpn_errno_socket ();
+	      msg (M_FATAL, "TCP/UDP: Socket lookup failed: %s",
+		   strerror_ts (errnum, &gc));
+	    }
+	}
     }
+
   gc_free (&gc);
 }

Reply via email to