X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fnetwork%2Fnetworkd-link.c;h=06e093a18516497f29ea05eb4a1490f2a68f6242;hb=1372d5eff4631aeec132b8e22d243fb81a4fdbc8;hp=7cffcb48d06aea87804f9ed9b344d4bb99b5fd38;hpb=00e8d83a5a6fce20443b53bc42066bc756d5caeb;p=elogind.git diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 7cffcb48d..06e093a18 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -576,32 +576,6 @@ int link_route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { return 1; } -int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { - _cleanup_link_unref_ Link *link = userdata; - int r; - - assert(rtnl); - assert(m); - assert(link); - assert(link->manager); - - for (; m; m = sd_rtnl_message_next(m)) { - r = sd_rtnl_message_get_errno(m); - if (r < 0) { - log_link_debug(link, "getting address failed: %s", - strerror(-r)); - continue; - } - - r = link_rtnl_process_address(rtnl, m, link->manager); - if (r < 0) - log_link_warning(link, "could not process address: %s", - strerror(-r)); - } - - return 1; -} - static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { _cleanup_link_unref_ Link *link = userdata; int r; @@ -622,11 +596,8 @@ 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_link_warning_errno(link, -r, "%-*s: could not set address: %m", IFNAMSIZ, link->ifname); - else if (r >= 0) { - /* calling handler directly so take a ref */ - link_ref(link); - link_get_address_handler(rtnl, m, link); - } + else if (r >= 0) + link_rtnl_process_address(rtnl, m, link->manager); if (link->link_messages == 0) { log_link_debug(link, "addresses set"); @@ -1074,6 +1045,7 @@ static int link_up(Link *link) { int r; assert(link); + assert(link->network); assert(link->manager); assert(link->manager->rtnl); @@ -1093,6 +1065,22 @@ static int link_up(Link *link) { return r; } + if (link->network->mac) { + r = sd_rtnl_message_append_ether_addr(req, IFLA_ADDRESS, link->network->mac); + if (r < 0) { + log_link_error(link, "Could not set MAC address: %s", strerror(-r)); + return r; + } + } + + if (link->network->mtu) { + r = sd_rtnl_message_append_u32(req, IFLA_MTU, link->network->mtu); + if (r < 0) { + log_link_error(link, "Could not set MTU: %s", strerror(-r)); + return r; + } + } + r = sd_rtnl_call_async(link->manager->rtnl, req, link_up_handler, link, 0, NULL); if (r < 0) { @@ -1400,8 +1388,7 @@ int link_initialized(Link *link, struct udev_device *device) { return 0; } -int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, - void *userdata) { +int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata) { Manager *m = userdata; Link *link = NULL; uint16_t type; @@ -1417,6 +1404,14 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, assert(message); assert(m); + if (sd_rtnl_message_is_error(message)) { + r = sd_rtnl_message_get_errno(message); + if (r < 0) + log_warning_errno(r, "rtnl: failed to receive address: %m"); + + return 0; + } + r = sd_rtnl_message_get_type(message, &type); if (r < 0) { log_warning("rtnl: could not get message type"); @@ -1424,13 +1419,16 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, } r = sd_rtnl_message_addr_get_ifindex(message, &ifindex); - if (r < 0 || ifindex <= 0) { - log_warning("rtnl: received address message without valid ifindex, ignoring"); + if (r < 0) { + log_warning_errno(r, "rtnl: could not get ifindex: %m"); + return 0; + } else if (ifindex <= 0) { + log_warning("rtnl: received address message with invalid ifindex: %d", ifindex); return 0; } else { r = link_get(m, ifindex, &link); if (r < 0 || !link) { - log_warning("rtnl: received address for a nonexistent link (%d), ignoring", ifindex); + log_warning("rtnl: received address for nonexistent link (%d), ignoring", ifindex); return 0; } } @@ -1559,7 +1557,6 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, int link_add(Manager *m, sd_rtnl_message *message, Link **ret) { Link *link; - _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL; _cleanup_udev_device_unref_ struct udev_device *device = NULL; char ifindex_str[2 + DECIMAL_STR_MAX(int)]; int r; @@ -1577,18 +1574,6 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) { log_link_debug(link, "link %d added", link->ifindex); - r = sd_rtnl_message_new_addr(m->rtnl, &req, RTM_GETADDR, link->ifindex, - 0); - if (r < 0) - return r; - - r = sd_rtnl_call_async(m->rtnl, req, link_get_address_handler, link, 0, - NULL); - if (r < 0) - return r; - - link_ref(link); - if (detect_container(NULL) <= 0) { /* not in a container, udev will be around */ sprintf(ifindex_str, "n%d", link->ifindex);