static inline bool valid_addr(const struct odhcpd_ipaddr *addr, time_t now)
{
- return (addr->prefix <= 96 && addr->preferred > (uint32_t)now);
+ return (addr->prefix <= 96 && addr->preferred_lt > (uint32_t)now);
}
static size_t get_preferred_addr(const struct odhcpd_ipaddr *addrs, const size_t addrlen)
size_t i, m;
for (i = 0, m = 0; i < addrlen; ++i) {
- if (addrs[i].preferred > addrs[m].preferred ||
- (addrs[i].preferred == addrs[m].preferred &&
+ if (addrs[i].preferred_lt > addrs[m].preferred_lt ||
+ (addrs[i].preferred_lt == addrs[m].preferred_lt &&
memcmp(&addrs[i].addr, &addrs[m].addr, 16) > 0))
m = i;
}
for (size_t i = 0; i < addrlen; ++i) {
struct in6_addr addr;
- uint32_t pref, valid;
+ uint32_t preferred_lt, valid;
int prefix = c->managed ? addrs[i].prefix : c->length;
if (!valid_addr(&addrs[i], now))
}
addr = addrs[i].addr.in6;
- pref = addrs[i].preferred;
+ preferred_lt = addrs[i].preferred_lt;
valid = addrs[i].valid;
if (c->flags & OAF_DHCPV6_NA) {
addr.s6_addr32[2] = addr.s6_addr32[3] = 0;
}
- if (pref > (uint32_t)c->preferred_until)
- pref = c->preferred_until;
+ if (preferred_lt > (uint32_t)c->preferred_until)
+ preferred_lt = c->preferred_until;
- if (pref > (uint32_t)c->valid_until)
- pref = c->valid_until;
+ if (preferred_lt > (uint32_t)c->valid_until)
+ preferred_lt = c->valid_until;
- if (pref != UINT32_MAX)
- pref -= now;
+ if (preferred_lt != UINT32_MAX)
+ preferred_lt -= now;
if (valid > (uint32_t)c->valid_until)
valid = c->valid_until;
if (valid != UINT32_MAX)
valid -= now;
- func(&addr, prefix, pref, valid, arg);
+ func(&addr, prefix, preferred_lt, valid, arg);
}
}
int buf_idx;
};
-static void dhcpv6_write_ia_addrhosts(struct in6_addr *addr, int prefix, _unused uint32_t pref,
+static void dhcpv6_write_ia_addrhosts(struct in6_addr *addr, int prefix, _unused uint32_t pref_lt,
_unused uint32_t valid, void *arg)
{
struct write_ctxt *ctxt = (struct write_ctxt *)arg;
}
}
-static void dhcpv6_write_ia_addr(struct in6_addr *addr, int prefix, _unused uint32_t pref,
+static void dhcpv6_write_ia_addr(struct in6_addr *addr, int prefix, _unused uint32_t pref_lt,
_unused uint32_t valid, void *arg)
{
struct write_ctxt *ctxt = (struct write_ctxt *)arg;
if (ADDR_MATCH_PIO_FILTER(addr, iface))
continue;
- if (addr->preferred > (uint32_t)now &&
+ if (addr->preferred_lt > (uint32_t)now &&
addr->prefix < 64 &&
addr->prefix > minprefix)
minprefix = addr->prefix;
continue;
x = strtok_r(NULL, ",", &saveptr2);
- if (sscanf(x, "%u", &n->preferred) < 1)
+ if (sscanf(x, "%u", &n->preferred_lt) < 1)
continue;
x = strtok_r(NULL, ",", &saveptr2);
if (sscanf(x, "%u", &n->valid) < 1)
continue;
- if (n->preferred > n->valid)
+ if (n->preferred_lt > n->valid)
continue;
- if (UINT32_MAX - now < n->preferred)
- n->preferred = UINT32_MAX;
+ if (UINT32_MAX - now < n->preferred_lt)
+ n->preferred_lt = UINT32_MAX;
else
- n->preferred += now;
+ n->preferred_lt += now;
if (UINT32_MAX - now < n->valid)
n->valid = UINT32_MAX;
}
if (a) {
- uint32_t leasetime, pref;
+ uint32_t leasetime, preferred_lt;
if (a->leasetime) {
leasetime = a->leasetime;
- pref = a->leasetime;
+ preferred_lt = a->leasetime;
} else {
leasetime = iface->dhcp_leasetime;
- pref = iface->preferred_lifetime;
+ preferred_lt = iface->preferred_lifetime;
}
uint32_t valid = leasetime;
size_t m = get_preferred_addr(addrs, addrlen);
for (size_t i = 0; i < addrlen; ++i) {
- uint32_t prefix_pref, prefix_valid;
+ uint32_t prefix_preferred_lt, prefix_valid;
if (!valid_addr(&addrs[i], now))
continue;
continue;
}
- prefix_pref = addrs[i].preferred;
+ prefix_preferred_lt = addrs[i].preferred_lt;
prefix_valid = addrs[i].valid;
- if (prefix_pref != UINT32_MAX)
- prefix_pref -= now;
+ if (prefix_preferred_lt != UINT32_MAX)
+ prefix_preferred_lt -= now;
- if (prefix_pref > pref)
- prefix_pref = pref;
+ if (prefix_preferred_lt > preferred_lt)
+ prefix_preferred_lt = preferred_lt;
if (prefix_valid != UINT32_MAX)
prefix_valid -= now;
if (prefix_valid > leasetime)
prefix_valid = leasetime;
- if (prefix_pref > prefix_valid)
- prefix_pref = prefix_valid;
+ if (prefix_preferred_lt > prefix_valid)
+ prefix_preferred_lt = prefix_valid;
if (a->flags & OAF_DHCPV6_PD) {
struct dhcpv6_ia_prefix o_ia_p = {
.type = htons(DHCPV6_OPT_IA_PREFIX),
.len = htons(sizeof(o_ia_p) - 4),
- .preferred = htonl(prefix_pref),
+ .preferred_lt = htonl(prefix_preferred_lt),
.valid = htonl(prefix_valid),
.prefix = (a->managed_size) ? addrs[i].prefix : a->length,
.addr = addrs[i].addr.in6,
.type = htons(DHCPV6_OPT_IA_ADDR),
.len = htons(sizeof(o_ia_a) - 4),
.addr = addrs[i].addr.in6,
- .preferred = htonl(prefix_pref),
+ .preferred_lt = htonl(prefix_preferred_lt),
.valid = htonl(prefix_valid)
};
}
/* Calculate T1 / T2 based on non-deprecated addresses */
- if (prefix_pref > 0) {
- if (prefix_pref < pref)
- pref = prefix_pref;
+ if (prefix_preferred_lt > 0) {
+ if (prefix_preferred_lt < preferred_lt)
+ preferred_lt = prefix_preferred_lt;
if (prefix_valid < valid)
valid = prefix_valid;
if (!INFINITE_VALID(a->preferred_until))
/* UINT32_MAX is considered as infinite leasetime */
- a->preferred_until = (pref == UINT32_MAX) ? 0 : pref + now;
+ a->preferred_until = (preferred_lt == UINT32_MAX) ? 0 : preferred_lt + now;
- o_ia.t1 = htonl((pref == UINT32_MAX) ? pref : pref * 5 / 10);
- o_ia.t2 = htonl((pref == UINT32_MAX) ? pref : pref * 8 / 10);
+ o_ia.t1 = htonl((preferred_lt == UINT32_MAX) ? preferred_lt : preferred_lt * 5 / 10);
+ o_ia.t2 = htonl((preferred_lt == UINT32_MAX) ? preferred_lt : preferred_lt * 8 / 10);
if (!o_ia.t1)
o_ia.t1 = htonl(1);
struct dhcpv6_ia_prefix o_ia_p = {
.type = htons(DHCPV6_OPT_IA_PREFIX),
.len = htons(sizeof(o_ia_p) - 4),
- .preferred = 0,
+ .preferred_lt = 0,
.valid = 0,
.prefix = ia_p->prefix,
.addr = ia_p->addr,
.type = htons(DHCPV6_OPT_IA_ADDR),
.len = htons(sizeof(o_ia_a) - 4),
.addr = ia_a->addr,
- .preferred = 0,
+ .preferred_lt = 0,
.valid = 0,
};
int buf_idx;
};
-static void dhcpv6_log_ia_addr(struct in6_addr *addr, int prefix, _unused uint32_t pref,
+static void dhcpv6_log_ia_addr(struct in6_addr *addr, int prefix, _unused uint32_t pref_lt,
_unused uint32_t valid, void *arg)
{
struct log_ctxt *ctxt = (struct log_ctxt *)arg;
for (ssize_t i = 0; !change && i < len; ++i) {
if (!IN6_ARE_ADDR_EQUAL(&addr[i].addr.in6, &iface->addr6[i].addr.in6) ||
addr[i].prefix != iface->addr6[i].prefix ||
- (addr[i].preferred > (uint32_t)now) != (iface->addr6[i].preferred > (uint32_t)now) ||
- addr[i].valid < iface->addr6[i].valid || addr[i].preferred < iface->addr6[i].preferred)
+ (addr[i].preferred_lt > (uint32_t)now) != (iface->addr6[i].preferred_lt > (uint32_t)now) ||
+ addr[i].valid < iface->addr6[i].valid || addr[i].preferred_lt < iface->addr6[i].preferred_lt)
change = true;
}
iface->invalid_addr6 = new_invalid_addr6;
iface->invalid_addr6_len++;
memcpy(&iface->invalid_addr6[pos], &iface->addr6[i], sizeof(*iface->invalid_addr6));
- iface->invalid_addr6[pos].valid = iface->invalid_addr6[pos].preferred = (uint32_t)now;
+ iface->invalid_addr6[pos].valid = iface->invalid_addr6[pos].preferred_lt = (uint32_t)now;
if (iface->invalid_addr6[pos].prefix < 64)
iface->invalid_addr6[pos].prefix = 64;
if (nla[IFA_CACHEINFO]) {
struct ifa_cacheinfo *ifc = nla_data(nla[IFA_CACHEINFO]);
- addrs[ctxt->ret].preferred = ifc->ifa_prefered;
+ addrs[ctxt->ret].preferred_lt = ifc->ifa_prefered;
addrs[ctxt->ret].valid = ifc->ifa_valid;
}
if (ifa->ifa_flags & IFA_F_DEPRECATED)
- addrs[ctxt->ret].preferred = 0;
+ addrs[ctxt->ret].preferred_lt = 0;
if (ifa->ifa_family == AF_INET6 &&
ifa->ifa_flags & IFA_F_TENTATIVE)
static int prefix6_cmp(const void *va, const void *vb)
{
const struct odhcpd_ipaddr *a = va, *b = vb;
- uint32_t a_pref = IN6_IS_ADDR_ULA(&a->addr.in6) ? 1 : a->preferred;
- uint32_t b_pref = IN6_IS_ADDR_ULA(&b->addr.in6) ? 1 : b->preferred;
- return (a_pref < b_pref) ? 1 : (a_pref > b_pref) ? -1 : 0;
+ uint32_t a_pref_lt = IN6_IS_ADDR_ULA(&a->addr.in6) ? 1 : a->preferred_lt;
+ uint32_t b_pref_lt = IN6_IS_ADDR_ULA(&b->addr.in6) ? 1 : b->preferred_lt;
+ return (a_pref_lt < b_pref_lt) ? 1 : (a_pref_lt > b_pref_lt) ? -1 : 0;
}
qsort(addr, ctxt.ret, sizeof(*addr), v6 ? prefix6_cmp : prefix_cmp);
for (ssize_t i = 0; i < ctxt.ret; ++i) {
- if (addr[i].preferred < UINT32_MAX - now)
- addr[i].preferred += now;
+ if (addr[i].preferred_lt < UINT32_MAX - now)
+ addr[i].preferred_lt += now;
if (addr[i].valid < UINT32_MAX - now)
addr[i].valid += now;
.tstamp = 0 };
time_t now = odhcpd_time();
- if (addr->preferred) {
- int64_t preferred = addr->preferred - now;
- if (preferred < 0)
- preferred = 0;
- else if (preferred > UINT32_MAX)
- preferred = UINT32_MAX;
+ if (addr->preferred_lt) {
+ int64_t preferred_lt = addr->preferred_lt - now;
+ if (preferred_lt < 0)
+ preferred_lt = 0;
+ else if (preferred_lt > UINT32_MAX)
+ preferred_lt = UINT32_MAX;
- cinfo.ifa_prefered = preferred;
+ cinfo.ifa_prefered = preferred_lt;
}
if (addr->valid) {
static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len)
{
struct odhcpd_ipaddr p = { .addr.in6 = IN6ADDR_ANY_INIT, .prefix = 0,
- .dprefix = 0, .preferred = 0, .valid = 0};
+ .dprefix = 0, .preferred_lt = 0, .valid = 0};
bool found_default = false;
char line[512], ifname[16];
for (ssize_t i = 0; i < valid_addr_cnt + invalid_addr_cnt; ++i) {
struct odhcpd_ipaddr *addr = &addrs[i];
struct nd_opt_prefix_info *p = NULL;
- uint32_t preferred = 0;
+ uint32_t preferred_lt = 0;
uint32_t valid = 0;
if (addr->prefix > 96 || (i < valid_addr_cnt && addr->valid <= (uint32_t)now)) {
memset(p, 0, sizeof(*p));
}
- if (addr->preferred > (uint32_t)now) {
- preferred = TIME_LEFT(addr->preferred, now);
+ if (addr->preferred_lt > (uint32_t)now) {
+ preferred_lt = TIME_LEFT(addr->preferred_lt, now);
if (iface->ra_useleasetime &&
- preferred > iface->preferred_lifetime)
- preferred = iface->preferred_lifetime;
+ preferred_lt > iface->preferred_lifetime)
+ preferred_lt = iface->preferred_lifetime;
}
if (addr->valid > (uint32_t)now) {
p->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_AUTO;
if (iface->ra_advrouter)
p->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_RADDR;
- p->nd_opt_pi_preferred_time = htonl(preferred);
+ p->nd_opt_pi_preferred_time = htonl(preferred_lt);
p->nd_opt_pi_valid_time = htonl(valid);
}