Browse code

Allow "tap-win32 dynamic <offset>" to be used in topology subnet mode.

Version 2.1.18

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

James Yonan authored on 2011/11/12 08:24:55
Showing 1 changed files
... ...
@@ -4438,6 +4438,27 @@ fork_register_dns_action (struct tuntap *tt)
4438 4438
     }
4439 4439
 }
4440 4440
 
4441
+static uint32_t
4442
+dhcp_masq_addr (const in_addr_t local, const in_addr_t netmask, const int offset)
4443
+{
4444
+  struct gc_arena gc = gc_new ();
4445
+  in_addr_t dsa; /* DHCP server addr */
4446
+
4447
+  if (offset < 0)
4448
+    dsa = (local | (~netmask)) + offset;
4449
+  else
4450
+    dsa = (local & netmask) + offset;
4451
+
4452
+  if (dsa == local)
4453
+    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));
4454
+
4455
+  if ((local & netmask) != (dsa & netmask))
4456
+    msg (M_FATAL, "ERROR: --tap-win32 dynamic [offset] : offset is outside of --ifconfig subnet");
4457
+
4458
+  gc_free (&gc);
4459
+  return htonl(dsa);
4460
+}
4461
+
4441 4462
 void
4442 4463
 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
4443 4464
 {
... ...
@@ -4696,33 +4717,18 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu
4696 4696
 	{
4697 4697
 	  if (tt->topology == TOP_SUBNET)
4698 4698
 	    {
4699
-	      const in_addr_t netmask_inv = ~tt->remote_netmask;
4700
-	      ep[2] = netmask_inv ? htonl ((tt->local | netmask_inv) - 1) : 0;
4699
+	      if (tt->options.dhcp_masq_custom_offset)
4700
+		ep[2] = dhcp_masq_addr (tt->local, tt->remote_netmask, tt->options.dhcp_masq_offset);
4701
+	      else
4702
+		ep[2] = dhcp_masq_addr (tt->local, tt->remote_netmask, -1);
4701 4703
 	    }
4702 4704
 	  else
4703 4705
 	    ep[2] = htonl (tt->remote_netmask);
4704
-
4705
-	  if (tt->options.dhcp_masq_custom_offset)
4706
-	    msg (M_WARN, "WARNING: because you are using '--dev tun' mode, the '--ip-win32 dynamic [offset]' option is ignoring the offset parameter");
4707 4706
 	}
4708 4707
       else
4709 4708
 	{
4710
-	  in_addr_t dsa; /* DHCP server addr */
4711
-
4712 4709
 	  ASSERT (tt->type == DEV_TYPE_TAP);
4713
-
4714
-	  if (tt->options.dhcp_masq_offset < 0)
4715
-	    dsa = (tt->local | (~tt->adapter_netmask)) + tt->options.dhcp_masq_offset;
4716
-	  else
4717
-	    dsa = (tt->local & tt->adapter_netmask) + tt->options.dhcp_masq_offset;
4718
-
4719
-	  if (dsa == tt->local)
4720
-	    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));
4721
-
4722
-	  if ((tt->local & tt->adapter_netmask) != (dsa & tt->adapter_netmask))
4723
-	    msg (M_FATAL, "ERROR: --tap-win32 dynamic [offset] : offset is outside of --ifconfig subnet");
4724
-
4725
-	  ep[2] = htonl (dsa);
4710
+	  ep[2] = dhcp_masq_addr (tt->local, tt->adapter_netmask, tt->options.dhcp_masq_custom_offset ? tt->options.dhcp_masq_offset : 0);
4726 4711
 	}
4727 4712
 
4728 4713
       /* lease time in seconds */