b = link_ipv4_forward_enabled(link);
- p = strappenda("/proc/sys/net/ipv4/conf/", link->ifname, "/forwarding");
+ p = strjoina("/proc/sys/net/ipv4/conf/", link->ifname, "/forwarding");
r = write_string_file_no_create(p, one_zero(b));
if (r < 0)
log_link_warning_errno(link, r, "Cannot configure IPv4 forwarding for interface %s: %m", link->ifname);
const char *p = NULL;
int r;
- p = strappenda("/proc/sys/net/ipv6/conf/", link->ifname, "/forwarding");
+ p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/forwarding");
r = write_string_file_no_create(p, one_zero(link_ipv6_forward_enabled(link)));
if (r < 0)
log_link_warning_errno(link, r, "Cannot configure IPv6 forwarding for interface: %m");
} else {
r = link_get(m, ifindex, &link);
if (r < 0 || !link) {
- log_warning("rtnl: received address for nonexistent link (%d), ignoring", ifindex);
+ /* when enumerating we might be out of sync, but we will
+ * get the address again, so just ignore it */
+ if (!m->enumerating)
+ log_warning("rtnl: received address for nonexistent link (%d), ignoring", ifindex);
return 0;
}
}
return 0;
}
+static int link_carrier_gained(Link *link) {
+ int r;
+
+ assert(link);
+
+ if (link->network) {
+ r = link_acquire_conf(link);
+ if (r < 0) {
+ link_enter_failed(link);
+ return r;
+ }
+ }
+
+ return 0;
+}
+
+static int link_carrier_lost(Link *link) {
+ int r;
+
+ assert(link);
+
+ r = link_stop_clients(link);
+ if (r < 0) {
+ link_enter_failed(link);
+ return r;
+ }
+
+ return 0;
+}
+
+int link_carrier_reset(Link *link) {
+ int r;
+
+ assert(link);
+
+ if (link_has_carrier(link)) {
+ r = link_carrier_lost(link);
+ if (r < 0)
+ return r;
+
+ r = link_carrier_gained(link);
+ if (r < 0)
+ return r;
+
+ log_link_info(link, "reset carrier");
+ }
+
+ return 0;
+}
+
+
int link_update(Link *link, sd_rtnl_message *m) {
struct ether_addr mac;
const char *ifname;
if (carrier_gained) {
log_link_info(link, "gained carrier");
- if (link->network) {
- r = link_acquire_conf(link);
- if (r < 0) {
- link_enter_failed(link);
- return r;
- }
- }
+ r = link_carrier_gained(link);
+ if (r < 0)
+ return r;
} else if (carrier_lost) {
log_link_info(link, "lost carrier");
- r = link_stop_clients(link);
- if (r < 0) {
- link_enter_failed(link);
+ r = link_carrier_lost(link);
+ if (r < 0)
return r;
- }
+
}
return 0;