diff options
author | hrs <hrs@FreeBSD.org> | 2011-07-14 10:09:58 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2011-07-14 10:09:58 +0000 |
commit | cdcbea6ad239dd44f37a01b119599e17dac4a5a8 (patch) | |
tree | c97e2a5f6ba4790dc756b51374a4d00de9f4ecae /usr.sbin/rtadvd/timer.c | |
parent | 90aa2cef03ff2efa8e9af771632eb3d02d0df168 (diff) | |
download | FreeBSD-src-cdcbea6ad239dd44f37a01b119599e17dac4a5a8.zip FreeBSD-src-cdcbea6ad239dd44f37a01b119599e17dac4a5a8.tar.gz |
- Refactoring the interface list. It now supports dynamically
added/removed interfaces in a more consistent manner and reloading
the configuration file.
- Add initial support for control socket. RA information in the
daemon can be obtained by rtadvctl(8) instead of SIGUSR1 in a similar
manner to ifconfig(8). The information dump has been removed in favor of it.
(reload the configuration file)
# rtadvctl reload
(show RA messages being sent on each interfaces)
# rtadvctl show
em0: flags=<UP,CONFIGURED,PERSIST> status=<RA_SEND> mtu 1280
DefaultLifetime: 30m
MinAdvInterval/MaxAdvInterval: 3m20s/3m20s
AdvLinkMTU: <none>, Flags: O, Preference: medium
ReachableTime: 0s, RetransTimer: 0s, CurHopLimit: 64
AdvIfPrefixes: yes
(show RA messages being sent only on em0)
# rtadvctl show em0
(rtadvctl -v show provides additional information)
# rtadvctl -v show em0
em0: flags=<UP,CONFIGURED,PERSIST> status=<RA_SEND> mtu 1280
DefaultLifetime: 30m
MinAdvInterval/MaxAdvInterval: 3m20s/3m20s
AdvLinkMTU: <none>, Flags: O, Preference: medium
ReachableTime: 0s, RetransTimer: 0s, CurHopLimit: 64
AdvIfPrefixes: yes
Prefixes (1):
2001:db8:1::/64 (CONFIG, vltime=30d, pltime=7d, flags=LA)
RDNSS entries:
2001:db8:1::128 (ltime=2m40s)
(stop rtadvd)
# rtadvctl shutdown
A remaining issue when reloading the configuration file is that
during that period rtadvd cannot communicate with rtadvctl due to some
additional RA sending for graceful shutdown. This will be fixed later.
Diffstat (limited to 'usr.sbin/rtadvd/timer.c')
-rw-r--r-- | usr.sbin/rtadvd/timer.c | 123 |
1 files changed, 59 insertions, 64 deletions
diff --git a/usr.sbin/rtadvd/timer.c b/usr.sbin/rtadvd/timer.c index 8cad6ad..d51c897 100644 --- a/usr.sbin/rtadvd/timer.c +++ b/usr.sbin/rtadvd/timer.c @@ -3,6 +3,7 @@ /* * Copyright (C) 1998 WIDE Project. + * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,15 +33,22 @@ #include <sys/time.h> #include <sys/queue.h> +#include <sys/socket.h> + +#include <net/if.h> +#include <net/if_dl.h> +#include <netinet/in.h> #include <unistd.h> #include <syslog.h> #include <stdlib.h> #include <string.h> #include <search.h> -#include "timer.h" +#include <netdb.h> -#define MILLION 1000000 +#include "rtadvd.h" +#include "timer_subr.h" +#include "timer.h" struct rtadvd_timer_head_t ra_timer = TAILQ_HEAD_INITIALIZER(ra_timer); @@ -55,6 +63,46 @@ rtadvd_timer_init(void) TAILQ_INIT(&ra_timer); } +void +rtadvd_update_timeout_handler(void) +{ + struct rainfo *rai; + struct ifinfo *ifi; + + TAILQ_FOREACH(ifi, &ifilist, ifi_next) { + rai = ifi->ifi_rainfo; + if (rai == NULL) + continue; + + switch (ifi->ifi_state) { + case IFI_STATE_CONFIGURED: + if (rai->rai_timer != NULL) + continue; + + syslog(LOG_DEBUG, "<%s> add timer for %s (idx=%d)", + __func__, ifi->ifi_ifname, ifi->ifi_ifindex); + rai->rai_timer = rtadvd_add_timer(ra_timeout, + ra_timer_update, rai, rai); + ra_timer_update((void *)rai, + &rai->rai_timer->rat_tm); + rtadvd_set_timer(&rai->rai_timer->rat_tm, + rai->rai_timer); + break; + case IFI_STATE_UNCONFIGURED: + if (rai->rai_timer == NULL) + continue; + + syslog(LOG_DEBUG, + "<%s> remove timer for %s (idx=%d)", __func__, + ifi->ifi_ifname, ifi->ifi_ifindex); + rtadvd_remove_timer(rai->rai_timer); + break; + } + } + + return; +} + struct rtadvd_timer * rtadvd_add_timer(struct rtadvd_timer *(*timeout)(void *), void (*update)(void *, struct timeval *), @@ -99,22 +147,6 @@ rtadvd_remove_timer(struct rtadvd_timer *rat) free(rat); } -void -rtadvd_set_timer(struct timeval *tm, struct rtadvd_timer *rat) -{ - struct timeval now; - - /* reset the timer */ - gettimeofday(&now, NULL); - TIMEVAL_ADD(&now, tm, &rat->rat_tm); - - /* update the next expiration time */ - if (TIMEVAL_LT(&rat->rat_tm, &tm_max)) - tm_max = rat->rat_tm; - - return; -} - /* * Check expiration for each timer. If a timer expires, * call the expire function for the timer and update the timer. @@ -151,55 +183,18 @@ rtadvd_check_timer(void) return (&returnval); } -struct timeval * -rtadvd_timer_rest(struct rtadvd_timer *rat) -{ - static struct timeval returnval, now; - - gettimeofday(&now, NULL); - if (TIMEVAL_LEQ(&rat->rat_tm, &now)) { - syslog(LOG_DEBUG, - "<%s> a timer must be expired, but not yet", - __func__); - returnval.tv_sec = returnval.tv_usec = 0; - } - else - TIMEVAL_SUB(&rat->rat_tm, &now, &returnval); - - return (&returnval); -} - -/* result = a + b */ void -TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result) +rtadvd_set_timer(struct timeval *tm, struct rtadvd_timer *rat) { - long l; + struct timeval now; - if ((l = a->tv_usec + b->tv_usec) < MILLION) { - result->tv_usec = l; - result->tv_sec = a->tv_sec + b->tv_sec; - } - else { - result->tv_usec = l - MILLION; - result->tv_sec = a->tv_sec + b->tv_sec + 1; - } -} + /* reset the timer */ + gettimeofday(&now, NULL); + TIMEVAL_ADD(&now, tm, &rat->rat_tm); -/* - * result = a - b - * XXX: this function assumes that a >= b. - */ -void -TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result) -{ - long l; + /* update the next expiration time */ + if (TIMEVAL_LT(&rat->rat_tm, &tm_max)) + tm_max = rat->rat_tm; - if ((l = a->tv_usec - b->tv_usec) >= 0) { - result->tv_usec = l; - result->tv_sec = a->tv_sec - b->tv_sec; - } - else { - result->tv_usec = MILLION + l; - result->tv_sec = a->tv_sec - b->tv_sec - 1; - } + return; } |