Skip to content

Commit 3ce7c97

Browse files
yuwatakeszybz
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)
1 parent ead4050 commit 3ce7c97

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
@@ -143,6 +143,14 @@ Address *address_free(Address *address) {
143143
return mfree(address);
144144
}
145145

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

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

161-
return true;
169+
return address_lifetime_is_valid(a);
162170
}
163171

164172
void link_mark_addresses(Link *link, NetworkConfigSource source) {
@@ -654,7 +662,7 @@ bool manager_has_address(Manager *manager, int family, const union in_addr_union
654662
if (manager_get_address(manager, family, address, 0, &a) < 0)
655663
return false;
656664

657-
return check_ready ? address_is_ready(a) : address_exists(a);
665+
return check_ready ? address_is_ready(a) : (address_exists(a) && address_lifetime_is_valid(a));
658666
}
659667

660668
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
@@ -39,6 +39,14 @@ unsigned routes_max(void) {
3939
return cached;
4040
}
4141

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

@@ -123,6 +131,8 @@ bool gateway_is_ready(Link *link, bool onlink, int family, const union in_addr_u
123131
SET_FOREACH(route, link->routes) {
124132
if (!route_exists(route))
125133
continue;
134+
if (!route_lifetime_is_valid(route))
135+
continue;
126136
if (route->family != family)
127137
continue;
128138
if (!in_addr_is_set(route->family, &route->dst) && route->dst_prefixlen == 0)
@@ -169,6 +179,9 @@ static int link_address_is_reachable_internal(
169179
if (!route_exists(route))
170180
continue;
171181

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

0 commit comments

Comments
 (0)