]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Allow "tap-win32 dynamic <offset>" to be used in topology
authorJames Yonan <james@openvpn.net>
Fri, 11 Nov 2011 23:24:55 +0000 (23:24 +0000)
committerDavid Sommerseth <davids@redhat.com>
Wed, 14 Dec 2011 16:06:24 +0000 (17:06 +0100)
subnet mode.

Version 2.1.18

git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@7706 e7ae566f-a301-0410-adde-c780ea21d3b5

tun.c

diff --git a/tun.c b/tun.c
index d71d902e916864fcff07efb1b1e45c08bfa1637e..ea0e2268bfbf498894e66027142d6e5aff20945d 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -4438,6 +4438,27 @@ fork_register_dns_action (struct tuntap *tt)
     }
 }
 
+static uint32_t
+dhcp_masq_addr (const in_addr_t local, const in_addr_t netmask, const int offset)
+{
+  struct gc_arena gc = gc_new ();
+  in_addr_t dsa; /* DHCP server addr */
+
+  if (offset < 0)
+    dsa = (local | (~netmask)) + offset;
+  else
+    dsa = (local & netmask) + offset;
+
+  if (dsa == local)
+    msg (M_FATAL, "ERROR: There is a clash between the --ifconfig local address and the internal DHCP server address -- both are set to %s -- please use the --ip-win32 dynamic option to choose a different free address from the --ifconfig subnet for the internal DHCP server", print_in_addr_t (dsa, 0, &gc));
+
+  if ((local & netmask) != (dsa & netmask))
+    msg (M_FATAL, "ERROR: --tap-win32 dynamic [offset] : offset is outside of --ifconfig subnet");
+
+  gc_free (&gc);
+  return htonl(dsa);
+}
+
 void
 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
 {
@@ -4696,33 +4717,18 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu
        {
          if (tt->topology == TOP_SUBNET)
            {
-             const in_addr_t netmask_inv = ~tt->remote_netmask;
-             ep[2] = netmask_inv ? htonl ((tt->local | netmask_inv) - 1) : 0;
+             if (tt->options.dhcp_masq_custom_offset)
+               ep[2] = dhcp_masq_addr (tt->local, tt->remote_netmask, tt->options.dhcp_masq_offset);
+             else
+               ep[2] = dhcp_masq_addr (tt->local, tt->remote_netmask, -1);
            }
          else
            ep[2] = htonl (tt->remote_netmask);
-
-         if (tt->options.dhcp_masq_custom_offset)
-           msg (M_WARN, "WARNING: because you are using '--dev tun' mode, the '--ip-win32 dynamic [offset]' option is ignoring the offset parameter");
        }
       else
        {
-         in_addr_t dsa; /* DHCP server addr */
-
          ASSERT (tt->type == DEV_TYPE_TAP);
-
-         if (tt->options.dhcp_masq_offset < 0)
-           dsa = (tt->local | (~tt->adapter_netmask)) + tt->options.dhcp_masq_offset;
-         else
-           dsa = (tt->local & tt->adapter_netmask) + tt->options.dhcp_masq_offset;
-
-         if (dsa == tt->local)
-           msg (M_FATAL, "ERROR: There is a clash between the --ifconfig local address and the internal DHCP server address -- both are set to %s -- please use the --ip-win32 dynamic option to choose a different free address from the --ifconfig subnet for the internal DHCP server", print_in_addr_t (dsa, 0, &gc));
-
-         if ((tt->local & tt->adapter_netmask) != (dsa & tt->adapter_netmask))
-           msg (M_FATAL, "ERROR: --tap-win32 dynamic [offset] : offset is outside of --ifconfig subnet");
-
-         ep[2] = htonl (dsa);
+         ep[2] = dhcp_masq_addr (tt->local, tt->adapter_netmask, tt->options.dhcp_masq_custom_offset ? tt->options.dhcp_masq_offset : 0);
        }
 
       /* lease time in seconds */