mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
network: clean up link_may_have_ipv6ll() and allow to run RADV on Tun interface (#38175)
Closes #38170.
This commit is contained in:
@@ -1345,7 +1345,7 @@ int link_drop_ipv6ll_addresses(Link *link) {
|
||||
/* IPv6LL address may be in the tentative state, and in that case networkd has not received it.
|
||||
* So, we need to dump all IPv6 addresses. */
|
||||
|
||||
if (link_may_have_ipv6ll(link, /* check_multicast = */ false))
|
||||
if (link_ipv6ll_enabled_harder(link))
|
||||
return 0;
|
||||
|
||||
r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_GETADDR, link->ifindex, AF_INET6);
|
||||
|
||||
@@ -43,41 +43,26 @@ bool link_ipv6ll_enabled(Link *link) {
|
||||
return link->network->link_local & ADDRESS_FAMILY_IPV6;
|
||||
}
|
||||
|
||||
bool link_may_have_ipv6ll(Link *link, bool check_multicast) {
|
||||
bool link_ipv6ll_enabled_harder(Link *link) {
|
||||
assert(link);
|
||||
|
||||
/*
|
||||
* This is equivalent to link_ipv6ll_enabled() for non-WireGuard interfaces.
|
||||
*
|
||||
* For WireGuard interface, the kernel does not assign any IPv6LL addresses, but we can assign
|
||||
* it manually. It is necessary to set an IPv6LL address manually to run NDisc or RADV on
|
||||
* WireGuard interface. Note, also Multicast=yes must be set. See #17380.
|
||||
*
|
||||
* TODO: May be better to introduce GenerateIPv6LinkLocalAddress= setting, and use algorithms
|
||||
* used in networkd-address-generation.c
|
||||
*/
|
||||
/* This is mostly equivalent to link_ipv6ll_enabled(), but also checks if an IPv6LL address is
|
||||
* manually configured. */
|
||||
|
||||
if (link_ipv6ll_enabled(link))
|
||||
return true;
|
||||
|
||||
/* IPv6LL address can be manually assigned on WireGuard interface. */
|
||||
if (streq_ptr(link->kind, "wireguard")) {
|
||||
Address *a;
|
||||
if (!link->network)
|
||||
return false;
|
||||
|
||||
if (!link->network)
|
||||
return false;
|
||||
|
||||
if (check_multicast && !FLAGS_SET(link->flags, IFF_MULTICAST) && link->network->multicast <= 0)
|
||||
return false;
|
||||
|
||||
ORDERED_HASHMAP_FOREACH(a, link->network->addresses_by_section) {
|
||||
if (a->family != AF_INET6)
|
||||
continue;
|
||||
if (in6_addr_is_set(&a->in_addr_peer.in6))
|
||||
continue;
|
||||
if (in6_addr_is_link_local(&a->in_addr.in6))
|
||||
return true;
|
||||
}
|
||||
Address *a;
|
||||
ORDERED_HASHMAP_FOREACH(a, link->network->addresses_by_section) {
|
||||
if (a->family != AF_INET6)
|
||||
continue;
|
||||
if (in6_addr_is_set(&a->in_addr_peer.in6))
|
||||
continue;
|
||||
if (in6_addr_is_link_local(&a->in_addr.in6))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef enum IPv6LinkLocalAddressGenMode {
|
||||
} IPv6LinkLocalAddressGenMode;
|
||||
|
||||
bool link_ipv6ll_enabled(Link *link);
|
||||
bool link_may_have_ipv6ll(Link *link, bool check_multicast);
|
||||
bool link_ipv6ll_enabled_harder(Link *link);
|
||||
|
||||
IPv6LinkLocalAddressGenMode link_get_ipv6ll_addrgen_mode(Link *link);
|
||||
int ipv6ll_addrgen_mode_fill_message(sd_netlink_message *message, IPv6LinkLocalAddressGenMode mode);
|
||||
|
||||
@@ -133,7 +133,7 @@ bool link_ipv6_enabled(Link *link) {
|
||||
if (link->network->bond)
|
||||
return false;
|
||||
|
||||
if (link_may_have_ipv6ll(link, /* check_multicast = */ false))
|
||||
if (link_ipv6ll_enabled(link))
|
||||
return true;
|
||||
|
||||
if (network_has_static_ipv6_configurations(link->network))
|
||||
@@ -2126,6 +2126,17 @@ bool link_has_carrier(Link *link) {
|
||||
return netif_has_carrier(link->kernel_operstate, link->flags);
|
||||
}
|
||||
|
||||
bool link_multicast_enabled(Link *link) {
|
||||
assert(link);
|
||||
|
||||
/* If Multicast= is specified, use the value. */
|
||||
if (link->network && link->network->multicast >= 0)
|
||||
return link->network->multicast;
|
||||
|
||||
/* Otherwise, return the current state. */
|
||||
return FLAGS_SET(link->flags, IFF_MULTICAST);
|
||||
}
|
||||
|
||||
#define FLAG_STRING(string, flag, old, new) \
|
||||
(((old ^ new) & flag) \
|
||||
? ((old & flag) ? (" -" string) : (" +" string)) \
|
||||
|
||||
@@ -229,6 +229,7 @@ void link_check_ready(Link *link);
|
||||
void link_update_operstate(Link *link, bool also_update_bond_master);
|
||||
|
||||
bool link_has_carrier(Link *link);
|
||||
bool link_multicast_enabled(Link *link);
|
||||
|
||||
bool link_ipv6_enabled(Link *link);
|
||||
int link_ipv6ll_gained(Link *link);
|
||||
|
||||
@@ -65,7 +65,10 @@ bool link_ndisc_enabled(Link *link) {
|
||||
if (!link->network)
|
||||
return false;
|
||||
|
||||
if (!link_may_have_ipv6ll(link, /* check_multicast = */ true))
|
||||
if (!link_multicast_enabled(link))
|
||||
return false;
|
||||
|
||||
if (!link_ipv6ll_enabled_harder(link))
|
||||
return false;
|
||||
|
||||
/* Honor explicitly specified value. */
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
bool link_radv_enabled(Link *link) {
|
||||
assert(link);
|
||||
|
||||
if (!link_may_have_ipv6ll(link, /* check_multicast = */ true))
|
||||
if (!link_multicast_enabled(link))
|
||||
return false;
|
||||
|
||||
if (link->hw_addr.length != ETH_ALEN)
|
||||
if (!link_ipv6ll_enabled_harder(link))
|
||||
return false;
|
||||
|
||||
return link->network->router_prefix_delegation;
|
||||
|
||||
Reference in New Issue
Block a user