diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-09-04 13:23:39 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-09-04 20:05:58 +0900 |
commit | 7314b39746cdc30a9e9bfe96d4b55da650428f27 (patch) | |
tree | b335728dd65d2051dc420431eda4a644cbbc3b8b /src | |
parent | dce65cd40f07ac800ee01cbc8c017b63d87fe593 (diff) | |
download | systemd-7314b39746cdc30a9e9bfe96d4b55da650428f27.tar.gz |
resolve: set DNS_STUB_LISTENER_YES if no protocol is specified in DNSStubListenExtra=
Diffstat (limited to 'src')
-rw-r--r-- | src/resolve/resolved-conf.c | 93 | ||||
-rw-r--r-- | src/resolve/resolved-dns-stub.c | 36 | ||||
-rw-r--r-- | src/resolve/resolved-manager.h | 6 |
3 files changed, 51 insertions, 84 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; } diff --git a/src/resolve/resolved-dns-stub.c b/src/resolve/resolved-dns-stub.c index 5179e86602..2a8637d378 100644 --- a/src/resolve/resolved-dns-stub.c +++ b/src/resolve/resolved-dns-stub.c @@ -22,7 +22,8 @@ int dns_stub_extra_new(DNSStubListenerExtra **ret) { return -ENOMEM; *l = (DNSStubListenerExtra) { - .fd = -1, + .udp_fd = -1, + .tcp_fd = -1, }; *ret = TAKE_PTR(l); @@ -461,7 +462,7 @@ static int manager_dns_stub_udp_fd_extra(Manager *m, DNSStubListenerExtra *l) { _cleanup_close_ int fd = -1; int r; - if (l->fd >= 0) + if (l->udp_fd >= 0) return 0; fd = socket(socket_address_family(&l->address), SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); @@ -483,19 +484,19 @@ static int manager_dns_stub_udp_fd_extra(Manager *m, DNSStubListenerExtra *l) { goto fail; } - r = sd_event_add_io(m->event, &l->event_source, fd, EPOLLIN, on_dns_stub_packet, m); + r = sd_event_add_io(m->event, &l->udp_event_source, fd, EPOLLIN, on_dns_stub_packet, m); if (r < 0) goto fail; - (void) sd_event_source_set_description(l->event_source, "dns-stub-udp-extra"); - - l->fd = TAKE_FD(fd); + (void) sd_event_source_set_description(l->udp_event_source, "dns-stub-udp-extra"); if (DEBUG_LOGGING) { (void) sockaddr_pretty(&l->address.sockaddr.sa, FAMILY_ADDRESS_SIZE(l->address.sockaddr.sa.sa_family), true, true, &pretty); log_debug("Listening on UDP socket %s.", strnull(pretty)); } + l->udp_fd = TAKE_FD(fd); + return 0; fail: @@ -608,7 +609,7 @@ static int manager_dns_stub_tcp_fd_extra(Manager *m, DNSStubListenerExtra *l) { _cleanup_close_ int fd = -1; int r; - if (l->fd >= 0) + if (l->tcp_fd >= 0) return 0; fd = socket(socket_address_family(&l->address), SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); @@ -639,19 +640,19 @@ static int manager_dns_stub_tcp_fd_extra(Manager *m, DNSStubListenerExtra *l) { goto fail; } - r = sd_event_add_io(m->event, &l->event_source, fd, EPOLLIN, on_dns_stub_packet, m); + r = sd_event_add_io(m->event, &l->tcp_event_source, fd, EPOLLIN, on_dns_stub_packet, m); if (r < 0) goto fail; - (void) sd_event_source_set_description(l->event_source, "dns-stub-tcp-extra"); - - l->fd = TAKE_FD(fd); + (void) sd_event_source_set_description(l->tcp_event_source, "dns-stub-tcp-extra"); if (DEBUG_LOGGING) { (void) sockaddr_pretty(&l->address.sockaddr.sa, FAMILY_ADDRESS_SIZE(l->address.sockaddr.sa.sa_family), true, true, &pretty); log_debug("Listening on TCP socket %s.", strnull(pretty)); } + l->tcp_fd = TAKE_FD(fd); + return 0; fail: @@ -712,11 +713,12 @@ int manager_dns_stub_start(Manager *m) { log_debug("Creating extra stub listeners."); - ORDERED_SET_FOREACH(l, m->dns_extra_stub_listeners, i) - if (l->mode == DNS_STUB_LISTENER_UDP) + ORDERED_SET_FOREACH(l, m->dns_extra_stub_listeners, i) { + if (FLAGS_SET(l->mode, DNS_STUB_LISTENER_UDP)) (void) manager_dns_stub_udp_fd_extra(m, l); - else + if (FLAGS_SET(l->mode, DNS_STUB_LISTENER_TCP)) (void) manager_dns_stub_tcp_fd_extra(m, l); + } } return 0; @@ -739,7 +741,9 @@ void manager_dns_stub_stop_extra(Manager *m) { assert(m); ORDERED_SET_FOREACH(l, m->dns_extra_stub_listeners, i) { - l->event_source = sd_event_source_unref(l->event_source); - l->fd = safe_close(l->fd); + l->udp_event_source = sd_event_source_unref(l->udp_event_source); + l->tcp_event_source = sd_event_source_unref(l->tcp_event_source); + l->udp_fd = safe_close(l->udp_fd); + l->tcp_fd = safe_close(l->tcp_fd); } } diff --git a/src/resolve/resolved-manager.h b/src/resolve/resolved-manager.h index f31557a8a3..2c6adfbcbd 100644 --- a/src/resolve/resolved-manager.h +++ b/src/resolve/resolved-manager.h @@ -32,11 +32,13 @@ typedef struct EtcHosts { } EtcHosts; typedef struct DNSStubListenerExtra { - int fd; + int udp_fd; + int tcp_fd; DnsStubListenerMode mode; SocketAddress address; - sd_event_source *event_source; + sd_event_source *udp_event_source; + sd_event_source *tcp_event_source; } DNSStubListenerExtra; struct Manager { |