diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-12-04 13:29:41 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-12-21 12:10:07 +0100 |
commit | f2fd3cdb454f745e73d7706a5f92ee1f6ee70e79 (patch) | |
tree | be9ab59d520170a8a0e4079e03ceb25689d8fd8f | |
parent | resolvectl: minor whitespace fix (diff) | |
download | systemd-f2fd3cdb454f745e73d7706a5f92ee1f6ee70e79.tar.gz systemd-f2fd3cdb454f745e73d7706a5f92ee1f6ee70e79.tar.bz2 systemd-f2fd3cdb454f745e73d7706a5f92ee1f6ee70e79.zip |
resolvectl: add support for reading/writing per-link 'default-route' boolean
-rw-r--r-- | man/resolvectl.xml | 23 | ||||
-rw-r--r-- | src/resolve/resolvectl.c | 62 |
2 files changed, 75 insertions, 10 deletions
diff --git a/man/resolvectl.xml b/man/resolvectl.xml index e07893dd1..defd592aa 100644 --- a/man/resolvectl.xml +++ b/man/resolvectl.xml @@ -241,6 +241,7 @@ <varlistentry> <term><option>dns [<replaceable>LINK</replaceable> [<replaceable>SERVER</replaceable>…]]</option></term> <term><option>domain [<replaceable>LINK</replaceable> [<replaceable>DOMAIN</replaceable>…]]</option></term> + <term><option>default-route [<replaceable>LINK</replaceable> [<replaceable>BOOL</replaceable>…]]</option></term> <term><option>llmnr [<replaceable>LINK</replaceable> [<replaceable>MODE</replaceable>]]</option></term> <term><option>mdns [<replaceable>LINK</replaceable> [<replaceable>MODE</replaceable>]]</option></term> <term><option>dnssec [<replaceable>LINK</replaceable> [<replaceable>MODE</replaceable>]]</option></term> @@ -248,18 +249,21 @@ <term><option>nta [<replaceable>LINK</replaceable> [<replaceable>DOMAIN</replaceable>…]]</option></term> <listitem> - <para>Get/set per-interface DNS configuration. These commands may be used to configure various DNS - settings for network interfaces that aren't managed by + <para>Get/set per-interface DNS configuration. These commands may be used to configure various DNS settings + for network interfaces that aren't managed by <citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>. (These commands will fail when used on interfaces that are managed by <command>systemd-networkd</command>, please configure their DNS settings directly inside the <filename>.network</filename> files instead.) These commands may be used to inform <command>systemd-resolved</command> about per-interface DNS configuration determined through external means. The <option>dns</option> command expects IPv4 or IPv6 address specifications of DNS servers to use. The <option>domain</option> command expects valid DNS domains, possibly prefixed with - <literal>~</literal>, and configures a per-interface search or route-only domain. The <option>llmnr</option>, - <option>mdns</option>, <option>dnssec</option> and <option>dnsovertls</option> commands may be used to configure - the per-interface LLMNR, MulticastDNS, DNSSEC and DNSOverTLS settings. Finally, <option>nta</option> command - may be used to configure additional per-interface DNSSEC NTA domains.</para> + <literal>~</literal>, and configures a per-interface search or route-only domain. The + <option>default-route</option> command expects a boolean paremeter, and configures whether the link may be + used as default route for DNS lookups, i.e. if it is suitable for lookups on domains no other link explicitly + is configured for. The <option>llmnr</option>, <option>mdns</option>, <option>dnssec</option> and + <option>dnsovertls</option> commands may be used to configure the per-interface LLMNR, MulticastDNS, DNSSEC + and DNSOverTLS settings. Finally, <option>nta</option> command may be used to configure additional + per-interface DNSSEC NTA domains.</para> <para>Options <option>dns</option>, <option>domain</option> and <option>nta</option> can take a single empty string argument to clear their respective value lists.</para> @@ -274,9 +278,10 @@ <listitem><para>Revert the per-interface DNS configuration. If the DNS configuration is reverted all per-interface DNS setting are reset to their defaults, undoing all effects of <option>dns</option>, - <option>domain</option>, <option>llmnr</option>, <option>mdns</option>, <option>dnssec</option>, - <option>dnsovertls</option>, <option>nta</option>. Note that when a network interface disappears all - configuration is lost automatically, an explicit reverting is not necessary in that case.</para></listitem> + <option>domain</option>, <option>default-route</option>, <option>llmnr</option>, <option>mdns</option>, + <option>dnssec</option>, <option>dnsovertls</option>, <option>nta</option>. Note that when a network interface + disappears all configuration is lost automatically, an explicit reverting is not necessary in that + case.</para></listitem> </varlistentry> </variablelist> diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 97ebbc3bf..4d533f851 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -67,6 +67,7 @@ typedef enum StatusMode { STATUS_ALL, STATUS_DNS, STATUS_DOMAIN, + STATUS_DEFAULT_ROUTE, STATUS_LLMNR, STATUS_MDNS, STATUS_PRIVATE, @@ -1369,6 +1370,7 @@ struct link_info { char **domains; char **ntas; bool dnssec_supported; + bool default_route; }; static void link_info_clear(struct link_info *p) { @@ -1384,6 +1386,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode { "DNS", "a(iay)", map_link_dns_servers, offsetof(struct link_info, dns) }, { "CurrentDNSServer", "(iay)", map_link_current_dns_server, offsetof(struct link_info, current_dns) }, { "Domains", "a(sb)", map_link_domains, offsetof(struct link_info, domains) }, + { "DefaultRoute", "b", NULL, offsetof(struct link_info, default_route) }, { "LLMNR", "s", NULL, offsetof(struct link_info, llmnr) }, { "MulticastDNS", "s", NULL, offsetof(struct link_info, mdns) }, { "DNSOverTLS", "s", NULL, offsetof(struct link_info, dns_over_tls) }, @@ -1439,6 +1442,14 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode if (mode == STATUS_NTA) return status_print_strv_ifindex(ifindex, name, link_info.ntas); + if (mode == STATUS_DEFAULT_ROUTE) { + printf("%sLink %i (%s)%s: %s\n", + ansi_highlight(), ifindex, name, ansi_normal(), + yes_no(link_info.default_route)); + + return 0; + } + if (mode == STATUS_LLMNR) { printf("%sLink %i (%s)%s: %s\n", ansi_highlight(), ifindex, name, ansi_normal(), @@ -1487,11 +1498,13 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode link_info.scopes_mask & SD_RESOLVED_MDNS_IPV4 ? " mDNS/IPv4" : "", link_info.scopes_mask & SD_RESOLVED_MDNS_IPV6 ? " mDNS/IPv6" : ""); - printf(" LLMNR setting: %s\n" + printf("DefaultRoute setting: %s\n" + " LLMNR setting: %s\n" "MulticastDNS setting: %s\n" " DNSOverTLS setting: %s\n" " DNSSEC setting: %s\n" " DNSSEC supported: %s\n", + yes_no(link_info.default_route), strna(link_info.llmnr), strna(link_info.mdns), strna(link_info.dns_over_tls), @@ -2020,6 +2033,51 @@ static int verb_domain(int argc, char **argv, void *userdata) { return 0; } +static int verb_default_route(int argc, char **argv, void *userdata) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + sd_bus *bus = userdata; + int r, b; + + assert(bus); + + if (argc >= 2) { + r = ifname_mangle(argv[1]); + if (r < 0) + return r; + } + + if (arg_ifindex <= 0) + return status_all(bus, STATUS_DEFAULT_ROUTE); + + if (argc < 3) + return status_ifindex(bus, arg_ifindex, NULL, STATUS_DEFAULT_ROUTE, NULL); + + b = parse_boolean(argv[2]); + if (b < 0) + return log_error_errno(b, "Failed to parse boolean argument: %s", argv[2]); + + r = sd_bus_call_method(bus, + "org.freedesktop.resolve1", + "/org/freedesktop/resolve1", + "org.freedesktop.resolve1.Manager", + "SetLinkDefaultRoute", + &error, + NULL, + "ib", arg_ifindex, b); + if (r < 0) { + if (sd_bus_error_has_name(&error, BUS_ERROR_LINK_BUSY)) + return log_interface_is_managed(r, arg_ifindex); + + if (arg_ifindex_permissive && + sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_LINK)) + return 0; + + return log_error_errno(r, "Failed to set default route configuration: %s", bus_error_message(&error, r)); + } + + return 0; +} + static int verb_llmnr(int argc, char **argv, void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus *bus = userdata; @@ -2407,6 +2465,7 @@ static int native_help(void) { " reset-server-features Forget learnt DNS server feature levels\n" " dns [LINK [SERVER...]] Get/set per-interface DNS server address\n" " domain [LINK [DOMAIN...]] Get/set per-interface search domain\n" + " default-route [LINK [BOOL]] Get/set per-interface default route flag\n" " llmnr [LINK [MODE]] Get/set per-interface LLMNR mode\n" " mdns [LINK [MODE]] Get/set per-interface MulticastDNS mode\n" " dnsovertls [LINK [MODE]] Get/set per-interface DNS-over-TLS mode\n" @@ -2950,6 +3009,7 @@ static int native_main(int argc, char *argv[], sd_bus *bus) { { "reset-server-features", VERB_ANY, 1, 0, reset_server_features }, { "dns", VERB_ANY, VERB_ANY, 0, verb_dns }, { "domain", VERB_ANY, VERB_ANY, 0, verb_domain }, + { "default-route", VERB_ANY, 3, 0, verb_default_route }, { "llmnr", VERB_ANY, 3, 0, verb_llmnr }, { "mdns", VERB_ANY, 3, 0, verb_mdns }, { "dnsovertls", VERB_ANY, 3, 0, verb_dns_over_tls }, |