ifconfig: Fix the -L flag when using netlink

By default, when ifconfig shows a v6 address derived from a
router-advertised prefix, it shows the initial preferred and valid
lifetimes.  When -L is specified, it is supposed to show the remaining
lifetimes, but this was broken in the conversion to netlink.

Fix that, and add a regression test which validates ifconfig output
before and after a short-lived address expires.

Reported by:	Franco Fichtner <franco@opnsense.org>
Reviewed by:	melifaro, allanjude, Seyed Pouria Mousavizadeh Tehrani
Fixes:		4c91a5dfe4 ("ifconfig: make interface and address listing use Netlink as transport")
MFC after:	2 weeks
Sponsored by:	OPNsense
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D54294

(cherry picked from commit df6861d755c8f72380ae7fb8df535b27eba8c0be)
This commit is contained in:
Mark Johnston 2025-12-19 14:11:20 +00:00 committed by Franco Fichtner
parent 3c7008c651
commit 4cccd67caa

View file

@ -375,8 +375,10 @@ show_lifetime(struct ifa_cacheinfo *ci)
vl = (ci->ifa_valid == ND6_INFINITE_LIFETIME) ? 0 : ci->ifa_valid;
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
print_lifetime("pltime", pl + now.tv_sec, &now);
print_lifetime("vltime", vl + now.tv_sec, &now);
print_lifetime("pltime",
pl + (ip6lifetime ? ci->tstamp / 1000 : now.tv_sec), &now);
print_lifetime("vltime",
vl + (ip6lifetime ? ci->tstamp / 1000 : now.tv_sec), &now);
}
static void