summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am42
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c12
-rw-r--r--src/libsystemd/sd-network/sd-network.c63
-rw-r--r--src/network/networkd-network.c16
-rw-r--r--src/resolve/resolved-bus.c2
-rw-r--r--src/resolve/resolved-dns-answer.c2
-rw-r--r--src/resolve/resolved-dns-packet.c2
-rw-r--r--src/resolve/resolved-dns-question.c2
-rw-r--r--src/resolve/resolved-dns-rr.c2
-rw-r--r--src/resolve/resolved-dns-scope.c2
-rw-r--r--src/resolve/resolved-dns-zone.c2
-rw-r--r--src/resolve/resolved-manager.c2
-rw-r--r--src/shared/dns-domain.c (renamed from src/resolve/resolved-dns-domain.c)2
-rw-r--r--src/shared/dns-domain.h (renamed from src/resolve/resolved-dns-domain.h)9
-rw-r--r--src/test/test-dns-domain.c (renamed from src/resolve/test-dns-domain.c)2
15 files changed, 117 insertions, 45 deletions
diff --git a/Makefile.am b/Makefile.am
index 9b42f23709..783e19b2f7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -762,6 +762,8 @@ libsystemd_shared_la_SOURCES = \
src/shared/udev-util.h \
src/shared/device-nodes.c \
src/shared/device-nodes.h \
+ src/shared/dns-domain.c \
+ src/shared/dns-domain.h \
src/shared/util.c \
src/shared/util.h \
src/shared/virt.c \
@@ -978,6 +980,7 @@ libsystemd_shared_la_CFLAGS = \
libsystemd_shared_la_LIBADD = \
$(SELINUX_LIBS) \
$(CAP_LIBS) \
+ $(LIBIDN_LIBS) \
-lm
# -----------------------------------------------------------------------------
@@ -1446,7 +1449,8 @@ tests += \
test-copy \
test-cap-list \
test-sigbus \
- test-verbs
+ test-verbs \
+ test-dns-domain
EXTRA_DIST += \
test/a.service \
@@ -1577,6 +1581,15 @@ test_hostname_SOURCES = \
test_hostname_LDADD = \
libsystemd-core.la
+test_dns_domain_SOURCES = \
+ src/test/test-dns-domain.c
+
+test_dns_domain_LDADD = \
+ libsystemd-network.la \
+ libsystemd-internal.la \
+ libsystemd-shared.la \
+ $(LIBIDN_LIBS)
+
if ENABLE_EFI
manual_tests += \
test-boot-timestamp
@@ -3382,7 +3395,8 @@ test_dhcp_client_SOURCES = \
test_dhcp_client_LDADD = \
libsystemd-network.la \
libsystemd-internal.la \
- libsystemd-shared.la
+ libsystemd-shared.la \
+ $(LIBIDN_LIBS)
test_dhcp_server_SOURCES = \
src/libsystemd-network/test-dhcp-server.c
@@ -5408,8 +5422,6 @@ systemd_resolved_SOURCES = \
src/resolve/resolved-link.h \
src/resolve/resolved-link.c \
src/resolve/resolved-def.h \
- src/resolve/resolved-dns-domain.h \
- src/resolve/resolved-dns-domain.c \
src/resolve/resolved-dns-rr.h \
src/resolve/resolved-dns-rr.c \
src/resolve/resolved-dns-question.h \
@@ -5479,20 +5491,6 @@ GENERAL_ALIASES += \
nodist_pkgsysconf_DATA += \
src/resolve/resolved.conf
-tests += \
- test-dns-domain
-
-test_dns_domain_SOURCES = \
- src/resolve/resolved-dns-domain.h \
- src/resolve/resolved-dns-domain.c \
- src/resolve/test-dns-domain.c
-
-test_dns_domain_LDADD = \
- libsystemd-network.la \
- libsystemd-internal.la \
- libsystemd-shared.la \
- $(LIBIDN_LIBS)
-
libnss_resolve_la_SOURCES = \
src/nss-resolve/nss-resolve.sym \
src/nss-resolve/nss-resolve.c
@@ -5523,8 +5521,6 @@ systemd_resolve_host_SOURCES = \
src/resolve/resolved-dns-answer.h \
src/resolve/resolved-dns-question.c \
src/resolve/resolved-dns-question.h \
- src/resolve/resolved-dns-domain.c \
- src/resolve/resolved-dns-domain.h \
src/resolve/dns-type.c \
src/resolve/dns-type.h
@@ -5554,7 +5550,8 @@ systemd_networkd_SOURCES = \
src/network/networkd.c
systemd_networkd_LDADD = \
- libsystemd-networkd-core.la
+ libsystemd-networkd-core.la \
+ $(LIBIDN_LIBS)
if HAVE_LIBIPTC
systemd_networkd_LDADD += \
@@ -5653,7 +5650,8 @@ test_network_SOURCES = \
src/network/test-network.c
test_network_LDADD = \
- libsystemd-networkd-core.la
+ libsystemd-networkd-core.la \
+ $(LIBIDN_LIBS)
if HAVE_LIBIPTC
test_network_LDADD += \
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 8a4220621b..d8bc76edda 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -32,6 +32,7 @@
#include "dhcp-lease-internal.h"
#include "sd-dhcp-lease.h"
#include "network-internal.h"
+#include "dns-domain.h"
int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr) {
assert_return(lease, -EINVAL);
@@ -504,9 +505,18 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
if (e)
*e = 0;
- if (!hostname_is_valid(domainname) || is_localhost(domainname))
+ if (is_localhost(domainname))
break;
+ r = dns_name_is_valid(domainname);
+ if (r <= 0) {
+ if (r < 0)
+ log_error_errno(r, "Failed to validate domain name: %s: %m", domainname);
+ if (r == 0)
+ log_warning("Domain name is not valid, ignoring: %s", domainname);
+ break;
+ }
+
free(lease->domainname);
lease->domainname = domainname;
domainname = NULL;
diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index 587941497d..207eda163b 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -297,8 +297,31 @@ static inline sd_network_monitor* FD_TO_MONITOR(int fd) {
return (sd_network_monitor*) (unsigned long) (fd + 1);
}
+static int monitor_add_inotify_watch(int fd) {
+ int k;
+
+ k = inotify_add_watch(fd, "/run/systemd/netif/links/", IN_MOVED_TO|IN_DELETE);
+ if (k >= 0)
+ return 0;
+ else if (errno != ENOENT)
+ return -errno;
+
+ k = inotify_add_watch(fd, "/run/systemd/netif/", IN_CREATE|IN_ISDIR);
+ if (k >= 0)
+ return 0;
+ else if (errno != ENOENT)
+ return -errno;
+
+ k = inotify_add_watch(fd, "/run/systemd/", IN_CREATE|IN_ISDIR);
+ if (k < 0)
+ return -errno;
+
+ return 0;
+}
+
_public_ int sd_network_monitor_new(sd_network_monitor **m, const char *category) {
- int fd, k;
+ _cleanup_close_ int fd = -1;
+ int k;
bool good = false;
assert_return(m, -EINVAL);
@@ -308,11 +331,9 @@ _public_ int sd_network_monitor_new(sd_network_monitor **m, const char *category
return -errno;
if (!category || streq(category, "links")) {
- k = inotify_add_watch(fd, "/run/systemd/netif/links/", IN_MOVED_TO|IN_DELETE);
- if (k < 0) {
- safe_close(fd);
- return -errno;
- }
+ k = monitor_add_inotify_watch(fd);
+ if (k < 0)
+ return k;
good = true;
}
@@ -323,6 +344,8 @@ _public_ int sd_network_monitor_new(sd_network_monitor **m, const char *category
}
*m = FD_TO_MONITOR(fd);
+ fd = -1;
+
return 0;
}
@@ -338,10 +361,36 @@ _public_ sd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m) {
}
_public_ int sd_network_monitor_flush(sd_network_monitor *m) {
+ union inotify_event_buffer buffer;
+ struct inotify_event *e;
+ ssize_t l;
+ int fd, k;
assert_return(m, -EINVAL);
- return flush_fd(MONITOR_TO_FD(m));
+ fd = MONITOR_TO_FD(m);
+
+ l = read(fd, &buffer, sizeof(buffer));
+ if (l < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ return 0;
+
+ return -errno;
+ }
+
+ FOREACH_INOTIFY_EVENT(e, buffer, l) {
+ if (e->mask & IN_ISDIR) {
+ k = monitor_add_inotify_watch(fd);
+ if (k < 0)
+ return k;
+
+ k = inotify_rm_watch(fd, e->wd);
+ if (k < 0)
+ return -errno;
+ }
+ }
+
+ return 0;
}
_public_ int sd_network_monitor_get_fd(sd_network_monitor *m) {
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 5947084106..6f32e5f4a4 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -30,6 +30,7 @@
#include "networkd-netdev.h"
#include "networkd-link.h"
#include "network-internal.h"
+#include "dns-domain.h"
static int network_load_one(Manager *manager, const char *filename) {
_cleanup_network_free_ Network *network = NULL;
@@ -466,11 +467,16 @@ int config_parse_domains(const char *unit,
STRV_FOREACH(domain, *domains) {
if (is_localhost(*domain))
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "'localhost' domain names may not be configured, ignoring assignment: %s", *domain);
- else if (!hostname_is_valid(*domain)) {
- if (!streq(*domain, "*"))
- log_syntax(unit, LOG_ERR, filename, line, EINVAL, "domain name is not valid, ignoring assignment: %s", *domain);
- } else
- continue;
+ else {
+ r = dns_name_is_valid(*domain);
+ if (r <= 0 && !streq(*domain, "*")) {
+ if (r < 0)
+ log_error_errno(r, "Failed to validate domain name: %s: %m", *domain);
+ if (r == 0)
+ log_warning("Domain name is not valid, ignoring assignment: %s", *domain);
+ } else
+ continue;
+ }
strv_remove(*domains, *domain);
diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c
index 171141e3a4..6db12511f9 100644
--- a/src/resolve/resolved-bus.c
+++ b/src/resolve/resolved-bus.c
@@ -22,7 +22,7 @@
#include "bus-common-errors.h"
#include "bus-util.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
#include "resolved-bus.h"
#include "resolved-def.h"
diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c
index e08eb667cc..f77b98e505 100644
--- a/src/resolve/resolved-dns-answer.c
+++ b/src/resolve/resolved-dns-answer.c
@@ -20,7 +20,7 @@
***/
#include "resolved-dns-answer.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
DnsAnswer *dns_answer_new(unsigned n) {
DnsAnswer *a;
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index 21756f566f..bb74b1828e 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -23,7 +23,7 @@
#include "util.h"
#include "strv.h"
#include "unaligned.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
#include "resolved-dns-packet.h"
int dns_packet_new(DnsPacket **ret, DnsProtocol protocol, size_t mtu) {
diff --git a/src/resolve/resolved-dns-question.c b/src/resolve/resolved-dns-question.c
index 45bcbbf23a..4d71f5e3d4 100644
--- a/src/resolve/resolved-dns-question.c
+++ b/src/resolve/resolved-dns-question.c
@@ -20,7 +20,7 @@
***/
#include "resolved-dns-question.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
DnsQuestion *dns_question_new(unsigned n) {
DnsQuestion *q;
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c
index 78d9e4a412..c1818eef9c 100644
--- a/src/resolve/resolved-dns-rr.c
+++ b/src/resolve/resolved-dns-rr.c
@@ -23,7 +23,7 @@
#include "strv.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
#include "resolved-dns-rr.h"
#include "resolved-dns-packet.h"
#include "dns-type.h"
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c
index 7369cbf50f..c25ac2216d 100644
--- a/src/resolve/resolved-dns-scope.c
+++ b/src/resolve/resolved-dns-scope.c
@@ -27,7 +27,7 @@
#include "af-list.h"
#include "random-util.h"
#include "hostname-util.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
#include "resolved-dns-scope.h"
#define MULTICAST_RATELIMIT_INTERVAL_USEC (1*USEC_PER_SEC)
diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c
index a4c9b7d7af..32d771a954 100644
--- a/src/resolve/resolved-dns-zone.c
+++ b/src/resolve/resolved-dns-zone.c
@@ -22,7 +22,7 @@
#include "list.h"
#include "resolved-dns-zone.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
#include "resolved-dns-packet.h"
/* Never allow more than 1K entries */
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 7fc2803ddb..f8d4db7aad 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -34,7 +34,7 @@
#include "random-util.h"
#include "hostname-util.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
#include "resolved-conf.h"
#include "resolved-bus.h"
#include "resolved-manager.h"
diff --git a/src/resolve/resolved-dns-domain.c b/src/shared/dns-domain.c
index e1eb3ddfe5..20a44ce4e1 100644
--- a/src/resolve/resolved-dns-domain.c
+++ b/src/shared/dns-domain.c
@@ -24,7 +24,7 @@
#include <stringprep.h>
#endif
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
int dns_label_unescape(const char **name, char *dest, size_t sz) {
const char *n;
diff --git a/src/resolve/resolved-dns-domain.h b/src/shared/dns-domain.h
index 516d244f7a..00caf5d700 100644
--- a/src/resolve/resolved-dns-domain.h
+++ b/src/shared/dns-domain.h
@@ -35,6 +35,15 @@ int dns_label_apply_idna(const char *encoded, size_t encoded_size, char *decoded
int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded, size_t decoded_max);
int dns_name_normalize(const char *s, char **_ret);
+static inline int dns_name_is_valid(const char *s) {
+ int r;
+ r = dns_name_normalize(s, NULL);
+ if (r == -EINVAL)
+ return 0;
+ if (r < 0)
+ return r;
+ return 1;
+}
unsigned long dns_name_hash_func(const void *s, const uint8_t hash_key[HASH_KEY_SIZE]);
int dns_name_compare_func(const void *a, const void *b);
diff --git a/src/resolve/test-dns-domain.c b/src/test/test-dns-domain.c
index c3208abc78..527cdd3b54 100644
--- a/src/resolve/test-dns-domain.c
+++ b/src/test/test-dns-domain.c
@@ -20,7 +20,7 @@
***/
#include "macro.h"
-#include "resolved-dns-domain.h"
+#include "dns-domain.h"
static void test_dns_label_unescape_one(const char *what, const char *expect, size_t buffer_sz, int ret) {
char buffer[buffer_sz];