Skip to contentSkip to conversation

Multiple DNS search suffixes on Windows

Openvpn-devel Superseded Jan Just Keijser 6 participants 28 messages Mar 5, 2020 – Jul 14, 2020 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]...

A message that is not in the archive (sent off-list or not yet received): [email protected]...

A message that is not in the archive (sent off-list or not yet received): [email protected]...

A message that is not in the archive (sent off-list or not yet received): [email protected]...

#4 lore raw

Hi,

Quoted 8 lines · Selva Nair
Quoted 7 lines · Gert Doering
Quoted 1 line · Leroy Tennison via Openvpn-users

Admittedly, and older server version (2.3) but is there a way to specify multiple DNS search suffixes for a Windows (10 if that makes a difference) client. The clients are part of a domain but I have no control over them via that avenue. I've tried multiple dhcp-option DOMAiN entries and the last one applies, I don't see another dhcp-option such as DOMAIN-SEARCH. Any options would be much appreciated. Thanks.

OpenVPN never had functionality to set the DHCP SEARCH LIST option on Windows.

Quoted 9 lines
Quoted 5 lines

So while you could always specify the option multiple times, it would only use one of them and put it into the DHCP DOMAIN option.

It's not very much missing code, but someone would have to do it (and the "core team" is very busy with other aspects right now).

IIRC, windows clients never queried DHCP option 119 (domain search). It seems that has changed since Windows 10, or has it?

I had to dig through my archives for this one - I found an OpenVPN 2.0.9  (!) source tree to which I had added rudimentary support for DHCP domain search, but that was *before* I found out that Windows did not support that... And yes, according to the comment section of https://www.normanbauer.com/2018/04/18/configuring-dhcp-option-119-domain-search-list-on-a-windows-dhcp-server/, Windows 10 1809+ finally has support for DHCP domain searches.

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

   --dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement
Also note that I did not fully implement the RFC3397 encoding of the search list, as that requires one to merge domain names that occur more than once - that would have made the code far more complicated.

share and enjoy,

JJK

From a969947cd86292c881f7cc1c704ac992e8f6f0d6 Mon Sep 17 00:00:00 2001
From: Jan Just Keijser <[email protected]...>
Date: Thu, 5 Mar 2020 13:41:00 +0100
Subject: [PATCH] Added support for DHCP option 119 (dns search suffix list)
for Windows. As of Windows 10 1809 Windows finally supports this so it makes sense to add support to OpenVPN as well.

---
 src/openvpn/options.c |  6 +++++
 src/openvpn/tun.c     | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/openvpn/tun.h     |  3 +++
 3 files changed, 71 insertions(+)
src/openvpn/options.c +6 -0
index 6c0e52e..e59b22b 100644
@@ -726,6 +726,7 @@ static const char usage_message[] =
     "                    which allow multiple addresses,\n"
     "                    --dhcp-option must be repeated.\n"
     "                    DOMAIN name : Set DNS suffix\n"
+    "                    SEARCH name : Set DNS domain search list\n"
     "                    DNS addr    : Set domain name server address(es) (IPv4 and IPv6)\n"
     "                    NTP         : Set NTP server address(es)\n"
     "                    NBDD        : Set NBDD server address(es)\n"
@@ -1175,6 +1176,7 @@ show_tuntap_options(const struct tuntap_options *o)
     SHOW_BOOL(dhcp_renew);
     SHOW_BOOL(dhcp_pre_release);
     SHOW_STR(domain);
+    SHOW_STR(domain_search_list);
     SHOW_STR(netbios_scope);
     SHOW_INT(netbios_node_type);
     SHOW_BOOL(disable_nbt);
