resolvectl: change syntax to use verb_dispatch()
This makes `resolvectl` use the verb style command line, e.g., `resolvectl status` or `resolvectl tlsa tcp fedoraproject.org:443`. For compatibility, if the invocation name is `systemd-resolve`, then it accepts the old syntax, e.g. `systemd-resolve --status`.
This commit is contained in:
parent
c2e84cab3a
commit
a7a4c60a25
|
@ -44,8 +44,6 @@ static int parse_nameserver(const char *string) {
|
|||
|
||||
for (;;) {
|
||||
_cleanup_free_ char *word = NULL;
|
||||
struct in_addr_data data, *n;
|
||||
int ifindex = 0;
|
||||
|
||||
r = extract_first_word(&string, &word, NULL, 0);
|
||||
if (r < 0)
|
||||
|
@ -53,27 +51,8 @@ static int parse_nameserver(const char *string) {
|
|||
if (r == 0)
|
||||
break;
|
||||
|
||||
r = in_addr_ifindex_from_string_auto(word, &data.family, &data.address, &ifindex);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse name server '%s': %m", word);
|
||||
|
||||
if (ifindex > 0 && ifindex != arg_ifindex) {
|
||||
log_error("Name server interface '%s' does not match selected interface: %m", word);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Some superficial filtering */
|
||||
if (in_addr_is_null(data.family, &data.address))
|
||||
continue;
|
||||
if (data.family == AF_INET && data.address.in.s_addr == htobe32(INADDR_DNS_STUB)) /* resolved's own stub? */
|
||||
continue;
|
||||
|
||||
n = reallocarray(arg_set_dns, arg_n_set_dns + 1, sizeof(struct in_addr_data));
|
||||
if (!n)
|
||||
if (strv_push(&arg_set_dns, word) < 0)
|
||||
return log_oom();
|
||||
arg_set_dns = n;
|
||||
|
||||
arg_set_dns[arg_n_set_dns++] = data;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -93,14 +72,6 @@ static int parse_search_domain(const char *string) {
|
|||
if (r == 0)
|
||||
break;
|
||||
|
||||
r = dns_name_is_valid(word);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to validate specified domain '%s': %m", word);
|
||||
if (r == 0) {
|
||||
log_error("Domain not valid: %s", word);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (strv_push(&arg_set_domain, word) < 0)
|
||||
return log_oom();
|
||||
|
||||
|
@ -252,6 +223,7 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
arg_ifindex = ifi;
|
||||
arg_ifname = iface;
|
||||
}
|
||||
|
||||
if (arg_mode == MODE_SET_LINK) {
|
||||
|
@ -302,7 +274,7 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
|
|||
} else if (type == TYPE_PRIVATE)
|
||||
log_debug("Private DNS server data not supported, ignoring.");
|
||||
|
||||
if (arg_n_set_dns == 0) {
|
||||
if (!arg_set_dns) {
|
||||
log_error("No DNS servers specified, refusing operation.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,6 +5,7 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
extern int arg_ifindex;
|
||||
extern const char *arg_ifname;
|
||||
extern bool arg_ifindex_permissive;
|
||||
|
||||
typedef enum ExecutionMode {
|
||||
|
@ -25,6 +26,5 @@ typedef enum ExecutionMode {
|
|||
|
||||
extern ExecutionMode arg_mode;
|
||||
|
||||
extern struct in_addr_data *arg_set_dns;
|
||||
extern size_t arg_n_set_dns;
|
||||
extern char **arg_set_dns;
|
||||
extern char **arg_set_domain;
|
||||
|
|
Loading…
Reference in a new issue