[systemd-commits] 11 commits - man/systemd.network.xml src/libsystemd src/network src/systemd src/udev TODO units/systemd-networkd.service.in

Tom Gundersen tomegun at kemper.freedesktop.org
Mon Sep 8 06:14:24 PDT 2014


 TODO                                     |    3 ---
 man/systemd.network.xml                  |    6 ++++++
 src/libsystemd/sd-network/sd-network.c   |   24 ++++++++++++++++++++++++
 src/network/networkctl.c                 |   12 +++++++++---
 src/network/networkd-dhcp4.c             |   17 ++++++++++++++---
 src/network/networkd-link.c              |    2 ++
 src/network/networkd-netdev-tuntap.c     |   10 ++++------
 src/network/networkd-netdev.c            |    2 +-
 src/network/networkd-network-gperf.gperf |    1 +
 src/network/networkd-network.c           |    1 +
 src/network/networkd-route.c             |   22 ++++++++++++++++++++++
 src/network/networkd.h                   |    2 ++
 src/systemd/sd-network.h                 |    3 +++
 src/udev/net/link-config.c               |    4 ++--
 src/udev/udev-builtin-net_setup_link.c   |    2 ++
 units/systemd-networkd.service.in        |    4 +++-
 16 files changed, 96 insertions(+), 19 deletions(-)

New commits:
commit 84b5b79a8f7b423c5b7cad4170eb68d57fe5e26c
Author: Angus Gibson <angus at agibson.me>
Date:   Mon Sep 8 20:26:47 2014 +1000

    networkd: allow specification of DHCP route metric
    
    This lets the routing metric for links to be specified per-network,
    still defaulting to DHCP_ROUTE_METRIC (1024) if unspecified. Hopefully
    this helps with multiple interfaces configured via DHCP.

diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 641e02a..4cc13b2 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -494,6 +494,12 @@
                                                 hand, this must not be enabled on networks where broadcasts are filtered out.</para>
                                         </listitem>
                                 </varlistentry>
+                                <varlistentry>
+                                        <term><varname>RouteMetric=</varname></term>
+                                        <listitem>
+                                                <para>Set the routing metric for routes specified by the DHCP server.</para>
+                                        </listitem>
+                                </varlistentry>
                        </variablelist>
 
         </refsect1>
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index b87fa73..e0b3aca 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -103,7 +103,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route_gw->dst_prefixlen = 32;
                 route_gw->prefsrc_addr.in = address;
                 route_gw->scope = RT_SCOPE_LINK;
