Skip to content

Commit 03d684b

Browse files
gtsiambluca
authored andcommitted
resolved: Tweak link-local addresses relevancy
We now consider link-local addresses routable when we have configured unicast link-local dns servers. This allows creating the DNS scope, even when the interface doesn't get a routable address. (cherry picked from commit c60d2a6) (cherry picked from commit bd9a51fc67faead42dcaac819f5c432741b4a32a) (cherry picked from commit 807e18536ad96a28d041ce57b760cfb81c980cd6) (cherry picked from commit 1272e28) (cherry picked from commit 81afa81)
1 parent 33d22f8 commit 03d684b

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/resolve/resolved-link.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,35 @@ int link_update(Link *l) {
664664
return 0;
665665
}
666666

667+
static bool link_has_link_local_dns(Link *l, int family) {
668+
669+
/* Check if the link has a link-local dns server for the specified family */
670+
671+
LIST_FOREACH(servers, s, l->dns_servers)
672+
if ((family == AF_UNSPEC || s->family == family) &&
673+
in_addr_is_link_local(s->family, &s->address))
674+
return true;
675+
676+
return false;
677+
}
678+
667679
bool link_relevant(Link *l, int family, bool local_multicast) {
680+
bool allow_link_local;
681+
668682
assert(l);
669683

670-
/* A link is relevant for local multicast traffic if it isn't a loopback device, has a link
671-
* beat, can do multicast and has at least one link-local (or better) IP address.
672-
*
673-
* A link is relevant for non-multicast traffic if it isn't a loopback device, has a link beat, and has at
674-
* least one routable address. */
684+
/*
685+
* A link is relevant if:
686+
* - it isn't a loopback device
687+
* - has a link beat
688+
* - for multicast traffic:
689+
* - can do multicast
690+
* - has at least one link-local (or better) IP address.
691+
* - for non-multicast traffic:
692+
* - has at least one address that must be:
693+
* - At least link-local, if using a link-local dns server to this interface.
694+
* - Better than link-local.
695+
*/
675696

676697
if ((l->flags & (IFF_LOOPBACK | IFF_DORMANT)) != 0)
677698
return false;
@@ -690,8 +711,11 @@ bool link_relevant(Link *l, int family, bool local_multicast) {
690711
!IN_SET(l->networkd_operstate, LINK_OPERSTATE_DEGRADED_CARRIER, LINK_OPERSTATE_DEGRADED, LINK_OPERSTATE_ROUTABLE))
691712
return false;
692713

714+
allow_link_local = local_multicast || link_has_link_local_dns(l, family);
715+
693716
LIST_FOREACH(addresses, a, l->addresses)
694-
if ((family == AF_UNSPEC || a->family == family) && link_address_relevant(a, local_multicast))
717+
if ((family == AF_UNSPEC || a->family == family) &&
718+
link_address_relevant(a, allow_link_local))
695719
return true;
696720

697721
return false;
@@ -1135,13 +1159,13 @@ int link_address_update_rtnl(LinkAddress *a, sd_netlink_message *m) {
11351159
return 0;
11361160
}
11371161

1138-
bool link_address_relevant(LinkAddress *a, bool local_multicast) {
1162+
bool link_address_relevant(LinkAddress *a, bool allow_link_local) {
11391163
assert(a);
11401164

11411165
if (a->flags & (IFA_F_DEPRECATED|IFA_F_TENTATIVE))
11421166
return false;
11431167

1144-
if (a->scope >= (local_multicast ? RT_SCOPE_HOST : RT_SCOPE_LINK))
1168+
if (a->scope >= (allow_link_local ? RT_SCOPE_HOST : RT_SCOPE_LINK))
11451169
return false;
11461170

11471171
return true;

src/resolve/resolved-link.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void link_remove_user(Link *l);
114114
int link_address_new(Link *l, LinkAddress **ret, int family, const union in_addr_union *in_addr);
115115
LinkAddress *link_address_free(LinkAddress *a);
116116
int link_address_update_rtnl(LinkAddress *a, sd_netlink_message *m);
117-
bool link_address_relevant(LinkAddress *l, bool local_multicast);
117+
bool link_address_relevant(LinkAddress *l, bool allow_link_local);
118118
void link_address_add_rrs(LinkAddress *a, bool force_remove);
119119

120120
bool link_negative_trust_anchor_lookup(Link *l, const char *name);

0 commit comments

Comments
 (0)