chiark / gitweb /
treewide: no need to negate errno for log_*_errno()
[elogind.git] / src / network / networkd-address.c
index e595cd6e94682f10f403ff452a7fe73733e42816..e95184b8ff6cd266d1a613b581a6d3e325995b1a 100644 (file)
@@ -125,7 +125,7 @@ int address_drop(Address *address, Link *link,
 
         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;
         }
 
@@ -141,7 +141,7 @@ int address_drop(Address *address, Link *link,
 
         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;
         }
 
@@ -171,19 +171,19 @@ int address_update(Address *address, Link *link,
 
         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;
         }
 
@@ -224,7 +224,7 @@ int address_update(Address *address, Link *link,
 
         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;
         }
 
@@ -251,11 +251,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;
         }
 
@@ -320,19 +320,19 @@ int address_configure(Address *address, Link *link,
 
         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;
         }
 
@@ -386,7 +386,7 @@ int address_configure(Address *address, Link *link,
 
         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;
         }
 
@@ -482,7 +482,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;
                 }
 
@@ -499,6 +499,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);