[systemd-commits] 4 commits - man/tmpfiles.d.xml src/libsystemd-network src/network src/shared units/systemd-tmpfiles-setup-dev.service.in

Tom Gundersen tomegun at kemper.freedesktop.org
Mon Oct 27 09:44:05 PDT 2014


 man/tmpfiles.d.xml                          |   14 +++++++--
 src/libsystemd-network/sd-dhcp-lease.c      |   24 +++++----------
 src/network/networkd-address.c              |   11 ++++++-
 src/shared/in-addr-util.c                   |   43 ++++++++++++++++++++++++++++
 src/shared/in-addr-util.h                   |    2 +
 units/systemd-tmpfiles-setup-dev.service.in |    2 -
 6 files changed, 77 insertions(+), 19 deletions(-)

New commits:
commit a2a85a22b3c82386633ab898012c4b249706d535
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Oct 27 17:39:18 2014 +0100

    networkd: network - if no prefixlength is given, try to deduce one from the address class
    
    In case of a class E or F address, ignore the address.

diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index e595cd6..ce85109 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -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);

commit df40eee8edccb6bf09a57c2b96f69d233032ce52
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Oct 27 17:38:03 2014 +0100

    shared: in-addr-utils - add default_subnet_mask and default_prefixlen methods
    
    These use the (deprecated) IPv4 address classes to deduce the corresponding subnet masks. This is useful when addresses
    without subnet masks and prefix lengths are given.
    
    Make use of these new functions from sd-dhcp-lease.

diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 6680d06..4fb01c0 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -30,6 +30,7 @@
 #include "list.h"
 #include "mkdir.h"
 #include "fileio.h"
+#include "in-addr-util.h"
 
 #include "dhcp-protocol.h"
 #include "dhcp-internal.h"
@@ -803,27 +804,20 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
 }
 
 int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease) {
-        uint32_t address;
+        struct in_addr address;
+        struct in_addr mask;
+        int r;
 
         assert(lease);
-        assert(lease->address != INADDR_ANY);
 
-        address = be32toh(lease->address);
+        address.s_addr = lease->address;
 
         /* fall back to the default subnet masks based on address class */
+        r = in_addr_default_subnet_mask(&address, &mask);
+        if (r < 0)
+                return r;
 
-        if ((address >> 31) == 0x0)
-                /* class A, leading bits: 0 */
-                lease->subnet_mask = htobe32(0xff000000);
-        else if ((address >> 30) == 0x2)
-                /* class B, leading bits 10 */
-                lease->subnet_mask = htobe32(0xffff0000);
-        else if ((address >> 29) == 0x6)
-                /* class C, leading bits 110 */
-                lease->subnet_mask = htobe32(0xffffff00);
-        else
-                /* class D or E, no default mask. give up */
-                return -ERANGE;
+        lease->subnet_mask = mask.s_addr;
 
         return 0;
 }
diff --git a/src/shared/in-addr-util.c b/src/shared/in-addr-util.c
index 457eedd..5fbee6c 100644
--- a/src/shared/in-addr-util.c
+++ b/src/shared/in-addr-util.c
@@ -248,3 +248,46 @@ unsigned in_addr_netmask_to_prefixlen(const struct in_addr *addr) {
 
         return 32 - u32ctz(be32toh(addr->s_addr));
 }
