chiark / gitweb /
test: always use assert_se in tests
[elogind.git] / src / network / networkd-manager.c
index c1ad69bf514295614654760642242c609ede98fc..55e5cafd00bcd6a248c2e583903d4cf958706f89 100644 (file)
@@ -52,7 +52,7 @@ int manager_new(Manager **ret) {
 
         sd_event_set_watchdog(m->event, true);
 
-        r = sd_rtnl_open(RTMGRP_LINK | RTMGRP_IPV4_IFADDR, &m->rtnl);
+        r = sd_rtnl_open(&m->rtnl, RTMGRP_LINK | RTMGRP_IPV4_IFADDR);
         if (r < 0)
                 return r;
 
@@ -145,30 +145,31 @@ bool manager_should_reload(Manager *m) {
 }
 
 static int manager_process_link(Manager *m, struct udev_device *device) {
-        Link *link;
+        Link *link = NULL;
         int r;
 
-        if (streq_ptr(udev_device_get_action(device), "remove")) {
-                uint64_t ifindex;
+        assert(m);
+        assert(device);
 
+        link_get(m, udev_device_get_ifindex(device), &link);
+
+        if (streq_ptr(udev_device_get_action(device), "remove")) {
                 log_debug("%s: link removed", udev_device_get_sysname(device));
 
-                ifindex = udev_device_get_ifindex(device);
-                link = hashmap_get(m->links, &ifindex);
-                if (!link)
+                if (link)
+                        link_free(link);
+        } else {
+                if (link) {
+                        log_debug("%s: link already exists, ignoring",
+                                  link->ifname);
                         return 0;
+                }
 
-                link_free(link);
-        } else {
                 r = link_add(m, device, &link);
                 if (r < 0) {
-                        if (r == -EEXIST)
-                                log_debug("%s: link already exists, ignoring",
-                                          link->ifname);
-                        else
-                                log_error("%s: could not handle link: %s",
-                                          udev_device_get_sysname(device),
-                                          strerror(-r));
+                        log_error("%s: could not handle link: %s",
+                                  udev_device_get_sysname(device),
+                                  strerror(-r));
                 } else
                         log_debug("%s: link (with ifindex %" PRIu64") added",
                                   link->ifname, link->ifindex);
@@ -251,9 +252,10 @@ int manager_udev_listen(Manager *m) {
         }
 
         r = sd_event_add_io(m->event,
+                        &m->udev_event_source,
                         udev_monitor_get_fd(m->udev_monitor),
                         EPOLLIN, manager_dispatch_link_udev,
-                        m, &m->udev_event_source);
+                        m);
         if (r < 0)
                 return r;
 
@@ -264,9 +266,12 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
         Manager *m = userdata;
         Link *link;
         const char *name;
-        uint64_t ifindex_64;
         int r, ifindex;
 
+        assert(rtnl);
+        assert(message);
+        assert(m);
+
         r = sd_rtnl_message_link_get_ifindex(message, &ifindex);
         if (r < 0 || ifindex <= 0) {
                 log_debug("received RTM_NEWLINK message without valid ifindex");
@@ -288,9 +293,8 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
                 }
         }
 
-        ifindex_64 = ifindex;
-        link = hashmap_get(m->links, &ifindex_64);
-        if (!link) {
+        r = link_get(m, ifindex, &link);
+        if (r < 0) {
                 log_debug("received RTM_NEWLINK message for untracked ifindex %d", ifindex);
                 return 0;
         }