chiark / gitweb /
networkd: link - improve link tracking logging
[elogind.git] / src / network / networkd-link.c
index 8674eee9487a8949ed05d1deb25e63fcddd9d1ad..961c1ab8ad13f3a1845f78b5ae3b7c80a4ceeddc 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <netinet/ether.h>
 #include <linux/if.h>
+#include <unistd.h>
 
 #include "networkd.h"
 #include "libudev-private.h"
@@ -78,7 +79,7 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
 
         r = sd_rtnl_message_read_ether_addr(message, IFLA_ADDRESS, &link->mac);
         if (r < 0)
-                return r;
+                log_debug_link(link, "MAC address not found for new device, continuing without");
 
         r = asprintf(&link->state_file, "/run/systemd/netif/links/%"PRIu64,
                      link->ifindex);
@@ -435,7 +436,6 @@ static int link_set_dhcp_routes(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->route_messages ++;
         }
 
@@ -467,7 +467,6 @@ static int link_enter_set_routes(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->route_messages ++;
         }
 
@@ -502,7 +501,6 @@ static int link_enter_set_routes(Link *link) {
                                 return r;
                         }
 
-                        link_ref(link);
                         link->route_messages ++;
                 }
         }
@@ -550,7 +548,6 @@ static int link_enter_set_routes(Link *link) {
                                 return r;
                         }
 
-                        link_ref(link);
                         link->route_messages ++;
 
                         route->family = AF_INET;
@@ -565,7 +562,6 @@ static int link_enter_set_routes(Link *link) {
                                 return r;
                         }
 
-                        link_ref(link);
                         link->route_messages ++;
                 }
 
@@ -662,7 +658,6 @@ static int link_enter_set_addresses(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->addr_messages ++;
         }
 
@@ -698,7 +693,6 @@ static int link_enter_set_addresses(Link *link) {
                                 return r;
                         }
 
-                        link_ref(link);
                         link->addr_messages ++;
                 }
         }
@@ -759,7 +753,6 @@ static int link_enter_set_addresses(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->addr_messages ++;
         }
 
@@ -956,7 +949,6 @@ static int dhcp_lease_lost(Link *link) {
                                         route->dst_prefixlen = routes[i].dst_prefixlen;
 
                                         route_drop(route, link, &route_drop_handler);
-                                        link_ref(link);
                                 }
                         }
                 }
@@ -977,7 +969,6 @@ static int dhcp_lease_lost(Link *link) {
                                 route_gw->scope = RT_SCOPE_LINK;
 
                                 route_drop(route_gw, link, &route_drop_handler);
-                                link_ref(link);
                         }
 
                         r = route_new_dynamic(&route);
@@ -986,7 +977,6 @@ static int dhcp_lease_lost(Link *link) {
                                 route->in_addr.in = gateway;
 
                                 route_drop(route, link, &route_drop_handler);
-                                link_ref(link);
                         }
                 }
 
