chiark / gitweb /
treewide: more log_*_errno() conversions, multiline calls
[elogind.git] / src / network / networkd-address.c
index ae87b8352425bf25d4cbcae9972344180f004ebb..9502fa8caae412a754f87e931b577b2e8b00ffcc 100644 (file)
@@ -22,6 +22,7 @@
 #include <net/if.h>
 
 #include "networkd.h"
+#include "networkd-link.h"
 
 #include "utf8.h"
 #include "util.h"
@@ -117,14 +118,13 @@ int address_drop(Address *address, Link *link,
         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));
+                log_error_errno(r, "Could not allocate RTM_DELADDR message: %m");
                 return r;
         }
 
         r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
         if (r < 0) {
-                log_error("Could not set prefixlen: %s", strerror(-r));
+                log_error_errno(r, "Could not set prefixlen: %m");
                 return r;
         }
 
@@ -133,14 +133,13 @@ int address_drop(Address *address, Link *link,
         else if (address->family == AF_INET6)
                 r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
         if (r < 0) {
-                log_error("Could not append IFA_LOCAL attribute: %s",
-                          strerror(-r));
+                log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
                 return r;
         }
 
         r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
         if (r < 0) {
-                log_error("Could not send rtnetlink message: %s", strerror(-r));
+                log_error_errno(r, "Could not send rtnetlink message: %m");
                 return r;
         }
 
@@ -163,26 +162,25 @@ int address_update(Address *address, Link *link,
         r = sd_rtnl_message_new_addr_update(link->manager->rtnl, &req,
                                      link->ifindex, address->family);
         if (r < 0) {
-                log_error("Could not allocate RTM_NEWADDR message: %s",
-                          strerror(-r));
+                log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m");
                 return r;
         }
 
         r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
         if (r < 0) {
-                log_error("Could not set prefixlen: %s", strerror(-r));
+                log_error_errno(r, "Could not set prefixlen: %m");
                 return r;
         }
 
         r = sd_rtnl_message_addr_set_flags(req, IFA_F_PERMANENT);
         if (r < 0) {
-                log_error("Could not set flags: %s", strerror(-r));
+                log_error_errno(r, "Could not set flags: %m");
                 return r;
         }
 
         r = sd_rtnl_message_addr_set_scope(req, address->scope);
         if (r < 0) {
-                log_error("Could not set scope: %s", strerror(-r));
+                log_error_errno(r, "Could not set scope: %m");
                 return r;
         }
 
@@ -191,16 +189,14 @@ int address_update(Address *address, Link *link,
         else if (address->family == AF_INET6)
                 r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
         if (r < 0) {
-                log_error("Could not append IFA_LOCAL attribute: %s",
-                          strerror(-r));
+                log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
                 return r;
         }
 
         if (address->family == AF_INET) {
                 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));
+                        log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m");
                         return r;
                 }
         }
@@ -208,22 +204,20 @@ int address_update(Address *address, Link *link,
         if (address->label) {
                 r = sd_rtnl_message_append_string(req, IFA_LABEL, address->label);
                 if (r < 0) {
-                        log_error("Could not append IFA_LABEL attribute: %s",
-                                  strerror(-r));
+                        log_error_errno(r, "Could not append IFA_LABEL attribute: %m");
                         return r;
                 }
         }
 
         r = sd_rtnl_message_append_cache_info(req, IFA_CACHEINFO, &address->cinfo);
         if (r < 0) {
-                log_error("Could not append IFA_CACHEINFO attribute: %s",
-                          strerror(-r));
+                log_error_errno(r, "Could not append IFA_CACHEINFO attribute: %m");
                 return r;
         }
 
         r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
         if (r < 0) {
-                log_error("Could not send rtnetlink message: %s", strerror(-r));
+                log_error_errno(r, "Could not send rtnetlink message: %m");
                 return r;
         }
 
@@ -250,11 +244,11 @@ static int address_acquire(Link *link, Address *original, Address **ret) {
          * Then let's acquire something more useful from the pool. */
         r = manager_address_pool_acquire(link->manager, original->family, original->prefixlen, &in_addr);
         if (r < 0) {
-                log_error_link(link, "Failed to acquire address from pool: %s", strerror(-r));
+                log_link_error(link, "Failed to acquire address from pool: %s", strerror(-r));
                 return r;
         }
         if (r == 0) {
-                log_error_link(link, "Couldn't find free address for interface, all taken.");
+                log_link_error(link, "Couldn't find free address for interface, all taken.");
                 return -EBUSY;
         }
 
@@ -312,26 +306,25 @@ int address_configure(Address *address, Link *link,
         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));
+                log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m");
                 return r;
         }
 
         r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
         if (r < 0) {
-                log_error("Could not set prefixlen: %s", strerror(-r));
+                log_error_errno(r, "Could not set prefixlen: %m");
                 return r;
         }
 
         r = sd_rtnl_message_addr_set_flags(req, IFA_F_PERMANENT);
         if (r < 0) {
-                log_error("Could not set flags: %s", strerror(-r));
+                log_error_errno(r, "Could not set flags: %m");
                 return r;
         }
 
         r = sd_rtnl_message_addr_set_scope(req, address->scope);
         if (r < 0) {
-                log_error("Could not set scope: %s", strerror(-r));
+                log_error_errno(r, "Could not set scope: %m");
                 return r;
         }
 
