pax_global_header 0000666 0000000 0000000 00000000064 13470321134 0014510 g ustar 00root root 0000000 0000000 52 comment=49cba47a55d9e5b3c3c8babbdd35bb4274f348a1
update-systemd-resolved-1.3.0/ 0000775 0000000 0000000 00000000000 13470321134 0016302 5 ustar 00root root 0000000 0000000 update-systemd-resolved-1.3.0/.gitignore 0000664 0000000 0000000 00000000035 13470321134 0020270 0 ustar 00root root 0000000 0000000 .*.sw[a-z0-9]
.sw[a-z0-9]
*~
update-systemd-resolved-1.3.0/.travis.yml 0000664 0000000 0000000 00000000147 13470321134 0020415 0 ustar 00root root 0000000 0000000 ---
# Don't need sudo access or to install anything
sudo: false
install: true
script:
- ./run-tests
update-systemd-resolved-1.3.0/CHANGELOG.md 0000664 0000000 0000000 00000016000 13470321134 0020110 0 ustar 00root root 0000000 0000000 # Changelog
## 1.3.0 (2019.05.19)
### NOTES
A number of pull-requests and updates added, fixing some bugs and adding new
features.
### IMPROVEMENTS
- Added support for DNS6 option which can take only IPv6 addresses
(@thecodingrobot)
- Based on some feedback by (@tbaumann), alter the handling of script_type and
dev within the body in the main() function to allow it to work more
effectively between the environment and command-line parameters.
- The DNS caches are now flushed when the script as made the configuration
changes for the link (@Edu4rdSHL)
- Change the handling of DOMAIN to support multiple options, with a change in the
way the values are processed and added to systemd-resolved (@adq)
- Updated the documentation in a number of areas, including a new section
specifically on DNS Leakage, links to the DBus commands, NetworkManager and
DNSSEC issues, and spelling corrections, etc. (Thanks to @bohlstry and
@dannyk81 for the help with a script for NetworkManager)
- Now recommended using the `up-restart` option in the configuration files to
ensure that `update-systemd-resolved` is re-run when the connection only
partially restarts (i.e connection restarts, but not the TUN/TAP device).
### BACKWARDS INCOMPATIBILITIES
- The DOMAIN option now supports multiple calls, and rather than the last
provided version being the primary domain for the link, the first value is the
primary domain, and all subsequent calls are added as the equivalent of
DOMAIN-SEARCH.
## 1.2.7 (2017.11.12)
### NOTES
Following a request by @JoshDobbin, support has been added for passing
`ADAPTER_DOMAIN_SUFFIX` via `dhcp-options` to work with the Microsoft standard.
Also included some additional notes in README.md about using `down` in dropped
privilege situations for clarification.
### IMPROVEMENTS
- Added support for ADAPTER_DOMAIN_SUFFIX (@jonathanio)
- Added notes in README.md about `down` with dropped privileges (@jonathanio)
## 1.2.6 (2017.07.24)
### NOTES
Improvements made to the `logger` command to prevent issues with privilege
dropping under the assistance of @dermarens, @terminalmage, @guruxu, and @benvh.
Updated some documentation for consistency and clarity. Thanks to @flungo and
@dawansv here.
### IMPROVEMENTS
- Updated to include a full list in PATH, including sbin paths. (@jonathanio)
- Updated documentation regarding DNS leakage. (@jonathanio)
- Updated all script locations to be consistent. (@jonathanio)
- Add some installation instructions to README.md. (@flungo)
- Update command-line parameters needed within Makefile/README.md. (@noraj1337)
- Fix script name in command-line path within README.md. (@phR0ze)
## 1.2.5 (2017.03.02)
### IMPROVEMENTS
- Updated to include a full list in PATH, including sbin paths. (@jonathanio)
## 1.2.4 (2017.03.02)
### NOTES
@piotr-dobrogost, @mgu, and @aRkadeFR helped improve the documentation.
### IMPROVEMENTS
- It was noted that the PATH setting used in the documentation doesn't work on
all systems (sorry, my bad), so it has now been updated so it should now work.
(@aRkadeFR)
## 1.2.3 (2016.12.25)
### NOTES
@Nauxuron provided a patch to improve DESTDIR and PREFIX handling in Makefile.
### IMPROVEMENTS
- Improve handling of DESTDIR and PREFIX in the Makefile to follow the GNU
guidelines. (@Nauxuron)
## 1.2.2 (2016.12.13)
### NOTES
This one is a thanks to @mikken and helps support OpenVPN 2.4 as well as fix
an issue with `DNSSEC` handling on the `busctl` call.
### BUG FIXES
- The incorrect usage of `down-pre` which as of OpenVPN 2.4 is now a fatal error
when you pass it an argument (i.e. the script we were originally thought it
should be calling). (@mikken)
- Issues with `busctl` and bash properly handling the "empty string" case to use
the default `DNSSEC` option. (@jonathanio)
- Noise when `busctl` is called on the down case when privileges have been
dropped in the client. (@mikken)
- Added documentation for `allow-downgrade` support in `DNSSEC` option (which
was supported, but not documented). (@jonathanio)
## 1.2.1 (2016.10.06)
### NOTES
Thanks for @arjenschol for spotting this one: An error in the AF_INET value
provided to SetLinkDNS prevented IPv6 DNS servers from being added.
### BUG FIXES
- Fix IPv6 DNS by specifying AF_INET6 value (10) insteadof array size (2)
(@arjenschol)
## 1.2.0 (2016.08.29)
### NOTES
Add support for DNSSEC processing, improve logic around `DOMAIN` and
`DOMAIN-SEARCH` handling, add support for `DOMAIN-ROUTE`, and improve
documentation.
### BACKWARDS INCOMPATIBILITIES
- Due to (probably) an incorrect assumption on my part (@jonathanio) in the
purpose of `DOMAIN-SEARCH` verses `DOMAIN`, domains added via `DOMAIN` were
marked as searchable, and so would be appended to bare domain names, while
those added via `DOMAIN-SEARCH` would not. This was a divergance from how
older OpenVPN handler scripts (such as `update-resolv-conf` and
`update-systemd-network`) processed them (i.e. in all cases they were just
made searchable). Note that both scripts didn't really have the concept of
`domain` in the same way as `/etc/resolv.conf` understood it. This script now
(hopefully) properly handles `DOMAIN` and `DOMAIN-SEARCH` (single of the
former, and is primary, multiple of the latter and secondary).
### FEATURES
- Add support for `DNSSEC` option which allows you to enable or disable (or
leave to system default) the `DNSSEC` setting for any DNS queries made to the
DNS servers provided for this link. (@jonathanio)
- Add support for `DOMAIN-ROUTE` which, through `systemd-resolved`, allows you
to set domain names which should be routed over this link to the DNS servers
provided. (@jonathanio)
### IMPROVEMENTS
- Correct the logic around the handling of `DOMAIN` and `DOMAIN-SEARCH` to be
more compatible with previous versions of these handlers. (@jonathanio)
## 1.1.1 (2016.08.10)
### NOTES
Thanks to the help from @pid1 for this release. The documentation mistakenly
noted to use pre-down for the script now (compared to down originally, which
failed as the tun or tap device would have been removed before the script
ran). However, this should have in fact been down-pre.
### BUG FIXES
- Fix `pre-down` to `down-pre` in the documentation else you'll break your
OpenVPN configuration. (@pid1)
## 1.1.0 (2016.08.08)
### NOTES
Thanks to the work by @BaxterStockman, the script has been refactored, hopefully
making it easier to read and follow, while additional tests around IPv6
processing have been added.
### IMPROVEMENTS
- Refactor the codebase to make it easier to read and expand. (@BaxterStockman)
- Improve run-tests so multiple tests can be run within a file, and can expect
failures within a test. (@BaxterStockman)
- Add tests for invalid IPv6 addresses. (@BaxterStockman)
## 1.0.0 (2016.06.23)
### NOTES
First release of `update-systemd-resolved`. Should fully support the three
standard DHCP options in OpenVPN (`DNS`, `DOMAIN`, and `DOMAIN-SEARCH`) with
integration tests around the code to manage and monitor regressions. Also
supports multiple (and combined) IPv4 and IPv6 DNS addresses.
update-systemd-resolved-1.3.0/LICENSE 0000664 0000000 0000000 00000001144 13470321134 0017307 0 ustar 00root root 0000000 0000000 This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
update-systemd-resolved-1.3.0/Makefile 0000664 0000000 0000000 00000002067 13470321134 0017747 0 ustar 00root root 0000000 0000000 PREFIX ?= /etc/openvpn/scripts
SRC = update-systemd-resolved
DEST = $(DESTDIR)$(PREFIX)/$(SRC)
.PHONY: all install info
all: install info
install:
@install -Dm750 $(SRC) $(DEST)
@install -Dm644 $(SRC).conf $(DEST).conf
info:
@printf 'Successfully installed %s to %s.\n' $(SRC) $(DEST)
@echo
@echo 'Now would be a good time to update /etc/nsswitch.conf:'
@echo
@echo ' # Use systemd-resolved first, then fall back to /etc/resolv.conf'
@echo ' hosts: files resolve dns myhostname'
@echo ' # Use /etc/resolv.conf first, then fall back to systemd-resolved'
@echo ' hosts: files dns resolve myhostname'
@echo
@echo 'You should also update your OpenVPN configuration:'
@echo
@printf ' setenv PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\n'
@echo ' script-security 2'
@printf ' up %s\n' $(DEST)
@echo ' up-restart'
@printf ' down %s\n' $(DEST)
@echo ' down-pre'
@echo
@printf 'or pass --config %s.conf\n' $(DEST)
@echo 'in addition to any other --config arguments to your openvpn command.'
test:
@./run-tests
update-systemd-resolved-1.3.0/README.md 0000664 0000000 0000000 00000035760 13470321134 0017574 0 ustar 00root root 0000000 0000000 # update-systemd-resolved
[](https://travis-ci.org/jonathanio/update-systemd-resolved)
This is a helper script designed to integrate OpenVPN with the
`systemd-resolved` service via DBus instead of trying to override
`/etc/resolv.conf`, or manipulate `systemd-networkd` configuration files.
Since systemd-229, the `systemd-resolved` service has an API available via DBus
which allows directly setting the DNS configuration for a link. This script
makes use of `busctl` from systemd to send DBus messages to `systemd-resolved`
to update the DNS for the link created by OpenVPN.
*NOTE*: This is a beta script. So long as you're using OpenVPN 2.1 or greater,
iproute2, and have at least version 229 of systemd, then it should work.
Nonetheless, if you do come across problems, fork and fix, or raise an issue.
All are most welcome.
## Installation
[aur]:https://aur.archlinux.org/packages/openvpn-update-systemd-resolved/
If you are using a distribution of Linux with uses the Arch User Repository, the
simplest way to install is by using the [openvpn-update-systemd-resolved][aur]
AUR package as this will take care of any updates through your package manager.
Alternatively, the package can be manually installed by running the following:
```bash
git clone https://github.com/jonathanio/update-systemd-resolved.git
cd update-systemd-resolved
make
```
## How to Enable
Make sure that you have `systemd-resolved` enabled and running. First, make sure
that `systemd-resolved.service` is enabled and started:
```bash
systemctl enable systemd-resolved.service
systemctl start systemd-resolved.service
```
Next, you can either configure the system libraries to talk to it using NSS, or
you can override the `resolv.conf` file to use `systemd-resolved` as a stub
resolver (or both):
### NSS and nssswitch.conf
Update your `/etc/nsswitch.conf` file to look up DNS via the `resolve` service
(you may need to install the NSS library which connects libnss to
`systemd-resolved`):
```conf
# Use /etc/resolv.conf first, then fall back to systemd-resolved
hosts: files dns resolve myhostname
# Use systemd-resolved first, then fall back to /etc/resolv.conf
hosts: files resolve dns myhostname
# Don't use /etc/resolv.conf at all
hosts: files resolve myhostname
```
The changes will be applied as soon as the file is saved.
### Stub Resolver
The `systemd-resolved` service (since systemd-231) also listens on `127.0.0.53`
via the `lo` interface, providing a stub resolver which any client can call to
request DNS, whether or not it uses the system libraries to resolve DNS, and
you no longer have to worry about trying to manage your `/etc/resolv.conf`
file. This set up can be installed by linking to `stub-resolv.conf`:
```bash
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
```
### Usage and Ubuntu and Fedora
#### Ubuntu
[LP1685045]:https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1685045
The NSS interface for `systemd-resolved` may be deprecated and has
already been flagged for deprecation in Ubuntu (see [LP#1685045][LP1685045] for
details). In this case, you should use the Stub Resolver method now.
#### Fedora
[authselect]:https://github.com/pbrezina/authselect
Fedora 28 makes use of `authselect` to manage the NSS settings on the system.
Directly editing `nsswitch.conf` is not recommended as it may be overwritten at
any time if `authselect` is run. Proper overrides may not yet be possible - see
[pbrezina/authselect][authselect] for details. However, like Ubuntu, the [Stub
Resolver](#stub-resolver) method is recommended here too.
### OpenVPN Configuration
Finally, update your OpenVPN configuration file and set the `up` and `down`
options to point to the script, and `down-pre` to ensure that the script is run
before the device is closed:
```conf
script-security 2
setenv PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
up /etc/openvpn/scripts/update-systemd-resolved
up-restart
down /etc/openvpn/scripts/update-systemd-resolved
down-pre
```
#### up-restart
It is recommended to use `up-restart` in your configuration to ensure that
`upate-systemd-resolved` is run on restarts - where the connection is
re-established but the TUN/TAP device remained open (for example, where the
original connection has timed out and `persist-tun` is enabled). If you do not
have `persist-tun` set, or you use `ping-exit` instead of `ping-timeout`, you
most likely will not need this.
#### down/pre-down with user/group
The `down` and `down-pre` options here will not work as expected where the
`openvpn` daemon drops privileges after establishing the connection (i.e. when
using the `user` and `group` options). This is because only the `root` user
will have the privileges required to talk to `systemd-resolved.service` over
DBus. The `openvpn-plugin-down-root.so` plug-in does provide support for
enabling the `down` script to be run as the `root` user, but this has been
known to be unreliable.
Ultimately this shouldn't affect normal operation as `systemd-resolved.service`
will remove all settings associated with the link (and therefore naturally
update `/etc/resolv.conf`, if you have it symlinked) when the TUN or TAP device
is closed. The option for `down` and `down-pre` just make this step explicit
before the device is torn down rather than implicit on the change in
environment.
### Command Line Settings
Alternatively if you don't want to edit your client configuration, you can add
the following options to your `openvpn` command:
```bash
openvpn \
--script-security 2 \
--setenv PATH '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' \
--up /etc/openvpn/scripts/update-systemd-resolved --up-restart \
--down /etc/openvpn/scripts/update-systemd-resolved --down-pre
```
Or, you can add the following argument to the command-line arguments of
`openvpn`, which will use the `update-systemd-resolve.conf` file instead:
```bash
openvpn \
--config /etc/openvpn/scripts/update-systemd-resolved.conf
```
## Usage
`update-systemd-resolved` works by processing the `dhcp-option` commands set in
OpenVPN, either through the server, or the client, configuration:
[resolved]:https://www.freedesktop.org/wiki/Software/systemd/resolved/
| Option | Examples | Notes | DBus Call |
|--:|---|---|---|
| `DNS` | `0.0.0.0`
`::1` | This sets the DNS servers for the link and can take any IPv4 or IPv6 address. | [SetLinkDNS][resolved] |
| `DNS6` | `::1` | This sets the DNS servers for the link and can take only IPv6 addresses. | [SetLinkDNS][resolved] |
| `DOMAIN` or `ADAPTER_DOMAIN_SUFFIX` | `example.com` | The primary domain for this host. If set multiple times, the first provided is used as the primary search domain for bare hostnames. Any subsequent `DOMAIN` options will be added as the equivalent of `DOMAIN-SEARCH` options. All requests for this domain as well will be routed to the `DNS` servers provided on this link. | [SetLinkDomains][resolved] |
| `DOMAIN-SEARCH` | `example.com` | Secondary domains which will be used to search for bare hostnames (after any `DOMAIN`, if set) and in the order provided. All requests for this domain will be routed to the `DNS` servers provided on this link. | [SetLinkDomains][resolved] |
| `DOMAIN-ROUTE` | `example.com` | All requests for these domains will be routed to the `DNS` servers provided on this link. They will *not* be used to search for bare hostnames, only routed. A `DOMAIN-ROUTE` option for `.` (single period) will instruct `systemd-resolved` to route the entire DNS name-space through to the `DNS` servers configured for this connection (unless a more specific route has been offered by another connection for a selected name/name-space). This is useful if you wish to prevent [DNS leakage](#dns-leakage). | [SetLinkDomains][resolved] |
| `DNSSEC` | `yes``default` | Control of DNSSEC should be enabled (`yes`) or disabled (`no`), or `allow-downgrade` to switch off DNSSEC only if the server doesn't support it, for any queries over this link only, or use the system default (`default`). | [SetLinkDNSSEC][resolved] |
**Note**: There are no local or system options to be configured. All configuration
for this script is handled through OpenVPN, including, for example, the name of
the interface to be configured.
### Example
```conf
push "dhcp-option DNS 10.62.3.2"
push "dhcp-option DNS 10.62.3.3"
push "dhcp-option DNS6 2001:db8::a3:c15c:b56e:619a"
push "dhcp-option DNS6 2001:db8::a3:ffec:f61c:2e06"
push "dhcp-option DOMAIN example.office"
push "dhcp-option DOMAIN example.lan"
push "dhcp-option DOMAIN-SEARCH example.com"
push "dhcp-option DOMAIN-ROUTE example.net"
push "dhcp-option DOMAIN-ROUTE example.org"
push "dhcp-option DNSSEC yes"
```
This, added to the OpenVPN server's configuration file will set two IPv4 DNS
servers and two IPv6 and will set the primary domain for the link to be
`example.office`. Therefore if you try to look up the bare address `mail` then
`mail.example.office` will be attempted first. The domains `example.lan` and
`example.com` are also added as an additional search domain, so if
`mail.example.office` fails, then `mail.example.lan` will be tried next,
followed by `mail.example.com`.
Requests for `example.net` and `example.org` will also be routed through to the
four DNS servers listed, but they will *not* be appended (i.e.
`mail.example.net` will not be attempted, nor `mail.example.org`, if
`mail.example.office` or `mail.example.com` do not exist).
Finally, DNSSEC has been enabled for this link (and this link only).
## DNS Leakage
DNS Leakage is something to be careful of when using any VPN or untrusted
network, and it can heavily depend on how you configure your normal DNS
settings as well as how you configure the DNS on your VPN connection.
By default, `systemd-resolved` will send **all** DNS queries to at least one
DNS server on **every** link configured with DNS servers. The first to reply
back with a valid query is the one returned to the client, and the last to
return back a failure (assuming all other queries also failed) will also be
returned to the client.
The changes in this handling come in when you start using the `DOMAIN`,
`DOMAIN-SEARCH` and `DOMAIN-ROUTE` options. The three differ in how domains
are treated for searching bare domains, but all three work exactly the same
when it comes to how it routes domains to specific DNS servers.
Any domain added using `DOMAIN`, `DOMAIN-SEARCH`, or `DOMAIN-ROUTE` will be
added explicitly to the VPN link and therefore any queries for domain suffixes
which match these will be routed through this link, and only this link. Any
other domains which do not match these will revert back to distributing the
queries across all links.
There are two ways to override this:
### Preventing Leakage in on untrusted networks
If you want to prevent DNS queries leaking over untrusted networks (for
example, over public WiFi hotspots), then you need to tell `systemd-resolved`
to send **all** DNS queries over the VPN link. To do this, add the following to
your server or client VPN configurations respectively:
```
# Server Configuration
push "dhcp-option DOMAIN-ROUTE ."
```
```
# Client Configuration
dhcp-option DOMAIN-ROUTE .
```
All DNS queries (which do not match a more explicit entry on another link) will
now be routed over the VPN only.
### Preventing Leakage to Corporate networks
In an alternate situation, you may want to have DNS queries specifically routed
over the VPN for corporate or private network access, but you don't want your
general DNS queries to be visible to anyone who has access to the logs of the
corporate DNS servers.
This option cannot be directly managed by `update-systemd-resolved` as you need
to configure the network settings of other links to send all queries by default
to your nominated DNS server (e.g. over `ens0` or `wlp2s0` for your Ethernet or
Wireless network cards). This needs to be configured under the `[Network]`
section of your `.network` file for your interface in `/etc/systemd/network`.
For example:
```
[Network]
DHCP=yes
DNS=8.8.8.8
DNS=8.8.4.4
Domains=.
```
When you connect, all domains except those explicitly listed using the `DOMAIN`,
`DOMAIN-SEARCH`, or `DOMAIN-ROUTE` options of your VPN link will be sent to the
DNS server of your nominated link.
### Concurrent Configuration
Note that these two options are mutually exclusive, as if you establish a VPN
link with `DOMAIN-ROUTE` set to `.` while you have also configured it inside a
`.network` file via `systemd-networkd`, then you will have two links
responsible for routing all queries, and so both links will get all requests.
How to manage the DNS settings of other links while the VPN is operational is
outside the scope of this script at this time.
## Known Issues
There are a number of known issues relating to some third-party servers and
services:
### NetworkManager
LP1671606:https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1671606
LP1688018:https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1688018
There is currently a regression with versions of NetworkManager 1.2.6 or later
(see [LP#1671606][LP1671606] and [LP#1688018][LP1688018]) which means that it
will automatically set all normal network interfaces with `~.` for DNS routing.
This means that even if you set `dhcp-option DOMAIN-ROUTE .` for your VPN
connection, you will still leak DNS queries over potentially insecure networks.
issue-59:https://github.com/jonathanio/update-systemd-resolved/issues/59
If you are concerned by potentially leaking DNS on systems which use
NetworkManager, you may need to configure an [additional script][issue-59]
into NetworkManager which change the domain routing settings on all non-VPN
interfaces.
### DNSSEC Issues
```shell
$ systemd-resolve eu-central-1.console.aws.amazon.com
eu-central-1.console.aws.amazon.com: resolve call failed: DNSSEC validation failed: no-signature
# or
$ systemd-resolve eu-central-1.console.aws.amazon.com
eu-central-1.console.aws.amazon.com: resolve call failed: DNSSEC validation failed: incompatible-server
```
If you are seeing failed queries in your logs due to DNSSEC issues, support may be
partially or fully enabled and you are now working with a server which does not
support this extension. You may therefore need to set `DNSSEC` to `no` (or
maybe just `allow-downgrade`) in your VPN configuration.
```
dhcp-option DNSSEC allow-downgrade
```
## How to help
If you can help with any of these areas, or have bug fixes, please fork and
raise a Pull Request for me.
I have built a basic test framework around the script which can be used to
monitor and validate the calls made by the script based on the environment
variables available to it at run-time. Please add a test for any new features
you may wish to add, or update any which are wrong, and test your code by
running `./run-tests` from the root of the repository. There are no dependencies
on `run-tests` - it runs 100% bash and doesn't call out to any other program or
language.
TravisCI is enabled on this repository: Click the link at the top of this README
to see the current state of the code and its tests.
## Licence
GPL
## Author
Jonathan Wright
update-systemd-resolved-1.3.0/run-tests 0000775 0000000 0000000 00000012213 13470321134 0020173 0 ustar 00root root 0000000 0000000 #!/bin/bash
#
# Test Framework for update-systemd-resolved.
# Copyright (C) 2016, Jonathan Wright
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Set colour escape sequences
RED='\033[0;31m'
YELLOW='\033[1;33m'
ORANGE='\033[0;33m'
GREEN='\033[0;32m'
DARK='\033[1;30m'
RESET='\033[0m'
# Set Pass/Fail signatures
PASS="✓"
FAIL="✗"
# Counters
COUNT_PASS=0
COUNT_FAIL=0
# Flag for determining whether a test script called the `runtest' function
RUNTEST_CALLED=0
AUTOMATED_TESTING=1
function busctl {
shift 4
_log "busctl called with: ${@}"
# Set that busctl has been called
busctl_called=1
case "${1}" in
SetLinkDNS)
shift 2
if [[ "${TEST_BUSCTL_DNS}" == "" ]]; then
[[ "${ip_ifindex} ${TEST_BUSCTL_DNS}" == "${@}" ]] || \
_fail "SetLinkDNS was called and should not be: '${@}'"
else
[[ "${ip_ifindex} ${TEST_BUSCTL_DNS}" == "${@}" ]] && \
_pass "SetLinkDNS was called correctly" || \
_fail "SetLinkDNS was not given the correct arguments:\n" \
" Expected: '${ip_ifindex} ${TEST_BUSCTL_DNS}'\n" \
" Received: '${@}'"
fi
;;
SetLinkDomains)
shift 2
if [[ "${TEST_BUSCTL_DOMAINS}" == "" ]]; then
[[ "${ip_ifindex} ${TEST_BUSCTL_DOMAINS}" == "${@}" ]] || \
_fail "SetLinkDomains was called and should not be: '${@}'"
else
[[ "${ip_ifindex} ${TEST_BUSCTL_DOMAINS}" == "${@}" ]] && \
_pass "SetLinkDomains was called correctly" || \
_fail "SetLinkDomains was not given the correct arguments:\n" \
" Expected: '${ip_ifindex} ${TEST_BUSCTL_DOMAINS}'\n" \
" Received: '${@}'"
fi
;;
SetLinkDNSSEC)
shift 2
[[ "${ip_ifindex} ${TEST_BUSCTL_DNSSEC}x" == "${@}x" ]] && \
_pass "SetLinkDNSSEC was called correctly" || \
_fail "SetLinkDNSSEC was not given the correct arguments:\n" \
" Expected: '${ip_ifindex} ${TEST_BUSCTL_DNSSEC}'\n" \
" Received: '${@}'"
;;
*)
_fail "Unknown command called on busctl: ${1}"
;;
esac
}
function ip {
_log "ip called with: ${@}"
[[ "${1} ${2} ${3} ${4}" == "link show dev ${dev}" ]] && \
_pass "ip was called correctly" || \
_fail "ip was called with incorrect or unknown arguments"
# Return fake ip statement
echo -e "${ip_ifindex}: ${dev}: " \
" mtu 1500 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen" \
" 100\n link/none"
}
function systemd-resolve {
_log "systemd-resolve called with: ${@}"
}
function logger {
# Remove standard options
local message="$*"
_log "-- ${message##* -- }"
}
function exit {
# Override
_log "exit called with status ${1}"
}
function _log {
( >&2 echo -e " ${DARK}${@}${RESET}" )
}
function _pass {
COUNT_PASS=$((COUNT_PASS+1))
( >&2 echo -e " ${GREEN}${PASS}${RESET} ${@}" )
}
function _fail {
COUNT_FAIL=$((COUNT_FAIL+1))
( >&2 echo -e " ${RED}${FAIL} ${@}${RESET}" )
}
function runtest {
# Increment counter so that we don't double-execute if a test script calls
# this function.
: ${RUNTEST_CALLED:=0}
(( RUNTEST_CALLED += 1 ))
echo -e "${GREEN}- Testing ${TEST_TITLE:-a nameless test}${RESET}"
# Source, don't run, so we don't need to export and internal functions override
# external calls out to system commands
source update-systemd-resolved
exit_status="$?"
exit_message="script exited with a ${exit_status} exit status"
if [[ "$(( exit_status > 0 ))" == "${EXPECT_FAILURE:-0}" ]]; then
_pass "$exit_message"
else
_fail "$exit_message"
fi
if [[ ${TEST_BUSCTL_CALLED} -eq 0 ]]; then
[[ ${busctl_called} -eq 0 ]] && \
_pass "busctl was not called, as expected" || \
_fail "busctl was called, not expected"
else
[[ ${busctl_called} -eq 0 ]] && \
_fail "busctl was not called, not expected"
fi
echo
}
echo "update-systemd-resolved Test Suite"
echo
for TEST in tests/*.sh; do
# Set/Reset loop variables
RUNTEST_CALLED=0
EXPECT_FAILURE=0
busctl_called=0
# Set/Reset expected results
TEST_BUSCTL_DNS=""
TEST_BUSCTL_DOMAINS=""
TEST_BUSCTL_DNSSEC=""
# Keep this random, as we will never know the ifindex up-front
ip_ifindex=$((RANDOM%=64))
# Clear foreign_option_*
foreign_option_1=""
foreign_option_2=""
foreign_option_3=""
foreign_option_4=""
foreign_option_5=""
foreign_option_6=""
# Import the test configuration
source "${TEST}"
(( RUNTEST_CALLED > 0 )) || runtest
done
echo -e " ${GREEN}${PASS} ${COUNT_PASS} Passed${RESET}"
echo -e " ${RED}${FAIL} ${COUNT_FAIL} Failed${RESET}"
# Make sure we fail if there are failed tests
[[ ${COUNT_FAIL} -eq 0 ]]
update-systemd-resolved-1.3.0/tests/ 0000775 0000000 0000000 00000000000 13470321134 0017444 5 ustar 00root root 0000000 0000000 update-systemd-resolved-1.3.0/tests/01_no_updates.sh 0000664 0000000 0000000 00000000151 13470321134 0022436 0 ustar 00root root 0000000 0000000 # Emulate OpenVPN environment
script_type="up"
dev="tun01"
TEST_TITLE="No Updates"
TEST_BUSCTL_CALLED=0
update-systemd-resolved-1.3.0/tests/02_single_ipv4_dns.sh 0000664 0000000 0000000 00000000246 13470321134 0023372 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun02"
foreign_option_1="dhcp-option DNS 1.23.4.56"
TEST_TITLE="Single IPv4 DNS Server"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="1 2 4 1 23 4 56"
update-systemd-resolved-1.3.0/tests/03a_multiple_ipv4_dns_1.sh 0000664 0000000 0000000 00000000353 13470321134 0024325 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun03"
foreign_option_1="dhcp-option DNS 1.23.4.56"
foreign_option_2="dhcp-option DNS 5.6.7.89"
TEST_TITLE="Multiple IPv4 DNS Servers (Part 1)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="2 2 4 1 23 4 56 2 4 5 6 7 89"
update-systemd-resolved-1.3.0/tests/03b_multiple_ipv4_dns_2.sh 0000664 0000000 0000000 00000000446 13470321134 0024332 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun03"
foreign_option_1="dhcp-option DNS 1.23.4.56"
foreign_option_2="dhcp-option DNS 5.6.7.89"
foreign_option_3="dhcp-option DNS 34.5.67.8"
TEST_TITLE="Multiple IPv4 DNS Servers (Part 2)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="3 2 4 1 23 4 56 2 4 5 6 7 89 2 4 34 5 67 8"
update-systemd-resolved-1.3.0/tests/04a_single_dns_domain.sh 0000664 0000000 0000000 00000000256 13470321134 0024123 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun04"
foreign_option_1="dhcp-option DOMAIN example.com"
TEST_TITLE="Single DNS Domain"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="1 example.com false"
update-systemd-resolved-1.3.0/tests/04b_multiple_dns_domains.sh 0000664 0000000 0000000 00000000363 13470321134 0024660 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun04"
foreign_option_1="dhcp-option DOMAIN example.com"
foreign_option_2="dhcp-option DOMAIN example.co"
TEST_TITLE="Multiple DNS Domains"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="2 example.com false example.co false"
update-systemd-resolved-1.3.0/tests/05a_dns_domain_and_search_1.sh 0000664 0000000 0000000 00000000413 13470321134 0025145 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun05"
foreign_option_1="dhcp-option DOMAIN example.com"
foreign_option_2="dhcp-option DOMAIN-SEARCH example.org"
TEST_TITLE="DNS Single Domain and Single Search"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="2 example.com false example.org false"
update-systemd-resolved-1.3.0/tests/05b_dns_domain_and_search_2.sh 0000664 0000000 0000000 00000000524 13470321134 0025152 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun05"
foreign_option_1="dhcp-option DOMAIN example.com"
foreign_option_2="dhcp-option DOMAIN-SEARCH example.org"
foreign_option_3="dhcp-option DOMAIN-SEARCH example.net"
TEST_TITLE="DNS Single Domain and Dual Search"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="3 example.com false example.org false example.net false"
update-systemd-resolved-1.3.0/tests/05c_dns_domain_and_search_3.sh 0000664 0000000 0000000 00000000547 13470321134 0025161 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun05"
foreign_option_1="dhcp-option DOMAIN-SEARCH example.org"
foreign_option_2="dhcp-option DOMAIN example.com"
foreign_option_3="dhcp-option DOMAIN-SEARCH example.net"
TEST_TITLE="DNS Single Domain and Dual Search (with Order Check)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="3 example.com false example.org false example.net false"
update-systemd-resolved-1.3.0/tests/05d_dns_domain_and_search_4.sh 0000664 0000000 0000000 00000000647 13470321134 0025164 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun05"
foreign_option_1="dhcp-option DOMAIN-SEARCH example.org"
foreign_option_2="dhcp-option DOMAIN example.co"
foreign_option_3="dhcp-option DOMAIN example.com"
foreign_option_4="dhcp-option DOMAIN-SEARCH example.net"
TEST_TITLE="DNS Dual Domain and Dual Search (with Order Check)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="4 example.co false example.org false example.com false example.net false"
update-systemd-resolved-1.3.0/tests/05e_dns_domain_alternate.sh 0000664 0000000 0000000 00000000322 13470321134 0024620 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun05"
foreign_option_1="dhcp-option ADAPTER_DOMAIN_SUFFIX example.org"
TEST_TITLE="DNS Doamin using ADAPTER_DOMAIN_SUFFIX"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="1 example.org false"
update-systemd-resolved-1.3.0/tests/06a_single_domain_route.sh 0000664 0000000 0000000 00000000262 13470321134 0024474 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun06"
foreign_option_1="dhcp-option DOMAIN-ROUTE example.com"
TEST_TITLE="Single DNS Route"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="1 example.com true"
update-systemd-resolved-1.3.0/tests/06b_multiple_domain_routes.sh 0000664 0000000 0000000 00000000506 13470321134 0025233 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun06"
foreign_option_1="dhcp-option DOMAIN-ROUTE example.com"
foreign_option_2="dhcp-option DOMAIN-ROUTE example.co"
foreign_option_3="dhcp-option DOMAIN-ROUTE example.co.uk"
TEST_TITLE="Single DNS Route"
TEST_BUSCTL_DOMAINS="3 example.com true example.co true example.co.uk true"
TEST_BUSCTL_CALLED=1
update-systemd-resolved-1.3.0/tests/07a_dns_domain_search_and_route_1.sh 0000664 0000000 0000000 00000000654 13470321134 0026374 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun07"
foreign_option_1="dhcp-option DOMAIN example.com"
foreign_option_2="dhcp-option DOMAIN-SEARCH example.org"
foreign_option_3="dhcp-option DOMAIN-SEARCH example.co.uk"
foreign_option_4="dhcp-option DOMAIN-ROUTE example.net"
TEST_TITLE="DNS Single Domain, Dual Search, Single Route"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="4 example.com false example.org false example.co.uk false example.net true"
update-systemd-resolved-1.3.0/tests/07b_dns_domain_search_and_route_2.sh 0000664 0000000 0000000 00000001114 13470321134 0026366 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun07"
foreign_option_1="dhcp-option DOMAIN example.com"
foreign_option_2="dhcp-option DOMAIN-SEARCH example.org"
foreign_option_3="dhcp-option DOMAIN-ROUTE example.net"
foreign_option_4="dhcp-option DOMAIN-SEARCH example.co.uk"
foreign_option_5="dhcp-option DOMAIN example.co"
foreign_option_6="dhcp-option DOMAIN-ROUTE example.uk.com"
TEST_TITLE="DNS Dual Domain, Dual Search, Dual Route (with Order Check)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="6 example.com false example.org false example.co.uk false example.co false example.net true example.uk.com true"
update-systemd-resolved-1.3.0/tests/08a_dns_ipv4_and_domain.sh 0000664 0000000 0000000 00000000502 13470321134 0024344 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun08"
foreign_option_1="dhcp-option DNS 1.23.4.56"
foreign_option_2="dhcp-option DNS 2.34.56.7"
foreign_option_3="dhcp-option DOMAIN example.com"
TEST_TITLE="DNS IPv4 Servers and Domain"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="2 2 4 1 23 4 56 2 4 2 34 56 7"
TEST_BUSCTL_DOMAINS="1 example.com false"
update-systemd-resolved-1.3.0/tests/08b_dns_ipv4_domain_and_search.sh 0000664 0000000 0000000 00000000743 13470321134 0025701 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun08"
foreign_option_1="dhcp-option DNS 1.23.4.56"
foreign_option_2="dhcp-option DNS 2.34.5.67"
foreign_option_3="dhcp-option DOMAIN example.co.uk"
foreign_option_4="dhcp-option DOMAIN-SEARCH example.co"
foreign_option_5="dhcp-option DOMAIN-SEARCH example.com"
TEST_TITLE="DNS IPv4 Servers, Domain, and Search"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="2 2 4 1 23 4 56 2 4 2 34 5 67"
TEST_BUSCTL_DOMAINS="3 example.co.uk false example.co false example.com false"
update-systemd-resolved-1.3.0/tests/08b_dns_ipv4_domain_search_and_route.sh 0000664 0000000 0000000 00000000750 13470321134 0027115 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun08"
foreign_option_1="dhcp-option DNS 1.23.4.56"
foreign_option_2="dhcp-option DNS 2.34.5.67"
foreign_option_3="dhcp-option DOMAIN example.co.uk"
foreign_option_4="dhcp-option DOMAIN-SEARCH example.co"
foreign_option_5="dhcp-option DOMAIN-ROUTE example.com"
TEST_TITLE="DNS IPv4 Servers, Domain, Search, and Route"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="2 2 4 1 23 4 56 2 4 2 34 5 67"
TEST_BUSCTL_DOMAINS="3 example.co.uk false example.co false example.com true"
update-systemd-resolved-1.3.0/tests/10_single_ipv6_dns_full.sh 0000664 0000000 0000000 00000000374 13470321134 0024417 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun10"
foreign_option_1="dhcp-option DNS 1234:5678:90ab:cdef:4321:8765:ba09:fedc"
TEST_TITLE="Single IPv6 DNS Server (Full)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="1 10 16 18 52 86 120 144 171 205 239 67 33 135 101 186 9 254 220"
update-systemd-resolved-1.3.0/tests/11_single_ipv6_dns_simple.sh 0000664 0000000 0000000 00000000363 13470321134 0024745 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun11"
foreign_option_1="dhcp-option DNS 1234:567:89:0:ab:cde:f123:4567"
TEST_TITLE="Single IPv6 DNS Server (Full, Simple)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="1 10 16 18 52 5 103 0 137 0 0 0 171 12 222 241 35 69 103"
update-systemd-resolved-1.3.0/tests/12_single_ipv6_dns_compact_1.sh 0000664 0000000 0000000 00000000367 13470321134 0025327 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun12"
foreign_option_1="dhcp-option DNS 1234:567:89:0:ab:cde:f123:4567"
TEST_TITLE="Single IPv6 DNS Server (Compact) (Part 1)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="1 10 16 18 52 5 103 0 137 0 0 0 171 12 222 241 35 69 103"
update-systemd-resolved-1.3.0/tests/13_single_ipv6_dns_compact_2.sh 0000664 0000000 0000000 00000000350 13470321134 0025321 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun13"
foreign_option_1="dhcp-option DNS 1234:567:89::ab:cdef"
TEST_TITLE="Single IPv6 DNS Server (Compact) (Part 2)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="1 10 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239"
update-systemd-resolved-1.3.0/tests/14_single_ipv6_dns_compact_3.sh 0000664 0000000 0000000 00000000322 13470321134 0025322 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun14"
foreign_option_1="dhcp-option DNS 20a0::1"
TEST_TITLE="Single IPv6 DNS Server (Compact) (Part 3)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="1 10 16 32 160 0 0 0 0 0 0 0 0 0 0 0 0 0 1"
update-systemd-resolved-1.3.0/tests/15_single_ipv6_dns_localhost.sh 0000664 0000000 0000000 00000000304 13470321134 0025443 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun15"
foreign_option_1="dhcp-option DNS ::1"
TEST_TITLE="Single IPv6 DNS Server (Localhost)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="1 10 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1"
update-systemd-resolved-1.3.0/tests/16_dual_ipv6_single_ipv4.sh 0000664 0000000 0000000 00000000441 13470321134 0024501 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun16"
foreign_option_1="dhcp-option DNS 1234:567:89::ab:cdef"
foreign_option_2="dhcp-option DNS 1.23.4.56"
TEST_TITLE="Single IPv6 and Single IPv4 DNS Servers"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="2 10 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239 2 4 1 23 4 56"
update-systemd-resolved-1.3.0/tests/16a_dual_ipv6_single_ipv4.sh 0000664 0000000 0000000 00000000451 13470321134 0024643 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun16"
foreign_option_1="dhcp-option DNS6 1234:567:89::ab:cdef"
foreign_option_2="dhcp-option DNS 1.23.4.56"
TEST_TITLE="Single IPv6 and Single IPv4 DNS Servers (DNS6)"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="2 10 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239 2 4 1 23 4 56"
update-systemd-resolved-1.3.0/tests/17_single_ipv6_single_ipv4.sh 0000664 0000000 0000000 00000000565 13470321134 0025045 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun17"
foreign_option_1="dhcp-option DNS 1234:567:89::ab:cdef"
foreign_option_2="dhcp-option DNS 1.23.4.56"
foreign_option_3="dhcp-option DNS 20a0::1"
TEST_TITLE="Single IPv6 and Single IPv4 DNS Servers"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="3 10 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239 2 4 1 23 4 56 10 16 32 160 0 0 0 0 0 0 0 0 0 0 0 0 0 1"
update-systemd-resolved-1.3.0/tests/18_dns_ipv4_ipv6_domain_and_search.sh 0000664 0000000 0000000 00000001165 13470321134 0026503 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun18"
foreign_option_1="dhcp-option DNS 1.23.4.56"
foreign_option_2="dhcp-option DNS 2.34.56.7"
foreign_option_3="dhcp-option DNS 1234:567:89::ab:cdef"
foreign_option_4="dhcp-option DNS 1234:567:89::ba:cdef"
foreign_option_5="dhcp-option DOMAIN example.com"
foreign_option_6="dhcp-option DOMAIN-SEARCH example.co"
TEST_TITLE="DNS IPv4 and IPv6 Servers, plus Domain and Search"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DNS="4 2 4 1 23 4 56 2 4 2 34 56 7 10 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239 10 16 18 52 5 103 0 137 0 0 0 0 0 0 0 186 205 239"
TEST_BUSCTL_DOMAINS="2 example.com false example.co false"
update-systemd-resolved-1.3.0/tests/19_dns_invalid_ipv6.sh 0000664 0000000 0000000 00000001250 13470321134 0023545 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun19"
# busctl should not be called for any test in here
TEST_BUSCTL_CALLED=0
# update-systemd-resolved should exit nonzero for all tests
EXPECT_FAILURE=1
declare -A test_attrs=(
["has more than one \`::'"]='1234::567::89:ab'
['too long']='1234:567:89:a:b:c:d:e:f'
['single 0 shortened']='1234::567:89:ab:c:de:f'
['zero-run in wrong location']='1234:0:0:567:89::ab'
['compressed run not longest zero-run']='1234:0:0:0:567::89'
['not maximally compressed']='2001:db8::0:1'
)
for test_title in "${!test_attrs[@]}"; do
TEST_TITLE="DNS IPv6 address $test_title"
foreign_option_1="dhcp-option DNS ${test_attrs["$test_title"]}"
runtest
done
update-systemd-resolved-1.3.0/tests/20_dnssec_only.sh 0000664 0000000 0000000 00000000755 13470321134 0022630 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun20"
TEST_BUSCTL_CALLED=1
declare -A test_options=(
['default']=''
['Default']=''
['true']='yes'
['True']='yes'
['yes']='yes'
['Yes']='yes'
['false']='no'
['False']='no'
['no']='no'
['No']='no'
['allow-downgrade']='allow-downgrade'
)
for test_option in "${!test_options[@]}"; do
TEST_TITLE="DNSSEC Set to $test_option"
TEST_BUSCTL_DNSSEC="${test_options["$test_option"]}"
foreign_option_1="dhcp-option DNSSEC $test_option"
runtest
done
update-systemd-resolved-1.3.0/tests/21_dnssec_invalid_options.sh 0000664 0000000 0000000 00000000430 13470321134 0025037 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun21"
TEST_BUSCTL_CALLED=0
EXPECT_FAILURE=1
declare -a test_invalids=(
'1'
'0'
'DOWNGRADE'
)
for test_option in "${test_invalids[@]}"; do
TEST_TITLE="DNSSEC Set to $test_option"
foreign_option_1="dhcp-option DNSSEC $test_option"
runtest
done
update-systemd-resolved-1.3.0/tests/22_dns_dnssec_domain_and_search.sh 0000664 0000000 0000000 00000001123 13470321134 0026121 0 ustar 00root root 0000000 0000000 script_type="up"
dev="tun22"
foreign_option_1="dhcp-option DNS 1.23.4.56"
foreign_option_2="dhcp-option DNS 1234:567:89::ab:cdef"
foreign_option_3="dhcp-option DOMAIN example.com"
foreign_option_4="dhcp-option DOMAIN-SEARCH example.org"
foreign_option_5="dhcp-option DOMAIN-ROUTE example.net"
foreign_option_6="dhcp-option DNSSEC yes"
TEST_TITLE="DNS, DNSSEC, Domain, Search, and Route"
TEST_BUSCTL_CALLED=1
TEST_BUSCTL_DOMAINS="3 example.com false example.org false example.net true"
TEST_BUSCTL_DNSSEC="yes"
TEST_BUSCTL_DNS="2 2 4 1 23 4 56 10 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239"
update-systemd-resolved-1.3.0/update-systemd-resolved 0000775 0000000 0000000 00000027351 13470321134 0023031 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
#
# OpenVPN helper to add DHCP information into systemd-resolved via DBus.
# Copyright (C) 2016, Jonathan Wright
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# This script will parse DHCP options set via OpenVPN (dhcp-option) to update
# systemd-resolved directly via DBus, instead of updating /etc/resolv.conf. To
# install, set as the 'up' and 'down' script in your OpenVPN configuration file
# or via the command-line arguments, alongside setting the 'down-pre' option to
# run the 'down' script before the device is closed. For example:
# up /etc/openvpn/scripts/update-systemd-resolved
# down /etc/openvpn/scripts/update-systemd-resolved
# down-pre
# Define what needs to be called via DBus
DBUS_DEST="org.freedesktop.resolve1"
DBUS_NODE="/org/freedesktop/resolve1"
SCRIPT_NAME="${BASH_SOURCE[0]##*/}"
log() {
logger -s -t "$SCRIPT_NAME" "$@"
}
for level in emerg err warning info debug; do
printf -v functext -- '%s() { log -p user.%s -- "$@" ; }' "$level" "$level"
eval "$functext"
done
usage() {
err "${1:?${1}. }. Usage: ${SCRIPT_NAME} up|down device_name."
}
busctl_call() {
# Preserve busctl's exit status
busctl call "$DBUS_DEST" "$DBUS_NODE" "${DBUS_DEST}.Manager" "$@" || {
local -i status=$?
emerg "'busctl' exited with status $status"
return $status
}
}
get_link_info() {
dev="$1"
shift
link=''
link="$(ip link show dev "$dev")" || return $?
echo "$dev" "${link%%:*}"
}
dhcp_settings() {
for foreign_option in "${!foreign_option_@}"; do
foreign_option_value="${!foreign_option}"
[[ "$foreign_option_value" == *dhcp-option* ]] \
&& echo "${foreign_option_value#dhcp-option }"
done
}
up() {
local link="$1"
shift
local if_index="$1"
shift
info "Link '$link' coming up"
# Preset values for processing -- will be altered in the various process_*
# functions.
local -a dns_servers=() dns_domain=() dns_search=() dns_routed=()
local -i dns_server_count=0 dns_domain_count=0 dns_search_count=0 dns_routed_count=0
local dns_sec=""
while read -r setting; do
setting_type="${setting%% *}"
setting_value="${setting#* }"
process_setting_function="${setting_type,,}"
process_setting_function="process_${process_setting_function//-/_}"
if declare -f "$process_setting_function" &>/dev/null; then
"$process_setting_function" "$setting_value" || return $?
else
warning "Not a recognized DHCP setting: '${setting}'"
fi
done < <(dhcp_settings)
if [[ "${#dns_servers[*]}" -gt 0 ]]; then
busctl_params=("$if_index" "$dns_server_count" "${dns_servers[@]}")
info "SetLinkDNS(${busctl_params[*]})"
busctl_call SetLinkDNS 'ia(iay)' "${busctl_params[@]}" || return $?
fi
if [[ "${#dns_domain[*]}" -gt 0 \
|| "${#dns_search[*]}" -gt 0 \
|| "${#dns_routed[*]}" -gt 0 ]]; then
dns_count=$((dns_domain_count+dns_search_count+dns_routed_count))
busctl_params=("$if_index" "$dns_count")
if [[ "${#dns_domain[*]}" -gt 0 ]]; then
busctl_params+=("${dns_domain[@]}")
fi
if [[ "${#dns_search[*]}" -gt 0 ]]; then
busctl_params+=("${dns_search[@]}")
fi
if [[ "${#dns_routed[*]}" -gt 0 ]]; then
busctl_params+=("${dns_routed[@]}")
fi
info "SetLinkDomains(${busctl_params[*]})"
busctl_call SetLinkDomains 'ia(sb)' "${busctl_params[@]}" || return $?
fi
if [[ -n "${dns_sec}" ]]; then
if [[ "${dns_sec}" == "default" ]]; then
# We need to provide an empty string to use the default settings
info "SetLinkDNSSEC($if_index '')"
busctl_call SetLinkDNSSEC 'is' "$if_index" "" || return $?
else
info "SetLinkDNSSEC($if_index ${dns_sec})"
busctl_call SetLinkDNSSEC 'is' "$if_index" "${dns_sec}" || return $?
fi
fi
}
down() {
local link="$1"
shift
local if_index="$1"
shift
info "Link '$link' going down"
if [[ "$(whoami 2>/dev/null)" != "root" ]]; then
# Cleanly handle the privilege dropped case by not calling RevertLink
info "Privileges dropped in the client: Cannot call RevertLink."
else
busctl_call RevertLink i "$if_index"
fi
}
process_dns() {
address="$1"
shift
if looks_like_ipv6 "$address"; then
process_dns_ipv6 "$address" || return $?
elif looks_like_ipv4 "$address"; then
process_dns_ipv4 "$address" || return $?
else
err "Not a valid IPv6 or IPv4 address: '$address'"
return 1
fi
}
process_dns6() {
process_dns $1
}
looks_like_ipv4() {
[[ -n "$1" ]] && {
local dots="${1//[^.]}"
(( ${#dots} == 3 ))
}
}
looks_like_ipv6() {
[[ -n "$1" ]] && {
local colons="${1//[^:]}"
(( ${#colons} >= 2 ))
}
}
process_dns_ipv4() {
local address="$1"
shift
info "Adding IPv4 DNS Server ${address}"
(( dns_server_count += 1 ))
dns_servers+=(2 4 ${address//./ })
}
# Enforces RFC 5952:
# 1. Don't shorten a single 0 field to '::'
# 2. Only longest run of zeros should be compressed
# 3. If there are multiple longest runs, the leftmost should be compressed
# 4. Address must be maximally compressed, so no all-zero runs next to '::'
#
# ...
#
# Thank goodness we don't have to handle port numbers, though :)
parse_ipv6() {
local raw_address="$1"
log_invalid_ipv6() {
local message="'$raw_address' is not a valid IPv6 address"
emerg "${message}: $*"
}
trap -- 'unset -f log_invalid_ipv6' RETURN
if [[ "$raw_address" == *::*::* ]]; then
log_invalid_ipv6 "address cannot contain more than one '::'"
return 1
elif [[ "$raw_address" =~ :0+:: ]] || [[ "$raw_address" =~ ::0+: ]]; then
log_invalid_ipv6 "address contains a 0-group adjacent to '::' and is not maximally shortened"
return 1
fi
local -i length=8
local -a raw_segments=()
IFS=$':' read -r -a raw_segments <<<"$raw_address"
local -i raw_length="${#raw_segments[@]}"
if (( raw_length > length )); then
log_invalid_ipv6 "expected ${length} segments, got ${raw_length}"
return 1
fi
# Store zero-runs keyed to their sizes, storing all non-zero segments prefixed
# with a token marking them as such.
local nonzero_prefix=$'!'
local -i zero_run_i=0 compressed_i=0
local -a tokenized_segments=()
local decimal_segment='' next_decimal_segment=''
for (( i = 0 ; i < raw_length ; i++ )); do
raw_segment="${raw_segments[i]}"
printf -v decimal_segment -- '%d' "0x${raw_segment:-0}"
# We're in the compressed group. The length of this run should be
# enough to bring the total number of segments to 8.
if [[ -z "$raw_segment" ]]; then
(( compressed_i = zero_run_i ))
# `+ 1' because the length of the current segment is counted in
# `raw_length'.
(( tokenized_segments[zero_run_i] = ((length - raw_length) + 1) ))
# If we have an address like `::1', skip processing the next group to
# avoid double-counting the zero-run, and increment the number of
# 0-groups to add since the second empty group is counted in
# `raw_length'.
if [[ -z "${raw_segments[i + 1]}" ]]; then
(( i++ ))
(( tokenized_segments[zero_run_i]++ ))
fi
(( zero_run_i++ ))
elif (( decimal_segment == 0 )); then
(( tokenized_segments[zero_run_i]++ ))
# The run is over if the next segment is not 0, so increment the
# tracking index.
printf -v next_decimal_segment -- '%d' "0x${raw_segments[i + 1]}"
(( next_decimal_segment != 0 )) && (( zero_run_i++ ))
else
# Prefix the raw segment with `nonzero_prefix' to mark this as a
# non-zero field.
tokenized_segments[zero_run_i]="${nonzero_prefix}${decimal_segment}"
(( zero_run_i++ ))
fi
done
if [[ "$raw_address" == *::* ]]; then
if (( ${#tokenized_segments[*]} == length )); then
log_invalid_ipv6 "single '0' fields should not be compressed"
return 1
else
local -i largest_run_i=0 largest_run=0
for (( i = 0 ; i < ${#tokenized_segments[@]}; i ++ )); do
# Skip groups that aren't zero-runs
[[ "${tokenized_segments[i]:0:1}" == "$nonzero_prefix" ]] && continue
if (( tokenized_segments[i] > largest_run )); then
(( largest_run_i = i ))
largest_run="${tokenized_segments[i]}"
fi
done
local -i compressed_run="${tokenized_segments[compressed_i]}"
if (( largest_run > compressed_run )); then
log_invalid_ipv6 "the compressed run of all-zero fields is smaller than the largest such run"
return 1
elif (( largest_run == compressed_run )) && (( largest_run_i < compressed_i )); then
log_invalid_ipv6 "only the leftmost largest run of all-zero fields should be compressed"
return 1
fi
fi
fi
for segment in "${tokenized_segments[@]}"; do
if [[ "${segment:0:1}" == "$nonzero_prefix" ]]; then
printf -- '%04x\n' "${segment#${nonzero_prefix}}"
else
for (( n = 0 ; n < segment ; n++ )); do
echo 0000
done
fi
done
}
process_dns_ipv6() {
local address="$1"
shift
info "Adding IPv6 DNS Server ${address}"
local -a segments=()
segments=($(parse_ipv6 "$address")) || return $?
# Add AF_INET6 and byte count
dns_servers+=(10 16)
for segment in "${segments[@]}"; do
dns_servers+=("$((16#${segment:0:2}))" "$((16#${segment:2:2}))")
done
(( dns_server_count += 1 ))
}
process_domain() {
local domain="$1"
shift
info "Adding DNS Domain ${domain}"
if [[ $dns_domain_count -eq 1 ]]; then
(( dns_search_count += 1 ))
dns_search+=("${domain}" false)
else
(( dns_domain_count = 1 ))
dns_domain+=("${domain}" false)
fi
}
process_adapter_domain_suffix() {
# This enables support for ADAPTER_DOMAIN_SUFFIX which is a Microsoft standard
# which works in the same way as DOMAIN to set the primary search domain on
# this specific link.
process_domain "$@"
}
process_domain_search() {
local domain="$1"
shift
info "Adding DNS Search Domain ${domain}"
(( dns_search_count += 1 ))
dns_search+=("${domain}" false)
}
process_domain_route() {
local domain="$1"
shift
info "Adding DNS Routed Domain ${domain}"
(( dns_routed_count += 1 ))
dns_routed+=("${domain}" true)
}
process_dnssec() {
local option="$1" setting=""
shift
case "${option,,}" in
yes|true)
setting="yes" ;;
no|false)
setting="no" ;;
default)
setting="default" ;;
allow-downgrade)
setting="allow-downgrade" ;;
*)
local message="'$option' is not a valid DNSSEC option"
emerg "${message}"
return 1 ;;
esac
info "Setting DNSSEC to ${setting}"
dns_sec="${setting}"
}
main() {
local script_type="${1}"
shift
local dev="${1:-$dev}"
shift
if [[ -z "$script_type" ]]; then
usage 'No script type specified'
return 1
elif [[ -z "$dev" ]]; then
usage 'No device name specified'
return 1
elif ! declare -f "${script_type}" &>/dev/null; then
usage "Invalid script type: '${script_type}'"
return 1
else
if ! read -r link if_index _ < <(get_link_info "$dev"); then
usage "Invalid device name: '$dev'"
return 1
fi
"$script_type" "$link" "$if_index" "$@" || return 1
# Flush the DNS cache
systemd-resolve --flush-caches
fi
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]] || [[ "$AUTOMATED_TESTING" == 1 ]]; then
set -o nounset
main "${script_type:-down}" "$@"
fi
update-systemd-resolved-1.3.0/update-systemd-resolved.conf 0000664 0000000 0000000 00000000321 13470321134 0023736 0 ustar 00root root 0000000 0000000 script-security 2
setenv PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
up /etc/openvpn/scripts/update-systemd-resolved
up-restart
down /etc/openvpn/scripts/update-systemd-resolved
down-pre