@@ -7327,6 +7329,10 @@ add_option(struct options *options,
         {
             o->domain = p[2];
         }
+        else if (streq(p[1], "SEARCH") && p[2])
+        {
+            o->domain_search_list = p[2];
+        }
         else if (streq(p[1], "NBS") && p[2])
         {
             o->netbios_scope = p[2];
src/openvpn/tun.c +62 -0

74 lines not on this page · raw message

src/openvpn/tun.h +3 -0
index 327d792..571b694 100644
@@ -89,6 +89,9 @@ struct tuntap_options {
 
     const char *domain;      /* DOMAIN (15) */
 
+#define SEARCH_LIST_LEN 256
+    const char *domain_search_list;      /* SEARCH (119), MacOS, Linux Win10 1809+ */
+
     const char *netbios_scope; /* NBS (47) */
 
     int netbios_node_type;   /* NBT 1,2,4,8 (46) */
Signature · 1 line
1.8.3.1
#5 lore raw

Hi all,

Quoted 23 lines · Jan Just Keijser

Hi,

Quoted 8 lines · Selva Nair
Quoted 7 lines · Gert Doering
Quoted 1 line · Leroy Tennison via Openvpn-users

Admittedly, and older server version (2.3) but is there a way to specify multiple DNS search suffixes for a Windows (10 if that makes a difference) client.  The clients are part of a domain but I have no control over them via that avenue.  I've tried multiple dhcp-option DOMAiN entries and the last one applies, I don't see another dhcp-option such as DOMAIN-SEARCH.  Any options would be much appreciated.  Thanks.

OpenVPN never had functionality to set the DHCP SEARCH LIST option on Windows.

Quoted 9 lines
Quoted 5 lines

So while you could always specify the option multiple times, it would only use one of them and put it into the DHCP DOMAIN option.

It's not very much missing code, but someone would have to do it (and the "core team" is very busy with other aspects right now).

IIRC, windows clients never queried DHCP option 119 (domain search). It seems that has changed since Windows 10, or has it?

I had to dig through my archives for this one - I found an OpenVPN 2.0.9  (!) source tree to which I had added rudimentary support for DHCP domain search, but that was *before* I found out that Windows did not support that... And yes, according to the comment section of https://www.normanbauer.com/2018/04/18/configuring-dhcp-option-119-domain-search-list-on-a-windows-dhcp-server/, Windows 10 1809+ finally has support for DHCP domain searches.

Quoted 9 lines

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

   --dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement
Also note that I did not fully implement the RFC3397 encoding of the search list, as that requires one to merge domain names that occur more than once - that would have made the code far more complicated.

to follow up on this:   I just found Jonathan's update-systemd-resolved thingie (https://github.com/jonathanio/update-systemd-resolved)  where he mentions that you can push --dhcp-option DOMAIN
multiple times to achieve a similar result - but at best that works on anything BUT Windows.
I do see that he lists a non-supported option
  --dhcp-option SEARCH-DOMAIN

instead of my 'SEARCH' ; it will be good to sync up with his script/code to ensure a smooth cooperation between platforms - provided, that is, that my patch is actually acceptable ;)

cheers,

JJK

#6 lore raw
In reply to Jan Just Keijser

Hi,

going through OpenVPN threads that went stale - I think this is actually a nice addition (read: other people have already asked me if this can be done).

Quoted 6 lines · Jan Just Keijser

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Quoted 6 lines

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

   --dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement

The patch looks okay-ish on quick reading.

Quoted 3 lines

Also note that I did not fully implement the RFC3397 encoding of the search list, as that requires one to merge domain names that occur more than once - that would have made the code far more complicated.

Indeed. I haven't looked at what other DHCP implementations do, but "correct" encoding definitly sounds like quite a bit of extra code just to save a few bytes on the wire - might come handy if you have many subdomains of a long internal DNS domain, though, but this can be added "if needed".

More interesting is the question "which option to use" - it should be synchronized between openvpn platform handlers. So if systemd-networkd uses "SEARCH-DOMAIN" it would make sense to use that for windows as well.

Is there an option in Tunnelblick to set MacOS DNS and search list? If yes, what option do they use?

Does anyone know about commercial VPN providers basing their clients on OpenVPN?

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#7 lore raw

Hi!

Quoted 34 lines · Gert Doering

Hi,

going through OpenVPN threads that went stale - I think this is actually a nice addition (read: other people have already asked me if this can be done).

Quoted 6 lines · Jan Just Keijser

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Quoted 6 lines

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

--dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement

The patch looks okay-ish on quick reading.

Quoted 3 lines

Also note that I did not fully implement the RFC3397 encoding of the search list, as that requires one to merge domain names that occur more than once - that would have made the code far more complicated.

Indeed. I haven't looked at what other DHCP implementations do, but "correct" encoding definitly sounds like quite a bit of extra code just to save a few bytes on the wire - might come handy if you have many subdomains of a long internal DNS domain, though, but this can be added "if needed".

Quoted 7 lines

More interesting is the question "which option to use" - it should be synchronized between openvpn platform handlers. So if systemd-networkd uses "SEARCH-DOMAIN" it would make sense to use that for windows as well.

Is there an option in Tunnelblick to set MacOS DNS and search list? If yes, what option do they use?

I apologize for not noticing this earlier. Two points to consider:

1. Tunnelblick does not accept "--dhcp-option SEARCH". Tunnelblick accepted DOMAIN-SEARCH starting in 2013, but users kept trying to use SEARCH-DOMAIN and then complaining when it didn't work, so in 2017 Tunnelblick started accepting also SEARCH-DOMAIN. If Windows starts using "SEARCH" I suppose we can add that, too. (**Sigh**.)

2. As is the case with using --dhcp-option to set DNS and WINS servers, Tunnelblick was designed to accept only one search domain per option, so one would use "--dhcp-option SEARCH-DOMAIN example.com --dhcp-option SEARCH-DOMAIN example.org --dhcp-option SEARCH-DOMAIN example.de" to set those three search domains. Our "up" script accepts multiple $foreign_option_X options and constructs appropriate instructions to have macOS use all of them. Parsing multiple search domains contained in one $foreign_option_X could be added but I'd rather avoid that if possible. (We'd probably have to do that if Windows does it. **Sigh**, again.)

Quoted 2 lines

Does anyone know about commercial VPN providers basing their clients on OpenVPN?

I don't think commercial VPN providers would use search domains. I think search domains would be used more by universities, corporations, etc. that want an easy way for their users to access their internal servers.

#8 lore raw
In reply to Gert Doering

Hi,

Quoted 14 lines · Gert Doering

Hi,

going through OpenVPN threads that went stale - I think this is actually a nice addition (read: other people have already asked me if this can be done).

Quoted 6 lines · Jan Just Keijser

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Quoted 8 lines
Quoted 6 lines

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

--dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement

The patch looks okay-ish on quick reading.

Feature wise yes, but some improvements needed..

I do not like that option format

"example.com; example.org" with quotes will parse right and fail later on because of the space, for example. And, we support multiple statements of dhcp options like DNS, so this is counter-intuitive. It's only a little more work to support a more forgiving format.

Quoted 10 lines
Quoted 4 lines

Also note that I did not fully implement the RFC3397 encoding of the search list, as that requires one to merge domain names that occur more than once - that would have made the code far more complicated.

Indeed. I haven't looked at what other DHCP implementations do, but "correct" encoding definitely sounds like quite a bit of extra code just to save a few bytes on the wire - might come handy if you have many subdomains of a long internal DNS domain, though, but this can be added "if needed".

Same as my thoughts, the encoding part could be kept simple as in here and possibly improved later. But option format is hard to change or deprecate.

Quoted 6 lines

More interesting is the question "which option to use" - it should be synchronized between openvpn platform handlers. So if systemd-networkd uses "SEARCH-DOMAIN" it would make sense to use that for windows as well.

I think we need both --- the current one retained as the connection specific suffix which would be just one entry and then this search list. As we allow multiple entries for DOMAIN right now, a user friendly approach would be to continue doing so but internally treat all but the first as a part of --dhcp-option DOMAIN-SEARCH. We could also deprecate the use of multiple entries in the dhcp-option DOMAIN keyword.

Selva

#9 lore raw

Hi,

Quoted 47 lines · Selva Nair

Hi,

Quoted 14 lines · Gert Doering

Hi,

going through OpenVPN threads that went stale - I think this is actually a nice addition (read: other people have already asked me if this can be done).

Quoted 6 lines · Jan Just Keijser

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Quoted 8 lines
Quoted 6 lines

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

--dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement

The patch looks okay-ish on quick reading.

Feature wise yes, but some improvements needed..

I do not like that option format

"example.com; example.org" with quotes will parse right and fail later on because of the space, for example. And, we support multiple statements of dhcp options like DNS, so this is counter-intuitive. It's only a little more work to support a more forgiving format.

Quoted 10 lines
Quoted 4 lines

Also note that I did not fully implement the RFC3397 encoding of the search list, as that requires one to merge domain names that occur more than once - that would have made the code far more complicated.

Indeed. I haven't looked at what other DHCP implementations do, but "correct" encoding definitely sounds like quite a bit of extra code just to save a few bytes on the wire - might come handy if you have many subdomains of a long internal DNS domain, though, but this can be added "if needed".

Quoted 3 lines

Same as my thoughts, the encoding part could be kept simple as in here and possibly improved later. But option format is hard to change or deprecate.

I agree.

Quoted 5 lines
Quoted 4 lines

More interesting is the question "which option to use" - it should be synchronized between openvpn platform handlers. So if systemd-networkd uses "SEARCH-DOMAIN" it would make sense to use that for windows as well.

Quoted 7 lines

I think we need both --- the current one retained as the connection specific suffix which would be just one entry and then this search list. As we allow multiple entries for DOMAIN right now, a user friendly approach would be to continue doing so but internally treat all but the first as a part of --dhcp-option DOMAIN-SEARCH. We could also deprecate the use of multiple entries in the dhcp-option DOMAIN keyword.

The man page says to use "DOMAIN" to set the"domain suffix", but there is no documented way to specify the computer's domain. The man page doesn't indicate that multiple --dhcp-option DOMAIN options are allowed, but it specifically states that multiple DNS and WINS are allowed (for example, "Repeat this option to set secondary DNS server addresses").

(Note that bad formatting on the online version of the man page [1] makes it hard to see that "DOMAIN" is allowed at all, since it is merged into the prior paragraph. Also note that the opening paragraph for the --dhcp-option section of the man page implies it is only for Windows tap adaptors, which hasn't been true for at least 11 years!)

For many years, Tunnelblick has
1. Accepted multiple SEARCH-DOMAIN or DOMAIN-SEARCH entries to set
the search domains, which is in keeping with the way multiple DNS and WINS entries are interpreted.
2. Ignored all but the last "--dhcp-option DOMAIN…" entry in $foreign_option_X.
3. Used that last entry to set the computer's domain.
4. Under certain conditions, prepended the search domains with that last entry.

Best regards,

Jon Bullard

[1] https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/#

#10 lore raw
In reply to Selva Nair

Hi,

Quoted 20 lines · Selva Nair
Quoted 12 lines · Gert Doering

going through OpenVPN threads that went stale - I think this is actually a nice addition (read: other people have already asked me if this can be done).

Quoted 6 lines · Jan Just Keijser

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Quoted 7 lines
Quoted 6 lines

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

--dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement

The patch looks okay-ish on quick reading.

Quoted 8 lines

Feature wise yes, but some improvements needed..

I do not like that option format

"example.com; example.org" with quotes will parse right and fail later on because of the space, for example. And, we support multiple statements of dhcp options like DNS, so this is counter-intuitive. It's only a little more work to support a more forgiving format.

actually, the patch will be a bit more invasive if we add that; parsing DNS/WINS etc is already there and it parses an option into an IP/IPv6 address. changing the dns-search option to an array of strings will require more work. I did look into that initially but decided not to do it as the patch would be lengthier.

Note that "multiple domain" option is also not support, really. The domain is stored in the tuntap_options struct as

 90     const char *domain;      /* DOMAIN (15) */

so it's "last option wins"  ; the fact that some platforms abuse this option to actually set multiple search domains is a different matter.

Quoted 17 lines
Quoted 8 lines
Quoted 3 lines

Also note that I did not fully implement the RFC3397 encoding of the search list, as that requires one to merge domain names that occur more than once - that would have made the code far more complicated.

Indeed. I haven't looked at what other DHCP implementations do, but "correct" encoding definitely sounds like quite a bit of extra code just to save a few bytes on the wire - might come handy if you have many subdomains of a long internal DNS domain, though, but this can be added "if needed".

Same as my thoughts, the encoding part could be kept simple as in here and possibly improved later. But option format is hard to change or deprecate.

Quoted 5 lines

More interesting is the question "which option to use" - it should be synchronized between openvpn platform handlers. So if systemd-networkd uses "SEARCH-DOMAIN" it would make sense to use that for windows as well.

Quoted 8 lines

I think we need both --- the current one retained as the connection specific suffix which would be just one entry and then this search list. As we allow multiple entries for DOMAIN right now, a user friendly approach would be to continue doing so but internally treat all but the first as a part of --dhcp-option DOMAIN-SEARCH. We could also deprecate the use of multiple entries in the dhcp-option DOMAIN keyword.

See above: like I said, multiple DOMAIN entries do not seem to be supported.

So what option do we want?

--dhcp-option SEARCH
--dhcp-option DOMAIN-SEARCH
--dhcp-option SEARCH-DOMAIN

all?

JJK

#11 lore raw

Hi,

Quoted 38 lines · Jan Just Keijser

Hi,

Quoted 20 lines · Selva Nair
Quoted 12 lines · Gert Doering

going through OpenVPN threads that went stale - I think this is actually a nice addition (read: other people have already asked me if this can be done).

Quoted 6 lines · Jan Just Keijser

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Quoted 7 lines
Quoted 6 lines

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

--dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement

The patch looks okay-ish on quick reading.

Quoted 8 lines

Feature wise yes, but some improvements needed..

I do not like that option format

"example.com; example.org" with quotes will parse right and fail later on because of the space, for example. And, we support multiple statements of dhcp options like DNS, so this is counter-intuitive. It's only a little more work to support a more forgiving format.

actually, the patch will be a bit more invasive if we add that; parsing DNS/WINS etc is already there and it parses an option into an IP/IPv6 address. changing the dns-search option to an array of strings will require more work. I did look into that initially but decided not to do it as the patch would be lengthier.

Quoted 4 lines

Note that "multiple domain" option is also not support, really. The domain is stored in the tuntap_options struct as

90 const char *domain; /* DOMAIN (15) */

Windows is probably the only platform where these options are "natively" supported through DHCP, and indeed DOMAIN (option 15) has to be a single domain. Android also seem to treat them internally. However, we export these as foreign_option in all other platforms, and do export anything that looks like "dhcp-option name value" with repetitions allowed. That said, I don't mind breaking scripts that use and misuse these...

Anyway my point about multiple values was about DNS and WINS where it's allowed, and we parse them one entry at a time. I believe this option (search list) also should use the same format instead of inventing yet another format.

Yes, it may need a bit "more work" to support one domain at a time, but that's no excuse not to use a sensible format. Concatenation of strings read one at a time with a delimiter added doesn't look that hard either.

Quoted 29 lines

so it's "last option wins" ; the fact that some platforms abuse this option to actually set multiple search domains is a different matter.

Quoted 17 lines
Quoted 8 lines
Quoted 3 lines

Also note that I did not fully implement the RFC3397 encoding of the search list, as that requires one to merge domain names that occur more than once - that would have made the code far more complicated.

Indeed. I haven't looked at what other DHCP implementations do, but "correct" encoding definitely sounds like quite a bit of extra code just to save a few bytes on the wire - might come handy if you have many subdomains of a long internal DNS domain, though, but this can be added "if needed".

Same as my thoughts, the encoding part could be kept simple as in here and possibly improved later. But option format is hard to change or deprecate.

Quoted 5 lines

More interesting is the question "which option to use" - it should be synchronized between openvpn platform handlers. So if systemd-networkd uses "SEARCH-DOMAIN" it would make sense to use that for windows as well.

Quoted 8 lines

I think we need both --- the current one retained as the connection specific suffix which would be just one entry and then this search list. As we allow multiple entries for DOMAIN right now, a user friendly approach would be to continue doing so but internally treat all but the first as a part of --dhcp-option DOMAIN-SEARCH. We could also deprecate the use of multiple entries in the dhcp-option DOMAIN keyword.

Quoted 7 lines

See above: like I said, multiple DOMAIN entries do not seem to be supported.

So what option do we want?

--dhcp-option SEARCH
--dhcp-option DOMAIN-SEARCH
--dhcp-option SEARCH-DOMAIN

RFC 3397 calls it "Domain Search" so it has to be DOMAIN-SEARCH, in my view. Platform scripts accepting other forms in foreign_option is up to them. We don't have to officially support that.

Selva

#12 lore raw

Hi,

Quoted 9 lines · Selva Nair
Quoted 5 lines

So what option do we want?

--dhcp-option SEARCH
--dhcp-option DOMAIN-SEARCH
--dhcp-option SEARCH-DOMAIN

RFC 3397 calls it "Domain Search" so it has to be DOMAIN-SEARCH, in my view. Platform scripts accepting other forms in foreign_option is up to them. We don't have to officially support that.

I like that argument.

(I do not care too much which string it is, in the end, but if we have an RFC which has a name for it, and that name maps directly to one of the candidates, this is a strong argument :-) )

On the "shall it be a single occurrance with multiple domains in it" or "shall it be multiple occurances that are concatenated into a single DHCP option which then has multiple domains in it", I do not have a truly strong opinion. So I'd go with "what Tunnelblick has", which is "multiple occurances, a single string each".

He who goes first wins :-)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#13 lore raw