-                route_gw->metrics = DHCP_ROUTE_METRIC;
+                route_gw->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route_gw, link, &dhcp4_route_handler);
                 if (r < 0) {
@@ -118,7 +118,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route->family = AF_INET;
                 route->in_addr.in = gateway;
                 route->prefsrc_addr.in = address;
-                route->metrics = DHCP_ROUTE_METRIC;
+                route->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route, link, &dhcp4_route_handler);
                 if (r < 0) {
@@ -157,7 +157,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route->in_addr.in = static_routes[i].gw_addr;
                 route->dst_addr.in = static_routes[i].dst_addr;
                 route->dst_prefixlen = static_routes[i].dst_prefixlen;
-                route->metrics = DHCP_ROUTE_METRIC;
+                route->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route, link, &dhcp4_route_handler);
                 if (r < 0) {
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index c5b9614..a736461 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -57,6 +57,7 @@ DHCP.SendHostname,           config_parse_bool,                  0,
 DHCP.RequestBroadcast,       config_parse_bool,                  0,                             offsetof(Network, dhcp_broadcast)
 DHCP.CriticalConnection,     config_parse_bool,                  0,                             offsetof(Network, dhcp_critical)
 DHCP.VendorClassIdentifier,  config_parse_string,                0,                             offsetof(Network, dhcp_vendor_class_identifier)
+DHCP.RouteMetric,            config_parse_unsigned,              0,                             offsetof(Network, dhcp_route_metric)
 /* backwards compatibility: do not add new entries to this section */
 DHCPv4.UseDNS,               config_parse_bool,                  0,                             offsetof(Network, dhcp_dns)
 DHCPv4.UseMTU,               config_parse_bool,                  0,                             offsetof(Network, dhcp_mtu)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index fc62395..a2e27e0 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -85,6 +85,7 @@ static int network_load_one(Manager *manager, const char *filename) {
         network->dhcp_hostname = true;
         network->dhcp_routes = true;
         network->dhcp_sendhost = true;
+        network->dhcp_route_metric = DHCP_ROUTE_METRIC;
 
         network->llmnr = LLMNR_SUPPORT_YES;
 
diff --git a/src/network/networkd.h b/src/network/networkd.h
index c6e6b22..7c5459b 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -100,6 +100,7 @@ struct Network {
         bool dhcp_broadcast;
         bool dhcp_critical;
         bool dhcp_routes;
+        unsigned dhcp_route_metric;
         bool ipv4ll;
         bool ipv4ll_route;
 

commit af5effc4220dab6c4c87a130bae7be441f6967ca
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Sep 8 14:18:32 2014 +0200

    networkctl: show the link file applied to each link

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 43258bb..b374121 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -295,7 +295,7 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
         _cleanup_udev_device_unref_ struct udev_device *d = NULL;
         char devid[2 + DECIMAL_STR_MAX(int)];
         _cleanup_free_ char *t = NULL, *network = NULL;
-        const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL;
+        const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL;
         const char *on_color_operational, *off_color_operational,
                    *on_color_setup, *off_color_setup;
         struct ether_addr e;
@@ -384,6 +384,7 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
         link_get_type_string(iftype, d, &t);
 
         if (d) {
+                link = udev_device_get_property_value(d, "ID_NET_LINK_FILE");
                 driver = udev_device_get_property_value(d, "ID_NET_DRIVER");
                 path = udev_device_get_property_value(d, "ID_PATH");
 
@@ -400,9 +401,11 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
 
         printf("%s%s%s %i: %s\n", on_color_operational, draw_special_char(DRAW_BLACK_CIRCLE), off_color_operational, ifindex, name);
 
-        printf("Network File: %s\n"
+        printf("   Link File: %s\n"
+               "Network File: %s\n"
                "        Type: %s\n"
                "       State: %s%s%s (%s%s%s)\n",
+               strna(link),
                strna(network),
                strna(t),
                on_color_operational, strna(operational_state), off_color_operational,

commit d95b83b87d7d7c50e550f7128827f73a321c8934
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Sep 8 14:17:46 2014 +0200

    udev: link-config - only set *name on success

diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index c2881d6..64ff00d 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -424,8 +424,6 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
         } else
                 new_name = NULL;
 
-        *name = new_name;
-
         switch (config->mac_policy) {
                 case MACPOLICY_PERSISTENT:
                         if (mac_is_random(device)) {
@@ -459,6 +457,8 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
                 return r;
         }
 
+        *name = new_name;
+
         return 0;
 }
 

commit ad6e5b348fa88f44d6cbfe7aabda7612a1d0463f
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Sep 8 14:00:58 2014 +0200

    udev: net_setup_link - export the .link filename applied to the link

diff --git a/src/udev/udev-builtin-net_setup_link.c b/src/udev/udev-builtin-net_setup_link.c
index 6207269..14351de 100644
--- a/src/udev/udev-builtin-net_setup_link.c
+++ b/src/udev/udev-builtin-net_setup_link.c
@@ -57,6 +57,8 @@ static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv
                 return EXIT_FAILURE;
         }
 
+        udev_builtin_add_property(dev, test, "ID_NET_LINK_FILE", link->filename);
+
         if (name)
                 udev_builtin_add_property(dev, test, "ID_NET_NAME", name);
 

commit 373d9f173f910d547159917401c4b1f84af85736
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Sep 8 14:00:34 2014 +0200

    networkctl: show the network file applied to each link

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index d6d2e1d..43258bb 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -294,7 +294,7 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
         _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
         _cleanup_udev_device_unref_ struct udev_device *d = NULL;
         char devid[2 + DECIMAL_STR_MAX(int)];
-        _cleanup_free_ char *t = NULL;
+        _cleanup_free_ char *t = NULL, *network = NULL;
         const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL;
         const char *on_color_operational, *off_color_operational,
                    *on_color_setup, *off_color_setup;
@@ -396,11 +396,14 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
                         model = udev_device_get_property_value(d, "ID_MODEL");
         }
 
+        sd_network_link_get_network_file(ifindex, &network);
 
         printf("%s%s%s %i: %s\n", on_color_operational, draw_special_char(DRAW_BLACK_CIRCLE), off_color_operational, ifindex, name);
 
-        printf("        Type: %s\n"
+        printf("Network File: %s\n"
+               "        Type: %s\n"
                "       State: %s%s%s (%s%s%s)\n",
+               strna(network),
                strna(t),
                on_color_operational, strna(operational_state), off_color_operational,
                on_color_setup, strna(setup_state), off_color_setup);

commit adc5b2e2ebcb91ee18b6a32681b8ec1e52793473
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Sep 8 13:50:52 2014 +0200

    sd-network: add _get_network_file api

diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index 3a3f535..d63e6f9 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -120,6 +120,30 @@ _public_ int sd_network_link_get_setup_state(int ifindex, char **state) {
         return 0;
 }
 
+_public_ int sd_network_link_get_network_file(int ifindex, char **filename) {
+        _cleanup_free_ char *s = NULL, *p = NULL;
+        int r;
+
+        assert_return(ifindex > 0, -EINVAL);
+        assert_return(filename, -EINVAL);
+
+        if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
+                return -ENOMEM;
+
+        r = parse_env_file(p, NEWLINE, "NETWORK_FILE", &s, NULL);
+        if (r == -ENOENT)
+                return -ENODATA;
+        if (r < 0)
+                return r;
+        if (isempty(s))
+                return -ENODATA;
+
+        *filename = s;
+        s = NULL;
+
+        return 0;
+}
+
 _public_ int sd_network_link_get_operational_state(int ifindex, char **state) {
         _cleanup_free_ char *s = NULL, *p = NULL;
         int r;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a88cf48..11ac130 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1785,6 +1785,8 @@ int link_save(Link *link) {
                 char **address, **domain;
                 bool space;
 
+                fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
+
                 fputs("DNS=", f);
                 space = false;
                 STRV_FOREACH(address, link->network->dns) {
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index b2086c7..203a2a6 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -93,6 +93,9 @@ int sd_network_link_get_setup_state(int ifindex, char **state);
  */
 int sd_network_link_get_operational_state(int ifindex, char **state);
 
+/* Get path to .network file applied to link */
+int sd_network_link_get_network_file(int ifindex, char **filename);
+
 /* Get DNS entries for a given link. These are string representations of
  * IP addresses */
 int sd_network_link_get_dns(int ifindex, char ***addr);

commit b70c73fcf1885b717b464353edecaf650a1e520a
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Sep 8 13:12:06 2014 +0200

    TODO

diff --git a/TODO b/TODO
index 7029769..f036430 100644
--- a/TODO
+++ b/TODO
@@ -77,9 +77,6 @@ Features:
 
 * networkd:
   - add LLDP client side support
-  - ipv4ll with multiple interfaces doesn't work when both dhcp and
-    ipv4ll is used. for some reasons the kernel will currently pick an
-    ipv4ll source address to reach non-ipv4ll gateways.
   - the DHCP lease data (such as NTP/DNS) is still made available when
     a carrier is lost on a link. It should be removed instantly.
   - .network setting that allows overriding of the hostname to send to the dhcp server

commit 46b0c76e2c355c0d0cc4792abb98cde07b28bc53
Author: Emil Renner Berthing <systemd at esmil.dk>
Date:   Fri Sep 5 11:56:02 2014 +0200

    networkd: add preferred source to dhcp4 gateway route
    
    This makes DHCPv4 and IPv4LL coexist peacefully.
    
    [tomegun: apply to both the dhcp routes, use in_addr_is_null() rather than a
    separate variable to indicate when prefsrc should be applied]

diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index 5e4ff2b..b87fa73 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -67,9 +67,18 @@ static int link_set_dhcp_routes(Link *link) {
                 return r;
         }
         if (r >= 0) {
+                struct in_addr address;
                 _cleanup_route_free_ Route *route = NULL;
                 _cleanup_route_free_ Route *route_gw = NULL;
 
+                r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
+                if (r < 0) {
+                        log_warning_link(link,
+                                         "DHCP error: could not get address: %s",
+                                         strerror(-r));
+                        return r;
+                }
+
                 r = route_new_dynamic(&route, RTPROT_DHCP);
                 if (r < 0) {
                         log_error_link(link,
@@ -92,6 +101,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route_gw->family = AF_INET;
                 route_gw->dst_addr.in = gateway;
                 route_gw->dst_prefixlen = 32;
+                route_gw->prefsrc_addr.in = address;
                 route_gw->scope = RT_SCOPE_LINK;
                 route_gw->metrics = DHCP_ROUTE_METRIC;
 
@@ -107,6 +117,7 @@ static int link_set_dhcp_routes(Link *link) {
 
                 route->family = AF_INET;
                 route->in_addr.in = gateway;
+                route->prefsrc_addr.in = address;
                 route->metrics = DHCP_ROUTE_METRIC;
 
                 r = route_configure(route, link, &dhcp4_route_handler);
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index aead4fb..10d8cd9 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -144,6 +144,17 @@ int route_drop(Route *route, Link *link,
                 }
         }
 
+        if (!in_addr_is_null(route->family, &route->prefsrc_addr)) {
+                if (route->family == AF_INET)
+                        r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
+                else if (route->family == AF_INET6)
+                        r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
+                if (r < 0) {
+                        log_error("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
+                        return r;
+                }
+        }
+
         r = sd_rtnl_message_route_set_scope(req, route->scope);
         if (r < 0) {
                 log_error("Could not set scope: %s", strerror(-r));
@@ -218,6 +229,17 @@ int route_configure(Route *route, Link *link,
                 }
         }
 
+        if (!in_addr_is_null(route->family, &route->prefsrc_addr)) {
+                if (route->family == AF_INET)
+                        r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
+                else if (route->family == AF_INET6)
+                        r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
+                if (r < 0) {
+                        log_error("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
+                        return r;
+                }
+        }
+
         r = sd_rtnl_message_route_set_scope(req, route->scope);
         if (r < 0) {
                 log_error("Could not set scope: %s", strerror(-r));
diff --git a/src/network/networkd.h b/src/network/networkd.h
index ab5df1a..c6e6b22 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -150,6 +150,7 @@ struct Route {
 
         union in_addr_union in_addr;
         union in_addr_union dst_addr;
+        union in_addr_union prefsrc_addr;
 
         LIST_FIELDS(Route, routes);
 };

commit 4bd5ace3e78ec0ca4c174bc875e3d9f6e1ae7405
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Sep 6 22:37:31 2014 +0200

    units: networkd - order after udev
    
    This way we are sure that /dev/net/tun has been given the right permissions before we try to connect to it.
    Ideally, we should create tun/tap devices over netlink, and then this whole issue would go away.

diff --git a/units/systemd-networkd.service.in b/units/systemd-networkd.service.in
index f33c65e..fe92da2 100644
--- a/units/systemd-networkd.service.in
+++ b/units/systemd-networkd.service.in
@@ -10,7 +10,9 @@ Description=Network Service
 Documentation=man:systemd-networkd.service(8)
 ConditionCapability=CAP_NET_ADMIN
 DefaultDependencies=no
-After=dbus.service network-pre.target systemd-sysusers.service
+# dbus.service can be dropped once on kdbus, and systemd-udevd.service can be
+# dropped once tuntap is moved to netlink
+After=systemd-udevd.service dbus.service network-pre.target systemd-sysusers.service
 Before=network.target multi-user.target shutdown.target
 Conflicts=shutdown.target
 Wants=network.target

commit 1eb808756e3e4cc724ba17725a8513e562551c21
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Sep 6 22:16:20 2014 +0200

    networkd: netdev - failing to create a netdev is not fatal, just fail that netdev

diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index 1a436f7..fd1f51e 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -721,7 +721,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
         case NETDEV_CREATE_INDEPENDENT:
                 r = netdev_create(netdev, NULL, NULL);
                 if (r < 0)
-                        return r;
+                        return 0;
 
                 break;
         default:

commit 6f44acfb48d4b58565d4c14714d082997389afd3
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Sep 6 22:06:58 2014 +0200

    networkd: tuntap - return correct error when /dev/net/tun cannot be opened

diff --git a/src/network/networkd-netdev-tuntap.c b/src/network/networkd-netdev-tuntap.c
index eef8747..eaf5df4 100644
--- a/src/network/networkd-netdev-tuntap.c
+++ b/src/network/networkd-netdev-tuntap.c
@@ -63,17 +63,15 @@ static int netdev_tuntap_add(NetDev *netdev, struct ifreq *ifr) {
         const char *group;
         uid_t uid;
         gid_t gid;
-        int r = 0;
+        int r;
 
         assert(netdev);
         assert(ifr);
 
         fd = open(TUN_DEV, O_RDWR);
         if (fd < 0) {
-                log_error_netdev(netdev,
-                                 "Failed to open tun dev: %s",
-                                 strerror(-r));
-                return r;
+                log_error_netdev(netdev, "Failed to open tun dev: %m");
+                return -errno;
         }
 
         r = ioctl(fd, TUNSETIFF, ifr);
@@ -139,7 +137,7 @@ static int netdev_tuntap_add(NetDev *netdev, struct ifreq *ifr) {
                 return r;
         }
 
-        return r;
+        return 0;
 }
 
 static int netdev_create_tuntap(NetDev *netdev) {



More information about the systemd-commits mailing list