chiark / gitweb /
networkd: rename netdev variables
[elogind.git] / src / network / networkd-link.c
index 4b59af4ab093b5f8343e047605e0d9e5bc8fdc80..f496978cbae6e64744548f1d3dbc2300f61eac02 100644 (file)
@@ -296,7 +296,7 @@ static int route_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EEXIST)
                 log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%*s: could not set route: %s",
+                                "MESSAGE=%-*s: could not set route: %s",
                                 IFNAMSIZ,
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
@@ -462,7 +462,7 @@ static int route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata)
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -ESRCH)
                 log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%*s: could not drop route: %s",
+                                "MESSAGE=%-*s: could not drop route: %s",
                                 IFNAMSIZ,
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
@@ -494,7 +494,7 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EEXIST)
                 log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%*s: could not set address: %s",
+                                "MESSAGE=%-*s: could not set address: %s",
                                 IFNAMSIZ,
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
@@ -641,7 +641,7 @@ static int address_update_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userd
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -ENOENT)
                 log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%*s: could not update address: %s",
+                                "MESSAGE=%-*s: could not update address: %s",
                                 IFNAMSIZ,
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
@@ -668,7 +668,7 @@ static int address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdat
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EADDRNOTAVAIL)
                 log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%*s: could not drop address: %s",
+                                "MESSAGE=%-*s: could not drop address: %s",
                                 IFNAMSIZ,
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
@@ -753,8 +753,8 @@ static int set_mtu_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         r = sd_rtnl_message_get_errno(m);
         if (r < 0)
                 log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%s: could not set MTU: %s",
-                                link->ifname, strerror(-r),
+                                "MESSAGE=%-*s: could not set MTU: %s",
+                                IFNAMSIZ, link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
                                 NULL);
 