Hi,

Quoted 18 lines · Gert Doering

Hi,

Quoted 8 lines · Selva Nair
Quoted 5 lines

So what option do we want?

--dhcp-option SEARCH
--dhcp-option DOMAIN-SEARCH
--dhcp-option SEARCH-DOMAIN

RFC 3397 calls it "Domain Search" so it has to be DOMAIN-SEARCH, in my view. Platform scripts accepting other forms in foreign_option is up to them. We don't have to officially support that.

I like that argument.

(I do not care too much which string it is, in the end, but if we have an RFC which has a name for it, and that name maps directly to one of the candidates, this is a strong argument :-) )

Quoted 7 lines

On the "shall it be a single occurrance with multiple domains in it" or "shall it be multiple occurances that are concatenated into a single DHCP option which then has multiple domains in it", I do not have a truly strong opinion. So I'd go with "what Tunnelblick has", which is "multiple occurances, a single string each".

He who goes first wins :-)

here's V2:
-  allow a user to specify
  dhcp-option DOMAIN-SEARCH
 multiple times
- only a single FQDN per entry

cheers,

JJK

From a82036c3f81d31af223a574f75de48797ba76698 Mon Sep 17 00:00:00 2001
From: Jan Just Keijser <[email protected]...>
Date: Tue, 30 Jun 2020 15:52:58 +0200
Subject: [PATCH] Added support for DHCP option 119 (dns search suffix list)
for Windows. As of Windows 10 1809 Windows finally supports this so it makes sense to add support to OpenVPN as well.

---
 src/openvpn/options.c | 13 +++++++++++++
 src/openvpn/tun.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/openvpn/tun.h     |  6 ++++++
 3 files changed, 67 insertions(+)
src/openvpn/options.c +13 -0
index 2073b4a..376b8e7 100644
@@ -729,6 +729,7 @@ static const char usage_message[] =
     "                    which allow multiple addresses,\n"
     "                    --dhcp-option must be repeated.\n"
     "                    DOMAIN name : Set DNS suffix\n"
+    "                    DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"
     "                    DNS addr    : Set domain name server address(es) (IPv4 and IPv6)\n"
     "                    NTP         : Set NTP server address(es)\n"
     "                    NBDD        : Set NBDD server address(es)\n"
@@ -7460,6 +7461,18 @@ add_option(struct options *options,
         {
             dhcp_option_address_parse("NBDD", p[2], o->nbdd, &o->nbdd_len, msglevel);
         }
+        else if (streq(p[1], "DOMAIN-SEARCH") && p[2])
+        {
+            if (o->domain_search_list_len < N_SEARCH_LIST_LEN)
+            {
+                o->domain_search_list[o->domain_search_list_len++] = p[2];
+            }
+            else
+            {
+                msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
+                    p[1], N_SEARCH_LIST_LEN);
+            }
+        }
         else if (streq(p[1], "DISABLE-NBT") && !p[2])
         {
             o->disable_nbt = 1;
src/openvpn/tun.c +48 -0

60 lines not on this page · raw message

src/openvpn/tun.h +6 -0
index b38e7e9..99826cf 100644
@@ -112,6 +112,12 @@ struct tuntap_options {
     in_addr_t nbdd[N_DHCP_ADDR];
     int nbdd_len;
 
+#define N_SEARCH_LIST_LEN 10 /* Max # of entries in domin-search list */
+
+    /* SEARCH (119), MacOS, Linux, Win10 1809+ */
+    const char *domain_search_list[N_SEARCH_LIST_LEN];
+    int domain_search_list_len;
+
     /* DISABLE_NBT (43, Vendor option 001) */
     bool disable_nbt;
 
Signature · 1 line
1.8.3.1
#14 lore raw

Hi,

src/openvpn/tun.c build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o) · line 5746

Quoted 8 lines · Jan Just Keijser
src/openvpn/tun.c +4 -0
@@ -5697,6 +5740,11 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
     write_dhcp_u32_array(buf, 42, (uint32_t *)o->ntp, o->ntp_len, &error);
     write_dhcp_u32_array(buf, 45, (uint32_t *)o->nbdd, o->nbdd_len, &error);
 
+    for (int i=0; i < o->domain_search_list_len; i++)
+    {
+        write_dhcp_search_str(buf, 119, o->domain_search_list[i], &error);
+    }

I assume that this won't work. In the DHCP answer, it must be a single option with the concatenated list, not multiple answers with a single domain name each.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#15 lore raw

hi,

Quoted 15 lines · Gert Doering

Hi,

src/openvpn/tun.c build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o) · line 5746

Quoted 8 lines · Jan Just Keijser
src/openvpn/tun.c +4 -0
@@ -5697,6 +5740,11 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
      write_dhcp_u32_array(buf, 42, (uint32_t *)o->ntp, o->ntp_len, &error);
      write_dhcp_u32_array(buf, 45, (uint32_t *)o->nbdd, o->nbdd_len, &error);
 
+    for (int i=0; i < o->domain_search_list_len; i++)
+    {
+        write_dhcp_search_str(buf, 119, o->domain_search_list[i], &error);
+    }

I assume that this won't work. In the DHCP answer, it must be a single option with the concatenated list, not multiple answers with a single domain name each.

Quoted 2 lines

gert

see https://tools.ietf.org/html/rfc3397

"

In the above diagram, Searchstring is a string specifying the
searchlist. If the length of the searchlist exceeds the maximum
permissible within a single option (255 octets), then multiple
options MAY be used, as described in "Encoding Long Options in the
Dynamic Host Configuration Protocol (DHCPv4)" [RFC3396 <https://tools.ietf.org/html/rfc3396>].

"

so you MAY use this option multiple times - and wireshark groks it fine. I don't have a Windows 10 client to test it against, however, so I am hoping that someone (Selva?) can do that for me.

cheers,

JJK

#16 lore raw
Quoted 30 lines · Jan Just Keijser

hi,

Quoted 15 lines · Gert Doering

Hi,

src/openvpn/tun.c build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o) · line 5746

Quoted 8 lines · Jan Just Keijser
src/openvpn/tun.c +4 -0
@@ -5697,6 +5740,11 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
     write_dhcp_u32_array(buf, 42, (uint32_t *)o->ntp, o->ntp_len, &error);
     write_dhcp_u32_array(buf, 45, (uint32_t *)o->nbdd, o->nbdd_len, &error);
 
+    for (int i=0; i < o->domain_search_list_len; i++)
+    {
+        write_dhcp_search_str(buf, 119, o->domain_search_list[i], &error);
+    }

I assume that this won't work. In the DHCP answer, it must be a single option with the concatenated list, not multiple answers with a single domain name each.

Quoted 2 lines

gert

see https://tools.ietf.org/html/rfc3397

"

In the above diagram, Searchstring is a string specifying the
searchlist. If the length of the searchlist exceeds the maximum
permissible within a single option (255 octets), then multiple
options MAY be used, as described in "Encoding Long Options in the
Dynamic Host Configuration Protocol (DHCPv4)" [RFC3396 <https://tools.ietf.org/html/rfc3396>].

Quoted 6 lines

"

so you MAY use this option multiple times - and wireshark groks it fine. I don't have a Windows 10 client to test it against, however, so I am hoping that someone (Selva?) can do that for me.

Hi,

Can we please see this discussion also in context of this mail thread, which tries to look a broader at this challenge?

Message-Id: <[email protected]...> URL:
<https://www.mail-archive.com/[email protected]/msg20101.html>

One change in that RFC since last time is that we will move IV_PROTO to be only about the OpenVPN wire protocol (features/settings only affecting protocol for the communication between the OpenVPN end-points themselves). The DNS settings and more related to host configuration and similar will be moved into an IV_FEAT field. Except of that, nothing else has changed from the initial mail.

The main purpose of that RFC is to ensure we handle DNS and --dhcp-options consistently across all OpenVPN implementations we care about, and that we document this properly.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#17 lore raw

Hi,

Quoted 53 lines · David Sommerseth
Quoted 30 lines · Jan Just Keijser

hi,

Quoted 15 lines · Gert Doering

Hi,

src/openvpn/tun.c build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o) · line 5746

Quoted 8 lines · Jan Just Keijser
src/openvpn/tun.c +4 -0
@@ -5697,6 +5740,11 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
      write_dhcp_u32_array(buf, 42, (uint32_t *)o->ntp, o->ntp_len, &error);
      write_dhcp_u32_array(buf, 45, (uint32_t *)o->nbdd, o->nbdd_len, &error);
 
+    for (int i=0; i < o->domain_search_list_len; i++)
+    {
+        write_dhcp_search_str(buf, 119, o->domain_search_list[i], &error);
+    }

I assume that this won't work. In the DHCP answer, it must be a single option with the concatenated list, not multiple answers with a single domain name each.

