]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix broken DHCP options
authorLev Stipakov <lev@openvpn.net>
Wed, 30 Jul 2025 18:04:26 +0000 (20:04 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 30 Jul 2025 18:13:46 +0000 (20:13 +0200)
Commit

  2dfc4f ("dns: deal with --dhcp-options when --dns is active")

broke support for --dhcp-options. It removed the setting of the
DHCP_OPTIONS_DHCP_OPTIONAL flag for some DHCP options. This flag is
required for those options to be applied correctly, as it is used
when building the DHCP options string that is passed to the TAP driver.

This commit fixes the issue by restoring the setting of this flag.

GitHub: fixes OpenVPN/openvpn#791

Change-Id: I0d75efcceb826d06e74abd003d5377468ff9fe3b
Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250730180527.25339-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32427.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/options.c

index b7328d7607a632c0e561be9b153e132dc862bbe2..53be6f5e052a6ddef3e47c930111ad2708cdcc50 100644 (file)
@@ -8712,9 +8712,12 @@ add_option(struct options *options,
 #endif
         VERIFY_PERMISSION(OPT_P_DHCPDNS);
 
+        bool dhcp_optional = false;
+
         if ((streq(p[1], "DOMAIN") || streq(p[1], "ADAPTER_DOMAIN_SUFFIX")) && p[2] && !p[3])
         {
             dhcp->domain = p[2];
+            dhcp_optional = true;
         }
         else if (streq(p[1], "DOMAIN-SEARCH") && p[2] && !p[3])
         {
@@ -8727,6 +8730,7 @@ add_option(struct options *options,
                 msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
                     p[1], N_SEARCH_LIST_LEN);
             }
+            dhcp_optional = true;
         }
         else if ((streq(p[1], "DNS") || streq(p[1], "DNS6")) && p[2] && !p[3]
                  && (!strstr(p[2], ":") || ipv6_addr_safe(p[2])))
@@ -8738,6 +8742,7 @@ add_option(struct options *options,
             else
             {
                 dhcp_option_address_parse("DNS", p[2], dhcp->dns, &dhcp->dns_len, msglevel);
+                dhcp_optional = true;
             }
         }
 #if defined(_WIN32) || defined(TARGET_ANDROID)
@@ -8761,6 +8766,7 @@ add_option(struct options *options,
         else if (streq(p[1], "WINS") && p[2] && !p[3])
         {
             dhcp_option_address_parse("WINS", p[2], o->wins, &o->wins_len, msglevel);
+            o->dhcp_options |= DHCP_OPTIONS_DHCP_OPTIONAL;
         }
         else if (streq(p[1], "NTP") && p[2] && !p[3])
         {
@@ -8792,6 +8798,13 @@ add_option(struct options *options,
 #else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
         setenv_foreign_option(options, p[1], p[2], es);
 #endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
+
+        if (dhcp_optional)
+        {
+#if defined(_WIN32) || defined(TARGET_ANDROID)
+            o->dhcp_options |= DHCP_OPTIONS_DHCP_OPTIONAL;
+#endif
+        }
     }
 #ifdef _WIN32
     else if (streq(p[0], "show-adapters") && !p[1])