Browse code

Always release dhcp address in close_tun() on Windows.

Also make sure --dhcp-pre-release results in not just dhcp_release()
in open_tun() but a subsequent dhcp_renew() as well. Else dhcp transaction
gets aborted as this call to release() happens after the adapter status
is changed to connected.

Fixes Trac #807 (but can't say the same for Trac #665 without knowing
how to reproduce it)

v2: Mark --dhcp-release as obsolete in manpage and option parser, and
remove the unused dhcp_release variable.
Enforce dhcp-renew with dhcp-pre-release while parsing the option
instead of in open_tun().

Trac: #807

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1483475883-17450-1-git-send-email-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg13814.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Selva Nair authored on 2017/01/04 05:38:03
Showing 4 changed files
... ...
@@ -5819,9 +5819,7 @@ flag.
5819 5819
 .TP
5820 5820
 .B \-\-dhcp\-release
5821 5821
 Ask Windows to release the TAP adapter lease on shutdown.
5822
-This option has the same caveats as
5823
-.B \-\-dhcp\-renew
5824
-above.
5822
+This option has no effect now, as it is enabled by default starting with version 2.4.1.
5825 5823
 .\"*********************************************************
5826 5824
 .TP
5827 5825
 .B \-\-register\-dns
... ...
@@ -715,7 +715,6 @@ static const char usage_message[] =
715 715
     "--dhcp-renew       : Ask Windows to renew the TAP adapter lease on startup.\n"
716 716
     "--dhcp-pre-release : Ask Windows to release the previous TAP adapter lease on\n"
717 717
     "                       startup.\n"
718
-    "--dhcp-release     : Ask Windows to release the TAP adapter lease on shutdown.\n"
719 718
     "--register-dns  : Run ipconfig /flushdns and ipconfig /registerdns\n"
720 719
     "                  on connection initiation.\n"
721 720
     "--tap-sleep n   : Sleep for n seconds after TAP adapter open before\n"
... ...
@@ -1212,7 +1211,6 @@ show_tuntap_options(const struct tuntap_options *o)
1212 1212
     SHOW_BOOL(dhcp_options);
1213 1213
     SHOW_BOOL(dhcp_renew);
1214 1214
     SHOW_BOOL(dhcp_pre_release);
1215
-    SHOW_BOOL(dhcp_release);
1216 1215
     SHOW_STR(domain);
1217 1216
     SHOW_STR(netbios_scope);
1218 1217
     SHOW_INT(netbios_node_type);
... ...
@@ -7185,11 +7183,11 @@ add_option(struct options *options,
7185 7185
     {
7186 7186
         VERIFY_PERMISSION(OPT_P_IPWIN32);
7187 7187
         options->tuntap_options.dhcp_pre_release = true;
7188
+        options->tuntap_options.dhcp_renew = true;
7188 7189
     }
7189 7190
     else if (streq(p[0], "dhcp-release") && !p[1])
7190 7191
     {
7191
-        VERIFY_PERMISSION(OPT_P_IPWIN32);
7192
-        options->tuntap_options.dhcp_release = true;
7192
+        msg(M_WARN, "Obsolete option --dhcp-release detected. This is now on by default");
7193 7193
     }
7194 7194
     else if (streq(p[0], "dhcp-internal") && p[1] && !p[2]) /* standalone method for internal use */
7195 7195
     {
... ...
@@ -6224,10 +6224,7 @@ close_tun(struct tuntap *tt)
6224 6224
         }
6225 6225
 #endif
6226 6226
 
6227
-        if (tt->options.dhcp_release)
6228
-        {
6229
-            dhcp_release(tt);
6230
-        }
6227
+        dhcp_release(tt);
6231 6228
 
6232 6229
         if (tt->hand != NULL)
6233 6230
         {
... ...
@@ -104,7 +104,6 @@ struct tuntap_options {
104 104
 
105 105
     bool dhcp_renew;
106 106
     bool dhcp_pre_release;
107
-    bool dhcp_release;
108 107
 
109 108
     bool register_dns;
110 109