chiark / gitweb /
networkd: split out vlan and macvlan handling
[elogind.git] / src / network / networkd-link.c
index 8674eee9487a8949ed05d1deb25e63fcddd9d1ad..660efedc61b0d0dd515b1ab1cae219e735cde7d8 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);
@@ -1723,6 +1724,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 +1752,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 +1763,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;
@@ -1992,6 +1993,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 +2002,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) {