chiark / gitweb /
networkd: allow more than one static DNS server
authorTom Gundersen <teg@jklm.no>
Thu, 13 Mar 2014 19:46:45 +0000 (20:46 +0100)
committerTom Gundersen <teg@jklm.no>
Fri, 14 Mar 2014 11:44:17 +0000 (12:44 +0100)
man/systemd.network.xml
src/network/networkd-address.c
src/network/networkd-manager.c
src/network/networkd-network.c
src/network/networkd.h

index 4118fc9..7609128 100644 (file)
                                         <term><varname>DNS=</varname></term>
                                         <listitem>
                                                 <para>A DNS server address, which must be in the format described in
-                                                <citerefentry><refentrytitle>inet_pton</refentrytitle><manvolnum>3</manvolnum></citerefentry>
-                                                .</para>
+                                                <citerefentry><refentrytitle>inet_pton</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
+                                                This option may be specified repeatedly.</para>
                                         </listitem>
                                 </varlistentry>
                                 <varlistentry>
index c924189..414b3bc 100644 (file)
@@ -225,7 +225,7 @@ int config_parse_dns(const char *unit,
                 const char *rvalue,
                 void *data,
                 void *userdata) {
-        Address **dns = data;
+        Set **dns = data;
         _cleanup_address_free_ Address *n = NULL;
         int r;
 
@@ -246,7 +246,7 @@ int config_parse_dns(const char *unit,
                 return 0;
         }
 
-        *dns = n;
+        set_put(*dns, n);
         n = NULL;
 
         return 0;
index 8c2f5ef..c730e71 100644 (file)
@@ -442,10 +442,17 @@ int manager_update_resolv_conf(Manager *m) {
                 }
         }
 
-        HASHMAP_FOREACH(link, m->links, i)
-                if (link->network && link->network->dns)
-                        append_dns(f, &link->network->dns->in_addr.in,
-                                   link->network->dns->family, &count);
+        HASHMAP_FOREACH(link, m->links, i) {
+                if (link->network && link->network->dns) {
+                        Address *address;
+                        Iterator j;
+
+                        SET_FOREACH(address, link->network->dns, j) {
+                                append_dns(f, &address->in_addr.in,
+                                           address->family, &count);
+                        }
+                }
+        }
 
         fflush(f);
 
index 6437ff4..6e9915b 100644 (file)
@@ -69,6 +69,10 @@ static int network_load_one(Manager *manager, const char *filename) {
         if (!network->routes_by_section)
                 return log_oom();
 
+        network->dns = set_new(NULL, NULL);
+        if (!network->dns)
+                return log_oom();
+
         network->filename = strdup(filename);
         if (!network->filename)
                 return log_oom();
@@ -136,6 +140,7 @@ int network_load(Manager *manager) {
 void network_free(Network *network) {
         Route *route;
         Address *address;
+        Iterator i;
 
         if (!network)
                 return;
@@ -150,7 +155,10 @@ void network_free(Network *network) {
 
         free(network->description);
 
-        address_free(network->dns);
+        SET_FOREACH(address, network->dns, i)
+                address_free(address);
+
+        set_free(network->dns);
 
         hashmap_free(network->vlans);
 
index 0c01719..311350c 100644 (file)
@@ -33,6 +33,7 @@
 #include "rtnl-util.h"
 #include "hashmap.h"
 #include "list.h"
+#include "set.h"
 #include "condition-util.h"
 
 typedef struct NetDev NetDev;
@@ -130,11 +131,12 @@ struct Network {
 
         LIST_HEAD(Address, static_addresses);
         LIST_HEAD(Route, static_routes);
-        Address *dns;
 
         Hashmap *addresses_by_section;
         Hashmap *routes_by_section;
 
+        Set *dns;
+
         LIST_FIELDS(Network, networks);
 };