diff options
Diffstat (limited to 'src/resolve/resolvectl.c')
-rw-r--r-- | src/resolve/resolvectl.c | 89 |
1 files changed, 88 insertions, 1 deletions
diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 26b3a811ad..750001d407 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -56,6 +56,7 @@ char **arg_set_dns = NULL; char **arg_set_domain = NULL; static const char *arg_set_llmnr = NULL; static const char *arg_set_mdns = NULL; +static const char *arg_set_private_dns = NULL; static const char *arg_set_dnssec = NULL; static char **arg_set_nta = NULL; @@ -65,6 +66,7 @@ typedef enum StatusMode { STATUS_DOMAIN, STATUS_LLMNR, STATUS_MDNS, + STATUS_PRIVATE, STATUS_DNSSEC, STATUS_NTA, } StatusMode; @@ -1337,6 +1339,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode uint64_t scopes_mask; const char *llmnr; const char *mdns; + const char *private_dns; const char *dnssec; char *current_dns; char **dns; @@ -1352,6 +1355,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode { "Domains", "a(sb)", map_link_domains, offsetof(struct link_info, domains) }, { "LLMNR", "s", NULL, offsetof(struct link_info, llmnr) }, { "MulticastDNS", "s", NULL, offsetof(struct link_info, mdns) }, + { "PrivateDNS", "s", NULL, offsetof(struct link_info, private_dns) }, { "DNSSEC", "s", NULL, offsetof(struct link_info, dnssec) }, { "DNSSECNegativeTrustAnchors", "as", NULL, offsetof(struct link_info, ntas) }, { "DNSSECSupported", "b", NULL, offsetof(struct link_info, dnssec_supported) }, @@ -1430,6 +1434,15 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode goto finish; } + if (mode == STATUS_PRIVATE) { + printf("%sLink %i (%s)%s: %s\n", + ansi_highlight(), ifindex, name, ansi_normal(), + strna(link_info.private_dns)); + + r = 0; + goto finish; + } + if (mode == STATUS_DNSSEC) { printf("%sLink %i (%s)%s: %s\n", ansi_highlight(), ifindex, name, ansi_normal(), @@ -1457,10 +1470,12 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode printf(" LLMNR setting: %s\n" "MulticastDNS setting: %s\n" + " PrivateDNS setting: %s\n" " DNSSEC setting: %s\n" " DNSSEC supported: %s\n", strna(link_info.llmnr), strna(link_info.mdns), + strna(link_info.private_dns), strna(link_info.dnssec), yes_no(link_info.dnssec_supported)); @@ -1602,6 +1617,7 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) { char **ntas; const char *llmnr; const char *mdns; + const char *private_dns; const char *dnssec; bool dnssec_supported; } global_info = {}; @@ -1614,6 +1630,7 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) { { "DNSSECNegativeTrustAnchors", "as", NULL, offsetof(struct global_info, ntas) }, { "LLMNR", "s", NULL, offsetof(struct global_info, llmnr) }, { "MulticastDNS", "s", NULL, offsetof(struct global_info, mdns) }, + { "PrivateDNS", "s", NULL, offsetof(struct global_info, private_dns) }, { "DNSSEC", "s", NULL, offsetof(struct global_info, dnssec) }, { "DNSSECSupported", "b", NULL, offsetof(struct global_info, dnssec_supported) }, {} @@ -1673,6 +1690,14 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) { goto finish; } + if (mode == STATUS_PRIVATE) { + printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(), + strna(global_info.private_dns)); + + r = 0; + goto finish; + } + if (mode == STATUS_DNSSEC) { printf("%sGlobal%s: %s\n", ansi_highlight(), ansi_normal(), strna(global_info.dnssec)); @@ -1685,10 +1710,12 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) { printf(" LLMNR setting: %s\n" "MulticastDNS setting: %s\n" + " PrivateDNS setting: %s\n" " DNSSEC setting: %s\n" " DNSSEC supported: %s\n", strna(global_info.llmnr), strna(global_info.mdns), + strna(global_info.private_dns), strna(global_info.dnssec), yes_no(global_info.dnssec_supported)); @@ -2081,6 +2108,50 @@ static int verb_mdns(int argc, char **argv, void *userdata) { return 0; } +static int verb_private_dns(int argc, char **argv, void *userdata) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + sd_bus *bus = userdata; + int ifindex, r; + + assert(bus); + + if (argc <= 1) + return status_all(bus, STATUS_PRIVATE); + + ifindex = parse_ifindex_with_warn(argv[1]); + if (ifindex < 0) + return ifindex; + + if (ifindex == LOOPBACK_IFINDEX) { + log_error("Interface can't be the loopback interface (lo). Sorry."); + return -EINVAL; + } + + if (argc == 2) + return status_ifindex(bus, ifindex, NULL, STATUS_PRIVATE, NULL); + + r = sd_bus_call_method(bus, + "org.freedesktop.resolve1", + "/org/freedesktop/resolve1", + "org.freedesktop.resolve1.Manager", + "SetLinkPrivateDNS", + &error, + NULL, + "is", ifindex, argv[2]); + if (r < 0) { + if (sd_bus_error_has_name(&error, BUS_ERROR_LINK_BUSY)) + return log_interface_is_managed(r, 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 PrivateDNS configuration: %s", bus_error_message(&error, r)); + } + + return 0; +} + static int verb_dnssec(int argc, char **argv, void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus *bus = userdata; @@ -2283,6 +2354,7 @@ static void compat_help(void) { " --set-domain=DOMAIN Set per-interface search domain\n" " --set-llmnr=MODE Set per-interface LLMNR mode\n" " --set-mdns=MODE Set per-interface MulticastDNS mode\n" + " --set-privatedns=MODE Set per-interface PrivateDNS mode\n" " --set-dnssec=MODE Set per-interface DNSSEC mode\n" " --set-nta=DOMAIN Set per-interface DNSSEC NTA\n" " --revert Revert per-interface configuration\n" @@ -2326,6 +2398,7 @@ static void native_help(void) { " domain [LINK [DOMAIN...]] Get/set per-interface search domain\n" " llmnr [LINK [MODE]] Get/set per-interface LLMNR mode\n" " mdns [LINK [MODE]] Get/set per-interface MulticastDNS mode\n" + " privatedns [LINK [MODE]] Get/set per-interface PrivateDNS mode\n" " dnssec [LINK [MODE]] Get/set per-interface DNSSEC mode\n" " nta [LINK [DOMAIN...]] Get/set per-interface DNSSEC NTA\n" " revert LINK Revert per-interface configuration\n" @@ -2359,6 +2432,7 @@ static int compat_parse_argv(int argc, char *argv[]) { ARG_SET_DOMAIN, ARG_SET_LLMNR, ARG_SET_MDNS, + ARG_SET_PRIVATE, ARG_SET_DNSSEC, ARG_SET_NTA, ARG_REVERT_LINK, @@ -2390,6 +2464,7 @@ static int compat_parse_argv(int argc, char *argv[]) { { "set-domain", required_argument, NULL, ARG_SET_DOMAIN }, { "set-llmnr", required_argument, NULL, ARG_SET_LLMNR }, { "set-mdns", required_argument, NULL, ARG_SET_MDNS }, + { "set-privatedns", required_argument, NULL, ARG_SET_PRIVATE }, { "set-dnssec", required_argument, NULL, ARG_SET_DNSSEC }, { "set-nta", required_argument, NULL, ARG_SET_NTA }, { "revert", no_argument, NULL, ARG_REVERT_LINK }, @@ -2608,6 +2683,11 @@ static int compat_parse_argv(int argc, char *argv[]) { arg_mode = MODE_SET_LINK; break; + case ARG_SET_PRIVATE: + arg_set_private_dns = optarg; + arg_mode = MODE_SET_LINK; + break; + case ARG_SET_DNSSEC: arg_set_dnssec = optarg; arg_mode = MODE_SET_LINK; @@ -2651,7 +2731,7 @@ static int compat_parse_argv(int argc, char *argv[]) { if (IN_SET(arg_mode, MODE_SET_LINK, MODE_REVERT_LINK)) { if (arg_ifindex <= 0) { - log_error("--set-dns=, --set-domain=, --set-llmnr=, --set-mdns=, --set-dnssec=, --set-nta= and --revert require --interface=."); + log_error("--set-dns=, --set-domain=, --set-llmnr=, --set-mdns=, --set-privatedns=, --set-dnssec=, --set-nta= and --revert require --interface=."); return -EINVAL; } @@ -2877,6 +2957,7 @@ static int native_main(int argc, char *argv[], sd_bus *bus) { { "domain", VERB_ANY, VERB_ANY, 0, verb_domain }, { "llmnr", VERB_ANY, 3, 0, verb_llmnr }, { "mdns", VERB_ANY, 3, 0, verb_mdns }, + { "privatedns", VERB_ANY, 3, 0, verb_private_dns }, { "dnssec", VERB_ANY, 3, 0, verb_dnssec }, { "nta", VERB_ANY, VERB_ANY, 0, verb_nta }, { "revert", 2, 2, 0, verb_revert_link }, @@ -2969,6 +3050,12 @@ static int compat_main(int argc, char *argv[], sd_bus *bus) { return r; } + if (arg_set_private_dns) { + r = translate("privatedns", arg_ifname, 1, (char **) &arg_set_private_dns, bus); + if (r < 0) + return r; + } + if (arg_set_dnssec) { r = translate("dnssec", arg_ifname, 1, (char **) &arg_set_dnssec, bus); if (r < 0) |