summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-network/network-internal.c7
-rw-r--r--src/libsystemd-network/network-internal.h2
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c8
-rw-r--r--src/network/networkd-address.c49
-rw-r--r--src/network/networkd-link.c72
-rw-r--r--src/network/networkd-network-gperf.gperf4
-rw-r--r--src/network/networkd-network.c11
-rw-r--r--src/network/networkd.h7
-rw-r--r--src/resolve/resolved-link.c52
9 files changed, 56 insertions, 156 deletions
diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c
index 3407537eb5..603ee6dbe9 100644
--- a/src/libsystemd-network/network-internal.c
+++ b/src/libsystemd-network/network-internal.c
@@ -339,21 +339,16 @@ int net_parse_inaddr(const char *address, int *family, void *dst) {
return 0;
}
-void serialize_in_addrs(FILE *f, const char *key, const struct in_addr *addresses, size_t size) {
+void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size) {
unsigned i;
assert(f);
- assert(key);
assert(addresses);
assert(size);
- fprintf(f, "%s=", key);
-
for (i = 0; i < size; i++)
fprintf(f, "%s%s", inet_ntoa(addresses[i]),
(i < (size - 1)) ? " ": "");
-
- fputs("\n", f);
}
int deserialize_in_addrs(struct in_addr **ret, const char *string) {
diff --git a/src/libsystemd-network/network-internal.h b/src/libsystemd-network/network-internal.h
index 765dff4f3f..6dd518bb48 100644
--- a/src/libsystemd-network/network-internal.h
+++ b/src/libsystemd-network/network-internal.h
@@ -67,7 +67,7 @@ int net_parse_inaddr(const char *address, int *family, void *dst);
int net_get_unique_predictable_data(struct udev_device *device, uint8_t result[8]);
const char *net_get_name(struct udev_device *device);
-void serialize_in_addrs(FILE *f, const char *key, const struct in_addr *addresses, size_t size);
+void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size);
int deserialize_in_addrs(struct in_addr **addresses, const char *string);
int deserialize_in6_addrs(struct in6_addr **addresses, const char *string);
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 4ed30f5d03..bfd1b0cd18 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -629,13 +629,17 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
if (r >= 0)
fprintf(f, "MTU=%" PRIu16 "\n", mtu);
+ fputs("DNS=", f);
r = sd_dhcp_lease_get_dns(lease, &addresses);
if (r >= 0)
- serialize_in_addrs(f, "DNS", addresses, r);
+ serialize_in_addrs(f, addresses, r);
+ fputs("\n", f);
+ fputs("NTP=", f);
r = sd_dhcp_lease_get_ntp(lease, &addresses);
if (r >= 0)
- serialize_in_addrs(f, "NTP", addresses, r);
+ serialize_in_addrs(f, addresses, r);
+ fputs("\n", f);
r = sd_dhcp_lease_get_domainname(lease, &string);
if (r >= 0)
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 8c4ef9964b..551c1ea9bf 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -394,55 +394,6 @@ int address_configure(Address *address, Link *link,
return 0;
}
-int config_parse_dns(const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
- Network *network = userdata;
- Address *tail;
- _cleanup_address_free_ Address *n = NULL;
- int r;
-
- assert(filename);
- assert(section);
- assert(lvalue);
- assert(rvalue);
- assert(network);
-
- r = address_new_dynamic(&n);
- if (r < 0)
- return r;
-
- r = net_parse_inaddr(rvalue, &n->family, &n->in_addr);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "DNS address is invalid, ignoring assignment: %s", rvalue);
- return 0;
- }
-
- if (streq(lvalue, "DNS")) {
- LIST_FIND_TAIL(addresses, network->dns, tail);
- LIST_INSERT_AFTER(addresses, network->dns, tail, n);
- } else if (streq(lvalue, "NTP")) {
- LIST_FIND_TAIL(addresses, network->ntp, tail);
- LIST_INSERT_AFTER(addresses, network->ntp, tail, n);
- } else {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Key is invalid, ignoring assignment: %s=%s", lvalue, rvalue);
- return 0;
- }
-
- n = NULL;
-
- return 0;
-}
-
int config_parse_broadcast(const char *unit,
const char *filename,
unsigned line,
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 86d4b83d3b..7e6bc7b1e9 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2419,27 +2419,6 @@ int link_update(Link *link, sd_rtnl_message *m) {
return link_update_flags(link, m);
}
-static void serialize_addresses(FILE *f, const char *key, Address *address) {
- Address *ad;
-
- assert(f);
- assert(key);
-
- if (!address)
- return;
-
- fprintf(f, "%s=", key);
-
- LIST_FOREACH(addresses, ad, address) {
- char buf[INET6_ADDRSTRLEN];
-
- if (inet_ntop(ad->family, &ad->in_addr, buf, INET6_ADDRSTRLEN))
- fprintf(f, "%s%s", buf, (ad->addresses_next) ? " ": "");
- }
-
- fputs("\n", f);
-}
-
static void link_update_operstate(Link *link) {
assert(link);
@@ -2510,8 +2489,47 @@ int link_save(Link *link) {
admin_state, oper_state);
if (link->network) {
- serialize_addresses(f, "DNS", link->network->dns);
- serialize_addresses(f, "NTP", link->network->ntp);
+ char **address;
+
+ fputs("DNS=", f);
+
+ if (link->network->dhcp_dns &&
+ link->dhcp_lease) {
+ const struct in_addr *addresses;
+
+ r = sd_dhcp_lease_get_dns(link->dhcp_lease, &addresses);
+ if (r > 0) {
+ serialize_in_addrs(f, addresses, r);
+ if (link->network->dns)
+ fputs(" ", f);
+ }
+ }
+
+ STRV_FOREACH(address, link->network->dns)
+ fprintf(f, "%s%s", *address,
+ (address + 1 ? " " : ""));
+
+ fputs("\n", f);
+
+ fprintf(f, "NTP=");
+
+ if (link->network->dhcp_ntp &&
+ link->dhcp_lease) {
+ const struct in_addr *addresses;
+
+ r = sd_dhcp_lease_get_ntp(link->dhcp_lease, &addresses);
+ if (r > 0) {
+ serialize_in_addrs(f, addresses, r);
+ if (link->network->ntp)
+ fputs(" ", f);
+ }
+ }
+
+ STRV_FOREACH(address, link->network->ntp)
+ fprintf(f, "%s%s", *address,
+ (address + 1 ? " " : ""));
+
+ fputs("\n", f);
}
if (link->dhcp_lease) {
@@ -2522,12 +2540,8 @@ int link_save(Link *link) {
goto finish;
fprintf(f,
- "DHCP_LEASE=%s\n"
- "DHCP_USE_DNS=%s\n"
- "DHCP_USE_NTP=%s\n",
- link->lease_file,
- yes_no(link->network->dhcp_dns),
- yes_no(link->network->dhcp_ntp));
+ "DHCP_LEASE=%s\n",
+ link->lease_file);
} else
unlink(link->lease_file);
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index f5156b43b2..2938f8aec3 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -35,8 +35,8 @@ Network.DHCPServer, config_parse_bool, 0,
Network.IPv4LL, config_parse_bool, 0, offsetof(Network, ipv4ll)
Network.Address, config_parse_address, 0, 0
Network.Gateway, config_parse_gateway, 0, 0
-Network.DNS, config_parse_dns, 0, offsetof(Network, dns)
-Network.NTP, config_parse_dns, 0, offsetof(Network, ntp)
+Network.DNS, config_parse_strv, 0, offsetof(Network, dns)
+Network.NTP, config_parse_strv, 0, offsetof(Network, ntp)
Network.Tunnel, config_parse_tunnel, 0, offsetof(Network, tunnel)
Address.Address, config_parse_address, 0, 0
Address.Peer, config_parse_address, 0, 0
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index bc9304291e..24fc26b929 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -169,15 +169,8 @@ void network_free(Network *network) {
free(network->description);
free(network->dhcp_vendor_class_identifier);
- while ((address = network->ntp)) {
- LIST_REMOVE(addresses, network->ntp, address);
- address_free(address);
- }
-
- while ((address = network->dns)) {
- LIST_REMOVE(addresses, network->dns, address);
- address_free(address);
- }
+ strv_free(network->ntp);
+ strv_free(network->dns);
netdev_unref(network->bridge);
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 7d291e5ea3..bae2852845 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -105,8 +105,7 @@ struct Network {
Hashmap *addresses_by_section;
Hashmap *routes_by_section;
- LIST_HEAD(Address, dns);
- LIST_HEAD(Address, ntp);
+ char **dns, **ntp;
LIST_FIELDS(Network, networks);
};
@@ -338,10 +337,6 @@ bool address_equal(Address *a1, Address *a2);
DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
#define _cleanup_address_free_ _cleanup_(address_freep)
-int config_parse_dns(const char *unit, const char *filename, unsigned line,
- const char *section, unsigned section_line, const char *lvalue,
- int ltype, const char *rvalue, void *data, void *userdata);
-
int config_parse_address(const char *unit, const char *filename, unsigned line,
const char *section, unsigned section_line, const char *lvalue,
int ltype, const char *rvalue, void *data, void *userdata);
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index 078301aa26..43f60d8bb6 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -136,57 +136,6 @@ int link_update_rtnl(Link *l, sd_rtnl_message *m) {
return 0;
}
-static int link_update_dhcp_dns_servers(Link *l) {
- _cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
- const struct in_addr *nameservers = NULL;
- DnsServer *s, *nx;
- int r, n, i;
-
- assert(l);
-
- r = sd_network_dhcp_use_dns(l->ifindex);
- if (r <= 0)
- goto clear;
-
- r = sd_network_get_dhcp_lease(l->ifindex, &lease);
- if (r < 0)
- goto clear;
-
- LIST_FOREACH(servers, s, l->dhcp_dns_servers)
- s->marked = true;
-
- n = sd_dhcp_lease_get_dns(lease, &nameservers);
- if (n < 0) {
- r = n;
- goto clear;
- }
-
- for (i = 0; i < n; i++) {
- union in_addr_union a = { .in = nameservers[i] };
-
- s = link_find_dns_server(l, DNS_SERVER_DHCP, AF_INET, &a);
- if (s)
- s->marked = false;
- else {
- r = dns_server_new(l->manager, NULL, DNS_SERVER_DHCP, l, AF_INET, &a);
- if (r < 0)
- goto clear;
- }
- }
-
- LIST_FOREACH_SAFE(servers, s, nx, l->dhcp_dns_servers)
- if (s->marked)
- dns_server_free(s);
-
- return 0;
-
-clear:
- while (l->dhcp_dns_servers)
- dns_server_free(l->dhcp_dns_servers);
-
- return r;
-}
-
static int link_update_link_dns_servers(Link *l) {
_cleanup_free_ struct in_addr *nameservers = NULL;
_cleanup_free_ struct in6_addr *nameservers6 = NULL;
@@ -252,7 +201,6 @@ clear:
int link_update_monitor(Link *l) {
assert(l);
- link_update_dhcp_dns_servers(l);
link_update_link_dns_servers(l);
link_allocate_scopes(l);