Quoted 2 lines

gert

see https://tools.ietf.org/html/rfc3397

"

In the above diagram, Searchstring is a string specifying the
searchlist. If the length of the searchlist exceeds the maximum
permissible within a single option (255 octets), then multiple
options MAY be used, as described in "Encoding Long Options in the
Dynamic Host Configuration Protocol (DHCPv4)" [RFC3396 <https://tools.ietf.org/html/rfc3396>].

Quoted 6 lines

"

so you MAY use this option multiple times - and wireshark groks it fine. I don't have a Windows 10 client to test it against, however, so I am hoping that someone (Selva?) can do that for me.

Hi,

Can we please see this discussion also in context of this mail thread, which tries to look a broader at this challenge?

Message-Id: <[email protected]...> URL:
<https://www.mail-archive.com/[email protected]/msg20101.html>

One change in that RFC since last time is that we will move IV_PROTO to be only about the OpenVPN wire protocol (features/settings only affecting protocol for the communication between the OpenVPN end-points themselves). The DNS settings and more related to host configuration and similar will be moved into an IV_FEAT field. Except of that, nothing else has changed from the initial mail.

Quoted 4 lines

The main purpose of that RFC is to ensure we handle DNS and --dhcp-options consistently across all OpenVPN implementations we care about, and that we document this properly.

I see one as an implementation issue (can we specify a particular DHCP option more than once) and one as an OpenVPN protocol issue.
I fully agree that it's time to think about and overhaul the DNS settings for OpenVPN but I also believe that further abusing the option 'dhcp-option' is not the best way forward.  The option 'dhcp-option' only really applies to the Windows tap-win adapter as that is the only adapter where you can use DHCP to add/change settings. AFAIK even the new win-tun adapter does not use DHCP for this. Hence the term 'dhcp-' is moot.

Thus, moving forward, I'd be more in favor of overhauling this *completely* and review all 'dhcp-option' flags to see how we can
a) specify then more logically and more neutrally
b) implement these features for each of the different platforms:

Windows+tap-win: use DHCP
Windows+win-tun:   use netsh ?
Linux:  use systemd? use scripts
BSD: scripts? systemd?
MacOS:   just copy what Jonathan is using ;)

JM2CW,

JJK

#18 lore raw
Quoted 8 lines
Quoted 7 lines

The main purpose of that RFC is to ensure we handle DNS and --dhcp-options
consistently across all OpenVPN implementations we care about, and that we
document this properly.

Quoted 7 lines

I see one as an implementation issue (can we specify a particular DHCP option more than once) and one as an OpenVPN protocol issue. I fully agree that it's time to think about and overhaul the DNS settings for OpenVPN but I also believe that further abusing the option 'dhcp-option' is not the best way forward.  The option 'dhcp-option' only really applies to the Windows tap-win adapter as that is the only adapter where you can use DHCP to add/change settings.

This not even remotely true anymore. Basically all platforms will accept the dhcp-options for modifying the DNS settings.

Quoted 3 lines

AFAIK even the
new win-tun adapter does not use DHCP for this. Hence the term 'dhcp-' is moot.

Yes. Of course we can specify nicer sounding names for these options and that also break all kind of backwards compatibility for little gain or we document that the dhcp- prefix in these options is for historic reasons.

Arne

#19 lore raw

Hi,

Quoted 16 lines · Arne Schwabe
Quoted 6 lines
Quoted 6 lines

The main purpose of that RFC is to ensure we handle DNS and --dhcp-options
consistently across all OpenVPN implementations we care about, and that we
document this properly.

Quoted 7 lines

I see one as an implementation issue (can we specify a particular DHCP option more than once) and one as an OpenVPN protocol issue. I fully agree that it's time to think about and overhaul the DNS settings for OpenVPN but I also believe that further abusing the option 'dhcp-option' is not the best way forward.  The option 'dhcp-option' only really applies to the Windows tap-win adapter as that is the only adapter where you can use DHCP to add/change settings.

This not even remotely true anymore. Basically all platforms will accept the dhcp-options for modifying the DNS settings.

Quoted 8 lines
Quoted 3 lines

AFAIK even the
new win-tun adapter does not use DHCP for this. Hence the term 'dhcp-' is moot.

Yes. Of course we can specify nicer sounding names for these options and that also break all kind of backwards compatibility for little gain or we document that the dhcp- prefix in these options is for historic reasons.

I should have worded it more carefully, but Jonathan beat me to it:

Quoted 9 lines · Jonathan K. Bullard

If you mean the term 'dhcp' should not be used in the name of the option, I agree. Perhaps something like "interface-option" would be better.

But the _option_ isn't only for Windows tap-win adaptor. The option's arguments are passed to scripts via $foreign_option_* environment variables (on macOS, at least, and I think on most or all platforms). And the Tunnelblick scripts use them to modify network settings, sort of as if they came from DHCP, but not actually using DHCP.

I fully understand that most of those options are supported (or should I say, '(ab)used' ) by the other platforms but what I meant was that the name 'dhcp-option' is totally misleading as it has nothing to do with DHCP *except* when using the tap-win adapter.

Thus, if we want an overhaul of this, let's do it right and change the name of this option.

JJK

#20 lore raw
In reply to Jan Just Keijser

Hi,

Quoted 62 lines · Jan Just Keijser

Hi,

Quoted 53 lines · David Sommerseth
Quoted 30 lines · Jan Just Keijser

hi,

Quoted 15 lines · Gert Doering

Hi,

src/openvpn/tun.c build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o) · line 5746

Quoted 8 lines · Jan Just Keijser
src/openvpn/tun.c +4 -0
@@ -5697,6 +5740,11 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
      write_dhcp_u32_array(buf, 42, (uint32_t *)o->ntp, o->ntp_len, &error);
      write_dhcp_u32_array(buf, 45, (uint32_t *)o->nbdd, o->nbdd_len, &error);
 
+    for (int i=0; i < o->domain_search_list_len; i++)
+    {
+        write_dhcp_search_str(buf, 119, o->domain_search_list[i], &error);
+    }

I assume that this won't work. In the DHCP answer, it must be a single option with the concatenated list, not multiple answers with a single domain name each.

Quoted 2 lines

gert

see https://tools.ietf.org/html/rfc3397

"

In the above diagram, Searchstring is a string specifying the
searchlist. If the length of the searchlist exceeds the maximum
permissible within a single option (255 octets), then multiple
options MAY be used, as described in "Encoding Long Options in the
Dynamic Host Configuration Protocol (DHCPv4)" [RFC3396 <https://tools.ietf.org/html/rfc3396>].

Quoted 6 lines

"

so you MAY use this option multiple times - and wireshark groks it fine. I don't have a Windows 10 client to test it against, however, so I am hoping that someone (Selva?) can do that for me.

Hi,

Can we please see this discussion also in context of this mail thread, which tries to look a broader at this challenge?

Message-Id: <[email protected]...> URL:
<https://www.mail-archive.com/[email protected]/msg20101.html>

One change in that RFC since last time is that we will move IV_PROTO to be only about the OpenVPN wire protocol (features/settings only affecting protocol for the communication between the OpenVPN end-points themselves). The DNS settings and more related to host configuration and similar will be moved into an IV_FEAT field. Except of that, nothing else has changed from the initial mail.

Quoted 4 lines

The main purpose of that RFC is to ensure we handle DNS and --dhcp-options consistently across all OpenVPN implementations we care about, and that we document this properly.

Quoted 5 lines

I see one as an implementation issue (can we specify a particular DHCP option more than once) and one as an OpenVPN protocol issue. I fully agree that it's time to think about and overhaul the DNS settings for OpenVPN but I also believe that further abusing the option 'dhcp-option' is not the best way forward.

+1

Quoted 5 lines

The option 'dhcp-option'
only really applies to the Windows tap-win adapter as that is the only adapter where you can use DHCP to add/change settings. AFAIK even the new win-tun adapter does not use DHCP for this. Hence the term 'dhcp-' is moot.

If you mean the term 'dhcp' should not be used in the name of the option, I agree. Perhaps something like "interface-option" would be better.

But the _option_ isn't only for Windows tap-win adaptor. The option's arguments are passed to scripts via $foreign_option_* environment variables (on macOS, at least, and I think on most or all platforms). And the Tunnelblick scripts use them to modify network settings, sort of as if they came from DHCP, but not actually using DHCP.

Quoted 10 lines

Thus, moving forward, I'd be more in favor of overhauling this *completely* and review all 'dhcp-option' flags to see how we can
a) specify then more logically and more neutrally
b) implement these features for each of the different platforms:

Windows+tap-win: use DHCP
Windows+win-tun: use netsh ?

Linux:  use systemd? use scripts
BSD: scripts? systemd?
MacOS:   just copy what Jonathan is using ;)

+1 here, too, for overhauling this "completely".

I'll have further comment soon on the other thread:

Quoted 3 lines
Quoted 3 lines

Message-Id: <[email protected]...> URL:
<https://www.mail-archive.com/[email protected]/msg20101.html>

Best regards,

Jon

#21 lore raw
In reply to David Sommerseth

Hi,

Quoted 2 lines · David Sommerseth

Can we please see this discussion also in context of this mail thread, which tries to look a broader at this challenge?

There's two things here - a small and useful featurette which can go into 2.5, and the broader negotiation / option rehaul work for 2.6.

Quoted 3 lines

The main purpose of that RFC is to ensure we handle DNS and --dhcp-options consistently across all OpenVPN implementations we care about, and that we document this properly.

As far as I understand, jjk's patch is in line with what Tunnelblick already does on MAC, and does not conflict with the larger plan.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#22 lore raw
In reply to Jan Just Keijser

Hi,

Quoted 24 lines · Jan Just Keijser
Quoted 5 lines · Gert Doering
Quoted 4 lines · Jan Just Keijser
src/openvpn/tun.c +0 -0
@@ -5697,6 +5740,11 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
      write_dhcp_u32_array(buf, 42, (uint32_t *)o->ntp, o->ntp_len, &error);
      write_dhcp_u32_array(buf, 45, (uint32_t *)o->nbdd, o->nbdd_len, &error);
 
