2 This file is part of systemd.
4 Copyright 2014 Zbigniew Jędrzejewski-Szmek
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "sd-netlink.h"
27 #include "alloc-util.h"
28 #include "bus-error.h"
31 #include "gcrypt-util.h"
32 #include "in-addr-util.h"
33 #include "netlink-util.h"
35 #include "parse-util.h"
36 #include "resolved-def.h"
37 #include "resolved-dns-packet.h"
39 #include "terminal-util.h"
41 #define DNS_CALL_TIMEOUT_USEC (45*USEC_PER_SEC)
43 static int arg_family
= AF_UNSPEC
;
44 static int arg_ifindex
= 0;
45 static uint16_t arg_type
= 0;
46 static uint16_t arg_class
= 0;
47 static bool arg_legend
= true;
48 static uint64_t arg_flags
= 0;
49 static bool arg_no_pager
= false;
51 typedef enum ServiceFamily
{
55 _SERVICE_FAMILY_INVALID
= -1,
57 static ServiceFamily arg_service_family
= SERVICE_FAMILY_TCP
;
59 typedef enum RawType
{
64 static RawType arg_raw
= RAW_NONE
;
73 MODE_RESET_STATISTICS
,
76 } arg_mode
= MODE_RESOLVE_HOST
;
78 static ServiceFamily
service_family_from_string(const char *s
) {
79 if (s
== NULL
|| streq(s
, "tcp"))
80 return SERVICE_FAMILY_TCP
;
82 return SERVICE_FAMILY_UDP
;
84 return SERVICE_FAMILY_SCTP
;
85 return _SERVICE_FAMILY_INVALID
;
88 static const char* service_family_to_string(ServiceFamily service
) {
90 case SERVICE_FAMILY_TCP
:
92 case SERVICE_FAMILY_UDP
:
94 case SERVICE_FAMILY_SCTP
:
97 assert_not_reached("invalid service");
101 static void print_source(uint64_t flags
, usec_t rtt
) {
102 char rtt_str
[FORMAT_TIMESTAMP_MAX
];
110 fputs("\n-- Information acquired via", stdout
);
113 printf(" protocol%s%s%s%s%s",
114 flags
& SD_RESOLVED_DNS
? " DNS" :"",
115 flags
& SD_RESOLVED_LLMNR_IPV4
? " LLMNR/IPv4" : "",
116 flags
& SD_RESOLVED_LLMNR_IPV6
? " LLMNR/IPv6" : "",
117 flags
& SD_RESOLVED_MDNS_IPV4
? "mDNS/IPv4" : "",
118 flags
& SD_RESOLVED_MDNS_IPV6
? "mDNS/IPv6" : "");
120 assert_se(format_timespan(rtt_str
, sizeof(rtt_str
), rtt
, 100));
122 printf(" in %s", rtt_str
);
127 printf("-- Data is authenticated: %s\n", yes_no(flags
& SD_RESOLVED_AUTHENTICATED
));
130 static int resolve_host(sd_bus
*bus
, const char *name
) {
132 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*req
= NULL
, *reply
= NULL
;
133 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
134 const char *canonical
= NULL
;
135 char ifname
[IF_NAMESIZE
] = "";
143 if (arg_ifindex
> 0 && !if_indextoname(arg_ifindex
, ifname
))
144 return log_error_errno(errno
, "Failed to resolve interface name for index %i: %m", arg_ifindex
);
146 log_debug("Resolving %s (family %s, interface %s).", name
, af_to_name(arg_family
) ?: "*", isempty(ifname
) ? "*" : ifname
);
148 r
= sd_bus_message_new_method_call(
151 "org.freedesktop.resolve1",
152 "/org/freedesktop/resolve1",
153 "org.freedesktop.resolve1.Manager",
156 return bus_log_create_error(r
);
158 r
= sd_bus_message_append(req
, "isit", arg_ifindex
, name
, arg_family
, arg_flags
);
160 return bus_log_create_error(r
);
162 ts
= now(CLOCK_MONOTONIC
);
164 r
= sd_bus_call(bus
, req
, DNS_CALL_TIMEOUT_USEC
, &error
, &reply
);
166 return log_error_errno(r
, "%s: resolve call failed: %s", name
, bus_error_message(&error
, r
));
168 ts
= now(CLOCK_MONOTONIC
) - ts
;
170 r
= sd_bus_message_enter_container(reply
, 'a', "(iiay)");
172 return bus_log_parse_error(r
);
174 while ((r
= sd_bus_message_enter_container(reply
, 'r', "iiay")) > 0) {
175 _cleanup_free_
char *pretty
= NULL
;
180 assert_cc(sizeof(int) == sizeof(int32_t));
182 r
= sd_bus_message_read(reply
, "ii", &ifindex
, &family
);
184 return bus_log_parse_error(r
);
186 r
= sd_bus_message_read_array(reply
, 'y', &a
, &sz
);
188 return bus_log_parse_error(r
);
190 r
= sd_bus_message_exit_container(reply
);
192 return bus_log_parse_error(r
);
194 if (!IN_SET(family
, AF_INET
, AF_INET6
)) {
195 log_debug("%s: skipping entry with family %d (%s)", name
, family
, af_to_name(family
) ?: "unknown");
199 if (sz
!= FAMILY_ADDRESS_SIZE(family
)) {
200 log_error("%s: systemd-resolved returned address of invalid size %zu for family %s", name
, sz
, af_to_name(family
) ?: "unknown");
205 if (ifindex
> 0 && !if_indextoname(ifindex
, ifname
))
206 log_warning_errno(errno
, "Failed to resolve interface name for index %i: %m", ifindex
);
208 r
= in_addr_ifindex_to_string(family
, a
, ifindex
, &pretty
);
210 return log_error_errno(r
, "Failed to print address for %s: %m", name
);
212 printf("%*s%s %s%s%s\n",
213 (int) strlen(name
), c
== 0 ? name
: "", c
== 0 ? ":" : " ",
215 isempty(ifname
) ? "" : "%", ifname
);
220 return bus_log_parse_error(r
);
222 r
= sd_bus_message_exit_container(reply
);
224 return bus_log_parse_error(r
);
226 r
= sd_bus_message_read(reply
, "st", &canonical
, &flags
);
228 return bus_log_parse_error(r
);
230 if (!streq(name
, canonical
))
231 printf("%*s%s (%s)\n",
232 (int) strlen(name
), c
== 0 ? name
: "", c
== 0 ? ":" : " ",
236 log_error("%s: no addresses found", name
);
240 print_source(flags
, ts
);
245 static int resolve_address(sd_bus
*bus
, int family
, const union in_addr_union
*address
, int ifindex
) {
246 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*req
= NULL
, *reply
= NULL
;
247 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
248 _cleanup_free_
char *pretty
= NULL
;
249 char ifname
[IF_NAMESIZE
] = "";
256 assert(IN_SET(family
, AF_INET
, AF_INET6
));
260 ifindex
= arg_ifindex
;
262 r
= in_addr_ifindex_to_string(family
, address
, ifindex
, &pretty
);
266 if (ifindex
> 0 && !if_indextoname(ifindex
, ifname
))
267 return log_error_errno(errno
, "Failed to resolve interface name for index %i: %m", ifindex
);
269 log_debug("Resolving %s%s%s.", pretty
, isempty(ifname
) ? "" : "%", ifname
);
271 r
= sd_bus_message_new_method_call(
274 "org.freedesktop.resolve1",
275 "/org/freedesktop/resolve1",
276 "org.freedesktop.resolve1.Manager",
279 return bus_log_create_error(r
);
281 r
= sd_bus_message_append(req
, "ii", ifindex
, family
);
283 return bus_log_create_error(r
);
285 r
= sd_bus_message_append_array(req
, 'y', address
, FAMILY_ADDRESS_SIZE(family
));
287 return bus_log_create_error(r
);
289 r
= sd_bus_message_append(req
, "t", arg_flags
);
291 return bus_log_create_error(r
);
293 ts
= now(CLOCK_MONOTONIC
);
295 r
= sd_bus_call(bus
, req
, DNS_CALL_TIMEOUT_USEC
, &error
, &reply
);
297 log_error("%s: resolve call failed: %s", pretty
, bus_error_message(&error
, r
));
301 ts
= now(CLOCK_MONOTONIC
) - ts
;
303 r
= sd_bus_message_enter_container(reply
, 'a', "(is)");
305 return bus_log_create_error(r
);
307 while ((r
= sd_bus_message_enter_container(reply
, 'r', "is")) > 0) {
310 assert_cc(sizeof(int) == sizeof(int32_t));
312 r
= sd_bus_message_read(reply
, "is", &ifindex
, &n
);
316 r
= sd_bus_message_exit_container(reply
);
321 if (ifindex
> 0 && !if_indextoname(ifindex
, ifname
))
322 log_warning_errno(errno
, "Failed to resolve interface name for index %i: %m", ifindex
);
324 printf("%*s%*s%*s%s %s\n",
325 (int) strlen(pretty
), c
== 0 ? pretty
: "",
326 isempty(ifname
) ? 0 : 1, c
> 0 || isempty(ifname
) ? "" : "%",
327 (int) strlen(ifname
), c
== 0 ? ifname
: "",
334 return bus_log_parse_error(r
);
336 r
= sd_bus_message_exit_container(reply
);
338 return bus_log_parse_error(r
);
340 r
= sd_bus_message_read(reply
, "t", &flags
);
342 return bus_log_parse_error(r
);
345 log_error("%s: no names found", pretty
);
349 print_source(flags
, ts
);
354 static int output_rr_packet(const void *d
, size_t l
, int ifindex
) {
355 _cleanup_(dns_resource_record_unrefp
) DnsResourceRecord
*rr
= NULL
;
356 _cleanup_(dns_packet_unrefp
) DnsPacket
*p
= NULL
;
358 char ifname
[IF_NAMESIZE
] = "";
360 r
= dns_packet_new(&p
, DNS_PROTOCOL_DNS
, 0);
364 p
->refuse_compression
= true;
366 r
= dns_packet_append_blob(p
, d
, l
, NULL
);
370 r
= dns_packet_read_rr(p
, &rr
, NULL
, NULL
);
372 return log_error_errno(r
, "Failed to parse RR: %m");
374 if (arg_raw
== RAW_PAYLOAD
) {
378 k
= dns_resource_record_payload(rr
, &data
);
380 return log_error_errno(k
, "Cannot dump RR: %m");
381 fwrite(data
, 1, k
, stdout
);
385 s
= dns_resource_record_to_string(rr
);
389 if (ifindex
> 0 && !if_indextoname(ifindex
, ifname
))
390 log_warning_errno(errno
, "Failed to resolve interface name for index %i: %m", ifindex
);
392 printf("%s%s%s\n", s
, isempty(ifname
) ? "" : " # interface ", ifname
);
398 static int resolve_record(sd_bus
*bus
, const char *name
, uint16_t class, uint16_t type
) {
399 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*req
= NULL
, *reply
= NULL
;
400 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
401 char ifname
[IF_NAMESIZE
] = "";
406 bool needs_authentication
= false;
410 if (arg_ifindex
> 0 && !if_indextoname(arg_ifindex
, ifname
))
411 return log_error_errno(errno
, "Failed to resolve interface name for index %i: %m", arg_ifindex
);
413 log_debug("Resolving %s %s %s (interface %s).", name
, dns_class_to_string(class), dns_type_to_string(type
), isempty(ifname
) ? "*" : ifname
);
415 r
= sd_bus_message_new_method_call(
418 "org.freedesktop.resolve1",
419 "/org/freedesktop/resolve1",
420 "org.freedesktop.resolve1.Manager",
423 return bus_log_create_error(r
);
425 r
= sd_bus_message_append(req
, "isqqt", arg_ifindex
, name
, class, type
, arg_flags
);
427 return bus_log_create_error(r
);
429 ts
= now(CLOCK_MONOTONIC
);
431 r
= sd_bus_call(bus
, req
, DNS_CALL_TIMEOUT_USEC
, &error
, &reply
);
433 log_error("%s: resolve call failed: %s", name
, bus_error_message(&error
, r
));
437 ts
= now(CLOCK_MONOTONIC
) - ts
;
439 r
= sd_bus_message_enter_container(reply
, 'a', "(iqqay)");
441 return bus_log_parse_error(r
);
443 while ((r
= sd_bus_message_enter_container(reply
, 'r', "iqqay")) > 0) {
449 assert_cc(sizeof(int) == sizeof(int32_t));
451 r
= sd_bus_message_read(reply
, "iqq", &ifindex
, &c
, &t
);
453 return bus_log_parse_error(r
);
455 r
= sd_bus_message_read_array(reply
, 'y', &d
, &l
);
457 return bus_log_parse_error(r
);
459 r
= sd_bus_message_exit_container(reply
);
461 return bus_log_parse_error(r
);
463 if (arg_raw
== RAW_PACKET
) {
464 uint64_t u64
= htole64(l
);
466 fwrite(&u64
, sizeof(u64
), 1, stdout
);
467 fwrite(d
, 1, l
, stdout
);
469 r
= output_rr_packet(d
, l
, ifindex
);
474 if (dns_type_needs_authentication(t
))
475 needs_authentication
= true;
480 return bus_log_parse_error(r
);
482 r
= sd_bus_message_exit_container(reply
);
484 return bus_log_parse_error(r
);
486 r
= sd_bus_message_read(reply
, "t", &flags
);
488 return bus_log_parse_error(r
);
491 log_error("%s: no records found", name
);
495 print_source(flags
, ts
);
497 if ((flags
& SD_RESOLVED_AUTHENTICATED
) == 0 && needs_authentication
) {
500 fprintf(stderr
, "\n%s"
501 "WARNING: The resources shown contain cryptographic key data which could not be\n"
502 " authenticated. It is not suitable to authenticate any communication.\n"
503 " This is usually indication that DNSSEC authentication was not enabled\n"
504 " or is not available for the selected protocol or DNS servers.%s\n",
505 ansi_highlight_red(),
512 static int resolve_rfc4501(sd_bus
*bus
, const char *name
) {
513 uint16_t type
= 0, class = 0;
514 const char *p
, *q
, *n
;
519 assert(startswith(name
, "dns:"));
521 /* Parse RFC 4501 dns: URIs */
531 e
= strchr(p
+ 2, '/');
536 log_warning("DNS authority specification not supported; ignoring specified authority.");
543 n
= strndupa(p
, q
- p
);
549 f
= startswith_no_case(q
, "class=");
551 _cleanup_free_
char *t
= NULL
;
555 log_error("DNS class specified twice.");
559 e
= strchrnul(f
, ';');
560 t
= strndup(f
, e
- f
);
564 r
= dns_class_from_string(t
);
566 log_error("Unknown DNS class %s.", t
);
580 f
= startswith_no_case(q
, "type=");
582 _cleanup_free_
char *t
= NULL
;
586 log_error("DNS type specified twice.");
590 e
= strchrnul(f
, ';');
591 t
= strndup(f
, e
- f
);
595 r
= dns_type_from_string(t
);
597 log_error("Unknown DNS type %s.", t
);
617 class = arg_class
?: DNS_CLASS_IN
;
619 type
= arg_type
?: DNS_TYPE_A
;
621 return resolve_record(bus
, n
, class, type
);
624 log_error("Invalid DNS URI: %s", name
);
628 static int resolve_service(sd_bus
*bus
, const char *name
, const char *type
, const char *domain
) {
629 const char *canonical_name
, *canonical_type
, *canonical_domain
;
630 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*req
= NULL
, *reply
= NULL
;
631 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
632 char ifname
[IF_NAMESIZE
] = "";
643 name
= empty_to_null(name
);
644 type
= empty_to_null(type
);
646 if (arg_ifindex
> 0 && !if_indextoname(arg_ifindex
, ifname
))
647 return log_error_errno(errno
, "Failed to resolve interface name for index %i: %m", arg_ifindex
);
650 log_debug("Resolving service \"%s\" of type %s in %s (family %s, interface %s).", name
, type
, domain
, af_to_name(arg_family
) ?: "*", isempty(ifname
) ? "*" : ifname
);
652 log_debug("Resolving service type %s of %s (family %s, interface %s).", type
, domain
, af_to_name(arg_family
) ?: "*", isempty(ifname
) ? "*" : ifname
);
654 log_debug("Resolving service type %s (family %s, interface %s).", domain
, af_to_name(arg_family
) ?: "*", isempty(ifname
) ? "*" : ifname
);
656 r
= sd_bus_message_new_method_call(
659 "org.freedesktop.resolve1",
660 "/org/freedesktop/resolve1",
661 "org.freedesktop.resolve1.Manager",
664 return bus_log_create_error(r
);
666 r
= sd_bus_message_append(req
, "isssit", arg_ifindex
, name
, type
, domain
, arg_family
, arg_flags
);
668 return bus_log_create_error(r
);
670 ts
= now(CLOCK_MONOTONIC
);
672 r
= sd_bus_call(bus
, req
, DNS_CALL_TIMEOUT_USEC
, &error
, &reply
);
674 return log_error_errno(r
, "Resolve call failed: %s", bus_error_message(&error
, r
));
676 ts
= now(CLOCK_MONOTONIC
) - ts
;
678 r
= sd_bus_message_enter_container(reply
, 'a', "(qqqsa(iiay)s)");
680 return bus_log_parse_error(r
);
683 (name
? strlen(name
) + 1 : 0) +
684 (type
? strlen(type
) + 1 : 0) +
688 while ((r
= sd_bus_message_enter_container(reply
, 'r', "qqqsa(iiay)s")) > 0) {
689 uint16_t priority
, weight
, port
;
690 const char *hostname
, *canonical
;
692 r
= sd_bus_message_read(reply
, "qqqs", &priority
, &weight
, &port
, &hostname
);
694 return bus_log_parse_error(r
);
697 printf("%*s%s", (int) strlen(name
), c
== 0 ? name
: "", c
== 0 ? "/" : " ");
699 printf("%*s%s", (int) strlen(type
), c
== 0 ? type
: "", c
== 0 ? "/" : " ");
701 printf("%*s%s %s:%u [priority=%u, weight=%u]\n",
702 (int) strlen(domain
), c
== 0 ? domain
: "",
707 r
= sd_bus_message_enter_container(reply
, 'a', "(iiay)");
709 return bus_log_parse_error(r
);
711 while ((r
= sd_bus_message_enter_container(reply
, 'r', "iiay")) > 0) {
712 _cleanup_free_
char *pretty
= NULL
;
716 assert_cc(sizeof(int) == sizeof(int32_t));
718 r
= sd_bus_message_read(reply
, "ii", &ifindex
, &family
);
720 return bus_log_parse_error(r
);
722 r
= sd_bus_message_read_array(reply
, 'y', &a
, &sz
);
724 return bus_log_parse_error(r
);
726 r
= sd_bus_message_exit_container(reply
);
728 return bus_log_parse_error(r
);
730 if (!IN_SET(family
, AF_INET
, AF_INET6
)) {
731 log_debug("%s: skipping entry with family %d (%s)", name
, family
, af_to_name(family
) ?: "unknown");
735 if (sz
!= FAMILY_ADDRESS_SIZE(family
)) {
736 log_error("%s: systemd-resolved returned address of invalid size %zu for family %s", name
, sz
, af_to_name(family
) ?: "unknown");
741 if (ifindex
> 0 && !if_indextoname(ifindex
, ifname
))
742 log_warning_errno(errno
, "Failed to resolve interface name for index %i: %m", ifindex
);
744 r
= in_addr_to_string(family
, a
, &pretty
);
746 return log_error_errno(r
, "Failed to print address for %s: %m", name
);
748 printf("%*s%s%s%s\n", (int) indent
, "", pretty
, isempty(ifname
) ? "" : "%s", ifname
);
751 return bus_log_parse_error(r
);
753 r
= sd_bus_message_exit_container(reply
);
755 return bus_log_parse_error(r
);
757 r
= sd_bus_message_read(reply
, "s", &canonical
);
759 return bus_log_parse_error(r
);
761 if (!streq(hostname
, canonical
))
762 printf("%*s(%s)\n", (int) indent
, "", canonical
);
764 r
= sd_bus_message_exit_container(reply
);
766 return bus_log_parse_error(r
);
771 return bus_log_parse_error(r
);
773 r
= sd_bus_message_exit_container(reply
);
775 return bus_log_parse_error(r
);
777 r
= sd_bus_message_enter_container(reply
, 'a', "ay");
779 return bus_log_parse_error(r
);
782 while ((r
= sd_bus_message_read_array(reply
, 'y', (const void**) &p
, &sz
)) > 0) {
783 _cleanup_free_
char *escaped
= NULL
;
785 escaped
= cescape_length(p
, sz
);
789 printf("%*s%s\n", (int) indent
, "", escaped
);
793 return bus_log_parse_error(r
);
795 r
= sd_bus_message_exit_container(reply
);
797 return bus_log_parse_error(r
);
799 r
= sd_bus_message_read(reply
, "ssst", &canonical_name
, &canonical_type
, &canonical_domain
, &flags
);
801 return bus_log_parse_error(r
);
803 canonical_name
= empty_to_null(canonical_name
);
804 canonical_type
= empty_to_null(canonical_type
);
806 if (!streq_ptr(name
, canonical_name
) ||
807 !streq_ptr(type
, canonical_type
) ||
808 !streq_ptr(domain
, canonical_domain
)) {
810 printf("%*s(", (int) indent
, "");
813 printf("%s/", canonical_name
);
815 printf("%s/", canonical_type
);
817 printf("%s)\n", canonical_domain
);
820 print_source(flags
, ts
);
825 static int resolve_openpgp(sd_bus
*bus
, const char *address
) {
826 const char *domain
, *full
;
828 _cleanup_free_
char *hashed
= NULL
;
833 domain
= strrchr(address
, '@');
835 log_error("Address does not contain '@': \"%s\"", address
);
837 } else if (domain
== address
|| domain
[1] == '\0') {
838 log_error("Address starts or ends with '@': \"%s\"", address
);
843 r
= string_hashsum_sha224(address
, domain
- 1 - address
, &hashed
);
845 return log_error_errno(r
, "Hashing failed: %m");
847 full
= strjoina(hashed
, "._openpgpkey.", domain
);
848 log_debug("Looking up \"%s\".", full
);
850 return resolve_record(bus
, full
,
851 arg_class
?: DNS_CLASS_IN
,
852 arg_type
?: DNS_TYPE_OPENPGPKEY
);
855 static int resolve_tlsa(sd_bus
*bus
, const char *address
) {
857 uint16_t port_num
= 443;
858 _cleanup_free_
char *full
= NULL
;
864 port
= strrchr(address
, ':');
866 r
= safe_atou16(port
+ 1, &port_num
);
867 if (r
< 0 || port_num
== 0)
868 return log_error_errno(r
, "Invalid port \"%s\".", port
+ 1);
870 address
= strndupa(address
, port
- address
);
873 r
= asprintf(&full
, "_%u.%s.%s",
875 service_family_to_string(arg_service_family
),
880 log_debug("Looking up \"%s\".", full
);
882 return resolve_record(bus
, full
,
883 arg_class
?: DNS_CLASS_IN
,
884 arg_type
?: DNS_TYPE_TLSA
);
887 static int show_statistics(sd_bus
*bus
) {
888 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
889 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
890 uint64_t n_current_transactions
, n_total_transactions
,
891 cache_size
, n_cache_hit
, n_cache_miss
,
892 n_dnssec_secure
, n_dnssec_insecure
, n_dnssec_bogus
, n_dnssec_indeterminate
;
893 int r
, dnssec_supported
;
897 r
= sd_bus_get_property_trivial(bus
,
898 "org.freedesktop.resolve1",
899 "/org/freedesktop/resolve1",
900 "org.freedesktop.resolve1.Manager",
906 return log_error_errno(r
, "Failed to get DNSSEC supported state: %s", bus_error_message(&error
, r
));
908 printf("DNSSEC supported by current servers: %s%s%s\n\n",
910 yes_no(dnssec_supported
),
913 r
= sd_bus_get_property(bus
,
914 "org.freedesktop.resolve1",
915 "/org/freedesktop/resolve1",
916 "org.freedesktop.resolve1.Manager",
917 "TransactionStatistics",
922 return log_error_errno(r
, "Failed to get transaction statistics: %s", bus_error_message(&error
, r
));
924 r
= sd_bus_message_read(reply
, "(tt)",
925 &n_current_transactions
,
926 &n_total_transactions
);
928 return bus_log_parse_error(r
);
930 printf("%sTransactions%s\n"
931 "Current Transactions: %" PRIu64
"\n"
932 " Total Transactions: %" PRIu64
"\n",
935 n_current_transactions
,
936 n_total_transactions
);
938 reply
= sd_bus_message_unref(reply
);
940 r
= sd_bus_get_property(bus
,
941 "org.freedesktop.resolve1",
942 "/org/freedesktop/resolve1",
943 "org.freedesktop.resolve1.Manager",
949 return log_error_errno(r
, "Failed to get cache statistics: %s", bus_error_message(&error
, r
));
951 r
= sd_bus_message_read(reply
, "(ttt)",
956 return bus_log_parse_error(r
);
958 printf("\n%sCache%s\n"
959 " Current Cache Size: %" PRIu64
"\n"
960 " Cache Hits: %" PRIu64
"\n"
961 " Cache Misses: %" PRIu64
"\n",
968 reply
= sd_bus_message_unref(reply
);
970 r
= sd_bus_get_property(bus
,
971 "org.freedesktop.resolve1",
972 "/org/freedesktop/resolve1",
973 "org.freedesktop.resolve1.Manager",
979 return log_error_errno(r
, "Failed to get DNSSEC statistics: %s", bus_error_message(&error
, r
));
981 r
= sd_bus_message_read(reply
, "(tttt)",
985 &n_dnssec_indeterminate
);
987 return bus_log_parse_error(r
);
989 printf("\n%sDNSSEC Verdicts%s\n"
990 " Secure: %" PRIu64
"\n"
991 " Insecure: %" PRIu64
"\n"
992 " Bogus: %" PRIu64
"\n"
993 " Indeterminate: %" PRIu64
"\n",
999 n_dnssec_indeterminate
);
1004 static int reset_statistics(sd_bus
*bus
) {
1005 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1008 r
= sd_bus_call_method(bus
,
1009 "org.freedesktop.resolve1",
1010 "/org/freedesktop/resolve1",
1011 "org.freedesktop.resolve1.Manager",
1017 return log_error_errno(r
, "Failed to reset statistics: %s", bus_error_message(&error
, r
));
1022 static int flush_caches(sd_bus
*bus
) {
1023 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1026 r
= sd_bus_call_method(bus
,
1027 "org.freedesktop.resolve1",
1028 "/org/freedesktop/resolve1",
1029 "org.freedesktop.resolve1.Manager",
1035 return log_error_errno(r
, "Failed to flush caches: %s", bus_error_message(&error
, r
));
1040 static int map_link_dns_servers(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
1041 char ***l
= userdata
;
1049 r
= sd_bus_message_enter_container(m
, 'a', "(iay)");
1059 r
= sd_bus_message_enter_container(m
, 'r', "iay");
1065 r
= sd_bus_message_read(m
, "i", &family
);
1069 r
= sd_bus_message_read_array(m
, 'y', &a
, &sz
);
1073 r
= sd_bus_message_exit_container(m
);
1077 if (!IN_SET(family
, AF_INET
, AF_INET6
)) {
1078 log_debug("Unexpected family, ignoring.");
1082 if (sz
!= FAMILY_ADDRESS_SIZE(family
)) {
1083 log_debug("Address size mismatch, ignoring.");
1087 r
= in_addr_to_string(family
, a
, &pretty
);
1091 r
= strv_consume(l
, pretty
);
1096 r
= sd_bus_message_exit_container(m
);
1103 static int map_link_domains(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
1104 char ***l
= userdata
;
1112 r
= sd_bus_message_enter_container(m
, 'a', "(sb)");
1121 r
= sd_bus_message_read(m
, "(sb)", &domain
, &route_only
);
1128 pretty
= strappend("~", domain
);
1130 pretty
= strdup(domain
);
1134 r
= strv_consume(l
, pretty
);
1139 r
= sd_bus_message_exit_container(m
);
1146 static int status_ifindex(sd_bus
*bus
, int ifindex
, const char *name
, bool *empty_line
) {
1149 uint64_t scopes_mask
;
1156 int dnssec_supported
;
1159 static const struct bus_properties_map property_map
[] = {
1160 { "ScopesMask", "t", NULL
, offsetof(struct link_info
, scopes_mask
) },
1161 { "DNS", "a(iay)", map_link_dns_servers
, offsetof(struct link_info
, dns
) },
1162 { "Domains", "a(sb)", map_link_domains
, offsetof(struct link_info
, domains
) },
1163 { "LLMNR", "s", NULL
, offsetof(struct link_info
, llmnr
) },
1164 { "MulticastDNS", "s", NULL
, offsetof(struct link_info
, mdns
) },
1165 { "DNSSEC", "s", NULL
, offsetof(struct link_info
, dnssec
) },
1166 { "DNSSECNegativeTrustAnchors", "as", NULL
, offsetof(struct link_info
, ntas
) },
1167 { "DNSSECSupported", "b", NULL
, offsetof(struct link_info
, dnssec_supported
) },
1171 _cleanup_free_
char *ifi
= NULL
, *p
= NULL
;
1172 char ifname
[IF_NAMESIZE
] = "";
1177 assert(ifindex
> 0);
1181 if (!if_indextoname(ifindex
, ifname
))
1182 return log_error_errno(errno
, "Failed to resolve interface name for %i: %m", ifindex
);
1187 if (asprintf(&ifi
, "%i", ifindex
) < 0)
1190 r
= sd_bus_path_encode("/org/freedesktop/resolve1/link", ifi
, &p
);
1194 r
= bus_map_all_properties(bus
,
1195 "org.freedesktop.resolve1",
1200 log_error_errno(r
, "Failed to get link data for %i: %m", ifindex
);
1204 pager_open(arg_no_pager
, false);
1207 fputc('\n', stdout
);
1209 printf("%sLink %i (%s)%s\n",
1210 ansi_highlight(), ifindex
, name
, ansi_normal());
1212 if (link_info
.scopes_mask
== 0)
1213 printf(" Current Scopes: none\n");
1215 printf(" Current Scopes:%s%s%s%s%s\n",
1216 link_info
.scopes_mask
& SD_RESOLVED_DNS
? " DNS" : "",
1217 link_info
.scopes_mask
& SD_RESOLVED_LLMNR_IPV4
? " LLMNR/IPv4" : "",
1218 link_info
.scopes_mask
& SD_RESOLVED_LLMNR_IPV6
? " LLMNR/IPv6" : "",
1219 link_info
.scopes_mask
& SD_RESOLVED_MDNS_IPV4
? " mDNS/IPv4" : "",
1220 link_info
.scopes_mask
& SD_RESOLVED_MDNS_IPV6
? " mDNS/IPv6" : "");
1222 printf(" LLMNR setting: %s\n"
1223 "MulticastDNS setting: %s\n"
1224 " DNSSEC setting: %s\n"
1225 " DNSSEC supported: %s\n",
1226 strna(link_info
.llmnr
),
1227 strna(link_info
.mdns
),
1228 strna(link_info
.dnssec
),
1229 yes_no(link_info
.dnssec_supported
));
1231 STRV_FOREACH(i
, link_info
.dns
) {
1233 i
== link_info
.dns
? "DNS Servers:" : " ",
1237 STRV_FOREACH(i
, link_info
.domains
) {
1239 i
== link_info
.domains
? "DNS Domain:" : " ",
1243 STRV_FOREACH(i
, link_info
.ntas
) {
1245 i
== link_info
.ntas
? "DNSSEC NTA:" : " ",
1254 strv_free(link_info
.dns
);
1255 strv_free(link_info
.domains
);
1256 free(link_info
.llmnr
);
1257 free(link_info
.mdns
);
1258 free(link_info
.dnssec
);
1259 strv_free(link_info
.ntas
);
1263 static int map_global_dns_servers(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
1264 char ***l
= userdata
;
1272 r
= sd_bus_message_enter_container(m
, 'a', "(iiay)");
1279 int family
, ifindex
;
1282 r
= sd_bus_message_enter_container(m
, 'r', "iiay");
1288 r
= sd_bus_message_read(m
, "ii", &ifindex
, &family
);
1292 r
= sd_bus_message_read_array(m
, 'y', &a
, &sz
);
1296 r
= sd_bus_message_exit_container(m
);
1300 if (ifindex
!= 0) /* only show the global ones here */
1303 if (!IN_SET(family
, AF_INET
, AF_INET6
)) {
1304 log_debug("Unexpected family, ignoring.");
1308 if (sz
!= FAMILY_ADDRESS_SIZE(family
)) {
1309 log_debug("Address size mismatch, ignoring.");
1313 r
= in_addr_to_string(family
, a
, &pretty
);
1317 r
= strv_consume(l
, pretty
);
1322 r
= sd_bus_message_exit_container(m
);
1329 static int map_global_domains(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
1330 char ***l
= userdata
;
1338 r
= sd_bus_message_enter_container(m
, 'a', "(isb)");
1344 int route_only
, ifindex
;
1347 r
= sd_bus_message_read(m
, "(isb)", &ifindex
, &domain
, &route_only
);
1353 if (ifindex
!= 0) /* only show the global ones here */
1357 pretty
= strappend("~", domain
);
1359 pretty
= strdup(domain
);
1363 r
= strv_consume(l
, pretty
);
1368 r
= sd_bus_message_exit_container(m
);
1375 static int status_global(sd_bus
*bus
, bool *empty_line
) {
1377 struct global_info
{
1383 static const struct bus_properties_map property_map
[] = {
1384 { "DNS", "a(iiay)", map_global_dns_servers
, offsetof(struct global_info
, dns
) },
1385 { "Domains", "a(isb)", map_global_domains
, offsetof(struct global_info
, domains
) },
1386 { "DNSSECNegativeTrustAnchors", "as", NULL
, offsetof(struct global_info
, ntas
) },
1396 r
= bus_map_all_properties(bus
,
1397 "org.freedesktop.resolve1",
1398 "/org/freedesktop/resolve1",
1402 log_error_errno(r
, "Failed to get global data: %m");
1406 if (strv_isempty(global_info
.dns
) && strv_isempty(global_info
.domains
) && strv_isempty(global_info
.ntas
)) {
1411 pager_open(arg_no_pager
, false);
1413 printf("%sGlobal%s\n", ansi_highlight(), ansi_normal());
1414 STRV_FOREACH(i
, global_info
.dns
) {
1416 i
== global_info
.dns
? "DNS Servers:" : " ",
1420 STRV_FOREACH(i
, global_info
.domains
) {
1422 i
== global_info
.domains
? "DNS Domain:" : " ",
1426 strv_sort(global_info
.ntas
);
1427 STRV_FOREACH(i
, global_info
.ntas
) {
1429 i
== global_info
.ntas
? "DNSSEC NTA:" : " ",
1438 strv_free(global_info
.dns
);
1439 strv_free(global_info
.domains
);
1440 strv_free(global_info
.ntas
);
1445 static int status_all(sd_bus
*bus
) {
1446 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
, *reply
= NULL
;
1447 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
1448 sd_netlink_message
*i
;
1449 bool empty_line
= false;
1454 r
= status_global(bus
, &empty_line
);
1458 r
= sd_netlink_open(&rtnl
);
1460 return log_error_errno(r
, "Failed to connect to netlink: %m");
1462 r
= sd_rtnl_message_new_link(rtnl
, &req
, RTM_GETLINK
, 0);
1464 return rtnl_log_create_error(r
);
1466 r
= sd_netlink_message_request_dump(req
, true);
1468 return rtnl_log_create_error(r
);
1470 r
= sd_netlink_call(rtnl
, req
, 0, &reply
);
1472 return log_error_errno(r
, "Failed to enumerate links: %m");
1475 for (i
= reply
; i
; i
= sd_netlink_message_next(i
)) {
1480 q
= sd_netlink_message_get_type(i
, &type
);
1482 return rtnl_log_parse_error(q
);
1484 if (type
!= RTM_NEWLINK
)
1487 q
= sd_rtnl_message_link_get_ifindex(i
, &ifindex
);
1489 return rtnl_log_parse_error(q
);
1491 if (ifindex
== LOOPBACK_IFINDEX
)
1494 q
= sd_netlink_message_read_string(i
, IFLA_IFNAME
, &name
);
1496 return rtnl_log_parse_error(q
);
1498 q
= status_ifindex(bus
, ifindex
, name
, &empty_line
);
1499 if (q
< 0 && r
>= 0)
1506 static void help_protocol_types(void) {
1508 puts("Known protocol types:");
1509 puts("dns\nllmnr\nllmnr-ipv4\nllmnr-ipv6");
1512 static void help_dns_types(void) {
1517 puts("Known DNS RR types:");
1518 for (i
= 0; i
< _DNS_TYPE_MAX
; i
++) {
1519 t
= dns_type_to_string(i
);
1525 static void help_dns_classes(void) {
1530 puts("Known DNS RR classes:");
1531 for (i
= 0; i
< _DNS_CLASS_MAX
; i
++) {
1532 t
= dns_class_to_string(i
);
1538 static void help(void) {
1539 printf("%1$s [OPTIONS...] HOSTNAME|ADDRESS...\n"
1540 "%1$s [OPTIONS...] --service [[NAME] TYPE] DOMAIN\n"
1541 "%1$s [OPTIONS...] --openpgp EMAIL@DOMAIN...\n"
1542 "%1$s [OPTIONS...] --statistics\n"
1543 "%1$s [OPTIONS...] --reset-statistics\n"
1545 "Resolve domain names, IPv4 and IPv6 addresses, DNS resource records, and services.\n\n"
1546 " -h --help Show this help\n"
1547 " --version Show package version\n"
1548 " --no-pager Do not pipe output into a pager\n"
1549 " -4 Resolve IPv4 addresses\n"
1550 " -6 Resolve IPv6 addresses\n"
1551 " -i --interface=INTERFACE Look on interface\n"
1552 " -p --protocol=PROTO|help Look via protocol\n"
1553 " -t --type=TYPE|help Query RR with DNS type\n"
1554 " -c --class=CLASS|help Query RR with DNS class\n"
1555 " --service Resolve service (SRV)\n"
1556 " --service-address=BOOL Resolve address for services (default: yes)\n"
1557 " --service-txt=BOOL Resolve TXT records for services (default: yes)\n"
1558 " --openpgp Query OpenPGP public key\n"
1559 " --tlsa Query TLS public key\n"
1560 " --cname=BOOL Follow CNAME redirects (default: yes)\n"
1561 " --search=BOOL Use search domains for single-label names\n"
1563 " --raw[=payload|packet] Dump the answer as binary data\n"
1564 " --legend=BOOL Print headers and additional info (default: yes)\n"
1565 " --statistics Show resolver statistics\n"
1566 " --reset-statistics Reset resolver statistics\n"
1567 " --status Show link and server status\n"
1568 " --flush-caches Flush all local DNS caches\n"
1569 , program_invocation_short_name
);
1572 static int parse_argv(int argc
, char *argv
[]) {
1574 ARG_VERSION
= 0x100,
1578 ARG_SERVICE_ADDRESS
,
1585 ARG_RESET_STATISTICS
,
1591 static const struct option options
[] = {
1592 { "help", no_argument
, NULL
, 'h' },
1593 { "version", no_argument
, NULL
, ARG_VERSION
},
1594 { "type", required_argument
, NULL
, 't' },
1595 { "class", required_argument
, NULL
, 'c' },
1596 { "legend", required_argument
, NULL
, ARG_LEGEND
},
1597 { "interface", required_argument
, NULL
, 'i' },
1598 { "protocol", required_argument
, NULL
, 'p' },
1599 { "cname", required_argument
, NULL
, ARG_CNAME
},
1600 { "service", no_argument
, NULL
, ARG_SERVICE
},
1601 { "service-address", required_argument
, NULL
, ARG_SERVICE_ADDRESS
},
1602 { "service-txt", required_argument
, NULL
, ARG_SERVICE_TXT
},
1603 { "openpgp", no_argument
, NULL
, ARG_OPENPGP
},
1604 { "tlsa", optional_argument
, NULL
, ARG_TLSA
},
1605 { "raw", optional_argument
, NULL
, ARG_RAW
},
1606 { "search", required_argument
, NULL
, ARG_SEARCH
},
1607 { "statistics", no_argument
, NULL
, ARG_STATISTICS
, },
1608 { "reset-statistics", no_argument
, NULL
, ARG_RESET_STATISTICS
},
1609 { "status", no_argument
, NULL
, ARG_STATUS
},
1610 { "flush-caches", no_argument
, NULL
, ARG_FLUSH_CACHES
},
1611 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
1620 while ((c
= getopt_long(argc
, argv
, "h46i:t:c:p:", options
, NULL
)) >= 0)
1625 return 0; /* done */;
1631 arg_family
= AF_INET
;
1635 arg_family
= AF_INET6
;
1641 if (parse_ifindex(optarg
, &ifi
) >= 0)
1644 ifi
= if_nametoindex(optarg
);
1646 return log_error_errno(errno
, "Unknown interface %s: %m", optarg
);
1655 if (streq(optarg
, "help")) {
1660 r
= dns_type_from_string(optarg
);
1662 log_error("Failed to parse RR record type %s", optarg
);
1665 arg_type
= (uint16_t) r
;
1666 assert((int) arg_type
== r
);
1668 arg_mode
= MODE_RESOLVE_RECORD
;
1672 if (streq(optarg
, "help")) {
1677 r
= dns_class_from_string(optarg
);
1679 log_error("Failed to parse RR record class %s", optarg
);
1682 arg_class
= (uint16_t) r
;
1683 assert((int) arg_class
== r
);
1688 r
= parse_boolean(optarg
);
1690 return log_error_errno(r
, "Failed to parse --legend= argument");
1696 if (streq(optarg
, "help")) {
1697 help_protocol_types();
1699 } else if (streq(optarg
, "dns"))
1700 arg_flags
|= SD_RESOLVED_DNS
;
1701 else if (streq(optarg
, "llmnr"))
1702 arg_flags
|= SD_RESOLVED_LLMNR
;
1703 else if (streq(optarg
, "llmnr-ipv4"))
1704 arg_flags
|= SD_RESOLVED_LLMNR_IPV4
;
1705 else if (streq(optarg
, "llmnr-ipv6"))
1706 arg_flags
|= SD_RESOLVED_LLMNR_IPV6
;
1708 log_error("Unknown protocol specifier: %s", optarg
);
1715 arg_mode
= MODE_RESOLVE_SERVICE
;
1719 arg_mode
= MODE_RESOLVE_OPENPGP
;
1723 arg_mode
= MODE_RESOLVE_TLSA
;
1724 arg_service_family
= service_family_from_string(optarg
);
1725 if (arg_service_family
< 0) {
1726 log_error("Unknown service family \"%s\".", optarg
);
1733 log_error("Refusing to write binary data to tty.");
1737 if (optarg
== NULL
|| streq(optarg
, "payload"))
1738 arg_raw
= RAW_PAYLOAD
;
1739 else if (streq(optarg
, "packet"))
1740 arg_raw
= RAW_PACKET
;
1742 log_error("Unknown --raw specifier \"%s\".", optarg
);
1750 r
= parse_boolean(optarg
);
1752 return log_error_errno(r
, "Failed to parse --cname= argument.");
1753 SET_FLAG(arg_flags
, SD_RESOLVED_NO_CNAME
, r
== 0);
1756 case ARG_SERVICE_ADDRESS
:
1757 r
= parse_boolean(optarg
);
1759 return log_error_errno(r
, "Failed to parse --service-address= argument.");
1760 SET_FLAG(arg_flags
, SD_RESOLVED_NO_ADDRESS
, r
== 0);
1763 case ARG_SERVICE_TXT
:
1764 r
= parse_boolean(optarg
);
1766 return log_error_errno(r
, "Failed to parse --service-txt= argument.");
1767 SET_FLAG(arg_flags
, SD_RESOLVED_NO_TXT
, r
== 0);
1771 r
= parse_boolean(optarg
);
1773 return log_error_errno(r
, "Failed to parse --search argument.");
1774 SET_FLAG(arg_flags
, SD_RESOLVED_NO_SEARCH
, r
== 0);
1777 case ARG_STATISTICS
:
1778 arg_mode
= MODE_STATISTICS
;
1781 case ARG_RESET_STATISTICS
:
1782 arg_mode
= MODE_RESET_STATISTICS
;
1785 case ARG_FLUSH_CACHES
:
1786 arg_mode
= MODE_FLUSH_CACHES
;
1790 arg_mode
= MODE_STATUS
;
1794 arg_no_pager
= true;
1801 assert_not_reached("Unhandled option");
1804 if (arg_type
== 0 && arg_class
!= 0) {
1805 log_error("--class= may only be used in conjunction with --type=.");
1809 if (arg_type
!= 0 && arg_mode
== MODE_RESOLVE_SERVICE
) {
1810 log_error("--service and --type= may not be combined.");
1814 if (arg_type
!= 0 && arg_class
== 0)
1815 arg_class
= DNS_CLASS_IN
;
1817 if (arg_class
!= 0 && arg_type
== 0)
1818 arg_type
= DNS_TYPE_A
;
1820 return 1 /* work to do */;
1823 int main(int argc
, char **argv
) {
1824 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1827 log_parse_environment();
1830 r
= parse_argv(argc
, argv
);
1834 r
= sd_bus_open_system(&bus
);
1836 log_error_errno(r
, "sd_bus_open_system: %m");
1842 case MODE_RESOLVE_HOST
:
1843 if (optind
>= argc
) {
1844 log_error("No arguments passed.");
1849 while (argv
[optind
]) {
1850 int family
, ifindex
, k
;
1851 union in_addr_union a
;
1853 if (startswith(argv
[optind
], "dns:"))
1854 k
= resolve_rfc4501(bus
, argv
[optind
]);
1856 k
= in_addr_ifindex_from_string_auto(argv
[optind
], &family
, &a
, &ifindex
);
1858 k
= resolve_address(bus
, family
, &a
, ifindex
);
1860 k
= resolve_host(bus
, argv
[optind
]);
1870 case MODE_RESOLVE_RECORD
:
1871 if (optind
>= argc
) {
1872 log_error("No arguments passed.");
1877 while (argv
[optind
]) {
1880 k
= resolve_record(bus
, argv
[optind
], arg_class
, arg_type
);
1888 case MODE_RESOLVE_SERVICE
:
1889 if (argc
< optind
+ 1) {
1890 log_error("Domain specification required.");
1894 } else if (argc
== optind
+ 1)
1895 r
= resolve_service(bus
, NULL
, NULL
, argv
[optind
]);
1896 else if (argc
== optind
+ 2)
1897 r
= resolve_service(bus
, NULL
, argv
[optind
], argv
[optind
+1]);
1898 else if (argc
== optind
+ 3)
1899 r
= resolve_service(bus
, argv
[optind
], argv
[optind
+1], argv
[optind
+2]);
1901 log_error("Too many arguments.");
1908 case MODE_RESOLVE_OPENPGP
:
1909 if (argc
< optind
+ 1) {
1910 log_error("E-mail address required.");
1917 while (optind
< argc
) {
1920 k
= resolve_openpgp(bus
, argv
[optind
++]);
1926 case MODE_RESOLVE_TLSA
:
1927 if (argc
< optind
+ 1) {
1928 log_error("Domain name required.");
1935 while (optind
< argc
) {
1938 k
= resolve_tlsa(bus
, argv
[optind
++]);
1944 case MODE_STATISTICS
:
1945 if (argc
> optind
) {
1946 log_error("Too many arguments.");
1951 r
= show_statistics(bus
);
1954 case MODE_RESET_STATISTICS
:
1955 if (argc
> optind
) {
1956 log_error("Too many arguments.");
1961 r
= reset_statistics(bus
);
1964 case MODE_FLUSH_CACHES
:
1965 if (argc
> optind
) {
1966 log_error("Too many arguments.");
1971 r
= flush_caches(bus
);
1976 if (argc
> optind
) {
1978 bool empty_line
= false;
1981 STRV_FOREACH(ifname
, argv
+ optind
) {
1984 q
= parse_ifindex(argv
[optind
], &ifindex
);
1986 ifindex
= if_nametoindex(argv
[optind
]);
1988 log_error_errno(errno
, "Failed to resolve interface name: %s", argv
[optind
]);
1993 q
= status_ifindex(bus
, ifindex
, NULL
, &empty_line
);
1994 if (q
< 0 && r
>= 0)
1998 r
= status_all(bus
);
2006 return r
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;