Browse code

Fix broken DHCP options

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>

Lev Stipakov authored on 2025/07/31 03:04:26
Showing 1 changed files
... ...
@@ -8712,9 +8712,12 @@ add_option(struct options *options,
8712 8712
 #endif
8713 8713
         VERIFY_PERMISSION(OPT_P_DHCPDNS);
8714 8714
 
8715
+        bool dhcp_optional = false;
8716
+
8715 8717
         if ((streq(p[1], "DOMAIN") || streq(p[1], "ADAPTER_DOMAIN_SUFFIX")) && p[2] && !p[3])
8716 8718
         {
8717 8719
             dhcp->domain = p[2];
8720
+            dhcp_optional = true;
8718 8721
         }
8719 8722
         else if (streq(p[1], "DOMAIN-SEARCH") && p[2] && !p[3])
8720 8723
         {
... ...
@@ -8727,6 +8730,7 @@ add_option(struct options *options,
8727 8727
                 msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
8728 8728
                     p[1], N_SEARCH_LIST_LEN);
8729 8729
             }
8730
+            dhcp_optional = true;
8730 8731
         }
8731 8732
         else if ((streq(p[1], "DNS") || streq(p[1], "DNS6")) && p[2] && !p[3]
8732 8733
                  && (!strstr(p[2], ":") || ipv6_addr_safe(p[2])))
... ...
@@ -8738,6 +8742,7 @@ add_option(struct options *options,
8738 8738
             else
8739 8739
             {
8740 8740
                 dhcp_option_address_parse("DNS", p[2], dhcp->dns, &dhcp->dns_len, msglevel);
8741
+                dhcp_optional = true;
8741 8742
             }
8742 8743
         }
8743 8744
 #if defined(_WIN32) || defined(TARGET_ANDROID)
... ...
@@ -8761,6 +8766,7 @@ add_option(struct options *options,
8761 8761
         else if (streq(p[1], "WINS") && p[2] && !p[3])
8762 8762
         {
8763 8763
             dhcp_option_address_parse("WINS", p[2], o->wins, &o->wins_len, msglevel);
8764
+            o->dhcp_options |= DHCP_OPTIONS_DHCP_OPTIONAL;
8764 8765
         }
8765 8766
         else if (streq(p[1], "NTP") && p[2] && !p[3])
8766 8767
         {
... ...
@@ -8792,6 +8798,13 @@ add_option(struct options *options,
8792 8792
 #else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
8793 8793
         setenv_foreign_option(options, p[1], p[2], es);
8794 8794
 #endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
8795
+
8796
+        if (dhcp_optional)
8797
+        {
8798
+#if defined(_WIN32) || defined(TARGET_ANDROID)
8799
+            o->dhcp_options |= DHCP_OPTIONS_DHCP_OPTIONAL;
8800
+#endif
8801
+        }
8795 8802
     }
8796 8803
 #ifdef _WIN32
8797 8804
     else if (streq(p[0], "show-adapters") && !p[1])