Quoted 7 lines

src/openvpn/tun.c build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o) · line 5746

Quoted 4 lines
src/openvpn/tun.c +4 -0
+    for (int i=0; i < o->domain_search_list_len; i++)
+    {
+        write_dhcp_search_str(buf, 119, o->domain_search_list[i], &error);
+    }

I assume that this won't work. In the DHCP answer, it must be a single option with the concatenated list, not multiple answers with a single domain name each.

see https://tools.ietf.org/html/rfc3397

"

In the above diagram, Searchstring is a string specifying the
searchlist. If the length of the searchlist exceeds the maximum
permissible within a single option (255 octets), then multiple
options MAY be used, as described in "Encoding Long Options in the
Dynamic Host Configuration Protocol (DHCPv4)" [RFC3396 <https://tools.ietf.org/html/rfc3396>].

Quoted 3 lines

"
so you MAY use this option multiple times - and wireshark groks it fine. I don't have a Windows 10 client to test it against, however, so I am hoping that someone (Selva?) can do that for me.

I did test, and my initial suspicion was correct - Windows accepts the option, but only one of them.

I am pushing

dhcp-option DOMAIN-SEARCH v6.de,dhcp-option DOMAIN-SEARCH leo.org,dhcp-option DOMAIN-SEARCH ov.greenie.net,dhcp-option DOMAIN-SEARCH nekosoft.de

(because these are domains that have more interesting hostnames in than just "www" and "mail", so I can see if "v4only.v6.de" is found, or "dict.leo.org")

and "ipconfig /all" only shows the "nekosoft.de" one.

This one works(!), so generally, Win10 accepts this DHCP option - but it seems to want "all domains in one".

Can you send a v3?

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#23 lore raw

Hi,

Quoted 40 lines · Gert Doering

Hi,

Quoted 23 lines · Jan Just Keijser
Quoted 5 lines · Gert Doering
Quoted 4 lines · Jan Just Keijser
(quoted diff) +0 -0
@@ -5697,6 +5740,11 @@ build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
       write_dhcp_u32_array(buf, 42, (uint32_t *)o->ntp, o->ntp_len, &error);
       write_dhcp_u32_array(buf, 45, (uint32_t *)o->nbdd, o->nbdd_len, &error);
 
Quoted 7 lines

Review build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o) · line 5746

Quoted 4 lines
(quoted diff) +4 -0
+    for (int i=0; i < o->domain_search_list_len; i++)
+    {
+        write_dhcp_search_str(buf, 119, o->domain_search_list[i], &error);
+    }

I assume that this won't work. In the DHCP answer, it must be a single option with the concatenated list, not multiple answers with a single domain name each.

see https://tools.ietf.org/html/rfc3397

"

In the above diagram, Searchstring is a string specifying the
searchlist. If the length of the searchlist exceeds the maximum
permissible within a single option (255 octets), then multiple
options MAY be used, as described in "Encoding Long Options in the
Dynamic Host Configuration Protocol (DHCPv4)" [RFC3396 <https://tools.ietf.org/html/rfc3396>].

Quoted 3 lines

"
so you MAY use this option multiple times - and wireshark groks it fine. I don't have a Windows 10 client to test it against, however, so I am hoping that someone (Selva?) can do that for me.

I did test, and my initial suspicion was correct - Windows accepts the option, but only one of them.

I am pushing

dhcp-option DOMAIN-SEARCH v6.de,dhcp-option DOMAIN-SEARCH leo.org,dhcp-option DOMAIN-SEARCH ov.greenie.net,dhcp-option DOMAIN-SEARCH nekosoft.de

(because these are domains that have more interesting hostnames in than just "www" and "mail", so I can see if "v4only.v6.de" is found, or "dict.leo.org")

Quoted 8 lines

and "ipconfig /all" only shows the "nekosoft.de" one.

This one works(!), so generally, Win10 accepts this DHCP option - but it seems to want "all domains in one".

Can you send a v3?

not sure if all went well , but here's V3.

cheers,

JJK

From 2a7f199252ddaf1bccf1eb399d26adc0a5aca137 Mon Sep 17 00:00:00 2001
From: Jan Just Keijser <[email protected]...>
Date: Tue, 7 Jul 2020 18:10:15 +0200
Subject: [PATCH] [V3] Added support for DHCP option 119 (dns search suffix
list) for Windows. As of Windows 10 1809 Windows finally supports this so it makes sense to add support to OpenVPN as well.

---
 src/openvpn/options.c |  34 ++++++++++++++---
 src/openvpn/tun.c     | 101 ++++++++++++++++++++++++++++----------------------
 src/openvpn/tun.h     |   9 +++--
 3 files changed, 90 insertions(+), 54 deletions(-)
src/openvpn/options.c +28 -6
index e59b22b..85f1d8a 100644
@@ -726,7 +726,7 @@ static const char usage_message[] =
     "                    which allow multiple addresses,\n"
     "                    --dhcp-option must be repeated.\n"
     "                    DOMAIN name : Set DNS suffix\n"
-    "                    SEARCH name : Set DNS domain search list\n"
+    "                    DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"
     "                    DNS addr    : Set domain name server address(es) (IPv4 and IPv6)\n"
     "                    NTP         : Set NTP server address(es)\n"
     "                    NBDD        : Set NBDD server address(es)\n"
@@ -1150,6 +1150,20 @@ parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren
 #ifndef ENABLE_SMALL
 
 static void
+show_dhcp_option_list(const char *name, const char * const*array, int len)
+{
+    int i;
+    for (i = 0; i < len; ++i)
+    {
+        msg(D_SHOW_PARMS, "  %s[%d] = %s",
+            name,
+            i,
+            array[i] );
+    }
+}
+
+
+static void
 show_dhcp_option_addrs(const char *name, const in_addr_t *array, int len)
 {
     struct gc_arena gc = gc_new();
@@ -1176,7 +1190,6 @@ show_tuntap_options(const struct tuntap_options *o)
     SHOW_BOOL(dhcp_renew);
     SHOW_BOOL(dhcp_pre_release);
     SHOW_STR(domain);
-    SHOW_STR(domain_search_list);
     SHOW_STR(netbios_scope);
     SHOW_INT(netbios_node_type);
     SHOW_BOOL(disable_nbt);
@@ -1185,6 +1198,7 @@ show_tuntap_options(const struct tuntap_options *o)
     show_dhcp_option_addrs("WINS", o->wins, o->wins_len);
     show_dhcp_option_addrs("NTP", o->ntp, o->ntp_len);
     show_dhcp_option_addrs("NBDD", o->nbdd, o->nbdd_len);
+    show_dhcp_option_list("DOMAIN-SEARCH", o->domain_search_list, o->domain_search_list_len);
 }
 
 #endif /* ifndef ENABLE_SMALL */