@@ -340,8 +333,7 @@ int address_configure(Address *address, Link *link,
         else if (address->family == AF_INET6)
                 r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
         if (r < 0) {
-                log_error("Could not append IFA_LOCAL attribute: %s",
-                          strerror(-r));
+                log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
                 return r;
         }
 
@@ -351,16 +343,14 @@ int address_configure(Address *address, Link *link,
                 else if (address->family == AF_INET6)
                         r = sd_rtnl_message_append_in6_addr(req, IFA_ADDRESS, &address->in_addr_peer.in6);
                 if (r < 0) {
-                        log_error("Could not append IFA_ADDRESS attribute: %s",
-                                  strerror(-r));
+                        log_error_errno(r, "Could not append IFA_ADDRESS attribute: %m");
                         return r;
                 }
         } else {
                 if (address->family == AF_INET) {
                         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));
+                                log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m");
                                 return r;
                         }
                 }
@@ -369,8 +359,7 @@ int address_configure(Address *address, Link *link,
         if (address->label) {
                 r = sd_rtnl_message_append_string(req, IFA_LABEL, address->label);
                 if (r < 0) {
-                        log_error("Could not append IFA_LABEL attribute: %s",
-                                  strerror(-r));
+                        log_error_errno(r, "Could not append IFA_LABEL attribute: %m");
                         return r;
                 }
         }
@@ -378,14 +367,13 @@ int address_configure(Address *address, Link *link,
         r = sd_rtnl_message_append_cache_info(req, IFA_CACHEINFO,
                                               &address->cinfo);
         if (r < 0) {
-                log_error("Could not append IFA_CACHEINFO attribute: %s",
-                          strerror(-r));
+                log_error_errno(r, "Could not append IFA_CACHEINFO attribute: %m");
                 return r;
         }
 
         r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
         if (r < 0) {
-                log_error("Could not send rtnetlink message: %s", strerror(-r));
+                log_error_errno(r, "Could not send rtnetlink message: %m");
                 return r;
         }
 
@@ -481,7 +469,7 @@ int config_parse_address(const char *unit,
                 r = safe_atou(e + 1, &i);
                 if (r < 0) {
                         log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                                   "Interface prefix length is invalid, ignoring assignment: %s", e + 1);
+                                   "Prefix length is invalid, ignoring assignment: %s", e + 1);
                         return 0;
                 }
 
@@ -498,6 +486,15 @@ int config_parse_address(const char *unit,
                 return 0;
         }
 
+        if (!e && f == AF_INET) {
+                r = in_addr_default_prefixlen(&buffer.in, &n->prefixlen);
+                if (r < 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                                   "Prefix length not specified, and a default one can not be deduced for '%s', ignoring assignment", address);
+                        return 0;
+                }
+        }
+
         if (n->family != AF_UNSPEC && f != n->family) {
                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
                            "Address is incompatible, ignoring assignment: %s", address);