#include <netinet/in.h>
#include <linux/if.h>
#include <linux/if_arp.h>
+#include <linux/if_link.h>
#include <unistd.h>
#include "alloc-util.h"
#include "networkd-manager.h"
#include "networkd-ndisc.h"
#include "networkd-neighbor.h"
+#include "networkd-sriov.h"
#include "networkd-radv.h"
#include "networkd-routing-policy-rule.h"
#include "networkd-wifi.h"
if (!netdev)
return;
+ if (netdev->ifindex <= 0)
+ return;
+
if (link_get(link->manager, netdev->ifindex, &master) < 0)
return;
Link *link;
assert(m);
- assert(ifindex);
+ assert(ifindex > 0);
assert(ret);
link = hashmap_get(m->links, INT_TO_PTR(ifindex));
return 1;
}
-int link_request_set_nexthop(Link *link) {
+static int link_request_set_nexthop(Link *link) {
NextHop *nh;
int r;
+ link->static_nexthops_configured = false;
+
LIST_FOREACH(nexthops, nh, link->network->static_nexthops) {
r = nexthop_configure(nh, link, nexthop_handler);
if (r < 0)
if (link->route_messages == 0) {
log_link_debug(link, "Routes set");
link->static_routes_configured = true;
- link_check_ready(link);
+ link_request_set_nexthop(link);
}
return 1;
assert(link->state != _LINK_STATE_INVALID);
link->static_routes_configured = false;
- link->static_routes_ready = false;
if (!link_has_carrier(link) && !link->network->configure_without_carrier)
/* During configuring addresses, the link lost its carrier. As networkd is dropping
if (link->route_messages == 0) {
link->static_routes_configured = true;
- link_check_ready(link);
+ link_request_set_nexthop(link);
} else {
log_link_debug(link, "Setting routes");
link_set_state(link, LINK_STATE_CONFIGURING);
assert(link);
- if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) {
+ log_link_debug(link, "%s(): link is in failed or linger state.", __func__);
return;
+ }
if (!link->network)
return;
- if (!link->addresses_configured)
+ if (!link->addresses_configured) {
+ log_link_debug(link, "%s(): static addresses are not configured.", __func__);
return;
+ }
- if (!link->neighbors_configured)
+ if (!link->neighbors_configured) {
+ log_link_debug(link, "%s(): static neighbors are not configured.", __func__);
return;
+ }
SET_FOREACH(a, link->addresses, i)
- if (!address_is_ready(a))
+ if (!address_is_ready(a)) {
+ _cleanup_free_ char *str = NULL;
+
+ (void) in_addr_to_string(a->family, &a->in_addr, &str);
+ log_link_debug(link, "%s(): an address %s/%d is not ready.", __func__, strnull(str), a->prefixlen);
return;
+ }
if (!link->addresses_ready) {
link->addresses_ready = true;
r = link_request_set_routes(link);
if (r < 0)
link_enter_failed(link);
+ log_link_debug(link, "%s(): static addresses are configured. Configuring static routes.", __func__);
return;
}
- if (!link->static_routes_configured)
+ if (!link->static_routes_configured) {
+ log_link_debug(link, "%s(): static routes are not configured.", __func__);
return;
+ }
- if (!link->static_routes_ready) {
- link->static_routes_ready = true;
- r = link_request_set_nexthop(link);
- if (r < 0)
- link_enter_failed(link);
+ if (!link->static_nexthops_configured) {
+ log_link_debug(link, "%s(): static nexthops are not configured.", __func__);
return;
}
- if (!link->static_nexthops_configured)
+ if (!link->routing_policy_rules_configured) {
+ log_link_debug(link, "%s(): static routing policy rules are not configured.", __func__);
return;
+ }
- if (!link->routing_policy_rules_configured)
+ if (!link->tc_configured) {
+ log_link_debug(link, "%s(): traffic controls are not configured.", __func__);
return;
+ }
- if (!link->tc_configured)
+ if (!link->sr_iov_configured) {
+ log_link_debug(link, "%s(): SR-IOV is not configured.", __func__);
return;
+ }
if (link_has_carrier(link) || !link->network->configure_without_carrier) {
- if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4) && !link->ipv4ll_address)
+ if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4) && !link->ipv4ll_address) {
+ log_link_debug(link, "%s(): IPv4LL is not configured.", __func__);
return;
+ }
if (link_ipv6ll_enabled(link) &&
- in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address))
+ in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address)) {
+ log_link_debug(link, "%s(): IPv6LL is not configured.", __func__);
return;
+ }
- if ((link_dhcp4_enabled(link) || link_dhcp6_enabled(link) || link_ipv6_accept_ra_enabled(link)) &&
- !link->dhcp4_configured &&
- !link->dhcp6_configured &&
- !link->ndisc_configured &&
- !(link_ipv4ll_enabled(link, ADDRESS_FAMILY_FALLBACK_IPV4) && link->ipv4ll_address))
- /* When DHCP or RA is enabled, at least one protocol must provide an address, or
- * an IPv4ll fallback address must be configured. */
+ if ((link_dhcp4_enabled(link) || link_dhcp6_enabled(link)) && set_isempty(link->addresses)) {
+ log_link_debug(link, "%s(): DHCP4 or DHCP6 is enabled but no address is assigned yet.", __func__);
return;
+ }
+
+ if (link_dhcp4_enabled(link) || link_dhcp6_enabled(link) || dhcp6_get_prefix_delegation(link) || link_ipv6_accept_ra_enabled(link)) {
+ if (!link->dhcp4_configured &&
+ !(link->dhcp6_address_configured && link->dhcp6_route_configured) &&
+ !(link->dhcp6_pd_address_configured && link->dhcp6_pd_route_configured) &&
+ !(link->ndisc_addresses_configured && link->ndisc_routes_configured) &&
+ !(link_ipv4ll_enabled(link, ADDRESS_FAMILY_FALLBACK_IPV4) && link->ipv4ll_address)) {
+ /* When DHCP or RA is enabled, at least one protocol must provide an address, or
+ * an IPv4ll fallback address must be configured. */
+ log_link_debug(link, "%s(): dynamic addresses or routes are not configured.", __func__);
+ return;
+ }
+
+ log_link_debug(link, "%s(): dhcp4:%s dhcp6_addresses:%s dhcp_routes:%s dhcp_pd_addresses:%s dhcp_pd_routes:%s ndisc_addresses:%s ndisc_routes:%s",
+ __func__,
+ yes_no(link->dhcp4_configured),
+ yes_no(link->dhcp6_address_configured),
+ yes_no(link->dhcp6_route_configured),
+ yes_no(link->dhcp6_pd_address_configured),
+ yes_no(link->dhcp6_pd_route_configured),
+ yes_no(link->ndisc_addresses_configured),
+ yes_no(link->ndisc_routes_configured));
+ }
}
if (link->state != LINK_STATE_CONFIGURED)
return 0;
}
-int address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+static int address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(rtnl);
link->addresses_ready = false;
link->neighbors_configured = false;
link->static_routes_configured = false;
- link->static_routes_ready = false;
link->static_nexthops_configured = false;
link->routing_policy_rules_configured = false;
return log_link_warning_errno(link, r, "Could not start IPv6 Router Advertisement: %m");
}
- if (link_dhcp6_enabled(link) && link->network->dhcp6_without_ra) {
+ if (link_dhcp6_enabled(link) && IN_SET(link->network->dhcp6_without_ra,
+ DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST,
+ DHCP6_CLIENT_START_MODE_SOLICIT)) {
assert(link->dhcp6_client);
assert(in_addr_is_link_local(AF_INET6, (const union in_addr_union*)&link->ipv6ll_address) > 0);
- r = dhcp6_request_address(link, true);
+ r = dhcp6_request_address(link, link->network->dhcp6_without_ra == DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST);
if (r < 0 && r != -EBUSY)
return log_link_warning_errno(link, r, "Could not acquire DHCPv6 lease: %m");
else
if (!link_ipv6ll_enabled(link))
ipv6ll_mode = IN6_ADDR_GEN_MODE_NONE;
- else if (link->network->ipv6_address_gen_mode < 0) {
+ else if (link->network->ipv6ll_address_gen_mode < 0) {
r = sysctl_read_ip_property(AF_INET6, link->ifname, "stable_secret", NULL);
if (r < 0) {
/* The file may not exist. And even if it exists, when stable_secret is unset,
} else
ipv6ll_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY;
} else
- ipv6ll_mode = link->network->ipv6_address_gen_mode;
+ ipv6ll_mode = link->network->ipv6ll_address_gen_mode;
r = sd_netlink_message_append_u8(req, IFLA_INET6_ADDR_GEN_MODE, ipv6ll_mode);
if (r < 0)
if (r < 0)
return r;
- r = set_ensure_allocated(&master->slaves, NULL);
- if (r < 0)
- return r;
-
- r = set_put(master->slaves, link);
+ r = set_ensure_put(&master->slaves, NULL, link);
if (r <= 0)
return r;
return 0;
}
+static int link_set_ipv4_accept_local(Link *link) {
+ int r;
+
+ if (link->flags & IFF_LOOPBACK)
+ return 0;
+
+ if (link->network->ipv4_accept_local < 0)
+ return 0;
+
+ r = sysctl_write_ip_property_boolean(AF_INET, link->ifname, "accept_local", link->network->ipv4_accept_local);
+ if (r < 0)
+ log_link_warning_errno(link, r, "Cannot set IPv4 accept_local flag for interface: %m");
+
+ return 0;
+}
+
static bool link_is_static_address_configured(Link *link, Address *address) {
Address *net_address;
return 0;
}
+static int link_configure_sr_iov(Link *link) {
+ SRIOV *sr_iov;
+ Iterator i;
+ int r;
+
+ link->sr_iov_configured = false;
+ link->sr_iov_messages = 0;
+
+ ORDERED_HASHMAP_FOREACH(sr_iov, link->network->sr_iov_by_section, i) {
+ r = sr_iov_configure(link, sr_iov);
+ if (r < 0)
+ return r;
+ }
+
+ if (link->sr_iov_messages == 0)
+ link->sr_iov_configured = true;
+ else
+ log_link_debug(link, "Configuring SR-IOV");
+
+ return 0;
+}
+
static int link_configure(Link *link) {
int r;
if (r < 0)
return r;
+ r = link_configure_sr_iov(link);
+ if (r < 0)
+ return r;
+
if (link->iftype == ARPHRD_CAN)
return link_configure_can(link);
if (r < 0)
return r;
+ r = link_set_ipv4_accept_local(link);
+ if (r < 0)
+ return r;
+
r = link_set_flags(link);
if (r < 0)
return r;
r = set_put(m->links_requesting_uuid, link);
if (r < 0)
return log_oom();
+ if (r > 0)
+ link_ref(link);
r = set_put(m->duids_requesting_uuid, duid);
if (r < 0)
return log_oom();
-
- link_ref(link);
}
return 0;
*dhcp4_address = NULL,
*ipv4ll_address = NULL;
union in_addr_union address;
- const char *p;
int r;
assert(link);
network_file_fail:
- if (addresses) {
- p = addresses;
-
- for (;;) {
- _cleanup_free_ char *address_str = NULL;
- char *prefixlen_str;
- int family;
- unsigned char prefixlen;
-
- r = extract_first_word(&p, &address_str, NULL, 0);
- if (r < 0) {
- log_link_debug_errno(link, r, "Failed to extract next address string: %m");
- continue;
- }
- if (r == 0)
- break;
-
- prefixlen_str = strchr(address_str, '/');
- if (!prefixlen_str) {
- log_link_debug(link, "Failed to parse address and prefix length %s", address_str);
- continue;
- }
+ for (const char *p = addresses; p; ) {
+ _cleanup_free_ char *address_str = NULL;
+ char *prefixlen_str;
+ int family;
+ unsigned char prefixlen;
- *prefixlen_str++ = '\0';
+ r = extract_first_word(&p, &address_str, NULL, 0);
+ if (r < 0)
+ log_link_warning_errno(link, r, "failed to parse ADDRESSES: %m");
+ if (r <= 0)
+ break;
- r = sscanf(prefixlen_str, "%hhu", &prefixlen);
- if (r != 1) {
- log_link_error(link, "Failed to parse prefixlen %s", prefixlen_str);
- continue;
- }
+ prefixlen_str = strchr(address_str, '/');
+ if (!prefixlen_str) {
+ log_link_debug(link, "Failed to parse address and prefix length %s", address_str);
+ continue;
+ }
+ *prefixlen_str++ = '\0';
- r = in_addr_from_string_auto(address_str, &family, &address);
- if (r < 0) {
- log_link_debug_errno(link, r, "Failed to parse address %s: %m", address_str);
- continue;
- }
+ r = sscanf(prefixlen_str, "%hhu", &prefixlen);
+ if (r != 1) {
+ log_link_error(link, "Failed to parse prefixlen %s", prefixlen_str);
+ continue;
+ }
- r = address_add(link, family, &address, prefixlen, NULL);
- if (r < 0)
- return log_link_error_errno(link, r, "Failed to add address: %m");
+ r = in_addr_from_string_auto(address_str, &family, &address);
+ if (r < 0) {
+ log_link_debug_errno(link, r, "Failed to parse address %s: %m", address_str);
+ continue;
}
+
+ r = address_add(link, family, &address, prefixlen, NULL);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Failed to add address: %m");
}
- if (routes) {
- p = routes;
+ for (const char *p = routes; p; ) {
+ _cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL;
+ _cleanup_(route_freep) Route *tmp = NULL;
+ _cleanup_free_ char *route_str = NULL;
+ char *prefixlen_str;
+ Route *route;
- for (;;) {
- _cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL;
- _cleanup_(route_freep) Route *tmp = NULL;
- _cleanup_free_ char *route_str = NULL;
- char *prefixlen_str;
- Route *route;
-
- r = extract_first_word(&p, &route_str, NULL, 0);
- if (r < 0) {
- log_link_debug_errno(link, r, "Failed to extract next route string: %m");
- continue;
- }
- if (r == 0)
- break;
+ r = extract_first_word(&p, &route_str, NULL, 0);
+ if (r < 0)
+ log_link_debug_errno(link, r, "failed to parse ROUTES: %m");
+ if (r <= 0)
+ break;
- prefixlen_str = strchr(route_str, '/');
- if (!prefixlen_str) {
- log_link_debug(link, "Failed to parse route %s", route_str);
- continue;
- }
+ prefixlen_str = strchr(route_str, '/');
+ if (!prefixlen_str) {
+ log_link_debug(link, "Failed to parse route %s", route_str);
+ continue;
+ }
+ *prefixlen_str++ = '\0';
- *prefixlen_str++ = '\0';
+ r = route_new(&tmp);
+ if (r < 0)
+ return log_oom();
- r = route_new(&tmp);
- if (r < 0)
- return log_oom();
+ r = sscanf(prefixlen_str,
+ "%hhu/%hhu/%"SCNu32"/%"PRIu32"/"USEC_FMT,
+ &tmp->dst_prefixlen,
+ &tmp->tos,
+ &tmp->priority,
+ &tmp->table,
+ &tmp->lifetime);
+ if (r != 5) {
+ log_link_debug(link,
+ "Failed to parse destination prefix length, tos, priority, table or expiration %s",
+ prefixlen_str);
+ continue;
+ }
- r = sscanf(prefixlen_str, "%hhu/%hhu/%"SCNu32"/%"PRIu32"/"USEC_FMT, &tmp->dst_prefixlen, &tmp->tos, &tmp->priority, &tmp->table, &tmp->lifetime);
- if (r != 5) {
- log_link_debug(link,
- "Failed to parse destination prefix length, tos, priority, table or expiration %s",
- prefixlen_str);
- continue;
- }
+ r = in_addr_from_string_auto(route_str, &tmp->family, &tmp->dst);
+ if (r < 0) {
+ log_link_debug_errno(link, r, "Failed to parse route destination %s: %m", route_str);
+ continue;
+ }
- r = in_addr_from_string_auto(route_str, &tmp->family, &tmp->dst);
- if (r < 0) {
- log_link_debug_errno(link, r, "Failed to parse route destination %s: %m", route_str);
- continue;
- }
+ r = route_add(link, tmp, &route);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Failed to add route: %m");
- r = route_add(link, tmp, &route);
+ if (route->lifetime != USEC_INFINITY && !kernel_route_expiration_supported()) {
+ r = sd_event_add_time(link->manager->event, &expire,
+ clock_boottime_or_monotonic(),
+ route->lifetime, 0, route_expire_handler, route);
if (r < 0)
- return log_link_error_errno(link, r, "Failed to add route: %m");
-
- if (route->lifetime != USEC_INFINITY && !kernel_route_expiration_supported()) {
- r = sd_event_add_time(link->manager->event, &expire, clock_boottime_or_monotonic(), route->lifetime,
- 0, route_expire_handler, route);
- if (r < 0)
- log_link_warning_errno(link, r, "Could not arm route expiration handler: %m");
- }
-
- sd_event_source_unref(route->expire);
- route->expire = TAKE_PTR(expire);
+ log_link_warning_errno(link, r, "Could not arm route expiration handler: %m");
}
+
+ sd_event_source_unref(route->expire);
+ route->expire = TAKE_PTR(expire);
}
if (dhcp4_address) {
const char *admin_state, *oper_state, *carrier_state, *address_state;
_cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
- Address *a;
Route *route;
+ Address *a;
Iterator i;
int r;
sd_dhcp6_lease_get_ntp_fqdn);
serialize_addresses(f, "SIP", NULL,
- link->network->sip,
+ NULL,
link->dhcp_lease,
link->network->dhcp_use_sip,
SD_DHCP_LEASE_SIP,
- false, NULL, NULL, NULL);
-
- serialize_addresses(f, "POP3", NULL,
- link->network->pop3,
- link->dhcp_lease,
- true,
- SD_DHCP_LEASE_POP3,
- false, NULL, NULL, NULL);
-
- serialize_addresses(f, "SMTP", NULL,
- link->network->smtp,
- link->dhcp_lease,
- true,
- SD_DHCP_LEASE_SMTP,
- false, NULL, NULL, NULL);
-
- serialize_addresses(f, "LPR", NULL,
- link->network->lpr,
- link->dhcp_lease,
- true,
- SD_DHCP_LEASE_LPR,
- false, NULL, NULL, NULL);
+ NULL, false, NULL, NULL);
/************************************************************/
print_link_hashmap(f, "CARRIER_BOUND_BY=", link->bound_by_links);
if (link->dhcp_lease) {
- struct in_addr address;
- const char *tz = NULL;
-
- assert(link->network);
-
- r = sd_dhcp_lease_get_timezone(link->dhcp_lease, &tz);
- if (r >= 0)
- fprintf(f, "TIMEZONE=%s\n", tz);
-
- r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
- if (r >= 0) {
- fputs("DHCP4_ADDRESS=", f);
- serialize_in_addrs(f, &address, 1, NULL, NULL);
- fputc('\n', f);
- }
-
r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
if (r < 0)
goto fail;
}
}
+ if (link->dhcp6_client) {
+ _cleanup_free_ char *duid = NULL;
+ uint32_t iaid;
+
+ r = sd_dhcp6_client_get_iaid(link->dhcp6_client, &iaid);
+ if (r >= 0)
+ fprintf(f, "DHCP6_CLIENT_IAID=0x%x\n", iaid);
+
+ r = sd_dhcp6_client_duid_as_string(link->dhcp6_client, &duid);
+ if (r >= 0)
+ fprintf(f, "DHCP6_CLIENT_DUID=%s\n", duid);
+ }
+
r = fflush_and_check(f);
if (r < 0)
goto fail;
/* mark manager dirty as link is dirty */
manager_dirty(link->manager);
- r = set_ensure_allocated(&link->manager->dirty_links, NULL);
- if (r < 0)
- /* allocation errors are ignored */
- return;
-
- r = set_put(link->manager->dirty_links, link);
+ r = set_ensure_put(&link->manager->dirty_links, NULL, link);
if (r <= 0)
- /* don't take another ref if the link was already dirty */
+ /* Ignore allocation errors and don't take another ref if the link was already dirty */
return;
-
link_ref(link);
}
link_unref(set_remove(link->manager->dirty_links, link));
}
-static const char* const link_ipv6_address_gen_mode_table[_LINK_IPV6_ADDRESS_GEN_MODE_MAX] = {
- [LINK_IPV6_ADDRESSS_GEN_MODE_EUI64] = "eui64",
- [LINK_IPV6_ADDRESSS_GEN_MODE_NONE] = "none",
- [LINK_IPV6_ADDRESSS_GEN_MODE_STABLE_PRIVACY] = "stable-privacy",
- [LINK_IPV6_ADDRESSS_GEN_MODE_RANDOM] = "random",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(link_ipv6_address_gen_mode, LinkIPv6AddressGenMode);
-DEFINE_CONFIG_PARSE_ENUM(config_parse_link_ipv6_address_gen_mode, link_ipv6_address_gen_mode, LinkIPv6AddressGenMode, "Failed to parse link IPv6 address generation mode");
-
static const char* const link_state_table[_LINK_STATE_MAX] = {
[LINK_STATE_PENDING] = "pending",
[LINK_STATE_INITIALIZED] = "initialized",