@@ -7329,10 +7343,6 @@ add_option(struct options *options,
         {
             o->domain = p[2];
         }
-        else if (streq(p[1], "SEARCH") && p[2])
-        {
-            o->domain_search_list = p[2];
-        }
         else if (streq(p[1], "NBS") && p[2])
         {
             o->netbios_scope = p[2];
@@ -7373,6 +7383,18 @@ add_option(struct options *options,
         {
             dhcp_option_address_parse("NBDD", p[2], o->nbdd, &o->nbdd_len, msglevel);
         }
+        else if (streq(p[1], "DOMAIN-SEARCH") && p[2])
+        {
+            if (o->domain_search_list_len < N_SEARCH_LIST_LEN)
+            {
+                o->domain_search_list[o->domain_search_list_len++] = p[2];
+            }
+            else
+            {
+                msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
+                    p[1], N_SEARCH_LIST_LEN);
+            }
+        }
         else if (streq(p[1], "DISABLE-NBT") && !p[2])
         {
             o->disable_nbt = 1;
src/openvpn/tun.c +56 -45

134 lines not on this page · raw message

src/openvpn/tun.h +6 -3
index 571b694..6a87387 100644
@@ -89,9 +89,6 @@ struct tuntap_options {
 
     const char *domain;      /* DOMAIN (15) */
 
-#define SEARCH_LIST_LEN 256
-    const char *domain_search_list;      /* SEARCH (119), MacOS, Linux Win10 1809+ */
-
     const char *netbios_scope; /* NBS (47) */
 
     int netbios_node_type;   /* NBT 1,2,4,8 (46) */
@@ -115,6 +112,12 @@ struct tuntap_options {
     in_addr_t nbdd[N_DHCP_ADDR];
     int nbdd_len;
 
+#define N_SEARCH_LIST_LEN 10 /* Max # of entries in domin-search list */
+
+    /* SEARCH (119), MacOS, Linux, Win10 1809+ */
+    const char *domain_search_list[N_SEARCH_LIST_LEN];
+    int domain_search_list_len;
+
     /* DISABLE_NBT (43, Vendor option 001) */
     bool disable_nbt;
 
Signature · 1 line
1.8.3.1
#24 lore raw

Hi,

Quoted 6 lines · Jan Just Keijser
Quoted 5 lines

This one works(!), so generally, Win10 accepts this DHCP option - but it seems to want "all domains in one".

Can you send a v3?

not sure if all went well , but here's V3.

Unfortunately not, that one seems to be based on your V1 patch, so we have "remove 'SEARCH', add 'DOMAIN-SEARCH'" hunks...

src/openvpn/options.c static const char usage_message[] = · line 729

Quoted 10 lines
src/openvpn/options.c +1 -1
index e59b22b..85f1d8a 100644
@@ -726,7 +726,7 @@ static const char usage_message[] =
     "                    which allow multiple addresses,\n"
     "                    --dhcp-option must be repeated.\n"
     "                    DOMAIN name : Set DNS suffix\n"
-    "                    SEARCH name : Set DNS domain search list\n"
+    "                    DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"

This is ok for me to have a look, but to actually merge I need something that applies "as it is" on top of master...

Quoted 6 lines
src/openvpn/tun.c +0 -0
index eed9ae6..60a149c 100644
@@ -5567,46 +5567,70 @@ write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error)
     buf_write(buf, str, len);

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5577

Quoted 10 lines
src/openvpn/tun.c +8 -0
 }
 
+/*
+ * RFC3397 states that multiple searchdomains are encoded as follows:
+ *  - at start the length of the entire option is given
+ *  - each subdomain is preceded by its length
+ *  - each searchdomain is separated by a NUL character
+ * e.g. if you want "openvpn.net" and "duckduckgo.com" then you end up with
+ *  0x13  0x7 openvpn 0x3 net 0x00 0x0A duckduckgo 0x3 com 0x00
+ */

Richard commented on IRC that the "0x13" does not seem to be right here
- adding up all of it (1+7+1+3+1+1+10+1+3+1 = 29). Can you double-check?

It's just a comment, but if that is wrong, it's not helpful in trying to understand the code.

Quoted 28 lines
src/openvpn/tun.c +23 -3
 static void
-write_dhcp_search_str(struct buffer *buf, const int type, const char *str, bool *error)
+write_dhcp_search_str(struct buffer *buf, const int type, const char * const *str_array,
+                      int array_len, bool *error)
 {
-    const char  *ptr = str, *dotptr = str;
-    int          i, j;
+    char         tmp_buf[256];
+    int          i;
+    int          len = 0;
+
+    for (i=0; i < array_len; i++)
+    {
+        const char  *ptr = str_array[i], *dotptr = str_array[i];
+        int          j, k;
+
+        msg(M_INFO, "Processing '%s'", ptr);
+
+        if (strlen(ptr) + len + 1 > sizeof(tmp_buf))
+        {
+            *error = true;
+            msg(M_WARN, "write_dhcp_search_str: temp buffer overflow building DHCP options");
+            return;
+        }
+        /* Loop over all subdomains separated by a dot and replace the dot
+           with the length of the subdomain */
+        while ((dotptr = strchr(ptr, '.')) != NULL)
+        {   

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5612

Quoted 10 lines
src/openvpn/tun.c +10 -0
+            j = dotptr - ptr;
+            tmp_buf[len++] = j;
+            for (k=0; k < j; k++) tmp_buf[len++] = ptr[k];
+            ptr = dotptr + 1;
+        }   
+
+        /* Now do the remainder after the last dot */
+        j = strlen(ptr);
+        tmp_buf[len++] = j;
+        for (k=0; k < j; k++) tmp_buf[len++] = ptr[k];

This should work. It might be possible to do this with slightly less code with strsep() (which will give you nicely null-terminated chunks, including "the remainder", but will require a writeable copy of the string).

It's overflow safe, so "good enough".

The restriction to max. 10 search domains sounds reasonable to me - since the total string is limited, and we do not implement multiple options (*and* windows 10 is, by observation, ignoring more than one anyway) this is "good enough for all reasonable deployments".

Can I have a v4, please? :-)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#25 lore raw

PATCH v4 1/1 Added support for DHCP option 119 (dns search suffix, list) for Windows. As of Windows 10 1809 Windows finally supports this so it, makes sense to add support to OpenVPN as well.

Quoted 1 line · Gert Doering

Can I have a v4, please? :-)

V4:

From fe0592df3235f3eb9bc9820586651ba8fc8bade0 Mon Sep 17 00:00:00 2001
From: Jan Just Keijser <[email protected]...>
Date: Fri, 10 Jul 2020 18:40:43 +0200
Subject: [PATCH] Added support for DHCP option 119 (dns search suffix list)
for Windows. As of Windows 10 1809 Windows finally supports this so it makes sense to add support to OpenVPN as well.

---
 src/openvpn/options.c | 27 +++++++++++++++++++
 src/openvpn/tun.c     | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/openvpn/tun.h     |  6 +++++
 3 files changed, 107 insertions(+)
src/openvpn/options.c +27 -0
index b93fd4f..ff3a116 100644
@@ -732,6 +732,7 @@ static const char usage_message[] =
     "                    DNS addr    : Set domain name server address(es) (IPv4 and IPv6)\n"
     "                    NTP         : Set NTP server address(es)\n"
     "                    NBDD        : Set NBDD server address(es)\n"
+    "                    DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"
     "                    WINS addr   : Set WINS server address(es)\n"
     "                    NBT type    : Set NetBIOS over TCP/IP Node type\n"
     "                                  1: B, 2: P, 4: M, 8: H\n"
@@ -1145,6 +1146,19 @@ parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren
 #ifndef ENABLE_SMALL
 
 static void
+show_dhcp_option_list(const char *name, const char * const*array, int len)
+{
+    int i;
+    for (i = 0; i < len; ++i)
+    {
+        msg(D_SHOW_PARMS, "  %s[%d] = %s",
+            name,
+            i,
+            array[i] );
+    }
+}
+
+static void
 show_dhcp_option_addrs(const char *name, const in_addr_t *array, int len)
 {
     struct gc_arena gc = gc_new();
@@ -1179,6 +1193,7 @@ show_tuntap_options(const struct tuntap_options *o)
     show_dhcp_option_addrs("WINS", o->wins, o->wins_len);
     show_dhcp_option_addrs("NTP", o->ntp, o->ntp_len);
     show_dhcp_option_addrs("NBDD", o->nbdd, o->nbdd_len);
+    show_dhcp_option_list("DOMAIN-SEARCH", o->domain_search_list, o->domain_search_list_len);
 }
 
 #endif /* ifndef ENABLE_SMALL */
@@ -7460,6 +7475,18 @@ add_option(struct options *options,
         {
             dhcp_option_address_parse("NBDD", p[2], o->nbdd, &o->nbdd_len, msglevel);
         }
+        else if (streq(p[1], "DOMAIN-SEARCH") && p[2])
+        {
+            if (o->domain_search_list_len < N_SEARCH_LIST_LEN)
+            {
+                o->domain_search_list[o->domain_search_list_len++] = p[2];
+            }
+            else
+            {
+                msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
+                    p[1], N_SEARCH_LIST_LEN);
+            }
+        }
         else if (streq(p[1], "DISABLE-NBT") && !p[2])
         {
             o->disable_nbt = 1;
src/openvpn/tun.c +74 -0

86 lines not on this page · raw message

src/openvpn/tun.h +6 -0
index b38e7e9..99826cf 100644
@@ -112,6 +112,12 @@ struct tuntap_options {
     in_addr_t nbdd[N_DHCP_ADDR];
     int nbdd_len;
 
+#define N_SEARCH_LIST_LEN 10 /* Max # of entries in domin-search list */
+
+    /* SEARCH (119), MacOS, Linux, Win10 1809+ */
+    const char *domain_search_list[N_SEARCH_LIST_LEN];
+    int domain_search_list_len;
+
     /* DISABLE_NBT (43, Vendor option 001) */
     bool disable_nbt;
 
Signature · 1 line
1.8.3.1
#26 lore raw

Re: [Openvpn-devel] [PATCH] [V4] Added support for DHCP option 119 (dns search suffix, list) for Windows. As of Windows 10 1809 Windows finally supports this so it, makes sense to add support to OpenVPN as well.

Hi,

Quoted 3 lines · Jan Just Keijser
Quoted 1 line · Gert Doering

Can I have a v4, please? :-)

V4:

Okay, here we go...

Generally speaking, it works now :-)

In the "ipconfig /all" output, I can now see a long list of DNS suffixes.

Together with a DNS search list on the LAN *and* block-outside-dns, this seems to have interesting effects on Win10 - namely, it tries all the search domains it has (on all interfaces), but it will try the "LAN" search domains only via the "LAN" nameservers - and these are blocked, so there might be interesting side effects if both are used togehter - *or* it might be a way to get Win10 DNS to behave better even without block-outside-DNS (by configuring a search domain on the TAP side).

Codewise, a few remarks...

Quoted 5 lines
src/openvpn/options.c +1 -0
@@ -1145,6 +1146,19 @@ parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren
 #ifndef ENABLE_SMALL
 
 static void
+show_dhcp_option_list(const char *name, const char * const*array, int len)

src/openvpn/options.c parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren · line 1159

Quoted 10 lines
src/openvpn/options.c +10 -0
+{
+    int i;
+    for (i = 0; i < len; ++i)
+    {
+        msg(D_SHOW_PARMS, "  %s[%d] = %s",
+            name,
+            i,
+            array[i] );
+    }
+}

This is not "forbidden" by the style guide, but I think a more compact form would increase readability - the old openvpn style of having individual function calls spread over 10+ lines because each parameter is getting its own line is not really something we do anymore. So:

Review parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren · line 1160

Quoted 1 line
(quoted diff) +1 -0
+        msg(D_SHOW_PARMS, "  %s[%d] = %s", name, i, array[i] );

... which is well below the 80 character limit and which I find more readable, tbh.

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5682

Quoted 7 lines
src/openvpn/tun.c +7 -0
+/*
+ * RFC3397 states that multiple searchdomains are encoded as follows:
+ *  - at start the length of the entire option is given
+ *  - each subdomain is preceded by its length
+ *  - each searchdomain is separated by a NUL character
+ * e.g. if you want "openvpn.net" and "duckduckgo.com" then you end up with
+ *  0x13  0x7 openvpn 0x3 net 0x00 0x0A duckduckgo 0x3 com 0x00

While at it, 0x1D :-)

Quoted 5 lines

+ */

src/openvpn/tun.c +4 -0
+static void
+write_dhcp_search_str(struct buffer *buf, const int type, const char * const *str_array,
+                      int array_len, bool *error)
+{

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5697

Quoted 10 lines
src/openvpn/tun.c +10 -0
+    char         tmp_buf[256];
+    int          i;
+    int          len = 0;
+
+    for (i=0; i < array_len; i++)
+    {
+        const char  *ptr = str_array[i], *dotptr = str_array[i];
+        int          j, k;
+
+        msg(M_INFO, "Processing '%s'", ptr);

This line should not stay as it is - if you see it in the log, it's mostly unclear "it's processing 'domain' - what for?", and M_INFO is too high for unspecific info.

Most other DHCP activities do not log anything (unless error), so for consistency I would just remove it. But if we keep it, it needs to be more clear, like

Quoted 1 line

+ msg(D_DHCP_OPT, "dhcp search domain '%s'", ptr);

or something like that.

Quoted 4 lines
src/openvpn/tun.c +4 -0
+        if (strlen(ptr) + len + 1 > sizeof(tmp_buf))
+        {
+            *error = true;
+            msg(M_WARN, "write_dhcp_search_str: temp buffer overflow building DHCP options");

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5711

Quoted 10 lines
src/openvpn/tun.c +9 -0
+            return;
+        }
 
+        /* Loop over all subdomains separated by a dot and replace the dot
+           with the length of the subdomain */
+        while ((dotptr = strchr(ptr, '.')) != NULL)
+        {   
+            j = dotptr - ptr;
+            tmp_buf[len++] = j;
+            for (k=0; k < j; k++) tmp_buf[len++] = ptr[k];

Side note: this violate coding style - for(), as if(), mandates brackets.

Quoted 1 line

+ for (k=0; k < j; k++)

               {
	           tmp_buf[len++] = ptr[k];
               }

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5718

Quoted 7 lines
src/openvpn/tun.c +7 -0
+            ptr = dotptr + 1;
+        }   
+
+        /* Now do the remainder after the last dot */
+        j = strlen(ptr);
+        tmp_buf[len++] = j;
+        for (k=0; k < j; k++) tmp_buf[len++] = ptr[k];

same here.

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5722

Quoted 4 lines
src/openvpn/tun.c +4 -0
+  
+        /* And close off with an extra NUL char */
+        tmp_buf[len++] = 0;
+    }

With these required brackets, the nested loops get long - and I do not find them overly elegant anyway (one could do a memcpy(), which would make more clear what is done, but it's still double-looping).

For this, I had the idea to code it as follows (mentioned yesterday, but now actually written down) - single pass, no nested loops:

    /* Loop over all subdomains separated by a dot and replace the dot
       with the length of the subdomain */

    /* label_length_pos points to the byte to be replaced by the length 
     * of the following domain label */
    int label_length_pos = len++;

    while(true)
    {
        if (*ptr == '.' || *ptr == '\0' )
	{
	    tmp_buf[label_length_pos] = (len-label_length_pos)-1;
	    label_length_pos = len;
	    if (*ptr == '\0')
	    {
		break;
	    }
	}
	tmp_buf[len++] = *ptr++;
    }
    /* And close off with an extra NUL char */
    tmp_buf[len++] = '\0';

(I've actually tested this and it works :-) - wireshark and Win10 confirms that the result is good - so if you want it, just use it for v5, if not, leave it)

Quoted 8 lines
src/openvpn/tun.c +8 -0
+
+    if (!buf_safe(buf, 2 + len))
+    {
+        *error = true;
+        msg(M_WARN, "write_search_dhcp_str: buffer overflow building DHCP options");
+        return;
+    }
+    if (len > 255)

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5740

Quoted 10 lines
src/openvpn/tun.c +10 -0
+    {
+        *error = true;
+        msg(M_WARN, "write_dhcp_search_str: search domain string must be <= 255 bytes");
+        return;
+    }
+
+    buf_write_u8(buf, type);
+    buf_write_u8(buf, len);
+    for (i=0; i < len; i++) buf_write_u8(buf, tmp_buf[i]);
+}

There's another set of brackets needed here... { buf_write_u8() }

But why use buf_write_u8() and another for() loop at all?

   buf_write(buf, tmp_buf, len);

should do the job just fine...

So - getting close. Technological issues solved, now style issues (which are much harder at times :-) ).

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#27 lore raw

PATCH v5 1/1 Added support for DHCP option 119 (dns search suffix, list) for Windows. As of Windows 10 1809 Windows finally supports this so it, makes sense to add support to OpenVPN as well.

Hi,

Quoted 5 lines · Gert Doering
Quoted 3 lines · Jan Just Keijser
Quoted 1 line · Gert Doering

Can I have a v4, please? :-)

V4:

Okay, here we go...

thanks for the review, I incorporated your suggestions and comments almost verbatim ;) See attached V5.

cheers,

JJK

Quoted 172 lines

Generally speaking, it works now :-)

In the "ipconfig /all" output, I can now see a long list of DNS suffixes.

Together with a DNS search list on the LAN *and* block-outside-dns, this seems to have interesting effects on Win10 - namely, it tries all the search domains it has (on all interfaces), but it will try the "LAN" search domains only via the "LAN" nameservers - and these are blocked, so there might be interesting side effects if both are used togehter - *or* it might be a way to get Win10 DNS to behave better even without block-outside-DNS (by configuring a search domain on the TAP side).

Codewise, a few remarks...

Quoted 5 lines
(quoted diff) +1 -0
@@ -1145,6 +1146,19 @@ parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren
  #ifndef ENABLE_SMALL
 
  static void
+show_dhcp_option_list(const char *name, const char * const*array, int len)

Review parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren · line 1159

Quoted 10 lines
(quoted diff) +10 -0
+{
+    int i;
+    for (i = 0; i < len; ++i)
+    {
+        msg(D_SHOW_PARMS, "  %s[%d] = %s",
+            name,
+            i,
+            array[i] );
+    }
+}

This is not "forbidden" by the style guide, but I think a more compact form would increase readability - the old openvpn style of having individual function calls spread over 10+ lines because each parameter is getting its own line is not really something we do anymore. So:

Review parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren · line 1160

Quoted 1 line
(quoted diff) +1 -0
+        msg(D_SHOW_PARMS, "  %s[%d] = %s", name, i, array[i] );

... which is well below the 80 character limit and which I find more readable, tbh.

Review parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren

Quoted 7 lines
(quoted diff) +7 -0
+/*
+ * RFC3397 states that multiple searchdomains are encoded as follows:
+ *  - at start the length of the entire option is given
+ *  - each subdomain is preceded by its length
+ *  - each searchdomain is separated by a NUL character
+ * e.g. if you want "openvpn.net" and "duckduckgo.com" then you end up with
+ *  0x13  0x7 openvpn 0x3 net 0x00 0x0A duckduckgo 0x3 com 0x00

While at it, 0x1D :-)

Quoted 5 lines

+ */

(quoted diff) +4 -0
+static void
+write_dhcp_search_str(struct buffer *buf, const int type, const char * const *str_array,
+                      int array_len, bool *error)
+{

Review

Quoted 10 lines
(quoted diff) +10 -0
+    char         tmp_buf[256];
+    int          i;
+    int          len = 0;
+
+    for (i=0; i < array_len; i++)
+    {
+        const char  *ptr = str_array[i], *dotptr = str_array[i];
+        int          j, k;
+
+        msg(M_INFO, "Processing '%s'", ptr);

This line should not stay as it is - if you see it in the log, it's mostly unclear "it's processing 'domain' - what for?", and M_INFO is too high for unspecific info.

Most other DHCP activities do not log anything (unless error), so for consistency I would just remove it. But if we keep it, it needs to be more clear, like

Quoted 1 line

+ msg(D_DHCP_OPT, "dhcp search domain '%s'", ptr);

or something like that.

Review

Quoted 13 lines
(quoted diff) +13 -0
+        if (strlen(ptr) + len + 1 > sizeof(tmp_buf))
+        {
+            *error = true;
+            msg(M_WARN, "write_dhcp_search_str: temp buffer overflow building DHCP options");
+            return;
+        }
+        /* Loop over all subdomains separated by a dot and replace the dot
+           with the length of the subdomain */
+        while ((dotptr = strchr(ptr, '.')) != NULL)
+        {
+            j = dotptr - ptr;
+            tmp_buf[len++] = j;
+            for (k=0; k < j; k++) tmp_buf[len++] = ptr[k];

Side note: this violate coding style - for(), as if(), mandates brackets.

Quoted 1 line

+ for (k=0; k < j; k++)

                {
	           tmp_buf[len++] = ptr[k];
                }

Review

Quoted 7 lines
(quoted diff) +7 -0
+            ptr = dotptr + 1;
+        }
+
+        /* Now do the remainder after the last dot */
+        j = strlen(ptr);
+        tmp_buf[len++] = j;
+        for (k=0; k < j; k++) tmp_buf[len++] = ptr[k];

same here.

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+        /* And close off with an extra NUL char */
+        tmp_buf[len++] = 0;
+    }

With these required brackets, the nested loops get long - and I do not find them overly elegant anyway (one could do a memcpy(), which would make more clear what is done, but it's still double-looping).

For this, I had the idea to code it as follows (mentioned yesterday, but now actually written down) - single pass, no nested loops:

     /* Loop over all subdomains separated by a dot and replace the dot
        with the length of the subdomain */

     /* label_length_pos points to the byte to be replaced by the length
      * of the following domain label */
     int label_length_pos = len++;

     while(true)
     {
         if (*ptr == '.' || *ptr == '\0' )
	{
	    tmp_buf[label_length_pos] = (len-label_length_pos)-1;
	    label_length_pos = len;
	    if (*ptr == '\0')
	    {
		break;
	    }
	}
	tmp_buf[len++] = *ptr++;
     }
     /* And close off with an extra NUL char */
     tmp_buf[len++] = '\0';

(I've actually tested this and it works :-) - wireshark and Win10 confirms that the result is good - so if you want it, just use it for v5, if not, leave it)

Quoted 8 lines
(quoted diff) +8 -0
+
+    if (!buf_safe(buf, 2 + len))
+    {
+        *error = true;
+        msg(M_WARN, "write_search_dhcp_str: buffer overflow building DHCP options");
+        return;
+    }
+    if (len > 255)

Review

Quoted 10 lines
(quoted diff) +10 -0
+    {
+        *error = true;
+        msg(M_WARN, "write_dhcp_search_str: search domain string must be <= 255 bytes");
+        return;
+    }
+
+    buf_write_u8(buf, type);
+    buf_write_u8(buf, len);
+    for (i=0; i < len; i++) buf_write_u8(buf, tmp_buf[i]);
+}

There's another set of brackets needed here... { buf_write_u8() }

But why use buf_write_u8() and another for() loop at all?

    buf_write(buf, tmp_buf, len);
Quoted 7 lines

should do the job just fine...

So - getting close. Technological issues solved, now style issues (which are much harder at times :-) ).

gert

From db6491450361aede405510edf412bc276cce6536 Mon Sep 17 00:00:00 2001
From: Jan Just Keijser <[email protected]...>
Date: Tue, 14 Jul 2020 11:39:10 +0200
Subject: [PATCH] Added support for DHCP option 119 (dns search suffix list)
for Windows. As of Windows 10 1809 Windows finally supports this so it makes sense to add support to OpenVPN as well.

---
 src/openvpn/options.c | 24 ++++++++++++++++
 src/openvpn/tun.c     | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/openvpn/tun.h     |  6 ++++
 3 files changed, 106 insertions(+)
src/openvpn/options.c +24 -0
index bf2760e..66c72f1 100644
@@ -729,6 +729,7 @@ static const char usage_message[] =
     "                    which allow multiple addresses,\n"
     "                    --dhcp-option must be repeated.\n"
     "                    DOMAIN name : Set DNS suffix\n"
+    "                    DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"
     "                    DNS addr    : Set domain name server address(es) (IPv4 and IPv6)\n"
     "                    NTP         : Set NTP server address(es)\n"
     "                    NBDD        : Set NBDD server address(es)\n"
@@ -1144,6 +1145,16 @@ parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren
 
 #ifndef ENABLE_SMALL
 
+static void 
+show_dhcp_option_list(const char *name, const char * const*array, int len) 
+{
+    int i;
+    for (i = 0; i < len; ++i) 
+    {    
+        msg(D_SHOW_PARMS, "  %s[%d] = %s", name, i, array[i] );
+    }    
+}
+
 static void
 show_dhcp_option_addrs(const char *name, const in_addr_t *array, int len)
 {
@@ -1179,6 +1190,7 @@ show_tuntap_options(const struct tuntap_options *o)
     show_dhcp_option_addrs("WINS", o->wins, o->wins_len);
     show_dhcp_option_addrs("NTP", o->ntp, o->ntp_len);
     show_dhcp_option_addrs("NBDD", o->nbdd, o->nbdd_len);
+    show_dhcp_option_list("DOMAIN-SEARCH", o->domain_search_list, o->domain_search_list_len);
 }
 
 #endif /* ifndef ENABLE_SMALL */
@@ -7460,6 +7472,18 @@ add_option(struct options *options,
         {
             dhcp_option_address_parse("NBDD", p[2], o->nbdd, &o->nbdd_len, msglevel);
         }
+        else if (streq(p[1], "DOMAIN-SEARCH") && p[2])
+        {
+            if (o->domain_search_list_len < N_SEARCH_LIST_LEN)
+            {
+                o->domain_search_list[o->domain_search_list_len++] = p[2];
+            }
+            else
+            {
+                msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
+                    p[1], N_SEARCH_LIST_LEN);
+            }
+        }
         else if (streq(p[1], "DISABLE-NBT") && !p[2])
         {
             o->disable_nbt = 1;
src/openvpn/tun.c +76 -0

88 lines not on this page · raw message

src/openvpn/tun.h +6 -0
index b38e7e9..99826cf 100644
@@ -112,6 +112,12 @@ struct tuntap_options {
     in_addr_t nbdd[N_DHCP_ADDR];
     int nbdd_len;
 
+#define N_SEARCH_LIST_LEN 10 /* Max # of entries in domin-search list */
+
+    /* SEARCH (119), MacOS, Linux, Win10 1809+ */
+    const char *domain_search_list[N_SEARCH_LIST_LEN];
+    int domain_search_list_len;
+
     /* DISABLE_NBT (43, Vendor option 001) */
     bool disable_nbt;
 
Signature · 1 line
1.8.3.1
Acked-by on v5 1/1
#28 lore raw

[Openvpn-devel] [PATCH applied] Re: Added support for DHCP option 119 (dns search suffix list) for Windows. As of Windows 10 1809 Windows finally supports this so it makes sense to add support to OpenVPN as well.

Yay :-)

(I have reviewed it once again, and tested on my Win10 VM, and it still works!)

Your patch has been applied to the master branch.

I have reformatted and extended the commit message to give more details on what you did and what it can and can not do.

commit 78359a0478da64e18d49b13ea2e09def2b89f4a6

Author: Jan Just Keijser
Date:   Tue Jul 14 11:39:10 2020 +0200
     Added support for DHCP option 119 (dns search suffix list) for Windows. 

     As of Windows 10 1809 Windows finally supports this so it makes sense 
     to add support to OpenVPN as well.

     Signed-off-by: Jan Just Keijser <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg20349.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#29 lore raw
In reply to Gert Doering

Hi all,

Quoted 42 lines · Gert Doering
Quoted 6 lines · Jan Just Keijser
Quoted 5 lines

This one works(!), so generally, Win10 accepts this DHCP option - but it seems to want "all domains in one".

Can you send a v3?

not sure if all went well , but here's V3.

Unfortunately not, that one seems to be based on your V1 patch, so we have "remove 'SEARCH', add 'DOMAIN-SEARCH'" hunks...

src/openvpn/options.c static const char usage_message[] = · line 729

Quoted 10 lines
src/openvpn/options.c +1 -1
index e59b22b..85f1d8a 100644
@@ -726,7 +726,7 @@ static const char usage_message[] =
      "                    which allow multiple addresses,\n"
      "                    --dhcp-option must be repeated.\n"
      "                    DOMAIN name : Set DNS suffix\n"
-    "                    SEARCH name : Set DNS domain search list\n"
+    "                    DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"

This is ok for me to have a look, but to actually merge I need something that applies "as it is" on top of master...

Quoted 6 lines
src/openvpn/tun.c +0 -0
index eed9ae6..60a149c 100644
@@ -5567,46 +5567,70 @@ write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error)
      buf_write(buf, str, len);

src/openvpn/tun.c write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) · line 5577

Quoted 10 lines
src/openvpn/tun.c +8 -0
  }
 