@@ -999,7 +989,6 @@ static int dhcp_lease_lost(Link *link) {
                 address->prefixlen = prefixlen;
 
                 address_drop(address, link, &address_drop_handler);
-                link_ref(link);
         }
 
         if (link->network->dhcp_mtu) {
@@ -1266,7 +1255,6 @@ static int ipv4ll_address_update(Link *link, bool deprecate) {
                 address->broadcast.s_addr = address->in_addr.in.s_addr | htonl(0xfffffffflu >> address->prefixlen);
 
                 address_update(address, link, &address_update_handler);
-                link_ref(link);
         }
 
         return 0;
@@ -1299,7 +1287,6 @@ static int ipv4ll_address_lost(Link *link) {
                 address->scope = RT_SCOPE_LINK;
 
                 address_drop(address, link, &address_drop_handler);
-                link_ref(link);
 
                 r = route_new_dynamic(&route);
                 if (r < 0) {
@@ -1313,7 +1300,6 @@ static int ipv4ll_address_lost(Link *link) {
                 route->metrics = 99;
 
                 route_drop(route, link, &route_drop_handler);
-                link_ref(link);
         }
 
         return 0;
@@ -1723,6 +1709,8 @@ static int link_enslaved(Link *link) {
         assert(link->state == LINK_STATE_ENSLAVING);
         assert(link->network);
 
+        log_debug_link(link, "enslaved");
+
         if (!(link->flags & IFF_UP)) {
                 r = link_up(link);
                 if (r < 0) {
@@ -1749,7 +1737,7 @@ static int enslave_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
                 return 1;
 
         r = sd_rtnl_message_get_errno(m);
-        if (r < 0) {
+        if (r < 0 && r != -EEXIST) {
                 log_struct_link(LOG_ERR, link,
                                 "MESSAGE=%-*s: could not enslave: %s",
                                 IFNAMSIZ,
@@ -1760,9 +1748,7 @@ static int enslave_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
                 return 1;
         }
 
-        log_debug_link(link, "enslaved");
-
-        if (link->enslaving == 0)
+        if (link->enslaving <= 0)
                 link_enslaved(link);
 
         return 1;
@@ -1809,7 +1795,6 @@ static int link_enter_enslave(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->enslaving ++;
         }
 
@@ -1833,7 +1818,6 @@ static int link_enter_enslave(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->enslaving ++;
         }
 
@@ -1857,7 +1841,6 @@ static int link_enter_enslave(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->enslaving ++;
         }
 
@@ -1878,7 +1861,6 @@ static int link_enter_enslave(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->enslaving ++;
         }
 
@@ -1899,7 +1881,6 @@ static int link_enter_enslave(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->enslaving ++;
         }
 
@@ -1920,7 +1901,6 @@ static int link_enter_enslave(Link *link) {
                         return r;
                 }
 
-                link_ref(link);
                 link->enslaving ++;
         }
 
@@ -1992,6 +1972,7 @@ static int link_configure(Link *link) {
                         if (r < 0)
                                 return r;
                 }
+
                 if (link->network->dhcp_routes) {
                         r = sd_dhcp_client_set_request_option(link->dhcp_client, DHCP_OPTION_STATIC_ROUTE);
                         if (r < 0)
@@ -2000,6 +1981,18 @@ static int link_configure(Link *link) {
                         if (r < 0)
                                 return r;
                 }
+
+                if (link->network->dhcp_sendhost) {
+                        _cleanup_free_ char *hostname = gethostname_malloc();
+                        if (!hostname)
+                                return -ENOMEM;
+
+                        if (!is_localhost(hostname)) {
+                                r = sd_dhcp_client_set_hostname(link->dhcp_client, hostname);
+                                if (r < 0)
+                                        return r;
+                        }
+                }
         }
 
         if (link->network->dhcp_server) {
@@ -2147,7 +2140,7 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use
 
         r = address_new_dynamic(&address);
         if (r < 0)
-                return 0;
+                return r;
 
         r = sd_rtnl_message_addr_get_family(message, &address->family);
         if (r < 0 || !IN_SET(address->family, AF_INET, AF_INET6)) {
@@ -2211,7 +2204,10 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use
         case RTM_NEWADDR:
                 if (!address_dropped)
                         log_debug_link(link, "added address: %s/%u", buf,
-                                      address->prefixlen);
+                                       address->prefixlen);
+                else
+                        log_debug_link(link, "updated address: %s/%u", buf,
+                                       address->prefixlen);
 
                 LIST_PREPEND(addresses, link->addresses, address);
                 address = NULL;
@@ -2222,10 +2218,12 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use
         case RTM_DELADDR:
                 if (address_dropped) {
                         log_debug_link(link, "removed address: %s/%u", buf,
-                                      address->prefixlen);
+                                       address->prefixlen);
 
                         link_save(link);
-                }
+                } else
+                        log_warning_link(link, "removing non-existent address: %s/%u",
+                                         buf, address->prefixlen);
 
                 break;
         default: