+ r = sd_rtnl_message_read_string(m, IFLA_IFNAME, &ifname);
+ if (r >= 0 && !streq(ifname, link->ifname)) {
+ log_info_link(link, "renamed to %s", ifname);
+
+ free(link->ifname);
+ link->ifname = strdup(ifname);
+ if (!link->ifname)
+ return -ENOMEM;
+ }
+
+ r = sd_rtnl_message_read_u32(m, IFLA_MTU, &mtu);
+ if (r >= 0 && mtu > 0) {
+ link->mtu = mtu;
+ if (!link->original_mtu) {
+ link->original_mtu = mtu;
+ log_debug_link(link, "saved original MTU: %"
+ PRIu32, link->original_mtu);
+ }
+
+ if (link->dhcp_client) {
+ r = sd_dhcp_client_set_mtu(link->dhcp_client,
+ link->mtu);
+ if (r < 0) {
+ log_warning_link(link,
+ "Could not update MTU in DHCP client: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+ }
+
+ /* The kernel may broadcast NEWLINK messages without the MAC address
+ set, simply ignore them. */
+ r = sd_rtnl_message_read_ether_addr(m, IFLA_ADDRESS, &mac);
+ if (r >= 0) {
+ if (memcmp(link->mac.ether_addr_octet, mac.ether_addr_octet,
+ ETH_ALEN)) {
+
+ memcpy(link->mac.ether_addr_octet, mac.ether_addr_octet,
+ ETH_ALEN);
+
+ log_debug_link(link, "MAC address: "
+ "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
+ mac.ether_addr_octet[0],
+ mac.ether_addr_octet[1],
+ mac.ether_addr_octet[2],
+ mac.ether_addr_octet[3],
+ mac.ether_addr_octet[4],
+ mac.ether_addr_octet[5]);
+
+ if (link->ipv4ll) {
+ r = sd_ipv4ll_set_mac(link->ipv4ll, &link->mac);
+ if (r < 0) {
+ log_warning_link(link,
+ "Could not update MAC address in IPv4LL client: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ if (link->dhcp_client) {
+ r = sd_dhcp_client_set_mac(link->dhcp_client,
+ &link->mac);
+ if (r < 0) {
+ log_warning_link(link,
+ "Could not update MAC address in DHCP client: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ if (link->dhcp6_client) {
+ r = sd_dhcp6_client_set_mac(link->dhcp6_client,
+ &link->mac);
+ if (r < 0) {
+ log_warning_link(link,
+ "Could not update MAC address in DHCPv6 client: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+ }
+ }
+
+ return link_update_flags(link, m);
+}
+
+static void link_update_operstate(Link *link) {
+
+ assert(link);
+
+ if (link->kernel_operstate == IF_OPER_DORMANT)
+ link->operstate = LINK_OPERSTATE_DORMANT;
+ else if (link_has_carrier(link->flags, link->kernel_operstate)) {
+ Address *address;
+ uint8_t scope = RT_SCOPE_NOWHERE;
+
+ /* if we have carrier, check what addresses we have */
+ LIST_FOREACH(addresses, address, link->addresses) {
+ if (address->scope < scope)
+ scope = address->scope;
+ }
+
+ if (scope < RT_SCOPE_SITE)
+ /* universally accessible addresses found */
+ link->operstate = LINK_OPERSTATE_ROUTABLE;
+ else if (scope < RT_SCOPE_HOST)
+ /* only link or site local addresses found */
+ link->operstate = LINK_OPERSTATE_DEGRADED;
+ else
+ /* no useful addresses found */
+ link->operstate = LINK_OPERSTATE_CARRIER;
+ } else if (link->flags & IFF_UP)
+ link->operstate = LINK_OPERSTATE_NO_CARRIER;
+ else
+ link->operstate = LINK_OPERSTATE_OFF;
+}
+
+int link_save(Link *link) {
+ _cleanup_free_ char *temp_path = NULL;
+ _cleanup_fclose_ FILE *f = NULL;
+ const char *admin_state, *oper_state;
+ int r;
+
+ assert(link);
+ assert(link->state_file);
+ assert(link->lease_file);
+ assert(link->manager);
+
+ link_update_operstate(link);
+
+ r = manager_save(link->manager);
+ if (r < 0)