chiark / gitweb /
networkd: manager - drop links and netdevs when we receive DELLINK
authorTom Gundersen <teg@jklm.no>
Thu, 8 May 2014 16:55:11 +0000 (18:55 +0200)
committerTom Gundersen <teg@jklm.no>
Fri, 9 May 2014 12:41:27 +0000 (14:41 +0200)
src/network/networkd-manager.c

index 71c5425..40a088b 100644 (file)
@@ -219,6 +219,7 @@ static int manager_udev_process_link(Manager *m, struct udev_device *device) {
 static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata) {
         Manager *m = userdata;
         Link *link = NULL;
+        uint16_t type;
         char *name;
         int r, ifindex;
 
@@ -226,6 +227,12 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
         assert(message);
         assert(m);
 
+        r = sd_rtnl_message_get_type(message, &type);
+        if (r < 0) {
+                log_warning("rtnl: could not get message type");
+                return 0;
+        }
+
         r = sd_rtnl_message_link_get_ifindex(message, &ifindex);
         if (r < 0 || ifindex <= 0) {
                 log_warning("rtnl: received link message without valid ifindex");
@@ -233,7 +240,9 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
         }
 
         link_get(m, ifindex, &link);
-        if (!link) {
+        if (type == RTM_DELLINK)
+                link_drop(link);
+        else if (!link) {
                 /* link is new, so add it */
                 r = link_add(m, message, &link);
                 if (r < 0) {
@@ -246,10 +255,12 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
         if (r < 0)
                 log_warning("rtnl: received link message without valid ifname");
         else {
-                NetDev *netdev;
+                NetDev *netdev = NULL;
 
-                r = netdev_get(m, name, &netdev);
-                if (r >= 0) {
+                netdev_get(m, name, &netdev);
+                if (type == RTM_DELLINK)
+                        netdev_drop(netdev);
+                else if (netdev) {
                         r = netdev_set_ifindex(netdev, message);
                         if (r < 0) {
                                 log_debug("could not set ifindex on netdev");
@@ -258,9 +269,11 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
                 }
         }
 
-        r = link_update(link, message);
-        if (r < 0)
-                return 0;
+        if (type == RTM_NEWLINK) {
+                r = link_update(link, message);
+                if (r < 0)
+                        return 0;
+        }
 
         return 1;
 }
@@ -358,6 +371,10 @@ int manager_rtnl_listen(Manager *m) {
         if (r < 0)
                 return r;
 
+        r = sd_rtnl_add_match(m->rtnl, RTM_DELLINK, &manager_rtnl_process_link, m);
+        if (r < 0)
+                return r;
+
         return 0;
 }