git: fb08f80eaf90 - main - in6: Add a helper function to compute expiry times
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 12 Jan 2026 15:34:50 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=fb08f80eaf90eb7ace202d8604634fc181be8980
commit fb08f80eaf90eb7ace202d8604634fc181be8980
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-01-12 13:49:34 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-01-12 15:34:43 +0000
in6: Add a helper function to compute expiry times
Tidy up a bunch of places that have the same duplicated logic. Simplify
callers of in6_init_prefix_ltimes(). No functional change intended.
Reviewed by: pouria, zlei, tuexen, glebius
MFC after: 2 weeks
Sponsored by: OPNsense
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D54561
---
sys/netinet6/in6.c | 23 +++++++++++++----------
sys/netinet6/in6.h | 2 ++
sys/netinet6/nd6_rtr.c | 38 +++++++-------------------------------
3 files changed, 22 insertions(+), 41 deletions(-)
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index a953bb5546d6..bdf19c876519 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1029,6 +1029,15 @@ in6_alloc_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, int flags)
return (ia);
}
+time_t
+in6_expire_time(uint32_t ltime)
+{
+ if (ltime == ND6_INFINITE_LIFETIME)
+ return (0);
+ else
+ return (time_uptime + ltime);
+}
+
/*
* Update/configure interface address parameters:
*
@@ -1051,16 +1060,10 @@ in6_update_ifa_internal(struct ifnet *ifp, struct in6_aliasreq *ifra,
* these members for applications.
*/
ia->ia6_lifetime = ifra->ifra_lifetime;
- if (ia->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME) {
- ia->ia6_lifetime.ia6t_expire =
- time_uptime + ia->ia6_lifetime.ia6t_vltime;
- } else
- ia->ia6_lifetime.ia6t_expire = 0;
- if (ia->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME) {
- ia->ia6_lifetime.ia6t_preferred =
- time_uptime + ia->ia6_lifetime.ia6t_pltime;
- } else
- ia->ia6_lifetime.ia6t_preferred = 0;
+ ia->ia6_lifetime.ia6t_expire =
+ in6_expire_time(ifra->ifra_lifetime.ia6t_vltime);
+ ia->ia6_lifetime.ia6t_preferred =
+ in6_expire_time(ifra->ifra_lifetime.ia6t_pltime);
/*
* backward compatibility - if IN6_IFF_DEPRECATED is set from the
diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h
index a7fe03b9c3d7..f250d7e49982 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -671,6 +671,8 @@ int in6_cksum_partial_l2(struct mbuf *m, uint8_t nxt, uint32_t off_l3,
uint32_t off_l4, uint32_t len, uint32_t cov);
int in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t);
+time_t in6_expire_time(uint32_t);
+
int in6_localaddr(struct in6_addr *);
int in6_localip(struct in6_addr *);
bool in6_localip_fib(struct in6_addr *, uint16_t);
diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c
index 7bbba30a3a21..821d6b27bc43 100644
--- a/sys/netinet6/nd6_rtr.c
+++ b/sys/netinet6/nd6_rtr.c
@@ -1146,39 +1146,18 @@ restart:
return (n);
}
-static int
+static void
in6_init_prefix_ltimes(struct nd_prefix *ndpr)
{
- if (ndpr->ndpr_pltime == ND6_INFINITE_LIFETIME)
- ndpr->ndpr_preferred = 0;
- else
- ndpr->ndpr_preferred = time_uptime + ndpr->ndpr_pltime;
- if (ndpr->ndpr_vltime == ND6_INFINITE_LIFETIME)
- ndpr->ndpr_expire = 0;
- else
- ndpr->ndpr_expire = time_uptime + ndpr->ndpr_vltime;
-
- return 0;
+ ndpr->ndpr_preferred = in6_expire_time(ndpr->ndpr_pltime);
+ ndpr->ndpr_expire = in6_expire_time(ndpr->ndpr_vltime);
}
static void
in6_init_address_ltimes(struct nd_prefix *new, struct in6_addrlifetime *lt6)
{
- /* init ia6t_expire */
- if (lt6->ia6t_vltime == ND6_INFINITE_LIFETIME)
- lt6->ia6t_expire = 0;
- else {
- lt6->ia6t_expire = time_uptime;
- lt6->ia6t_expire += lt6->ia6t_vltime;
- }
-
- /* init ia6t_preferred */
- if (lt6->ia6t_pltime == ND6_INFINITE_LIFETIME)
- lt6->ia6t_preferred = 0;
- else {
- lt6->ia6t_preferred = time_uptime;
- lt6->ia6t_preferred += lt6->ia6t_pltime;
- }
+ lt6->ia6t_preferred = in6_expire_time(lt6->ia6t_pltime);
+ lt6->ia6t_expire = in6_expire_time(lt6->ia6t_vltime);
}
static struct in6_ifaddr *
@@ -1394,11 +1373,8 @@ nd6_prelist_add(struct nd_prefixctl *pr, struct nd_defrouter *dr,
new->ndpr_vltime = pr->ndpr_vltime;
new->ndpr_pltime = pr->ndpr_pltime;
new->ndpr_flags = pr->ndpr_flags;
- if ((error = in6_init_prefix_ltimes(new)) != 0) {
- free(new, M_IP6NDP);
- return (error);
- }
new->ndpr_lastupdate = time_uptime;
+ in6_init_prefix_ltimes(new);
/* initialization */
LIST_INIT(&new->ndpr_advrtrs);
@@ -1542,7 +1518,7 @@ prelist_update(struct nd_prefixctl *new, struct nd_defrouter *dr,
if (new->ndpr_raf_onlink) {
pr->ndpr_vltime = new->ndpr_vltime;
pr->ndpr_pltime = new->ndpr_pltime;
- (void)in6_init_prefix_ltimes(pr); /* XXX error case? */
+ in6_init_prefix_ltimes(pr);
pr->ndpr_lastupdate = time_uptime;
}