static int ipv4ll_address_lost(Link *link) { _cleanup_address_free_ Address *address = NULL; _cleanup_route_free_ Route *route = NULL; struct in_addr addr; int r; assert(link); link->ipv4ll_route = false; link->ipv4ll_address = false; r = sd_ipv4ll_get_address(link->ipv4ll, &addr); if (r < 0) return 0; log_link_debug(link, "IPv4 link-local release %u.%u.%u.%u", ADDRESS_FMT_VAL(addr)); r = address_new(&address); if (r < 0) { log_link_error_errno(link, r, "Could not allocate address: %m"); return r; } address->family = AF_INET; address->in_addr.in = addr; address->prefixlen = 16; address->scope = RT_SCOPE_LINK; address_remove(address, link, &link_address_remove_handler); r = route_new(&route); if (r < 0) { log_link_error_errno(link, r, "Could not allocate route: %m"); return r; } route->family = AF_INET; route->scope = RT_SCOPE_LINK; route->priority = IPV4LL_ROUTE_METRIC; route_remove(route, link, &link_route_remove_handler); link_check_ready(link); return 0; }
static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) { int r; Link *link = userdata; assert(link); assert(link->network); assert(link->manager); if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) return; switch(event) { case DHCP6_EVENT_STOP: case DHCP6_EVENT_RESEND_EXPIRE: case DHCP6_EVENT_RETRANS_MAX: log_link_debug(link, "DHCPv6 event %d", event); break; case DHCP6_EVENT_IP_ACQUIRE: r = dhcp6_lease_address_acquired(client, link); if (r < 0) { link_enter_failed(link); return; } /* fall through */ case DHCP6_EVENT_INFORMATION_REQUEST: r = dhcp6_lease_information_acquired(client, link); if (r < 0) { link_enter_failed(link); return; } break; default: if (event < 0) log_link_warning(link, "DHCPv6 error: %s", strerror(-event)); else log_link_warning(link, "DHCPv6 unknown event: %d", event); return; } }
/* dhcp4_set_promote_secondaries will ensure this interface has * the "promote_secondaries" option in the kernel set. If this sysctl * is not set DHCP will work only as long as the IP address does not * changes between leases. The kernel will remove all secondary IP * addresses of an interface otherwise. The way systemd-network works * is that the new IP of a lease is added as a secondary IP and when * the primary one expires it relies on the kernel to promote the * secondary IP. See also https://github.com/systemd/systemd/issues/7163 */ int dhcp4_set_promote_secondaries(Link *link) { int r; assert(link); assert(link->network); assert(link->network->dhcp & ADDRESS_FAMILY_IPV4); /* check if the kernel has promote_secondaries enabled for our * interface. If it is not globally enabled or enabled for the * specific interface we must either enable it. */ if (!(promote_secondaries_enabled("all") || promote_secondaries_enabled(link->ifname))) { char *promote_secondaries_path = NULL; log_link_debug(link, "promote_secondaries is unset, setting it"); promote_secondaries_path = strjoina("net/ipv4/conf/", link->ifname, "/promote_secondaries"); r = sysctl_write(promote_secondaries_path, "1"); if (r < 0) log_link_warning_errno(link, r, "cannot set sysctl %s to 1", promote_secondaries_path); return r > 0; } return 0; }
static int route_expire_callback(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { Link *link = userdata; int r; assert(rtnl); assert(m); assert(link); assert(link->ifname); assert(link->link_messages > 0); if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) return 1; link->link_messages--; r = sd_netlink_message_get_errno(m); if (r < 0 && r != -EEXIST) log_link_warning_errno(link, r, "could not remove route: %m"); if (link->link_messages == 0) log_link_debug(link, "route removed"); return 1; }