summaryrefslogtreecommitdiffstats
path: root/src/resolve/resolved-conf.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-09-04 06:23:39 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-09-04 13:05:58 +0200
commit7314b39746cdc30a9e9bfe96d4b55da650428f27 (patch)
treeb335728dd65d2051dc420431eda4a644cbbc3b8b /src/resolve/resolved-conf.c
parentresolve: Manager::dns_stub_listener_mode is not relevant to extra stub listeners (diff)
downloadsystemd-7314b39746cdc30a9e9bfe96d4b55da650428f27.tar.xz
systemd-7314b39746cdc30a9e9bfe96d4b55da650428f27.zip
resolve: set DNS_STUB_LISTENER_YES if no protocol is specified in DNSStubListenExtra=
Diffstat (limited to 'src/resolve/resolved-conf.c')
-rw-r--r--src/resolve/resolved-conf.c93
1 files changed, 27 insertions, 66 deletions
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index 3b2b4d2063..1c934b34cf 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -444,10 +444,8 @@ int config_parse_dns_stub_listener_extra(
void *data,
void *userdata) {
- _cleanup_free_ DNSStubListenerExtra *udp = NULL, *tcp = NULL;
- _cleanup_free_ char *word = NULL;
+ _cleanup_free_ DNSStubListenerExtra *stub = NULL;
Manager *m = userdata;
- bool both = false;
const char *p;
int r;
@@ -461,78 +459,41 @@ int config_parse_dns_stub_listener_extra(
return 0;
}
- p = rvalue;
- r = extract_first_word(&p, &word, ":", 0);
- if (r == -ENOMEM)
+ r = dns_stub_extra_new(&stub);
+ if (r < 0)
return log_oom();
- if (r <= 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid DNSStubListenExtra='%s', ignoring assignment", rvalue);
- return 0;
- }
- /* First look for udp/tcp. If not specified then turn both TCP and UDP */
- if (!STR_IN_SET(word, "tcp", "udp")) {
- both = true;
- p = rvalue;
- }
-
- if (streq(word, "tcp") || both) {
- r = dns_stub_extra_new(&tcp);
- if (r < 0)
- return log_oom();
-
- tcp->mode = DNS_STUB_LISTENER_TCP;
- }
-
- if (streq(word, "udp") || both) {
- r = dns_stub_extra_new(&udp);
- if (r < 0)
- return log_oom();
-
- udp->mode = DNS_STUB_LISTENER_UDP;
- }
-
- if (tcp) {
- r = socket_addr_port_from_string_auto(p, 53, &tcp->address);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse address in DNSStubListenExtra='%s', ignoring", rvalue);
- return 0;
- }
- }
-
- if (udp) {
- r = socket_addr_port_from_string_auto(p, 53, &udp->address);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse address in DNSStubListenExtra='%s', ignoring", rvalue);
- return 0;
+ p = startswith(rvalue, "udp:");
+ if (p)
+ stub->mode = DNS_STUB_LISTENER_UDP;
+ else {
+ p = startswith(rvalue, "tcp:");
+ if (p)
+ stub->mode = DNS_STUB_LISTENER_TCP;
+ else {
+ stub->mode = DNS_STUB_LISTENER_YES;
+ p = rvalue;
}
}
- if (tcp) {
- r = ordered_set_ensure_put(&m->dns_extra_stub_listeners, &dns_stub_listener_extra_hash_ops, tcp);
- if (r < 0) {
- if (r == -ENOMEM)
- return log_oom();
-
- log_warning_errno(r, "Failed to store TCP DNSStubListenExtra='%s', ignoring assignment: %m", rvalue);
- return 0;
- }
+ r = socket_addr_port_from_string_auto(p, 53, &stub->address);
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Failed to parse address in %s=%s, ignoring assignment: %m",
+ lvalue, rvalue);
+ return 0;
}
- if (udp) {
- r = ordered_set_ensure_put(&m->dns_extra_stub_listeners, &dns_stub_listener_extra_hash_ops, udp);
- if (r < 0) {
- if (r == -ENOMEM)
- return log_oom();
-
- log_warning_errno(r, "Failed to store UDP DNSStubListenExtra='%s', ignoring assignment: %m", rvalue);
- return 0;
- }
+ r = ordered_set_ensure_put(&m->dns_extra_stub_listeners, &dns_stub_listener_extra_hash_ops, stub);
+ if (r == -ENOMEM)
+ return log_oom();
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Failed to store %s=%s, ignoring assignment: %m", lvalue, rvalue);
+ return 0;
}
- TAKE_PTR(tcp);
- TAKE_PTR(udp);
+ TAKE_PTR(stub);
return 0;
}