[systemd-commits] 2 commits - src/libsystemd-network src/network src/systemd

Tom Gundersen tomegun at kemper.freedesktop.org
Tue Apr 29 15:05:42 PDT 2014


 src/libsystemd-network/sd-dhcp-lease.c |   26 +++--
 src/network/networkd-link.c            |  160 ++++++++++++++++++---------------
 src/network/sd-network.c               |   12 ++
 src/systemd/sd-network.h               |    2 
 4 files changed, 116 insertions(+), 84 deletions(-)

New commits:
commit 8ddbeaa23c20659fe3b1b79502d746aceb396ce8
Author: Umut Tezduyar Lindskog <umut.tezduyar at axis.com>
Date:   Tue Apr 29 22:40:38 2014 +0200

    networkd: dont configure route if lease doesn't have one

diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index acdcca8..3e43ab6 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -126,7 +126,10 @@ int sd_dhcp_lease_get_router(sd_dhcp_lease *lease, struct in_addr *addr) {
         assert_return(lease, -EINVAL);
         assert_return(addr, -EINVAL);
 
-        addr->s_addr = lease->router;
+        if (lease->router != INADDR_ANY)
+                addr->s_addr = lease->router;
+        else
+                return -ENOENT;
 
         return 0;
 }
@@ -297,6 +300,7 @@ int dhcp_lease_new(sd_dhcp_lease **ret) {
         if (!lease)
                 return -ENOMEM;
 
+        lease->router = INADDR_ANY;
         lease->n_ref = REFCNT_INIT;
 
         *ret = lease;
@@ -370,18 +374,16 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
                 "# This is private data. Do not parse.\n"
                 "ADDRESS=%s\n", inet_ntoa(address));
 
-        r = sd_dhcp_lease_get_router(lease, &address);
-        if (r < 0)
-                goto finish;
-
-        fprintf(f, "ROUTER=%s\n", inet_ntoa(address));
-
         r = sd_dhcp_lease_get_netmask(lease, &address);
         if (r < 0)
                 goto finish;
 
         fprintf(f, "NETMASK=%s\n", inet_ntoa(address));
 