+/*
+ * RFC3397 states that multiple searchdomains are encoded as follows:
+ *  - at start the length of the entire option is given
+ *  - each subdomain is preceded by its length
+ *  - each searchdomain is separated by a NUL character
+ * e.g. if you want "openvpn.net" and "duckduckgo.com" then you end up with
+ *  0x13  0x7 openvpn 0x3 net 0x00 0x0A duckduckgo 0x3 com 0x00
+ */

Richard commented on IRC that the "0x13" does not seem to be right here
- adding up all of it (1+7+1+3+1+1+10+1+3+1 = 29). Can you double-check?

Quoted 4 lines

It's just a comment, but if that is wrong, it's not helpful in trying to understand the code.

just submitted patch v4 but forgot to fix that:   richard is right 29 decimal is  0x1D -  or just 29, I guess  - not 0x13

Want a v5 for that :P ?

cheers,

JJK

#30 lore raw

Hi,

Quoted 7 lines · Jan Just Keijser
Quoted 3 lines

It's just a comment, but if that is wrong, it's not helpful in trying to understand the code.

just submitted patch v4 but forgot to fix that:   richard is right 29 decimal is  0x1D -  or just 29, I guess  - not 0x13

Want a v5 for that :P ?

If the rest is working nicely, I usually fix comment or commit message errors (if the proposer agrees) on the fly.