+
+int in_addr_default_prefixlen(const struct in_addr *addr, unsigned char *prefixlen) {
+        uint32_t address;
+
+        assert(addr);
+        assert(addr->s_addr != INADDR_ANY);
+        assert(prefixlen);
+
+        address = be32toh(addr->s_addr);
+
+        if ((address >> 31) == 0x0)
+                /* class A, leading bits: 0 */
+                *prefixlen = 8;
+        else if ((address >> 30) == 0x2)
+                /* class B, leading bits 10 */
+                *prefixlen = 16;
+        else if ((address >> 29) == 0x6)
+                /* class C, leading bits 110 */
+                *prefixlen = 24;
+        else
+                /* class D or E, no default prefixlen */
+                return -ERANGE;
+
+        return 0;
+}
+
+int in_addr_default_subnet_mask(const struct in_addr *addr, struct in_addr *mask) {
+        unsigned char prefixlen;
+        int r;
+
+        assert(addr);
+        assert(mask);
+
+        r = in_addr_default_prefixlen(addr, &prefixlen);
+        if (r < 0)
+                return r;
+
+        assert(prefixlen > 0 && prefixlen < 32);
+
+        mask->s_addr = htobe32((0xffffffff << (32 - prefixlen)) & 0xffffffff);
+
+        return 0;
+}
diff --git a/src/shared/in-addr-util.h b/src/shared/in-addr-util.h
index 0036ace..8da030c 100644
--- a/src/shared/in-addr-util.h
+++ b/src/shared/in-addr-util.h
@@ -40,6 +40,8 @@ int in_addr_to_string(int family, const union in_addr_union *u, char **ret);
 int in_addr_from_string(int family, const char *s, union in_addr_union *ret);
 int in_addr_from_string_auto(const char *s, int *family, union in_addr_union *ret);
 unsigned in_addr_netmask_to_prefixlen(const struct in_addr *addr);
+int in_addr_default_prefixlen(const struct in_addr *addr, unsigned char *prefixlen);
+int in_addr_default_subnet_mask(const struct in_addr *addr, struct in_addr *mask);
 
 static inline size_t FAMILY_ADDRESS_SIZE(int family) {
         assert(family == AF_INET || family == AF_INET6);

commit 1dfcee5985e8097fdbe0a77ca31fa23f683fadc2
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Oct 27 17:28:29 2014 +0100

    man: tmpfiles.d - recommend using b! and c!
    
    We should avoid creating static device nodes at runtime.

diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml
index 81457c4..f2360ba 100644
--- a/man/tmpfiles.d.xml
+++ b/man/tmpfiles.d.xml
@@ -210,7 +210,12 @@ L    /tmp/foobar -    -    -    -   /dev/null</programlisting>
                                         device node is to be created,
                                         it will be removed and be
                                         replaced by the device
-                                        node.</para></listitem>
+                                        node. It is recommended to suffix this
+                                        entry with an exclamation mark to only
+                                        create static device nodes at boot,
+                                        as udev will not manage static device
+                                        nodes that are created at runtime.
+                                        </para></listitem>
                                 </varlistentry>
 
                                 <varlistentry>
@@ -224,7 +229,12 @@ L    /tmp/foobar -    -    -    -   /dev/null</programlisting>
                                         device node is to be created,
                                         it will be removed and be
                                         replaced by the device
-                                        node.</para></listitem>
+                                        node. It is recommended to suffix this
+                                        entry with an exclamation mark to only
+                                        create static device nodes at boot,
+                                        as udev will not manage static device
+                                        nodes that are created at runtime.
+                                        </para></listitem>
                                 </varlistentry>
 
                                 <varlistentry>

commit 8c94052ee543c3598a3c7b0c46688150aa2c6168
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Oct 27 17:15:42 2014 +0100

    units: tmpfiles-setup-dev - allow unsafe file creation to happen in /dev at boot
    
    This will allow us to mark static device nodes with '!' to indicate that they should only be created at early boot.

diff --git a/units/systemd-tmpfiles-setup-dev.service.in b/units/systemd-tmpfiles-setup-dev.service.in
index f3833fd..0123a03 100644
--- a/units/systemd-tmpfiles-setup-dev.service.in
+++ b/units/systemd-tmpfiles-setup-dev.service.in
@@ -17,4 +17,4 @@ ConditionCapability=CAP_SYS_MODULE
 [Service]
 Type=oneshot
 RemainAfterExit=yes
-ExecStart=@rootbindir@/systemd-tmpfiles --prefix=/dev --create
+ExecStart=@rootbindir@/systemd-tmpfiles --prefix=/dev --create --boot



More information about the systemd-commits mailing list