Skip to content

Commit b3ce39b

Browse files
yuwatabluca
authored andcommitted
network: check lifetime of address and route before configure
Otherwise, we may configure a route that depends on the existence of an address or another route, and may fail when lifetime of one of them are already zero. Hopefully fixes #28358. (cherry picked from commit dc32de3) (cherry picked from commit 3ce7c97)
1 parent 789d978 commit b3ce39b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/network/networkd-address.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ Address *address_free(Address *address) {
142142
return mfree(address);
143143
}
144144

145+
static bool address_lifetime_is_valid(const Address *a) {
146+
assert(a);
147+
148+
return
149+
a->lifetime_valid_usec == USEC_INFINITY ||
150+
a->lifetime_valid_usec > now(CLOCK_BOOTTIME);
151+
}
152+
145153
bool address_is_ready(const Address *a) {
146154
assert(a);
147155

@@ -157,7 +165,7 @@ bool address_is_ready(const Address *a) {
157165
if (!FLAGS_SET(a->state, NETWORK_CONFIG_STATE_CONFIGURED))
158166
return false;
159167

160-
return true;
168+
return address_lifetime_is_valid(a);
161169
}
162170

163171
void link_mark_addresses(Link *link, NetworkConfigSource source) {
@@ -668,7 +676,7 @@ bool manager_has_address(Manager *manager, int family, const union in_addr_union
668676
if (manager_get_address(manager, family, address, 0, &a) < 0)
669677
return false;
670678

671-
return check_ready ? address_is_ready(a) : address_exists(a);
679+
return check_ready ? address_is_ready(a) : (address_exists(a) && address_lifetime_is_valid(a));
672680
}
673681

674682
const char* format_lifetime(char *buf, size_t l, usec_t lifetime_usec) {

src/network/networkd-route-util.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ unsigned routes_max(void) {
3838
return cached;
3939
}
4040

41+
static bool route_lifetime_is_valid(const Route *route) {
42+
assert(route);
43+
44+
return
45+
route->lifetime_usec == USEC_INFINITY ||
46+
route->lifetime_usec > now(CLOCK_BOOTTIME);
47+
}
48+
4149
static Route *link_find_default_gateway(Link *link, int family, Route *gw) {
4250
Route *route;
4351

@@ -122,6 +130,8 @@ bool gateway_is_ready(Link *link, bool onlink, int family, const union in_addr_u
122130
SET_FOREACH(route, link->routes) {
123131
if (!route_exists(route))
124132
continue;
133+
if (!route_lifetime_is_valid(route))
134+
continue;
125135
if (route->family != family)
126136
continue;
127137
if (!in_addr_is_set(route->family, &route->dst) && route->dst_prefixlen == 0)
@@ -168,6 +178,9 @@ static int link_address_is_reachable_internal(
168178
if (!route_exists(route))
169179
continue;
170180

181+
if (!route_lifetime_is_valid(route))
182+
continue;
183+
171184
if (route->type != RTN_UNICAST)
172185
continue;
173186

0 commit comments

Comments
 (0)