+        r = sd_dhcp_lease_get_router(lease, &address);
+        if (r >= 0)
+                fprintf(f, "ROUTER=%s\n", inet_ntoa(address));
+
         r = sd_dhcp_lease_get_server_identifier(lease, &address);
         if (r >= 0)
                 fprintf(f, "SERVER_ADDRESS=%s\n",
@@ -474,11 +476,13 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
 
         lease->address = addr.s_addr;
 
-        r = inet_pton(AF_INET, router, &addr);
-        if (r < 0)
-                return r;
+        if (router) {
+                r = inet_pton(AF_INET, router, &addr);
+                if (r < 0)
+                        return r;
 
-        lease->router = addr.s_addr;
+                lease->router = addr.s_addr;
+        }
 
         r = inet_pton(AF_INET, netmask, &addr);
         if (r < 0)
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index d3b2b14..058fbc2 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -301,55 +301,60 @@ static int link_enter_set_routes(Link *link) {
                 struct in_addr gateway;
 
                 r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
-                if (r < 0) {
-                        log_warning_link(link, "DHCP error: no router: %s",
-                                         strerror(-r));
+                if (r < 0 && r != -ENOENT) {
+                        log_warning_link(link, "DHCP error: %s", strerror(-r));
                         return r;
                 }
 
-                r = route_new_dynamic(&route);
-                if (r < 0) {
-                        log_error_link(link, "Could not allocate route: %s",
-                                       strerror(-r));
-                        return r;
-                }
+                if (r >= 0) {
+                        r = route_new_dynamic(&route);
+                        if (r < 0) {
+                                log_error_link(link, "Could not allocate route: %s",
+                                               strerror(-r));
+                                return r;
+                        }
 
-                r = route_new_dynamic(&route_gw);
-                if (r < 0) {
-                        log_error_link(link, "Could not allocate route: %s",
-                                       strerror(-r));
-                        return r;
-                }
+                        r = route_new_dynamic(&route_gw);
+                        if (r < 0) {
+                                log_error_link(link, "Could not allocate route: %s",
+                                               strerror(-r));
+                                return r;
+                        }
 
-                /* The dhcp netmask may mask out the gateway. Add an explicit
-                 * route for the gw host so that we can route no matter the
-                 * netmask or existing kernel route tables. */
-                route_gw->family = AF_INET;
-                route_gw->dst_addr.in = gateway;
-                route_gw->dst_prefixlen = 32;
-                route_gw->scope = RT_SCOPE_LINK;
+                        /* The dhcp netmask may mask out the gateway. Add an explicit
+                         * route for the gw host so that we can route no matter the
+                         * netmask or existing kernel route tables. */
+                        route_gw->family = AF_INET;
+                        route_gw->dst_addr.in = gateway;
+                        route_gw->dst_prefixlen = 32;
+                        route_gw->scope = RT_SCOPE_LINK;
 
-                r = route_configure(route_gw, link, &route_handler);
-                if (r < 0) {
-                        log_warning_link(link,
-                                         "could not set host route: %s", strerror(-r));
-                        return r;
-                }
+                        r = route_configure(route_gw, link, &route_handler);
+                        if (r < 0) {
+                                log_warning_link(link,
+                                                 "could not set host route: %s", strerror(-r));
+                                return r;
+                        }
 
-                link->route_messages ++;
+                        link->route_messages ++;
 
-                route->family = AF_INET;
-                route->in_addr.in = gateway;
+                        route->family = AF_INET;
+                        route->in_addr.in = gateway;
 
-                r = route_configure(route, link, &route_handler);
-                if (r < 0) {
-                        log_warning_link(link,
-                                         "could not set routes: %s", strerror(-r));
-                        link_enter_failed(link);
-                        return r;
+                        r = route_configure(route, link, &route_handler);
+                        if (r < 0) {
+                                log_warning_link(link,
+                                                 "could not set routes: %s", strerror(-r));
+                                link_enter_failed(link);
+                                return r;
+                        }
+
+                        link->route_messages ++;
                 }
+        }
 
-                link->route_messages ++;
+        if (link->route_messages == 0) {
+                link_enter_configured(link);
         }
 
         return 0;
@@ -680,29 +685,31 @@ static int dhcp_lease_lost(Link *link) {
 
         r = address_new_dynamic(&address);
         if (r >= 0) {
-                sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
-                sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
-                sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
-                prefixlen = net_netmask_to_prefixlen(&netmask);
-
-                r = route_new_dynamic(&route_gw);
+                r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
                 if (r >= 0) {
-                        route_gw->family = AF_INET;
-                        route_gw->dst_addr.in = gateway;
-                        route_gw->dst_prefixlen = 32;
-                        route_gw->scope = RT_SCOPE_LINK;
+                        r = route_new_dynamic(&route_gw);
+                        if (r >= 0) {
+                                route_gw->family = AF_INET;
+                                route_gw->dst_addr.in = gateway;
+                                route_gw->dst_prefixlen = 32;
+                                route_gw->scope = RT_SCOPE_LINK;
 
-                        route_drop(route_gw, link, &route_drop_handler);
-                }
+                                route_drop(route_gw, link, &route_drop_handler);
+                        }
 
-                r = route_new_dynamic(&route);
-                if (r >= 0) {
-                        route->family = AF_INET;
-                        route->in_addr.in = gateway;
+                        r = route_new_dynamic(&route);
+                        if (r >= 0) {
+                                route->family = AF_INET;
+                                route->in_addr.in = gateway;
 
-                        route_drop(route, link, &route_drop_handler);
+                                route_drop(route, link, &route_drop_handler);
+                        }
                 }
 
+                sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
+                sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
+                prefixlen = net_netmask_to_prefixlen(&netmask);
+
                 address->family = AF_INET;
                 address->in_addr.in = addr;
                 address->prefixlen = prefixlen;
@@ -777,25 +784,36 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
         prefixlen = net_netmask_to_prefixlen(&netmask);
 
         r = sd_dhcp_lease_get_router(lease, &gateway);
-        if (r < 0) {
-                log_warning_link(link, "DHCP error: no router: %s",
-                                 strerror(-r));
+        if (r < 0 && r != -ENOENT) {
+                log_warning_link(link, "DHCP error: %s", strerror(-r));
                 return r;
         }
 
-        log_struct_link(LOG_INFO, link,
-                        "MESSAGE=%s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
-                         link->ifname,
-                         ADDRESS_FMT_VAL(address),
-                         prefixlen,
-                         ADDRESS_FMT_VAL(gateway),
-                         "ADDRESS=%u.%u.%u.%u",
-                         ADDRESS_FMT_VAL(address),
-                         "PREFIXLEN=%u",
-                         prefixlen,
-                         "GATEWAY=%u.%u.%u.%u",
-                         ADDRESS_FMT_VAL(gateway),
-                         NULL);
+        if (r >= 0)
+                log_struct_link(LOG_INFO, link,
+                                "MESSAGE=%s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
+                                 link->ifname,
+                                 ADDRESS_FMT_VAL(address),
+                                 prefixlen,
+                                 ADDRESS_FMT_VAL(gateway),
+                                 "ADDRESS=%u.%u.%u.%u",
+                                 ADDRESS_FMT_VAL(address),
+                                 "PREFIXLEN=%u",
+                                 prefixlen,
+                                 "GATEWAY=%u.%u.%u.%u",
+                                 ADDRESS_FMT_VAL(gateway),
+                                 NULL);
+        else
+                log_struct_link(LOG_INFO, link,
+                                "MESSAGE=%s: DHCPv4 address %u.%u.%u.%u/%u",
+                                 link->ifname,
+                                 ADDRESS_FMT_VAL(address),
+                                 prefixlen,
+                                 "ADDRESS=%u.%u.%u.%u",
+                                 ADDRESS_FMT_VAL(address),
+                                 "PREFIXLEN=%u",
+                                 prefixlen,
+                                 NULL);
 
         link->dhcp_lease = lease;
 

commit 7e141e498c73ec7c8b61a0df37c4937f1d6becc7
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Apr 29 22:27:29 2014 +0200

    sd-network: add support for only listening to some types of changes

diff --git a/src/network/sd-network.c b/src/network/sd-network.c
index 3b541a2..1dfb282 100644
--- a/src/network/sd-network.c
+++ b/src/network/sd-network.c
@@ -166,7 +166,7 @@ _public_ int sd_network_monitor_new(const char *category, sd_network_monitor **m
         if (fd < 0)
                 return -errno;
 
-        if (!category || streq(category, "netif")) {
+        if (!category || streq(category, "links")) {
                 k = inotify_add_watch(fd, "/run/systemd/network/links/", IN_MOVED_TO|IN_DELETE);
                 if (k < 0) {
                         safe_close(fd);
@@ -176,6 +176,16 @@ _public_ int sd_network_monitor_new(const char *category, sd_network_monitor **m
                 good = true;
         }
 
+        if (!category || streq(category, "leases")) {
+                k = inotify_add_watch(fd, "/run/systemd/network/leases/", IN_MOVED_TO|IN_DELETE);
+                if (k < 0) {
+                        safe_close(fd);
+                        return -errno;
+                }
+
+                good = true;
+        }
+
         if (!good) {
                 close_nointr(fd);
                 return -EINVAL;
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index 71a83ec..9562b78 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -64,7 +64,7 @@ int sd_network_get_ifindices(unsigned **indices);
 /* Monitor object */
 typedef struct sd_network_monitor sd_network_monitor;
 
-/* Create a new monitor. Category must be NULL. */
+/* Create a new monitor. Category must be NULL, "links" or "leases". */
 int sd_network_monitor_new(const char *category, sd_network_monitor** ret);
 
 /* Destroys the passed monitor. Returns NULL. */



More information about the systemd-commits mailing list