chiark / gitweb /
networkd: allow more than one static DNS server
[elogind.git] / src / network / networkd-address.c
index 3f787948f92dfcccb5afe703e99986773b6dfcd4..414b3bccfa6430409fb48fc3e7006ca2f88944bb 100644 (file)
@@ -46,6 +46,9 @@ int address_new_static(Network *network, unsigned section, Address **ret) {
         if (!address)
                 return -ENOMEM;
 
+        address->family = AF_UNSPEC;
+        address->scope = RT_SCOPE_UNIVERSE;
+
         address->network = network;
 
         LIST_PREPEND(static_addresses, network->static_addresses, address);
@@ -68,6 +71,9 @@ int address_new_dynamic(Address **ret) {
         if (!address)
                 return -ENOMEM;
 
+        address->family = AF_UNSPEC;
+        address->scope = RT_SCOPE_UNIVERSE;
+
         *ret = address;
         address = NULL;
 
@@ -91,7 +97,7 @@ void address_free(Address *address) {
 
 int address_drop(Address *address, Link *link,
                  sd_rtnl_message_handler_t callback) {
-        _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
         int r;
 
         assert(address);
@@ -101,7 +107,8 @@ int address_drop(Address *address, Link *link,
         assert(link->manager);
         assert(link->manager->rtnl);
 
-        r = sd_rtnl_message_addr_new(RTM_DELADDR, link->ifindex, address->family, &req);
+        r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_DELADDR,
+                                     link->ifindex, address->family);
         if (r < 0) {
                 log_error("Could not allocate RTM_DELADDR message: %s",
                           strerror(-r));
@@ -135,7 +142,7 @@ int address_drop(Address *address, Link *link,
 
 int address_configure(Address *address, Link *link,
                       sd_rtnl_message_handler_t callback) {
-        _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
         int r;
 
         assert(address);
@@ -145,8 +152,8 @@ int address_configure(Address *address, Link *link,
         assert(link->manager);
         assert(link->manager->rtnl);
 
-        r = sd_rtnl_message_addr_new(RTM_NEWADDR, link->ifindex,
-                        address->family, &req);
+        r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_NEWADDR,
+                                     link->ifindex, address->family);
         if (r < 0) {
                 log_error("Could not allocate RTM_NEWADDR message: %s",
                           strerror(-r));
@@ -165,7 +172,7 @@ int address_configure(Address *address, Link *link,
                 return r;
         }
 
-        r = sd_rtnl_message_addr_set_scope(req, RT_SCOPE_UNIVERSE);
+        r = sd_rtnl_message_addr_set_scope(req, address->scope);
         if (r < 0) {
                 log_error("Could not set scope: %s", strerror(-r));
                 return r;
@@ -182,11 +189,7 @@ int address_configure(Address *address, Link *link,
         }
 
         if (address->family == AF_INET) {
-                struct in_addr broadcast;
-
-                broadcast.s_addr = address->in_addr.in.s_addr | address->netmask.s_addr;
-
-                r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &broadcast);
+                r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast);
                 if (r < 0) {
                         log_error("Could not append IFA_BROADCAST attribute: %s",
                                   strerror(-r));
@@ -222,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;
 
@@ -243,7 +246,51 @@ int config_parse_dns(const char *unit,
                 return 0;
         }
 
-        *dns = n;
+        set_put(*dns, n);
+        n = NULL;
+
+        return 0;
+}
+
+int config_parse_broadcast(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;
+        _cleanup_address_free_ Address *n = NULL;
+        _cleanup_free_ char *address = NULL;
+        int r;
+
+        assert(filename);
+        assert(section);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = address_new_static(network, section_line, &n);
+        if (r < 0)
+                return r;
+
+        if (n->family == AF_INET6) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Broadcast is not valid for IPv6 addresses, "
+                           "ignoring assignment: %s", address);
+                return 0;
+        }
+
+        r = net_parse_inaddr(address, &n->family, &n->broadcast);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Broadcast is invalid, ignoring assignment: %s", address);
+                return 0;
+        }
+
         n = NULL;
 
         return 0;
@@ -296,7 +343,6 @@ int config_parse_address(const char *unit,
                 }
 
                 n->prefixlen = (unsigned char) i;
-                n->netmask.s_addr = htonl(0xfffffffflu >> n->prefixlen);
 
                 address = strndup(rvalue, e - rvalue);
                 if (!address)
@@ -314,6 +360,10 @@ int config_parse_address(const char *unit,
                 return 0;
         }
 
+        if (n->family == AF_INET && !n->broadcast.s_addr)
+                n->broadcast.s_addr = n->in_addr.in.s_addr |
+                                      htonl(0xfffffffflu >> n->prefixlen);
+
         n = NULL;
 
         return 0;