summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2020-10-30 18:28:39 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2020-10-30 18:28:39 +0000
commit01f511c73fd8e90c3e0d24a20fa7f2787e8cdfdc (patch)
tree2b75447327d29b67cf9c250ad25915d4ac66dfda
parentb6bc9705ae78312bfa61dd2bca3362846d40e2f7 (diff)
Follow RFC 4941 and calculate the desync_factor at startup.
There is probably nothing wrong with calculating a new random value everytime we create an address, but we are also not gaining anything. Makes math in upcomming diffs easier.
-rw-r--r--sbin/slaacd/engine.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/sbin/slaacd/engine.c b/sbin/slaacd/engine.c
index f10feb28301..edddd8573c1 100644
--- a/sbin/slaacd/engine.c
+++ b/sbin/slaacd/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.54 2020/10/30 18:27:39 florian Exp $ */
+/* $OpenBSD: engine.c,v 1.55 2020/10/30 18:28:38 florian Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@@ -329,6 +329,8 @@ struct imsgev *iev_frontend;
struct imsgev *iev_main;
int64_t proposal_id;
+uint32_t desync_factor;
+
void
engine_sig_handler(int sig, short event, void *arg)
{
@@ -400,6 +402,8 @@ engine(int debug, int verbose)
LIST_INIT(&slaacd_interfaces);
+ desync_factor = arc4random_uniform(PRIV_MAX_DESYNC_FACTOR);
+
event_dispatch();
engine_shutdown();
@@ -1910,11 +1914,11 @@ update_iface_ra_prefix(struct slaacd_iface *iface, struct radv *ra,
/* privacy addresses do not depend on eui64 */
if (!found_privacy && iface->autoconfprivacy) {
- if (prefix->pltime < PRIV_MAX_DESYNC_FACTOR) {
+ if (prefix->pltime < desync_factor) {
log_warnx("%s: pltime from %s is too small: %d < %d; "
"not generating privacy address", __func__,
sin6_to_str(&ra->from), prefix->pltime,
- PRIV_MAX_DESYNC_FACTOR);
+ desync_factor);
} else
/* new privacy proposal */
gen_address_proposal(iface, ra, prefix, 1);
@@ -2048,8 +2052,8 @@ gen_address_proposal(struct slaacd_iface *iface, struct radv *ra, struct
addr_proposal->vltime = prefix->vltime;
if (prefix->pltime > PRIV_PREFERRED_LIFETIME)
- addr_proposal->pltime = PRIV_PREFERRED_LIFETIME
- - arc4random_uniform(PRIV_MAX_DESYNC_FACTOR);
+ addr_proposal->pltime = PRIV_PREFERRED_LIFETIME -
+ desync_factor;
else
addr_proposal->pltime = prefix->pltime;
} else {