(int) strlen(name), c == 0 ? name : "", c == 0 ? ":" : " ",
canonical);
- if (c == 0) {
- log_error("%s: no addresses found", name);
- return -ESRCH;
- }
+ if (c == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "%s: no addresses found", name);
print_source(flags, ts);
if (r < 0)
return bus_log_parse_error(r);
- if (c == 0) {
- log_error("%s: no names found", pretty);
- return -ESRCH;
- }
+ if (c == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "%s: no names found", pretty);
print_source(flags, ts);
if (r < 0)
return r;
+ strv_sort(*l);
+
return 0;
}
size_t our_len = utf8_console_width(*i); /* This returns -1 on invalid utf-8 (which shouldn't happen).
* If that happens, we'll just print one item per line. */
- if (position <= indent || SIZE_ADD(SIZE_ADD(position, 1), our_len) < cols) {
+ if (position <= indent || size_add(size_add(position, 1), our_len) < cols) {
printf(" %s", *i);
- position = SIZE_ADD(SIZE_ADD(position, 1), our_len);
+ position = size_add(size_add(position, 1), our_len);
} else {
printf("\n%*s%s", indent, "", *i);
- position = SIZE_ADD(our_len, indent);
+ position = size_add(our_len, indent);
}
}
r = table_add_many(table,
TABLE_STRING, prefix,
- TABLE_STRV, l);
+ TABLE_STRV_WRAPPED, l);
if (r < 0)
return table_log_add_error(r);
return 0;
}
+static int strv_extend_extended_bool(char ***strv, const char *name, const char *value) {
+ int r;
+
+ if (value) {
+ r = parse_boolean(value);
+ if (r >= 0)
+ return strv_extendf(strv, "%s%s", plus_minus(r), name);
+ }
+
+ return strv_extendf(strv, "%s=%s", name, value ?: "???");
+}
+
+static char** link_protocol_status(const LinkInfo *info) {
+ _cleanup_strv_free_ char **s = NULL;
+
+ if (strv_extendf(&s, "%sDefaultRoute", plus_minus(info->default_route)) < 0)
+ return NULL;
+
+ if (strv_extend_extended_bool(&s, "LLMNR", info->llmnr) < 0)
+ return NULL;
+
+ if (strv_extend_extended_bool(&s, "mDNS", info->mdns) < 0)
+ return NULL;
+
+ if (strv_extend_extended_bool(&s, "DNSOverTLS", info->dns_over_tls) < 0)
+ return NULL;
+
+ if (strv_extendf(&s, "DNSSEC=%s/%s",
+ info->dnssec ?: "???",
+ info->dnssec_supported ? "supported" : "unsupported") < 0)
+ return NULL;
+
+ return TAKE_PTR(s);
+}
+
+static char** global_protocol_status(const GlobalInfo *info) {
+ _cleanup_strv_free_ char **s = NULL;
+
+ if (strv_extend_extended_bool(&s, "LLMNR", info->llmnr) < 0)
+ return NULL;
+
+ if (strv_extend_extended_bool(&s, "mDNS", info->mdns) < 0)
+ return NULL;
+
+ if (strv_extend_extended_bool(&s, "DNSOverTLS", info->dns_over_tls) < 0)
+ return NULL;
+
+ if (strv_extendf(&s, "DNSSEC=%s/%s",
+ info->dnssec ?: "???",
+ info->dnssec_supported ? "supported" : "unsupported") < 0)
+ return NULL;
+
+ return TAKE_PTR(s);
+}
+
static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode mode, bool *empty_line) {
static const struct bus_properties_map property_map[] = {
{ "ScopesMask", "t", NULL, offsetof(LinkInfo, scopes_mask) },
{ "MulticastDNS", "s", NULL, offsetof(LinkInfo, mdns) },
{ "DNSOverTLS", "s", NULL, offsetof(LinkInfo, dns_over_tls) },
{ "DNSSEC", "s", NULL, offsetof(LinkInfo, dnssec) },
- { "DNSSECNegativeTrustAnchors", "as", NULL, offsetof(LinkInfo, ntas) },
+ { "DNSSECNegativeTrustAnchors", "as", bus_map_strv_sort, offsetof(LinkInfo, ntas) },
{ "DNSSECSupported", "b", NULL, offsetof(LinkInfo, dnssec_supported) },
{}
};
if (r < 0)
return table_log_add_error(r);
+ _cleanup_strv_free_ char **pstatus = link_protocol_status(&link_info);
+ if (!pstatus)
+ return log_oom();
+
r = table_add_many(table,
- TABLE_STRING, "DefaultRoute setting:",
- TABLE_BOOLEAN, link_info.default_route,
- TABLE_STRING, "LLMNR setting:",
- TABLE_STRING, strna(link_info.llmnr),
- TABLE_STRING, "MulticastDNS setting:",
- TABLE_STRING, strna(link_info.mdns),
- TABLE_STRING, "DNSOverTLS setting:",
- TABLE_STRING, strna(link_info.dns_over_tls),
- TABLE_STRING, "DNSSEC setting:",
- TABLE_STRING, strna(link_info.dnssec),
- TABLE_STRING, "DNSSEC supported:",
- TABLE_BOOLEAN, link_info.dnssec_supported);
+ TABLE_STRING, "Protocols:",
+ TABLE_STRV_WRAPPED, pstatus);
if (r < 0)
return table_log_add_error(r);
if (r < 0)
return r;
+ strv_sort(*l);
+
return 0;
}
{ "CurrentDNSServer", "(iiay)", map_global_current_dns_server, offsetof(GlobalInfo, current_dns) },
{ "CurrentDNSServerEx", "(iiayqs)", map_global_current_dns_server_ex, offsetof(GlobalInfo, current_dns_ex) },
{ "Domains", "a(isb)", map_global_domains, offsetof(GlobalInfo, domains) },
- { "DNSSECNegativeTrustAnchors", "as", NULL, offsetof(GlobalInfo, ntas) },
+ { "DNSSECNegativeTrustAnchors", "as", bus_map_strv_sort, offsetof(GlobalInfo, ntas) },
{ "LLMNR", "s", NULL, offsetof(GlobalInfo, llmnr) },
{ "MulticastDNS", "s", NULL, offsetof(GlobalInfo, mdns) },
{ "DNSOverTLS", "s", NULL, offsetof(GlobalInfo, dns_over_tls) },
table_set_header(table, false);
+ _cleanup_strv_free_ char **pstatus = global_protocol_status(&global_info);
+ if (!pstatus)
+ return log_oom();
+
r = table_add_many(table,
- TABLE_STRING, "LLMNR setting:",
+ TABLE_STRING, "Protocols:",
TABLE_SET_ALIGN_PERCENT, 100,
- TABLE_STRING, strna(global_info.llmnr),
- TABLE_STRING, "MulticastDNS setting:",
- TABLE_STRING, strna(global_info.mdns),
- TABLE_STRING, "DNSOverTLS setting:",
- TABLE_STRING, strna(global_info.dns_over_tls),
- TABLE_STRING, "DNSSEC setting:",
- TABLE_STRING, strna(global_info.dnssec),
- TABLE_STRING, "DNSSEC supported:",
- TABLE_BOOLEAN, global_info.dnssec_supported);
+ TABLE_STRV_WRAPPED, pstatus);
if (r < 0)
return table_log_add_error(r);
r = dns_name_is_valid(n);
if (r < 0)
return log_error_errno(r, "Failed to validate specified domain %s: %m", n);
- if (r == 0) {
- log_error("Domain not valid: %s", n);
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Domain not valid: %s",
+ n);
r = sd_bus_message_append(req, "(sb)", n, **p == '~');
if (r < 0)
r = dns_name_is_valid(*p);
if (r < 0)
return log_error_errno(r, "Failed to validate specified domain %s: %m", *p);
- if (r == 0) {
- log_error("Domain not valid: %s", *p);
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Domain not valid: %s",
+ *p);
}
r = call_nta(bus, clear ? NULL : argv + 2, bus_resolve_mgr, &error);