@@ -922,7 +922,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
 
         if (r >= 0)
                 log_struct_link(LOG_INFO, link,
-                                "MESSAGE=%*s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
+                                "MESSAGE=%-*s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
                                  IFNAMSIZ,
                                  link->ifname,
                                  ADDRESS_FMT_VAL(address),
@@ -937,7 +937,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
                                  NULL);
         else
                 log_struct_link(LOG_INFO, link,
-                                "MESSAGE=%*s: DHCPv4 address %u.%u.%u.%u/%u",
+                                "MESSAGE=%-*s: DHCPv4 address %u.%u.%u.%u/%u",
                                  IFNAMSIZ,
                                  link->ifname,
                                  ADDRESS_FMT_VAL(address),
@@ -1164,7 +1164,7 @@ static int ipv4ll_address_claimed(sd_ipv4ll *ll, Link *link) {
                 return r;
 
         log_struct_link(LOG_INFO, link,
-                        "MESSAGE=%*s: IPv4 link-local address %u.%u.%u.%u",
+                        "MESSAGE=%-*s: IPv4 link-local address %u.%u.%u.%u",
                         IFNAMSIZ,
                         link->ifname,
                         ADDRESS_FMT_VAL(address),
@@ -1384,7 +1384,7 @@ static int link_up_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
                 /* we warn but don't fail the link, as it may
                    be brought up later */
                 log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%*s: could not bring up interface: %s",
+                                "MESSAGE=%-*s: could not bring up interface: %s",
                                 IFNAMSIZ,
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
@@ -1471,7 +1471,7 @@ static int enslave_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         r = sd_rtnl_message_get_errno(m);
         if (r < 0) {
                 log_struct_link(LOG_ERR, link,
-                                "MESSAGE=%*s: could not enslave: %s",
+                                "MESSAGE=%-*s: could not enslave: %s",
                                 IFNAMSIZ,
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
@@ -1513,7 +1513,7 @@ static int link_enter_enslave(Link *link) {
 
         if (link->network->bond) {
                 log_struct_link(LOG_DEBUG, link,
-                                "MESSAGE=%*s: enslaving by '%s'",
+                                "MESSAGE=%-*s: enslaving by '%s'",
                                 IFNAMSIZ,
                                 link->ifname, link->network->bond->ifname,
                                 NETDEV(link->network->bond),
@@ -1522,7 +1522,7 @@ static int link_enter_enslave(Link *link) {
                 r = netdev_enslave(link->network->bond, link, &enslave_handler);
                 if (r < 0) {
                         log_struct_link(LOG_WARNING, link,
-                                        "MESSAGE=%*s: could not enslave by '%s': %s",
+                                        "MESSAGE=%-*s: could not enslave by '%s': %s",
                                         IFNAMSIZ,
                                         link->ifname, link->network->bond->ifname, strerror(-r),
                                         NETDEV(link->network->bond),
@@ -1537,7 +1537,7 @@ static int link_enter_enslave(Link *link) {
 
         if (link->network->bridge) {
                 log_struct_link(LOG_DEBUG, link,
-                                "MESSAGE=%*s: enslaving by '%s'",
+                                "MESSAGE=%-*s: enslaving by '%s'",
                                 IFNAMSIZ,
                                 link->ifname, link->network->bridge->ifname,
                                 NETDEV(link->network->bridge),
@@ -1546,7 +1546,7 @@ static int link_enter_enslave(Link *link) {
                 r = netdev_enslave(link->network->bridge, link, &enslave_handler);
                 if (r < 0) {
                         log_struct_link(LOG_WARNING, link,
-                                        "MESSAGE=%*s: could not enslave by '%s': %s",
+                                        "MESSAGE=%-*s: could not enslave by '%s': %s",
                                         IFNAMSIZ,
                                         link->ifname, link->network->bridge->ifname, strerror(-r),
                                         NETDEV(link->network->bridge),
@@ -1561,7 +1561,7 @@ static int link_enter_enslave(Link *link) {
 
         if (link->network->tunnel) {
                 log_struct_link(LOG_DEBUG, link,
-                                "MESSAGE=%*s: enslaving by '%s'",
+                                "MESSAGE=%-*s: enslaving by '%s'",
                                 IFNAMSIZ,
                                 link->ifname, link->network->tunnel->ifname,
                                 NETDEV(link->network->tunnel),
@@ -1570,7 +1570,7 @@ static int link_enter_enslave(Link *link) {
                 r = netdev_enslave(link->network->tunnel, link, &enslave_handler);
                 if (r < 0) {
                         log_struct_link(LOG_WARNING, link,
-                                        "MESSAGE=%*s: could not enslave by '%s': %s",
+                                        "MESSAGE=%-*s: could not enslave by '%s': %s",
                                         IFNAMSIZ,
                                         link->ifname, link->network->tunnel->ifname, strerror(-r),
                                         NETDEV(link->network->tunnel),
@@ -1585,14 +1585,14 @@ static int link_enter_enslave(Link *link) {
 
         HASHMAP_FOREACH(vlan, link->network->vlans, i) {
                 log_struct_link(LOG_DEBUG, link,
-                                "MESSAGE=%*s: enslaving by '%s'",
+                                "MESSAGE=%-*s: enslaving by '%s'",
                                 IFNAMSIZ,
                                 link->ifname, vlan->ifname, NETDEV(vlan), NULL);
 
                 r = netdev_enslave(vlan, link, &enslave_handler);
                 if (r < 0) {
                         log_struct_link(LOG_WARNING, link,
-                                        "MESSAGE=%*s: could not enslave by '%s': %s",
+                                        "MESSAGE=%-*s: could not enslave by '%s': %s",
                                         IFNAMSIZ,
                                         link->ifname, vlan->ifname, strerror(-r),
                                         NETDEV(vlan), NULL);
@@ -1606,14 +1606,14 @@ static int link_enter_enslave(Link *link) {
 
         HASHMAP_FOREACH(macvlan, link->network->macvlans, i) {
                 log_struct_link(LOG_DEBUG, link,
-                                "MESSAGE=%*s: enslaving by '%s'",
+                                "MESSAGE=%-*s: enslaving by '%s'",
                                 IFNAMSIZ,
                                 link->ifname, macvlan->ifname, NETDEV(macvlan), NULL);
 
                 r = netdev_enslave(macvlan, link, &enslave_handler);
                 if (r < 0) {
                         log_struct_link(LOG_WARNING, link,
-                                        "MESSAGE=%*s: could not enslave by '%s': %s",
+                                        "MESSAGE=%-*s: could not enslave by '%s': %s",
                                         IFNAMSIZ,
                                         link->ifname, macvlan->ifname, strerror(-r),
                                         NETDEV(macvlan), NULL);
@@ -1723,6 +1723,8 @@ static int link_configure(Link *link) {
                         pool_start.s_addr = htobe32(be32toh(address->in_addr.in.s_addr) + 1);
                         r = sd_dhcp_server_set_lease_pool(link->dhcp_server,
                                                           &pool_start, 32);
+                        if (r < 0)
+                                return r;
 
                         break;
                 }
@@ -1749,7 +1751,8 @@ static int link_configure(Link *link) {
         return link_enter_enslave(link);
 }
 
-int link_initialized(Link *link, struct udev_device *device) {
+static int link_initialized_and_synced(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+        Link *link = userdata;
         Network *network;
         int r;
 
@@ -1760,12 +1763,9 @@ int link_initialized(Link *link, struct udev_device *device) {
         if (link->state != LINK_STATE_INITIALIZING)
                 return 0;
 
-        if (device)
-                link->udev_device = udev_device_ref(device);
+        log_debug_link(link, "link state is up-to-date");
 
-        log_debug_link(link, "udev initialized link");
-
-        r = network_get(link->manager, device, link->ifname, &link->mac, &network);
+        r = network_get(link->manager, link->udev_device, link->ifname, &link->mac, &network);
         if (r == -ENOENT) {
                 link_enter_unmanaged(link);
                 return 0;
@@ -1783,6 +1783,38 @@ int link_initialized(Link *link, struct udev_device *device) {
         return 0;
 }
 
+int link_initialized(Link *link, struct udev_device *device) {
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+        int r;
+
+        assert(link);
+        assert(link->manager);
+        assert(link->manager->rtnl);
+        assert(device);
+
+        if (link->state != LINK_STATE_INITIALIZING)
+                return 0;
+
+        log_debug_link(link, "udev initialized link");
+
+        link->udev_device = udev_device_ref(device);
+
+        /* udev has initialized the link, but we don't know if we have yet processed
+           the NEWLINK messages with the latest state. Do a GETLINK, when it returns
+           we know that the pending NEWLINKs have already been processed and that we
+           are up-to-date */
+
+        r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_GETLINK, link->ifindex);
+        if (r < 0)
+                return r;
+
+        r = sd_rtnl_call_async(link->manager->rtnl, req, link_initialized_and_synced, link, 0, NULL);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
 int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata) {
         Manager *m = userdata;
         Link *link = NULL;
@@ -1970,11 +2002,15 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
                         log_debug_link(link, "udev initializing link...");
                         return 0;
                 }
-        }
 
-        r = link_initialized(link, device);
-        if (r < 0)
-                return r;
+                r = link_initialized(link, device);
+                if (r < 0)
+                        return r;
+        } else {
+                r = link_initialized_and_synced(m->rtnl, NULL, link);
+                if (r < 0)
+                        return r;
+        }
 
         return 0;
 }
@@ -2150,6 +2186,8 @@ int link_save(Link *link) {
         }
 
         if (link->dhcp_lease) {
+                assert(link->network);
+
                 r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
                 if (r < 0)
                         goto finish;