static bool ipv4ll_is_bound(sd_ipv4ll *ll);
static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
- _cleanup_link_free_ Link *link = NULL;
+ _cleanup_link_unref_ Link *link = NULL;
uint16_t type;
char *ifname;
int r, ifindex;
if (!link)
return -ENOMEM;
+ link->n_ref = 1;
link->manager = manager;
link->state = LINK_STATE_INITIALIZING;
link->ifindex = ifindex;
if (r < 0)
return -ENOMEM;
+ r = asprintf(&link->lease_file, "/run/systemd/network/leases/%"PRIu64,
+ link->ifindex);
+ if (r < 0)
+ return -ENOMEM;
+
r = hashmap_put(manager->links, &link->ifindex, link);
if (r < 0)
return r;
return 0;
}
-void link_free(Link *link) {
+static void link_free(Link *link) {
if (!link)
return;
sd_dhcp_client_unref(link->dhcp_client);
sd_dhcp_lease_unref(link->dhcp_lease);
+ unlink(link->lease_file);
+ free(link->lease_file);
+
sd_ipv4ll_unref(link->ipv4ll);
hashmap_remove(link->manager->links, &link->ifindex);
free(link->ifname);
+
+ unlink(link->state_file);
free(link->state_file);
udev_device_unref(link->udev_device);
free(link);
}
+Link *link_unref(Link *link) {
+ if (link && (-- link->n_ref <= 0))
+ link_free(link);
+
+ return NULL;
+}
+
+Link *link_ref(Link *link) {
+ if (link)
+ assert_se(++ link->n_ref >= 2);
+
+ return link;
+}
+
int link_get(Manager *m, int ifindex, Link **ret) {
Link *link;
uint64_t ifindex_64;
return 0;
}
+void link_drop(Link *link) {
+ if (!link || link->state == LINK_STATE_LINGER)
+ return;
+
+ link->state = LINK_STATE_LINGER;
+
+ log_debug_link(link, "link removed");
+
+ link_unref(link);
+
+ return;
+}
+
static int link_enter_configured(Link *link) {
assert(link);
assert(link->state == LINK_STATE_SETTING_ROUTES);
static void link_enter_failed(Link *link) {
assert(link);
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
return;
log_warning_link(link, "failed");
int r;
assert(link->route_messages > 0);
- assert(link->state == LINK_STATE_SETTING_ADDRESSES ||
- link->state == LINK_STATE_SETTING_ROUTES ||
- link->state == LINK_STATE_FAILED);
+ assert(IN_SET(link->state, LINK_STATE_SETTING_ADDRESSES,
+ LINK_STATE_SETTING_ROUTES, LINK_STATE_FAILED,
+ LINK_STATE_LINGER));
link->route_messages --;
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
return 1;
+ }
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST)
link_enter_configured(link);
}
+ link_unref(link);
+
return 1;
}
link->state = LINK_STATE_SETTING_ROUTES;
if (!link->network->static_routes && !link->dhcp_lease &&
- (!link->ipv4ll || ipv4ll_is_bound(link->ipv4ll) == false))
+ (!link->ipv4ll || ipv4ll_is_bound(link->ipv4ll) == false))
return link_enter_configured(link);
log_debug_link(link, "setting routes");
return r;
}
+ link_ref(link);
link->route_messages ++;
}
return r;
}
+ link_ref(link);
link->route_messages ++;
}
}
return r;
}
+ link_ref(link);
link->route_messages ++;
route->family = AF_INET;
return r;
}
+ link_ref(link);
link->route_messages ++;
}
}
assert(link);
assert(link->ifname);
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
return 1;
+ }
r = sd_rtnl_message_get_errno(m);
- if (r < 0 && r != -ENOENT)
+ if (r < 0 && r != -ESRCH)
log_struct_link(LOG_WARNING, link,
"MESSAGE=%s: could not drop route: %s",
link->ifname, strerror(-r),
"ERRNO=%d", -r,
NULL);
+ link_unref(link);
+
return 0;
}
assert(link);
assert(link->ifname);
assert(link->addr_messages > 0);
- assert(link->state == LINK_STATE_SETTING_ADDRESSES || link->state == LINK_STATE_FAILED);
+ assert(IN_SET(link->state, LINK_STATE_SETTING_ADDRESSES,
+ LINK_STATE_FAILED, LINK_STATE_LINGER));
link->addr_messages --;
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
return 1;
+ }
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST)
link_enter_set_routes(link);
}
+ link_unref(link);
+
return 1;
}
return r;
}
+ link_ref(link);
link->addr_messages ++;
}
return r;
}
+ link_ref(link);
link->addr_messages ++;
}
}
return r;
}
+ link_ref(link);
link->addr_messages ++;
}
assert(link);
assert(link->ifname);
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
return 1;
+ }
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -ENOENT)
"ERRNO=%d", -r,
NULL);
+ link_unref(link);
+
return 0;
}
assert(link);
assert(link->ifname);
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
return 1;
+ }
r = sd_rtnl_message_get_errno(m);
- if (r < 0 && r != -ENOENT)
+ if (r < 0 && r != -EADDRNOTAVAIL)
log_struct_link(LOG_WARNING, link,
"MESSAGE=%s: could not drop address: %s",
link->ifname, strerror(-r),
"ERRNO=%d", -r,
NULL);
+ link_unref(link);
+
return 0;
}
static int set_hostname_handler(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
+ Link *link = userdata;
int r;
+ assert(link);
+
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
+ return 1;
+ }
+
r = sd_bus_message_get_errno(m);
if (r < 0)
log_warning("Could not set hostname: %s", strerror(-r));
+ link_unref(link);
+
return 1;
}
-static int set_hostname(sd_bus *bus, const char *hostname) {
+static int link_set_hostname(Link *link, const char *hostname) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
int r = 0;
+ assert(link);
+ assert(link->manager);
assert(hostname);
- log_debug("Setting transient hostname: '%s'", hostname);
+ log_debug_link(link, "Setting transient hostname: '%s'", hostname);
- if (!bus) { /* TODO: replace by assert when we can rely on kdbus */
- log_info("Not connected to system bus, ignoring transient hostname.");
+ if (!link->manager->bus) { /* TODO: replace by assert when we can rely on kdbus */
+ log_info_link(link, "Not connected to system bus, ignoring transient hostname.");
return 0;
}
r = sd_bus_message_new_method_call(
- bus,
+ link->manager->bus,
&m,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
if (r < 0)
return r;
- r = sd_bus_call_async(bus, m, set_hostname_handler, NULL, 0, NULL);
+ r = sd_bus_call_async(link->manager->bus, m, set_hostname_handler, link, 0, NULL);
if (r < 0)
- log_error("Could not set transient hostname: %s", strerror(-r));
+ log_error_link(link, "Could not set transient hostname: %s", strerror(-r));
+
+ link_ref(link);
return r;
}
assert(link);
assert(link->ifname);
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
return 1;
+ }
r = sd_rtnl_message_get_errno(m);
if (r < 0)
"ERRNO=%d", -r,
NULL);
+ link_unref(link);
+
return 1;
}
return r;
}
+ link_unref(link);
+
return 0;
}
route_gw->scope = RT_SCOPE_LINK;
route_drop(route_gw, link, &route_drop_handler);
+ link_ref(link);
}
r = route_new_dynamic(&route);
route->in_addr.in = gateway;
route_drop(route, link, &route_drop_handler);
+ link_ref(link);
}
}
address->prefixlen = prefixlen;
address_drop(address, link, &address_drop_handler);
+ link_ref(link);
}
if (link->network->dhcp_mtu) {
r = sd_dhcp_lease_get_hostname(link->dhcp_lease, &hostname);
if (r >= 0 && hostname) {
- r = set_hostname(link->manager->bus, "");
+ r = link_set_hostname(link, "");
if (r < 0)
log_error("Failed to reset transient hostname");
}
r = sd_dhcp_lease_get_hostname(lease, &hostname);
if (r >= 0) {
- r = set_hostname(link->manager->bus, hostname);
+ r = link_set_hostname(link, hostname);
if (r < 0)
log_error("Failed to set transient hostname "
"to '%s'", hostname);
assert(link->network);
assert(link->manager);
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
return;
switch (event) {
address->broadcast.s_addr = address->in_addr.in.s_addr | htonl(0xfffffffflu >> address->prefixlen);
address_update(address, link, &address_update_handler);
+ link_ref(link);
}
return 0;
address->scope = RT_SCOPE_LINK;
address_drop(address, link, &address_drop_handler);
+ link_ref(link);
r = route_new_dynamic(&route);
if (r < 0) {
route->metrics = 99;
route_drop(route, link, &route_drop_handler);
+ link_ref(link);
}
return 0;
assert(link->network);
assert(link->manager);
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+ return;
+
switch(event) {
case IPV4LL_EVENT_STOP:
case IPV4LL_EVENT_CONFLICT:
return false;
}
+#define FLAG_STRING(string, flag, old, new) \
+ (((old ^ new) & flag) \
+ ? ((old & flag) ? (" -" string) : (" +" string)) \
+ : "")
+
static int link_update_flags(Link *link, sd_rtnl_message *m) {
- unsigned flags, flags_added, flags_removed, generic_flags;
+ unsigned flags, unknown_flags_added, unknown_flags_removed, unknown_flags;
uint8_t operstate;
bool carrier_gained = false, carrier_lost = false;
int r;
if ((link->flags == flags) && (link->operstate == operstate))
return 0;
- flags_added = (link->flags ^ flags) & flags;
- flags_removed = (link->flags ^ flags) & link->flags;
- generic_flags = ~(IFF_UP | IFF_LOWER_UP | IFF_DORMANT | IFF_DEBUG |
- IFF_MULTICAST | IFF_BROADCAST | IFF_PROMISC |
- IFF_NOARP | IFF_MASTER | IFF_SLAVE | IFF_RUNNING);
-
- if (flags_added & IFF_UP)
- log_debug_link(link, "link is up");
- else if (flags_removed & IFF_UP)
- log_debug_link(link, "link is down");
-
- if (flags_added & IFF_LOWER_UP)
- log_debug_link(link, "link is lower up");
- else if (flags_removed & IFF_LOWER_UP)
- log_debug_link(link, "link is lower down");
-
- if (flags_added & IFF_DORMANT)
- log_debug_link(link, "link is dormant");
- else if (flags_removed & IFF_DORMANT)
- log_debug_link(link, "link is not dormant");
-
- if (flags_added & IFF_DEBUG)
- log_debug_link(link, "debugging enabled in the kernel");
- else if (flags_removed & IFF_DEBUG)
- log_debug_link(link, "debugging disabled in the kernel");
-
- if (flags_added & IFF_MULTICAST)
- log_debug_link(link, "multicast enabled");
- else if (flags_removed & IFF_MULTICAST)
- log_debug_link(link, "multicast disabled");
-
- if (flags_added & IFF_BROADCAST)
- log_debug_link(link, "broadcast enabled");
- else if (flags_removed & IFF_BROADCAST)
- log_debug_link(link, "broadcast disabled");
-
- if (flags_added & IFF_PROMISC)
- log_debug_link(link, "promiscuous mode enabled");
- else if (flags_removed & IFF_PROMISC)
- log_debug_link(link, "promiscuous mode disabled");
-
- if (flags_added & IFF_NOARP)
- log_debug_link(link, "ARP protocol disabled");
- else if (flags_removed & IFF_NOARP)
- log_debug_link(link, "ARP protocol enabled");
-
- if (flags_added & IFF_MASTER)
- log_debug_link(link, "link is master");
- else if (flags_removed & IFF_MASTER)
- log_debug_link(link, "link is no longer master");
-
- if (flags_added & IFF_SLAVE)
- log_debug_link(link, "link is slave");
- else if (flags_removed & IFF_SLAVE)
- log_debug_link(link, "link is no longer slave");
-
- /* link flags are currently at most 18 bits, let's default to printing 20 */
- if (flags_added & generic_flags)
- log_debug_link(link, "unknown link flags gained: %#.5x (ignoring)",
- flags_added & generic_flags);
-
- if (flags_removed & generic_flags)
- log_debug_link(link, "unknown link flags lost: %#.5x (ignoring)",
- flags_removed & generic_flags);
+ if (link->flags != flags) {
+ log_debug_link(link, "flags change:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+ FLAG_STRING("LOOPBACK", IFF_LOOPBACK, link->flags, flags),
+ FLAG_STRING("MASTER", IFF_MASTER, link->flags, flags),
+ FLAG_STRING("SLAVE", IFF_SLAVE, link->flags, flags),
+ FLAG_STRING("UP", IFF_UP, link->flags, flags),
+ FLAG_STRING("DORMANT", IFF_DORMANT, link->flags, flags),
+ FLAG_STRING("LOWER_UP", IFF_LOWER_UP, link->flags, flags),
+ FLAG_STRING("RUNNING", IFF_RUNNING, link->flags, flags),
+ FLAG_STRING("MULTICAST", IFF_MULTICAST, link->flags, flags),
+ FLAG_STRING("BROADCAST", IFF_BROADCAST, link->flags, flags),
+ FLAG_STRING("POINTOPOINT", IFF_POINTOPOINT, link->flags, flags),
+ FLAG_STRING("PROMISC", IFF_PROMISC, link->flags, flags),
+ FLAG_STRING("ALLMULTI", IFF_ALLMULTI, link->flags, flags),
+ FLAG_STRING("PORTSEL", IFF_PORTSEL, link->flags, flags),
+ FLAG_STRING("AUTOMEDIA", IFF_AUTOMEDIA, link->flags, flags),
+ FLAG_STRING("DYNAMIC", IFF_DYNAMIC, link->flags, flags),
+ FLAG_STRING("NOARP", IFF_NOARP, link->flags, flags),
+ FLAG_STRING("NOTRAILERS", IFF_NOTRAILERS, link->flags, flags),
+ FLAG_STRING("DEBUG", IFF_DEBUG, link->flags, flags),
+ FLAG_STRING("ECHO", IFF_ECHO, link->flags, flags));
+
+ unknown_flags = ~(IFF_LOOPBACK | IFF_MASTER | IFF_SLAVE | IFF_UP |
+ IFF_DORMANT | IFF_LOWER_UP | IFF_RUNNING |
+ IFF_MULTICAST | IFF_BROADCAST | IFF_POINTOPOINT |
+ IFF_PROMISC | IFF_ALLMULTI | IFF_PORTSEL |
+ IFF_AUTOMEDIA | IFF_DYNAMIC | IFF_NOARP |
+ IFF_NOTRAILERS | IFF_DEBUG | IFF_ECHO);
+ unknown_flags_added = ((link->flags ^ flags) & flags & unknown_flags);
+ unknown_flags_removed = ((link->flags ^ flags) & link->flags & unknown_flags);
+
+ /* link flags are currently at most 18 bits, let's align to printing 20 */
+ if (unknown_flags_added)
+ log_debug_link(link, "unknown link flags gained: %#.5x (ignoring)",
+ unknown_flags_added);
+
+ if (unknown_flags_removed)
+ log_debug_link(link, "unknown link flags lost: %#.5x (ignoring)",
+ unknown_flags_removed);
+ }
carrier_gained = !link_has_carrier(link->flags, link->operstate) &&
link_has_carrier(flags, operstate);
assert(link);
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
return 1;
+ }
r = sd_rtnl_message_get_errno(m);
if (r < 0) {
NULL);
}
+ link_unref(link);
+
return 1;
}
return r;
}
+ link_ref(link);
+
return 0;
}
int r;
assert(link);
- assert(link->state == LINK_STATE_ENSLAVING || link->state == LINK_STATE_FAILED);
+ assert(IN_SET(link->state, LINK_STATE_ENSLAVING, LINK_STATE_FAILED,
+ LINK_STATE_LINGER));
assert(link->network);
link->enslaving --;
- if (link->state == LINK_STATE_FAILED)
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ link_unref(link);
return 1;
+ }
r = sd_rtnl_message_get_errno(m);
if (r < 0) {
"ERRNO=%d", -r,
NULL);
link_enter_failed(link);
+ link_unref(link);
return 1;
}
if (link->enslaving == 0)
link_enslaved(link);
+ link_unref(link);
+
return 1;
}
link_save(link);
- if (!link->network->bridge && !link->network->bond &&
+ if (!link->network->bridge &&
+ !link->network->bond &&
+ !link->network->tunnel &&
hashmap_isempty(link->network->vlans) &&
hashmap_isempty(link->network->macvlans))
return link_enslaved(link);
+ if (link->network->bond) {
+ log_struct_link(LOG_DEBUG, link,
+ "MESSAGE=%s: enslaving by '%s'",
+ link->ifname, link->network->bond->name,
+ NETDEV(link->network->bond),
+ NULL);
+
+ 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",
+ link->ifname, link->network->bond->name, strerror(-r),
+ NETDEV(link->network->bond),
+ NULL);
+ link_enter_failed(link);
+ return r;
+ }
+
+ link_ref(link);
+ link->enslaving ++;
+ }
+
if (link->network->bridge) {
log_struct_link(LOG_DEBUG, link,
"MESSAGE=%s: enslaving by '%s'",
return r;
}
+ link_ref(link);
link->enslaving ++;
}
- if (link->network->bond) {
+ if (link->network->tunnel) {
log_struct_link(LOG_DEBUG, link,
"MESSAGE=%s: enslaving by '%s'",
- link->ifname, link->network->bond->name,
- NETDEV(link->network->bond),
+ link->ifname, link->network->tunnel->name,
+ NETDEV(link->network->tunnel),
NULL);
- r = netdev_enslave(link->network->bond, link, &enslave_handler);
+ 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",
- link->ifname, link->network->bond->name, strerror(-r),
- NETDEV(link->network->bond),
+ link->ifname, link->network->tunnel->name, strerror(-r),
+ NETDEV(link->network->tunnel),
NULL);
link_enter_failed(link);
return r;
}
+ link_ref(link);
link->enslaving ++;
}
return r;
}
+ link_ref(link);
link->enslaving ++;
}
return r;
}
+ link_ref(link);
link->enslaving ++;
}
return 0;
}
+int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata) {
+ Manager *m = userdata;
+ Link *link = NULL;
+ uint16_t type;
+ _cleanup_address_free_ Address *address = NULL;
+ char buf[INET6_ADDRSTRLEN];
+ int r, ifindex;
+
+ assert(rtnl);
+ assert(message);
+ assert(m);
+
+ r = sd_rtnl_message_get_type(message, &type);
+ if (r < 0) {
+ log_warning("rtnl: could not get message type");
+ return 0;
+ }
+
+ r = sd_rtnl_message_addr_get_ifindex(message, &ifindex);
+ if (r < 0 || ifindex <= 0) {
+ log_warning("rtnl: received address message without valid ifindix, ignoring");
+ return 0;
+ } else {
+ r = link_get(m, ifindex, &link);
+ if (r < 0 || !link) {
+ log_warning("rtnl: received address for non-existing link, ignoring");
+ return 0;
+ }
+ }
+
+ r = address_new_dynamic(&address);
+ if (r < 0)
+ return 0;
+
+ r = sd_rtnl_message_addr_get_family(message, &address->family);
+ if (r < 0 || !IN_SET(address->family, AF_INET, AF_INET6)) {
+ log_warning("rtnl: received address with invalid family, ignoring");
+ return 0;
+ }
+
+ r = sd_rtnl_message_addr_get_prefixlen(message, &address->prefixlen);
+ if (r < 0) {
+ log_warning("rtnl: recevied address with invalid prefixlen, ignoring");
+ return 0;
+ }
+
+ switch (address->family) {
+ case AF_INET:
+ r = sd_rtnl_message_read_in_addr(message, IFA_LOCAL, &address->in_addr.in);
+ if (r < 0) {
+ log_warning("rtnl: received address without valid address, ignoring");
+ return 0;
+ }
+
+ break;
+
+ case AF_INET6:
+ r = sd_rtnl_message_read_in6_addr(message, IFA_ADDRESS, &address->in_addr.in6);
+ if (r < 0) {
+ log_warning("rtnl: received address without valid address, ignoring");
+ return 0;
+ }
+
+ break;
+
+ default:
+ assert_not_reached("invalid address family");
+ }
+
+ if (!inet_ntop(address->family, &address->in_addr, buf, INET6_ADDRSTRLEN)) {
+ log_warning("could not print address");
+ return 0;
+ }
+
+ switch (type) {
+ case RTM_NEWADDR:
+ log_info("added address: %s/%u to ifindex %d", buf,
+ address->prefixlen, ifindex);
+ break;
+
+ case RTM_DELADDR:
+ log_info("removed address: %s/%u from ifindex %d", buf,
+ address->prefixlen, ifindex);
+ break;
+ default:
+ assert_not_reached("Received invalid RTNL message type");
+ }
+
+ return 1;
+}
+
+static int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+ Link *link = userdata;
+ int r;
+
+ assert(rtnl);
+ assert(m);
+ assert(link);
+
+ for (; m; m = sd_rtnl_message_next(m)) {
+ r = sd_rtnl_message_get_errno(m);
+ if (r < 0) {
+ log_debug_link(link, "getting address failed: %s", strerror(-r));
+ continue;
+ }
+
+ r = link_rtnl_process_address(rtnl, m, link->manager);
+ if (r < 0)
+ log_warning_link(link, "could not process address: %s", strerror(-r));
+ }
+
+ return 1;
+}
+
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;
assert(m);
+ assert(m->rtnl);
assert(message);
assert(ret);
log_debug_link(link, "link added");
+ 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;
+
if (detect_container(NULL) <= 0) {
/* not in a container, udev will be around */
sprintf(ifindex_str, "n%"PRIu64, link->ifindex);
assert(link->ifname);
assert(m);
+ if (link->state == LINK_STATE_LINGER) {
+ link_ref(link);
+ log_info_link(link, "link readded");
+ link->state = LINK_STATE_ENSLAVING;
+ }
+
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);
}
int link_save(Link *link) {
- _cleanup_free_ char *temp_path = NULL, *lease_file = NULL;
+ _cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
const char *admin_state, *oper_state = "unknown";
int r;
assert(link);
assert(link->state_file);
+ assert(link->lease_file);
assert(link->manager);
r = manager_save(link->manager);
if (r < 0)
return r;
+ if (link->state == LINK_STATE_LINGER) {
+ unlink(link->state_file);
+ return 0;
+ }
+
admin_state = link_state_to_string(link->state);
assert(admin_state);
else if (link_has_carrier(link->flags, link->operstate))
oper_state = "carrier";
- r = asprintf(&lease_file, "/run/systemd/network/leases/%"PRIu64,
- link->ifindex);
- if (r < 0)
- return -ENOMEM;
-
r = fopen_temporary(link->state_file, &f, &temp_path);
if (r < 0)
goto finish;
admin_state, oper_state, link->flags);
if (link->dhcp_lease) {
- r = dhcp_lease_save(link->dhcp_lease, lease_file);
+ r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
if (r < 0)
goto finish;
- fprintf(f, "DHCP_LEASE=%s\n", lease_file);
+ fprintf(f, "DHCP_LEASE=%s\n", link->lease_file);
} else
- unlink(lease_file);
+ unlink(link->lease_file);
fflush(f);
[LINK_STATE_CONFIGURED] = "configured",
[LINK_STATE_UNMANAGED] = "unmanaged",
[LINK_STATE_FAILED] = "failed",
+ [LINK_STATE_LINGER] = "linger",
};
DEFINE_STRING_TABLE_LOOKUP(link_state, LinkState);