dns option: allow up to eight addresses per server
PATCH 1/3 dns option: allow up to eight addresses per server
This change allows configuration of more than one address per family for a DNS server. This way you can specify backup addresses in case a server is not reachable. During closer inspection of the various DNS backend in supported operation systems it turned out that our previous idea to have more than one DNS server applied in order of priority does not work in most cases. Thus it became important to be able to specify backup addresses. So instead of doing
dns server 1 address 1.2.3.4 2001::1
dns server 2 address 5.6.7.8 2001::2
to specify a backup addresses, this is now done like so:
dns server 1 address 1.2.3.4 2001::1
dns server 1 address 5.6.7.8 2001::2
or you can have all the addresses on one line if you like:
dns server 1 address 1.2.3.4 2001::1 2001::2 5.6.7.8
This also saves some repeated options when (backup) servers share the same settings like "resolve-domains" compared to the originally intended way.
The order in which addresses are given is retained for backends that support this sort of cross address family ordering.
--- doc/man-sections/client-options.rst | 9 ++-- doc/man-sections/script-options.rst | 6 +-- src/openvpn/dns.c | 83 +++++++++++++++-------------- src/openvpn/dns.h | 18 ++++--- src/openvpn/options.c | 76 ++++++++++++++------------ 5 files changed, 103 insertions(+), 89 deletions(-)
doc/man-sections/client-options.rst +5 -4
@@ -168,7 +168,7 @@ configuration. :: dns search-domains domain [domain ...] - dns server n address addr[:port] [addr[:port]] + dns server n address addr[:port] [addr[:port] ...] dns server n resolve-domains|exclude-domains domain [domain ...] dns server n dnssec yes|optional|no dns server n transport DoH|DoT|plain
@@ -186,9 +186,10 @@ configuration. lower numbers come first. DNS servers being pushed to a client replace already configured DNS servers with the same server id. - The ``address`` option configures the IPv4 and / or IPv6 address of - the DNS server. Optionally a port can be appended after a colon. IPv6 - addresses need to be enclosed in brackets if a port is appended. + The ``address`` option configures the IPv4 and / or IPv6 address(es) of + the DNS server. Up to eight addresses can be specified per DNS server. + Optionally a port can be appended after a colon. IPv6 addresses need to + be enclosed in brackets if a port is appended. The ``resolve-domains`` and ``exclude-domains`` options take one or more DNS domains which are explicitly resolved or explicitly not resolved
doc/man-sections/script-options.rst +2 -4
@@ -660,10 +660,8 @@ instances. :: dns_search_domain_{n} - dns_server_{n}_address4 - dns_server_{n}_port4 - dns_server_{n}_address6 - dns_server_{n}_port6 + dns_server_{n}_address_{m} + dns_server_{n}_port_{m} dns_server_{n}_resolve_domain_{m} dns_server_{n}_exclude_domain_{m} dns_server_{n}_dnssec
src/openvpn/dns.c +42 -41
133 lines not on this page · raw message
src/openvpn/dns.h +12 -6
@@ -52,15 +52,21 @@ struct dns_domain {const char *name; }; +struct dns_server_addr +{ +union { +struct in_addr a4; +struct in6_addr a6; + } in; +sa_family_t family; +in_port_t port; +}; +struct dns_server {struct dns_server *next;long priority; -bool addr4_defined; -bool addr6_defined; -struct in_addr addr4; -struct in6_addr addr6; -in_port_t port4; -in_port_t port6; +size_t addr_count; +struct dns_server_addr addr[8 ];struct dns_domain *domains;enum dns_domain_type domain_type;enum dns_security dnssec;
src/openvpn/options.c +42 -34
106 lines not on this page · raw message
Signature · 1 line
2.37.2
PATCH 2/3 dns option: remove support for exclude-domains
No DNS resolver currently supports this and it is not possible to emulate the behavior without the chance of errors. Finding the effective default system DNS server(s) to specify the exclude DNS routes is not trivial and cannot be verified to be correct without resolver internal knowledge. So, it is better to not support this instead of supporting it, but incorrectly.
--- doc/man-sections/client-options.rst | 14 +++++--------- doc/man-sections/script-options.rst | 1 - src/openvpn/dns.c | 13 ++----------- src/openvpn/dns.h | 7 ------- src/openvpn/options.c | 17 ----------------- 5 files changed, 7 insertions(+), 45 deletions(-)
doc/man-sections/client-options.rst +5 -9
@@ -169,7 +169,7 @@ configuration. dns search-domains domain [domain ...] dns server n address addr[:port] [addr[:port] ...] - dns server n resolve-domains|exclude-domains domain [domain ...] + dns server n resolve-domains domain [domain ...] dns server n dnssec yes|optional|no dns server n transport DoH|DoT|plain dns server n sni server-name
@@ -191,14 +191,10 @@ configuration. Optionally a port can be appended after a colon. IPv6 addresses need to be enclosed in brackets if a port is appended. - The ``resolve-domains`` and ``exclude-domains`` options take one or - more DNS domains which are explicitly resolved or explicitly not resolved - by a server. Only one of the options can be configured for a server. - ``resolve-domains`` is used to define a split-dns setup, where only - given domains are resolved by a server. ``exclude-domains`` is used to - define domains which will never be resolved by a server (e.g. domains - which can only be resolved locally). Systems which do not support fine - grained DNS domain configuration, will ignore these settings. + The ``resolve-domains`` option takes one or more DNS domains used to define + a split-dns or dns-routing setup, where only the given domains are resolved + by the server. Systems which do not support fine grained DNS domain + configuration, will ignore this setting. The ``dnssec`` option is used to configure validation of DNSSEC records. While the exact semantics may differ for resolvers on different systems,
doc/man-sections/script-options.rst +0 -1
@@ -663,7 +663,6 @@ instances. dns_server_{n}_address_{m} dns_server_{n}_port_{m} dns_server_{n}_resolve_domain_{m} - dns_server_{n}_exclude_domain_{m} dns_server_{n}_dnssec dns_server_{n}_transport dns_server_{n}_sni
src/openvpn/dns.c +2 -11
@@ -402,11 +402,9 @@ setenv_dns_options(const struct dns_options *o, struct env_set *es)if (s->domains) { -const char *format = s->domain_type ==DNS_RESOLVE_DOMAINS ? -"dns_server_%d_resolve_domain_%d" :"dns_server_%d_exclude_domain_%d" ;for (j =1 , d = s->domains; d !=NULL ; j++, d = d->next) { -setenv_dns_option (es, format, i, j, d->name); +setenv_dns_option (es,"dns_server_%d_resolve_domain_%d" , i, j, d->name); } }
@@ -484,14 +482,7 @@ show_dns_options(const struct dns_options *o)struct dns_domain *domain = server->domains;if (domain) { -if (server->domain_type ==DNS_RESOLVE_DOMAINS ) - { -msg (D_SHOW_PARMS ," resolve domains:" ); - } -else - { -msg (D_SHOW_PARMS ," exclude domains:" ); - } +msg (D_SHOW_PARMS ," resolve domains:" );while (domain) {msg (D_SHOW_PARMS ," %s" , domain->name);
src/openvpn/dns.h +0 -7
@@ -27,12 +27,6 @@#include "buffer.h" #include "env_set.h" -enum dns_domain_type { -DNS_DOMAINS_UNSET , -DNS_RESOLVE_DOMAINS , -DNS_EXCLUDE_DOMAINS -}; -enum dns_security {DNS_SECURITY_UNSET ,DNS_SECURITY_NO ,
@@ -68,7 +62,6 @@ struct dns_server {size_t addr_count;struct dns_server_addr addr[8 ];struct dns_domain *domains; -enum dns_domain_type domain_type;enum dns_security dnssec;enum dns_server_transport transport;const char *sni;
src/openvpn/options.c +0 -17
@@ -514,7 +514,6 @@ static const char usage_message[] =" Valid options are :\n" " address <addr[:port]> [addr[:port] ...] : server addresses 4/6\n" " resolve-domains <domain> [domain ...] : split domains\n" -" exclude-domains <domain> [domain ...] : domains not to resolve\n" " dnssec <yes|no|optional> : option to use DNSSEC\n" " type <DoH|DoT> : query server over HTTPS / TLS\n" " sni <domain> : DNS server name indication\n"
@@ -8022,22 +8021,6 @@ add_option(struct options *options, }else if (streq (p[3 ],"resolve-domains" )) { -if (server->domain_type ==DNS_EXCLUDE_DOMAINS ) - { -msg (msglevel,"--dns server %ld: cannot use resolve-domains and exclude-domains" , priority); - goto err; - } - server->domain_type =DNS_RESOLVE_DOMAINS ; -dns_domain_list_append (&server->domains, &p[4 ], &options->dns_options.gc); - } -else if (streq (p[3 ],"exclude-domains" )) - { -if (server->domain_type ==DNS_RESOLVE_DOMAINS ) - { -msg (msglevel,"--dns server %ld: cannot use exclude-domains and resolve-domains" , priority); - goto err; - } - server->domain_type =DNS_EXCLUDE_DOMAINS ;dns_domain_list_append (&server->domains, &p[4 ], &options->dns_options.gc); }else if (streq (p[3 ],"dnssec" ) && !p[5 ])
Signature · 1 line
2.37.2
PATCH 3/3 dns option: make server id/priority optional
In reply to Heiko HundWith the discovery that most of the time only one DNS server's settings can be applied on various systems, the priority value will likely serve no purpose most of the time.
This is to make it optional to give a --dns server priority, for cases where you only specify one DNS server anyway. We keep the priority because it still serves the case where you want to override pushed server settings with local ones and when you run backends which do support multiple server's settings like dnsmasq(8).
--- doc/man-sections/client-options.rst | 11 ++++---- src/openvpn/dns.c | 9 +++++-- src/openvpn/dns.h | 4 ++- src/openvpn/options.c | 41 +++++++++++++++-------------- 4 files changed, 37 insertions(+), 28 deletions(-)
doc/man-sections/client-options.rst +6 -5
@@ -168,11 +168,11 @@ configuration. :: dns search-domains domain [domain ...] - dns server n address addr[:port] [addr[:port] ...] - dns server n resolve-domains domain [domain ...] - dns server n dnssec yes|optional|no - dns server n transport DoH|DoT|plain - dns server n sni server-name + dns server [n] address addr[:port] [addr[:port] ...] + dns server [n] resolve-domains domain [domain ...] + dns server [n] dnssec yes|optional|no + dns server [n] transport DoH|DoT|plain + dns server [n] sni server-name The ``--dns search-domains`` directive takes one or more domain names to be added as DNS domain suffixes. If it is repeated multiple times within
@@ -180,6 +180,7 @@ configuration. a server will amend locally defined ones. The ``--dns server`` directive is used to configure DNS server ``n``. + If the ``n`` parameter is omitted the directive configures DNS server ``0``. The server id ``n`` must be a value between -128 and 127. For pushed DNS server options it must be between 0 and 127. The server id is used to group options and also for ordering the list of configured DNS servers;
src/openvpn/dns.c +7 -2
@@ -159,13 +159,18 @@ dns_domain_list_append(struct dns_domain **entry, char **domains, struct gc_aren }bool -dns_server_priority_parse (long *priority,const char *str,bool pulled) +dns_server_priority_parse (long *priority,size_t *subidx,const char *str,bool pulled) {char *endptr;const long min = pulled ?0 :INT8_MIN ;const long max =INT8_MAX ;long prio =strtol (str, &endptr,10 ); -if (*endptr !='\0' || prio < min || prio > max) +if (endptr == str) + { +/* No priority found, str isn't numeric */ + *subidx -=1 ; + } +else if (*endptr !='\0' || prio < min || prio > max) {return false; }
src/openvpn/dns.h +3 -1
@@ -78,11 +78,13 @@ struct dns_options {* Parses a string DNS server priority and validates it. * * @param priority Pointer to where the priority should be stored +* @param subidx Pointer to the sub-option index, decremented if no +* priority value could be found * @param str Priority string to parse * @param pulled Whether this was pulled from a server * @return True if priority in string is valid */ -bool dns_server_priority_parse (long *priority,const char *str,bool pulled); +bool dns_server_priority_parse (long *priority,size_t *subidx,const char *str,bool pulled);/** * Find or create DNS server with priority in a linked list.
src/openvpn/options.c +21 -20
104 lines not on this page · raw message
Signature · 1 line
2.37.2
Am 10.03.23 um 06:08 schrieb Heiko Hund:
Quoted 8 lines
This change allows configuration of more than one address per family for a DNS server. This way you can specify backup addresses in case a server is not reachable. During closer inspection of the various DNS backend in supported operation systems it turned out that our previous idea to have more than one DNS server applied in order of priority does not work in most cases. Thus it became important to be able to specify backup addresses. So instead of doing
I've submitted this to "basic client/server testing" plus "GHA build", just to be sure that nothing breaks - but this doesn't excercise the new code at all.
Stare-at-code says "it should do what it says on the lid", and the code is actually a bit simpler this way, not having to maintain separate addr4/addr6_defined variables etc.
Some basic tests (running openvpn from the cli with --dns option and looking at "show_dns_options()" output) look good. Didn't look at the environment variables or Windows DHCP.
The error message for "--dns server 3 address" (with no addresses) is a bit confusing now
Options error: --dns: unknown option type 'server' or missing or unknown parameter
but it does not crash or otherwise misbehave. Exceeding the number of allowed addresses leads to
Options error: --dns server 3: malformed address or maximum exceeded '9.9.9.9'
(good).
Your patch has been applied to the master and release/2.6 branch.
commit 424ae5906388af8769ae448080fa3b7ec266e8d8 (master) commit 3b967e7e05f679203ce26e027fcea5f7b4709eaa (release/2.6)
Author: Heiko Hund Date: Fri Mar 10 06:08:12 2023 +0100
dns option: allow up to eight addresses per server
Signed-off-by: Heiko Hund <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg26386.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering