[systemd-commits] 3 commits - man/systemd-networkd.service.xml src/libsystemd src/network

Tom Gundersen tomegun at kemper.freedesktop.org
Sat Jan 25 02:49:23 PST 2014


 man/systemd-networkd.service.xml   |   17 ++++++++-
 src/libsystemd/sd-rtnl/test-rtnl.c |    2 +
 src/network/networkd-gperf.gperf   |    2 +
 src/network/networkd-link.c        |   64 ++++++++++++++++++++++++-----------
 src/network/networkd-netdev.c      |   67 ++++++++++++++++++++++++++++++++-----
 src/network/networkd-network.c     |   37 ++++++++++++++++++++
 src/network/networkd.h             |    8 ++++
 7 files changed, 167 insertions(+), 30 deletions(-)

New commits:
commit c9ccc19f9eb0599109094c57b7a2f668d708f0c1
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Jan 25 11:39:22 2014 +0100

    networkd: improve logging a bit
    
    Fix/add some structured logging messages, and be uniform about when we WARN and ERR.

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 17e7047..d9622ac 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -166,7 +166,11 @@ static int route_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EEXIST)
-                log_warning_link(link, "could not set route: %s", strerror(-r));
+                log_struct_link(LOG_WARNING, link,
+                                "MESSAGE=%s: could not set route: %s",
+                                link->ifname, strerror(-r),
+                                "ERRNO=%d", -r,
+                                NULL);
 
         /* we might have received an old reply after moving back to SETTING_ADDRESSES,
          * ignore it */
@@ -237,7 +241,7 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EEXIST)
-                log_struct_link(LOG_ERR, link,
+                log_struct_link(LOG_WARNING, link,
                                 "MESSAGE=%s: could not set address: %s",
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
@@ -305,8 +309,12 @@ static int address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdat
                 return 1;
 
         r = sd_rtnl_message_get_errno(m);
-        if (r < 0 && r != -EEXIST)
-                log_warning_link(link, "could not drop address: %s", strerror(-r));
+        if (r < 0 && r != -ENOENT)
+                log_struct_link(LOG_WARNING, link,
+                                "MESSAGE=%s: could not drop address: %s",
+                                link->ifname, strerror(-r),
+                                "ERRNO=%d", -r,
+                                NULL);
 
         return 1;
 }
@@ -367,8 +375,12 @@ static int set_mtu_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
                 return 1;
 
         r = sd_rtnl_message_get_errno(m);
-        if (r < 0 && r != -EEXIST)
-                log_warning_link(link, "Could not set MTU: %s", strerror(-r));
+        if (r < 0)
+                log_struct_link(LOG_WARNING, link,
+                                "MESSAGE=%s: could not set MTU: %s",
+                                link->ifname, strerror(-r),
+                                "ERRNO=%d", -r,
+                                NULL);
 
         return 1;
 }
@@ -687,9 +699,13 @@ static int link_up_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0) {
-                log_warning_link(link,
-                                 "could not bring up interface: %s", strerror(-r));
+                log_struct_link(LOG_ERR, link,
+                                "MESSAGE=%s: could not bring up interface: %s",
+                                link->ifname, strerror(-r),
+                                "ERRNO=%d", -r,
+                                NULL);
                 link_enter_failed(link);
+                return 1;
         }
 
         link_update_flags(link, link->flags | IFF_UP);
@@ -763,8 +779,11 @@ static int enslave_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0) {
-                log_error_link(link, "could not enslave: %s",
-                               strerror(-r));
+                log_struct_link(LOG_ERR, link,
+                                "MESSAGE=%s: could not enslave: %s",
+                                link->ifname, strerror(-r),
+                                "ERRNO=%d", -r,
+                                NULL);
                 link_enter_failed(link);
                 return 1;
         }
@@ -792,7 +811,7 @@ static int link_enter_enslave(Link *link) {
         if (link->network->bridge) {
                 log_struct_link(LOG_DEBUG, link,
                                 "MESSAGE=%s: enslaving by '%s'",
-                                link->network->bridge->name,
+                                link->ifname, link->network->bridge->name,
                                 NETDEV(link->network->bridge),
                                 NULL);
 
@@ -800,7 +819,7 @@ static int link_enter_enslave(Link *link) {
                 if (r < 0) {
                         log_struct_link(LOG_WARNING, link,
                                         "MESSAGE=%s: could not enslave by '%s': %s",
-                                        link->network->bridge->name, strerror(-r),
+                                        link->ifname, link->network->bridge->name, strerror(-r),
                                         NETDEV(link->network->bridge),
                                         NULL);
                         link_enter_failed(link);
@@ -813,7 +832,7 @@ static int link_enter_enslave(Link *link) {
         if (link->network->vlan) {
                 log_struct_link(LOG_DEBUG, link,
                                 "MESSAGE=%s: enslaving by '%s'",
-                                link->network->vlan->name,
+                                link->ifname, link->network->vlan->name,
                                 NETDEV(link->network->vlan),
                                 NULL);
 
@@ -821,8 +840,8 @@ static int link_enter_enslave(Link *link) {
                 if (r < 0) {
                         log_struct_link(LOG_WARNING, link,
                                         "MESSAGE=%s: could not enslave by '%s': %s",
-                                        link->network->vlan->name, strerror(-r),
-                                        NETDEV(link->network->vlan),
+                                        link->ifname, link->network->vlan->name,
+                                        strerror(-r), NETDEV(link->network->vlan),
                                         NULL);
                         link_enter_failed(link);
                         return r;
@@ -845,8 +864,13 @@ static int link_get_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0) {
-                log_warning_link(link, "could not get state: %s", strerror(-r));
+                log_struct_link(LOG_ERR, link,
+                                "MESSAGE=%s: could not get state: %s",
+                                link->ifname, strerror(-r),
+                                "ERRNO=%d", -r,
+                                NULL);
                 link_enter_failed(link);
+                return 1;
         }
 
         log_debug_link(link, "got link state");

commit 54abf461d6b10dc270c4bb2aeac65f240ff1c5cd
Author: Tom Gundersen <teg at jklm.no>
Date:   Wed Jan 22 14:49:24 2014 +0100

    networkd: add basic VLAN support

diff --git a/man/systemd-networkd.service.xml b/man/systemd-networkd.service.xml
index 57a3a7c..3403a7a 100644
--- a/man/systemd-networkd.service.xml
+++ b/man/systemd-networkd.service.xml
@@ -105,11 +105,24 @@
                                 <varlistentry>
                                         <term><varname>Kind</varname></term>
                                         <listitem>
-                                                <para>The netdev kind. Currently, 'bridge' and 'bond' are
-                                                supported. This option is compulsory.</para>
+                                                <para>The netdev kind. Currently, 'bridge', 'bond' and 'vlan'
+                                                are supported. This option is compulsory.</para>
                                         </listitem>
                                 </varlistentry>
                         </variablelist>
+
+                        <para>The <literal>[VLAN]</literal> section only applies for netdevs of kind 'vlan',
+                        and accepts the following keys:</para>
+
+                        <variablelist class='network-directives'>
+                                <varlistentry>
+                                        <term><varname>Id</varname></term>
+                                        <listitem>
+                                                <para>The VLAN ID to use. This option is compulsory.</para>
+                                        </listitem>
+                                </varlistentry>
+                        </variablelist>
+
                 </refsect2>
 
                 <refsect2><title>Networks</title>
diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf
index 7181cf8..aff23bb 100644
--- a/src/network/networkd-gperf.gperf
+++ b/src/network/networkd-gperf.gperf
@@ -23,6 +23,7 @@ Match.Name,              config_parse_ifname,           0,       offsetof(Networ
 Network.Description,     config_parse_string,           0,       offsetof(Network, description)
 Network.Bridge,          config_parse_bridge,           0,       offsetof(Network, bridge)
 Network.Bond,            config_parse_bond,             0,       offsetof(Network, bond)
+Network.VLAN,            config_parse_vlan,             0,       offsetof(Network, vlan)
 Network.DHCP,            config_parse_bool,             0,       offsetof(Network, dhcp)
 Network.Address,         config_parse_address,          0,       0
 Network.Gateway,         config_parse_gateway,          0,       0
@@ -38,3 +39,4 @@ DHCPv4.UseDomainName,    config_parse_bool,             0,       offsetof(Networ
 Netdev.Description,      config_parse_string,           0,       offsetof(Netdev, description)
 Netdev.Name,             config_parse_ifname,           0,       offsetof(Netdev, name)
 Netdev.Kind,             config_parse_netdev_kind,      0,       offsetof(Netdev, kind)
+VLAN.Id,                 config_parse_int,              0,       offsetof(Netdev, vlanid)
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index f746f2d..17e7047 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -786,7 +786,7 @@ static int link_enter_enslave(Link *link) {
 
         link->state = LINK_STATE_ENSLAVING;
 
-        if (!link->network->bridge && !link->network->bond)
+        if (!link->network->bridge && !link->network->bond && !link->network->vlan)
                 return link_enslaved(link);
 
         if (link->network->bridge) {
@@ -810,19 +810,19 @@ static int link_enter_enslave(Link *link) {
                 link->enslaving ++;
         }
 
-        if (link->network->bond) {
+        if (link->network->vlan) {
                 log_struct_link(LOG_DEBUG, link,
                                 "MESSAGE=%s: enslaving by '%s'",
-                                link->network->bond->name,
-                                NETDEV(link->network->bond),
+                                link->network->vlan->name,
+                                NETDEV(link->network->vlan),
                                 NULL);
 
-                r = netdev_enslave(link->network->bond, link, &enslave_handler);
+                r = netdev_enslave(link->network->vlan, link, &enslave_handler);
                 if (r < 0) {
                         log_struct_link(LOG_WARNING, link,
                                         "MESSAGE=%s: could not enslave by '%s': %s",
-                                        link->network->bond->name, strerror(-r),
-                                        NETDEV(link->network->bond),
+                                        link->network->vlan->name, strerror(-r),
+                                        NETDEV(link->network->vlan),
                                         NULL);
                         link_enter_failed(link);
                         return r;
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index 2d1cef1..1a6eebe 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -28,7 +28,8 @@
 
 static const char* const netdev_kind_table[] = {
         [NETDEV_KIND_BRIDGE] = "bridge",
-        [NETDEV_KIND_BOND] = "bond"
+        [NETDEV_KIND_BOND] = "bond",
+        [NETDEV_KIND_VLAN] = "vlan",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetdevKind);
@@ -154,13 +155,13 @@ static int netdev_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userda
         return 1;
 }
 
-static int netdev_create(Netdev *netdev) {
+static int netdev_create(Netdev *netdev, Link *link, sd_rtnl_message_handler_t callback) {
         _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
         const char *kind;
         int r;
 
         assert(netdev);
-        assert(netdev->state == _NETDEV_STATE_INVALID);
+        assert(!(netdev->kind == NETDEV_KIND_VLAN) || (link && callback && netdev->vlanid >= 0));
         assert(netdev->name);
         assert(netdev->manager);
         assert(netdev->manager->rtnl);
@@ -173,6 +174,16 @@ static int netdev_create(Netdev *netdev) {
                 return r;
         }
 
+        if (link) {
+                r = sd_rtnl_message_append_u32(req, IFLA_LINK, link->ifindex);
+                if (r < 0) {
+                        log_error_netdev(netdev,
+                                         "Could not append IFLA_LINK attribute: %s",
+                                         strerror(-r));
+                        return r;
+                }
+        }
+
         r = sd_rtnl_message_append_string(req, IFLA_IFNAME, netdev->name);
         if (r < 0) {
                 log_error_netdev(netdev,
@@ -203,6 +214,32 @@ static int netdev_create(Netdev *netdev) {
                 return r;
         }
 
+        if (netdev->vlanid >= 0) {
+                r = sd_rtnl_message_open_container(req, IFLA_INFO_DATA);
+                if (r < 0) {
+                        log_error_netdev(netdev,
+                                         "Could not open IFLA_INFO_DATA container: %s",
+                                         strerror(-r));
+                        return r;
+                }
+
+                r = sd_rtnl_message_append_u16(req, IFLA_VLAN_ID, netdev->vlanid);
+                if (r < 0) {
+                        log_error_netdev(netdev,
+                                         "Could not append IFLA_VLAN_ID attribute: %s",
+                                         strerror(-r));
+                        return r;
+                }
+
+                r = sd_rtnl_message_close_container(req);
+                if (r < 0) {
+                        log_error_netdev(netdev,
+                                         "Could not close IFLA_INFO_DATA container %s",
+                                         strerror(-r));
+                        return r;
+                }
+        }
+
         r = sd_rtnl_message_close_container(req);
         if (r < 0) {
                 log_error_netdev(netdev,
@@ -211,7 +248,10 @@ static int netdev_create(Netdev *netdev) {
                 return r;
         }
 
-        r = sd_rtnl_call_async(netdev->manager->rtnl, req, &netdev_create_handler, netdev, 0, NULL);
+        if (link)
+                r = sd_rtnl_call_async(netdev->manager->rtnl, req, callback, link, 0, NULL);
+        else
+                r = sd_rtnl_call_async(netdev->manager->rtnl, req, &netdev_create_handler, netdev, 0, NULL);
         if (r < 0) {
                 log_error_netdev(netdev,
                                  "Could not send rtnetlink message: %s", strerror(-r));
@@ -226,6 +266,9 @@ static int netdev_create(Netdev *netdev) {
 }
 
 int netdev_enslave(Netdev *netdev, Link *link, sd_rtnl_message_handler_t callback) {
+        if (netdev->kind == NETDEV_KIND_VLAN)
+                return netdev_create(netdev, link, callback);
+
         if (netdev->state == NETDEV_STATE_READY) {
                 netdev_enslave_ready(netdev, link, callback);
         } else {
@@ -289,8 +332,9 @@ static int netdev_load_one(Manager *manager, const char *filename) {
         netdev->manager = manager;
         netdev->state = _NETDEV_STATE_INVALID;
         netdev->kind = _NETDEV_KIND_INVALID;
+        netdev->vlanid = -1;
 
-        r = config_parse(NULL, filename, file, "Netdev\0", config_item_perf_lookup,
+        r = config_parse(NULL, filename, file, "Netdev\0VLAN\0", config_item_perf_lookup,
                         (void*) network_gperf_lookup, false, false, netdev);
         if (r < 0) {
                 log_warning("Could not parse config file %s: %s", filename, strerror(-r));
@@ -307,6 +351,11 @@ static int netdev_load_one(Manager *manager, const char *filename) {
                 return 0;
         }
 
+        if (netdev->kind == NETDEV_KIND_VLAN && netdev->vlanid < 0) {
+                log_warning("VLAN without Id configured in %s. Ignoring", filename);
+                return 0;
+        }
+
         netdev->filename = strdup(filename);
         if (!netdev->filename)
                 return log_oom();
@@ -317,9 +366,11 @@ static int netdev_load_one(Manager *manager, const char *filename) {
 
         LIST_HEAD_INIT(netdev->callbacks);
 
-        r = netdev_create(netdev);
-        if (r < 0)
-                return r;
+        if (netdev->kind != NETDEV_KIND_VLAN) {
+                r = netdev_create(netdev, NULL, NULL);
+                if (r < 0)
+                        return r;
+        }
 
         netdev = NULL;
 
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index e703294..2a72034 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -285,3 +285,40 @@ int config_parse_bond(const char *unit,
 
         return 0;
 }
+
+int config_parse_vlan(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;
+        Netdev *netdev;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = netdev_get(network->manager, rvalue, &netdev);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "VLAN is invalid, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+
+        if (netdev->kind != NETDEV_KIND_VLAN) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Netdev is not a VLAN, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+
+        network->vlan = netdev;
+
+        return 0;
+}
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 2323e3d..22dcbd0 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -53,6 +53,7 @@ struct netdev_enslave_callback {
 typedef enum NetdevKind {
         NETDEV_KIND_BRIDGE,
         NETDEV_KIND_BOND,
+        NETDEV_KIND_VLAN,
         _NETDEV_KIND_MAX,
         _NETDEV_KIND_INVALID = -1
 } NetdevKind;
@@ -74,6 +75,8 @@ struct Netdev {
         char *name;
         NetdevKind kind;
 
+        int vlanid;
+
         Link *link;
         NetdevState state;
 
@@ -94,6 +97,7 @@ struct Network {
         char *description;
         Netdev *bridge;
         Netdev *bond;
+        Netdev *vlan;
         bool dhcp;
         bool dhcp_dns;
         bool dhcp_mtu;
@@ -258,6 +262,10 @@ int config_parse_bond(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);
 
+int config_parse_vlan(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);
+
 /* gperf */
 
 const struct ConfigPerfItem* network_gperf_lookup(const char *key, unsigned length);

commit 168a3f602fa2250dc0d0aab140ab91945d5f6efa
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Jan 25 01:22:54 2014 +0100

    sd-rtnl: extend tests a bit

diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
index a173b0f..ec6b294 100644
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ b/src/libsystemd/sd-rtnl/test-rtnl.c
@@ -241,10 +241,12 @@ static void test_container(void) {
         assert(sd_rtnl_message_read(m, &type, &data) >= 0);
         assert(type == IFLA_VLAN_ID);
         assert(*(uint16_t *)data == 100);
+        assert(sd_rtnl_message_read(m, &type, &data) == 0);
         assert(sd_rtnl_message_exit_container(m) >= 0);
         assert(sd_rtnl_message_read(m, &type, &data) >= 0);
         assert(type == IFLA_INFO_KIND);
         assert(streq("kind", (char *)data));
+        assert(sd_rtnl_message_read(m, &type, &data) == 0);
         assert(sd_rtnl_message_exit_container(m) >= 0);
         assert(sd_rtnl_message_exit_container(m) == -EINVAL);
 }



More information about the systemd-commits mailing list