So, will test v4 tomorrow, and then report back :-)

While I couldn't sleep a few nights ago, I came up with a more elegant approach than strtok()/strchr()/strsep() though... just walk the string, remember where to put the lenght byte, and every time you hit a "." or "\0", put (p-lenght_p)-1 into *length_p and remember the current position
as new "length_p"... less code, no remainder to deal with, and
single-pass... :-) - so if v4 is not working yet, that might be another thing for v5.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#31 lore raw
In reply to Gert Doering
Quoted 13 lines · Gert Doering

Hi,

going through OpenVPN threads that went stale - I think this is actually a nice addition (read: other people have already asked me if this can be done).

Quoted 6 lines · Jan Just Keijser

So, for what it's worth, I've dusted off the patch again and rebased it to the current openvpn master tree. See attached. Note that I did only rudimentary testing, as I don't use Windows 10 a lot and I was testing using a mingw cross-compile only. In wireshark I *do* see that the correct DHCP offer is sent to the tap-win adapter.

Quoted 8 lines
Quoted 6 lines

Also note that I implemented multiple search domains by separating them using semi-colons, e.g.

   --dhcp-option SEARCH example.com;example.org;example.nl;example.de

etc as that was easier to implement

The patch looks okay-ish on quick reading.

Feature-ACK from my side as well. But there are a few things we need to look more into.

[...snip...]

Quoted 4 lines

More interesting is the question "which option to use" - it should be synchronized between openvpn platform handlers. So if systemd-networkd uses "SEARCH-DOMAIN" it would make sense to use that for windows as well.

Nit-pick, systemd-resolved is the target service in this case though. But it is related to systemd-networkd.

But I agree, we should synchronize this a bit. IIRC, there might already be somewhat partial support for this in OpenVPN Connect clients as well, which might also be used in Access Server. I would also expect the OpenVPN Cloud service to facilitate such a feature. I have recently been working on systemd-resolved support in OpenVPN 3 Linux as well, and reached out earlier this week to Jonathan (update-systemd-resolved maintainer) to see if we can join forces better and standardize on a common understanding of the DHCP options.

I would also like to at least consider pulling update-systemd-resolved (or a similar approach) into our OpenVPN distribution, as an alternative to the rather hacky pull-resolv-conf scripts we're shipping.

I quickly spoke with Arne late on Friday about it as well, and we might also want to consider some IV flags from client to server as well, to flag support for features like split-dns (which at least systemd-resolved can provide).

Quoted 2 lines

Does anyone know about commercial VPN providers basing their clients on OpenVPN?

I will clarify with our folks internally how this will influence OpenVPN Cloud. I can't imagine many other commercial VPNs depending on such a feature, this is more typically a business feature than a consumer VPN feature. There might be a few ones implementing or needing such a feature, but if they don't appear here and raise there concerns here, I don't think we should spend time on them.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc