summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-07-23 13:48:18 +0200
committerTom Gundersen <teg@jklm.no>2014-07-23 23:54:51 +0200
commitb0e39c8284b5195850a58e4efcce2f059bdcc6ad (patch)
treee5f1183bec258450f9cd59ce1a8e255179467e0d /src/network
parent36d054aae0847df38687640909304dde1452b22d (diff)
networkd: merge DNS and NTP entries when exporting
In the state files, do not distinguish where the various entries came from (static or DHCP), but include them all in the same list.
Diffstat (limited to 'src/network')
-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
5 files changed, 48 insertions, 95 deletions
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);