#include "odhcp6c.h"
#include "ra.h"
+#ifdef EXT_BFD_PING
+#include "bfd.h"
+#endif
+
static void sighandler(int signal);
static int usage(void);
-
static uint8_t *state_data[_STATE_MAX] = {NULL};
static size_t state_len[_STATE_MAX] = {0};
static struct in6_addr ifid = IN6ADDR_ANY_INIT;
int sol_timeout = 120;
+#ifdef EXT_BFD_PING
+ int bfd_interval = 0, bfd_loss = 3;
+#endif
+
bool help = false, daemonize = false;
int logopt = LOG_PID;
int c, request_pd = 0;
- while ((c = getopt(argc, argv, "S::N:P:Fc:i:r:s:kt:hedp:")) != -1) {
+ while ((c = getopt(argc, argv, "S::N:P:FB:c:i:r:s:kt:hedp:")) != -1) {
switch (c) {
case 'S':
allow_slaac_only = (optarg) ? atoi(optarg) : -1;
if (request_pd == 0)
request_pd = -1;
- ia_pd_mode = IA_MODE_TRY;
break;
case 'F':
ia_pd_mode = IA_MODE_FORCE;
break;
+#ifdef EXT_BFD_PING
+ case 'B':
+ bfd_interval = atoi(optarg);
+ break;
+#endif
+
case 'c':
l = script_unhexlify(&buf[4], sizeof(buf) - 4, optarg);
if (l > 0) {
int res = dhcpv6_request(DHCPV6_MSG_SOLICIT);
odhcp6c_signal_process();
- if (res < 0) {
+ if (res <= 0) {
continue; // Might happen if we got a signal
} else if (res == DHCPV6_STATELESS) { // Stateless mode
while (do_signal == 0 || do_signal == SIGUSR1) {
}
// Stateful mode
- if (dhcpv6_request(DHCPV6_MSG_REQUEST) < 0)
+ if (dhcpv6_request(DHCPV6_MSG_REQUEST) <= 0)
continue;
odhcp6c_signal_process();
script_call("bound");
bound = true;
syslog(LOG_NOTICE, "entering stateful-mode on %s", ifname);
+#ifdef EXT_BFD_PING
+ if (bfd_interval > 0)
+ bfd_start(ifname, bfd_loss, bfd_interval);
+#endif
while (do_signal == 0 || do_signal == SIGUSR1) {
// Renew Cycle
// Wait for T1 to expire or until we get a reconfigure
int res = dhcpv6_poll_reconfigure();
odhcp6c_signal_process();
- if (res >= 0) {
- if (res > 0)
- script_call("updated");
-
+ if (res > 0) {
+ script_call("updated");
continue;
}
else
r = dhcpv6_request(DHCPV6_MSG_RENEW);
odhcp6c_signal_process();
- if (r > 0) // Publish updates
+ if (r > 0) { // Renew was succesfull
+ // Publish updates
script_call("updated");
- if (r >= 0)
continue; // Renew was successful
+ }
odhcp6c_clear_state(STATE_SERVER_ID); // Remove binding
odhcp6c_get_state(STATE_IA_PD, &ia_pd_new);
odhcp6c_get_state(STATE_IA_NA, &ia_na_new);
- if (res < 0 || (ia_pd_new == 0 && ia_pd_len) ||
+ if (res <= 0 || (ia_pd_new == 0 && ia_pd_len) ||
(ia_na_new == 0 && ia_na_len))
break; // We lost all our IAs, restart
else if (res > 0)
script_call("rebound");
}
+#ifdef EXT_BFD_PING
+ bfd_stop();
+#endif
+
size_t ia_pd_len, ia_na_len, server_id_len;
odhcp6c_get_state(STATE_IA_PD, &ia_pd_len);
" -N <mode> Mode for requesting addresses [try|force|none]\n"
" -P <length> Request IPv6-Prefix (0 = auto)\n"
" -F Force IPv6-Prefix\n"
+#ifdef EXT_BFD_PING
+ " -B <interval> Enable BFD ping check\n"
+#endif
" -c <clientid> Override client-ID (base-16 encoded)\n"
" -i <iface-id> Use a custom interface identifier for RA handling\n"
" -r <options> Options to be requested (comma-separated)\n"
do_signal = 0;
bool ra_updated = ra_process();
+ if (ra_link_up())
+ do_signal = SIGUSR2;
+
if (ra_updated && (bound || allow_slaac_only == 0))
script_call("ra-updated"); // Immediate process urgent events
else if (ra_updated && !bound && allow_slaac_only > 0)
script_delay_call("ra-updated", allow_slaac_only);
+
+#ifdef EXT_BFD_PING
+ bfd_receive();
+#endif
}
return do_signal != 0;
size_t len;
struct odhcp6c_entry *x = odhcp6c_find_entry(state, new);
struct odhcp6c_entry *start = odhcp6c_get_state(state, &len);
- bool changed = true;
if (x && x->valid > new->valid && new->valid < safe)
new->valid = safe;
new->preferred >= x->preferred &&
new->preferred - x->preferred < 60 &&
x->class == new->class)
- changed = false;
+ return false;
x->valid = new->valid;
x->preferred = new->preferred;
+ x->t1 = new->t1;
+ x->t2 = new->t2;
x->class = new->class;
} else {
odhcp6c_add_state(state, new, sizeof(*new));
} else if (x) {
odhcp6c_remove_state(state, (x - start) * sizeof(*x), sizeof(*x));
}
- return changed;
+ return true;
}
size_t len;
struct odhcp6c_entry *start = odhcp6c_get_state(state, &len);
for (struct odhcp6c_entry *c = start; c < &start[len / sizeof(*c)]; ++c) {
+ if (c->t1 < elapsed)
+ c->t1 = 0;
+ else if (c->t1 != UINT32_MAX)
+ c->t1 -= elapsed;
+
+ if (c->t2 < elapsed)
+ c->t2 = 0;
+ else if (c->t2 != UINT32_MAX)
+ c->t2 -= elapsed;
+
if (c->preferred < elapsed)
c->preferred = 0;
else if (c->preferred != UINT32_MAX)
read(urandom_fd, buf, len);
}
+bool odhcp6c_is_bound(void)
+{
+ return bound;
+}
static void sighandler(int signal)
{