[systemd-commits] 3 commits - src/libsystemd-dhcp src/network

Tom Gundersen tomegun at kemper.freedesktop.org
Thu Jan 2 16:36:20 PST 2014


 src/libsystemd-dhcp/dhcp-client.c |    2 -
 src/network/networkd-link.c       |   50 +++++++++++++++++++++++++-------------
 2 files changed, 33 insertions(+), 19 deletions(-)

New commits:
commit a2db1d6b3f0a6ef52bb5cb5cef40f2de5db380e5
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Jan 3 01:25:18 2014 +0100

    libsystemd-dhcp: don't assert on client_stop()
    
    We need to be able to stop the dhcp client at any time, and the function appears to be written to handle this.

diff --git a/src/libsystemd-dhcp/dhcp-client.c b/src/libsystemd-dhcp/dhcp-client.c
index b9492a5..f6a6211 100644
--- a/src/libsystemd-dhcp/dhcp-client.c
+++ b/src/libsystemd-dhcp/dhcp-client.c
@@ -260,8 +260,6 @@ static int client_notify(sd_dhcp_client *client, int event)
 static int client_stop(sd_dhcp_client *client, int error)
 {
         assert_return(client, -EINVAL);
-        assert_return(client->state != DHCP_STATE_INIT &&
-                      client->state != DHCP_STATE_INIT_REBOOT, -EALREADY);
 
         client->receive_message =
                 sd_event_source_unref(client->receive_message);

commit b1b532f58c99f8d199e6081fa9f23b99f8af2a84
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Jan 3 00:55:35 2014 +0100

    networkd: dhcp - avoid null pointer dereference

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 87f32f0..17a1e49 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -513,13 +513,17 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) {
 
         if (event == DHCP_EVENT_IP_CHANGE || event == DHCP_EVENT_EXPIRED ||
             event == DHCP_EVENT_STOP) {
-                address_drop(link->dhcp_address, link, address_drop_handler);
+                if (link->dhcp_address) {
+                        address_drop(link->dhcp_address, link, address_drop_handler);
 
-                address_free(link->dhcp_address);
-                link->dhcp_address = NULL;
+                        address_free(link->dhcp_address);
+                        link->dhcp_address = NULL;
+                }
 
-                route_free(link->dhcp_route);
-                link->dhcp_route = NULL;
+                if (link->dhcp_route) {
+                        route_free(link->dhcp_route);
+                        link->dhcp_route = NULL;
+                }
         }
 
         r = sd_dhcp_client_get_address(client, &address);

commit 1746cf2ad70d95c36064686d4f9b07a80e3bae99
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Jan 3 00:55:09 2014 +0100

    networkd: add more asserts and ignore all events when link has failed

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a594340..87f32f0 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -288,6 +288,11 @@ static int link_up_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         Link *link = userdata;
         int r;
 
+        assert(link);
+
+        if (link->state == LINK_STATE_FAILED)
+                return 1;
+
         r = sd_rtnl_message_get_errno(m);
         if (r < 0) {
                 log_warning("%s: could not bring up interface: %s",
@@ -295,6 +300,8 @@ static int link_up_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
                 link_enter_failed(link);
         }
 
+        log_debug("%s: brought up interface", link->ifname);
+
         return 1;
 }
 
@@ -342,12 +349,8 @@ static int link_bridge_joined(Link *link) {
                 return r;
         }
 
-        if (!link->network->dhcp) {
-                r = link_enter_set_addresses(link);
-                if (r < 0)
-                        link_enter_failed(link);
-                        return r;
-        }
+        if (!link->network->dhcp)
+                return link_enter_set_addresses(link);
 
         return 0;
 }
@@ -356,6 +359,7 @@ static int bridge_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         Link *link = userdata;
         int r;
 
+        assert(link);
         assert(link->state == LINK_STATE_JOINING_BRIDGE || link->state == LINK_STATE_FAILED);
         assert(link->network);
 
@@ -406,6 +410,11 @@ static int link_get_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         Link *link = userdata;
         int r;
 
+        assert(link);
+
+        if (link->state == LINK_STATE_FAILED)
+                return 1;
+
         r = sd_rtnl_message_get_errno(m);
         if (r < 0) {
                 log_warning("%s: could not get state: %s",
@@ -413,6 +422,8 @@ static int link_get_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
                 link_enter_failed(link);
         }
 
+        log_debug("%s: got link state", link->ifname);
+
         link_update(link, m);
 
         return 1;
@@ -456,11 +467,7 @@ int link_configure(Link *link) {
                 return r;
         }
 
-        r = link_enter_join_bridge(link);
-        if (r < 0)
-                return r;
-
-        return 0;
+        return link_enter_join_bridge(link);
 }
 
 static int address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
@@ -490,6 +497,8 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) {
         int prefixlen;
         int r;
 
+        assert(link);
+
         if (link->state == LINK_STATE_FAILED)
                 return;
 
@@ -622,6 +631,9 @@ int link_update(Link *link, sd_rtnl_message *m) {
         assert(link->network);
         assert(m);
 
+        if (link->state == LINK_STATE_FAILED)
+                return 0;
+
         r = sd_rtnl_message_link_get_flags(m, &flags);
         if (r < 0) {
                 log_warning("%s: could not get link flags", link->ifname);
@@ -657,7 +669,7 @@ int link_update(Link *link, sd_rtnl_message *m) {
 
         link->flags = flags;
 
-        log_debug("%s: updated state", link->ifname);
+        log_debug("%s: updated link state", link->ifname);
 
         return 0;
 }



More information about the systemd-commits mailing list