From 56920baef21f23307c3df9719914e75fe729e0b8 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Fri, 31 May 2013 15:45:42 +0200 Subject: [PATCH 01/16] Work around false-positive DAD-hits --- src/odhcp6c.c | 12 +++++++++--- src/odhcp6c.h | 1 + src/ra.c | 14 +++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/odhcp6c.c b/src/odhcp6c.c index d70546b..4fefcd7 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -42,6 +42,7 @@ static size_t state_len[_STATE_MAX] = {0}; static volatile int do_signal = 0; static int urandom_fd = -1, allow_slaac_only = 0; static bool bound = false, release = true; +static time_t last_update = 0; int main(_unused int argc, char* const argv[]) @@ -357,9 +358,10 @@ bool odhcp6c_signal_process(void) { if (do_signal == SIGIO) { do_signal = 0; + bool ra_rtnled = ra_rtnl_process(); bool ra_updated = ra_process(); - if (ra_rtnl_process() || (ra_updated && (bound || allow_slaac_only == 0))) + if (ra_rtnled || (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); @@ -467,9 +469,7 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed) void odhcp6c_expire(void) { - static time_t last_update = 0; time_t now = odhcp6c_get_milli_time() / 1000; - uint32_t elapsed = (last_update > 0) ? now - last_update : 0; last_update = now; @@ -481,6 +481,12 @@ void odhcp6c_expire(void) } +uint32_t odhcp6c_elapsed(void) +{ + return odhcp6c_get_milli_time() / 1000 - last_update; +} + + void odhcp6c_random(void *buf, size_t len) { read(urandom_fd, buf, len); diff --git a/src/odhcp6c.h b/src/odhcp6c.h index b0a1980..2e7107c 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -244,3 +244,4 @@ void odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new); void odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe); void odhcp6c_expire(void); +uint32_t odhcp6c_elapsed(void); diff --git a/src/ra.c b/src/ra.c index 24c99c5..1b2f729 100644 --- a/src/ra.c +++ b/src/ra.c @@ -155,12 +155,16 @@ static bool ra_deduplicate(const struct in6_addr *any, uint8_t length) bool ra_rtnl_process(void) { bool found = false; + uint32_t elapsed = odhcp6c_elapsed(); uint8_t buf[8192]; while (true) { ssize_t len = recv(rtnl_sock, buf, sizeof(buf), MSG_DONTWAIT); if (len < 0) break; + if (elapsed > 10) + continue; + for (struct nlmsghdr *nh = (struct nlmsghdr*)buf; NLMSG_OK(nh, (size_t)len); nh = NLMSG_NEXT(nh, len)) { struct ifaddrmsg *ifa = NLMSG_DATA(nh); @@ -197,7 +201,6 @@ bool ra_process(void) struct nd_router_advert *adv = (struct nd_router_advert*)buf; struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, 0, 0, IN6ADDR_ANY_INIT, 0, 0}; const struct in6_addr any = IN6ADDR_ANY_INIT; - odhcp6c_expire(); while (true) { struct sockaddr_in6 from; @@ -214,7 +217,10 @@ bool ra_process(void) rs_attempt = 0; } - found = true; + if (!found) { + odhcp6c_expire(); + found = true; + } uint32_t router_valid = ntohs(adv->nd_ra_router_lifetime); // Parse default route @@ -308,6 +314,8 @@ bool ra_process(void) entry[i].valid = router_valid; } - odhcp6c_expire(); + if (found) + odhcp6c_expire(); + return found; } -- 2.39.2 From 3e286ae023682c7681c72a8cd18457036b1f7d85 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Fri, 31 May 2013 16:05:00 +0200 Subject: [PATCH 02/16] Update README --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index a6fa298..16ac904 100644 --- a/README +++ b/README @@ -68,7 +68,7 @@ Environment: * SIP_DOMAIN A space-separated list of SIP domains * OPTION_ Custom option received as base-16 * PREFIXES A space-separated list of prefixes currently assigned - Format: /,preferred,valid,/ + Format: /,preferred,valid[,excluded=/] * ADDRESSES A space-separated list of addresses currently assigned Format:
/,preferred,valid * RA_ADDRESSES A space-separated list of addresses from RA-prefixes -- 2.39.2 From 83114b179091cb080f09cf4142ee1c9949ea4e30 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Thu, 13 Jun 2013 08:36:31 +0200 Subject: [PATCH 03/16] Add sanity checks for NDP and MTU parameters from RAs --- src/ra.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ra.c b/src/ra.c index 1b2f729..b1526ae 100644 --- a/src/ra.c +++ b/src/ra.c @@ -235,10 +235,10 @@ bool ra_process(void) odhcp6c_update_entry(STATE_RA_ROUTE, &entry); // Parse ND parameters - if (adv->nd_ra_reachable) + if (ntohl(adv->nd_ra_reachable) <= 3600000) update_proc("neigh", "base_reachable_time_ms", ntohl(adv->nd_ra_reachable)); - if (adv->nd_ra_retransmit) + if (ntohl(adv->nd_ra_retransmit) <= 60000) update_proc("neigh", "retrans_time_ms", ntohl(adv->nd_ra_retransmit)); @@ -247,7 +247,8 @@ bool ra_process(void) icmpv6_for_each_option(opt, &adv[1], &buf[len]) { if (opt->type == ND_OPT_MTU) { uint32_t *mtu = (uint32_t*)&opt->data[2]; - update_proc("conf", "mtu", ntohl(*mtu)); + if (ntohl(*mtu) >= 1280 && ntohl(*mtu) <= 65535) + update_proc("conf", "mtu", ntohl(*mtu)); } else if (opt->type == ND_OPT_ROUTE_INFORMATION && opt->len <= 3) { entry.router = from.sin6_addr; entry.target = any; -- 2.39.2 From eaf3a11cad8a5dd389d5f52cc76e424e0242074b Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Tue, 18 Jun 2013 14:44:43 +0200 Subject: [PATCH 04/16] Allow overriding the interface-identifier for public addresses --- src/odhcp6c.c | 12 ++++++++++-- src/ra.c | 23 +++++++++++++---------- src/ra.h | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 4fefcd7..df89eb9 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "odhcp6c.h" #include "ra.h" @@ -55,11 +56,12 @@ int main(_unused int argc, char* const argv[]) char *optpos; uint16_t opttype; enum odhcp6c_ia_mode ia_na_mode = IA_MODE_TRY; + static struct in6_addr ifid = IN6ADDR_ANY_INIT; bool help = false, daemonize = false; int logopt = LOG_PID; int c, request_pd = 0; - while ((c = getopt(argc, argv, "S::N:P:c:r:s:khedp:")) != -1) { + while ((c = getopt(argc, argv, "S::N:P:c:i:r:s:khedp:")) != -1) { switch (c) { case 'S': allow_slaac_only = (optarg) ? atoi(optarg) : -1; @@ -98,6 +100,11 @@ int main(_unused int argc, char* const argv[]) } break; + case 'i': + if (inet_pton(AF_INET6, optarg, &ifid) != 1) + help = true; + break; + case 'r': optpos = optarg; while (optpos[0]) { @@ -151,7 +158,7 @@ int main(_unused int argc, char* const argv[]) signal(SIGUSR2, sighandler); if ((urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY)) < 0 || - init_dhcpv6(ifname, request_pd) || ra_init(ifname) || + init_dhcpv6(ifname, request_pd) || ra_init(ifname, &ifid) || script_init(script, ifname)) { syslog(LOG_ERR, "failed to initialize: %s", strerror(errno)); return 3; @@ -314,6 +321,7 @@ static int usage(void) " -N Mode for requesting addresses [try|force|none]\n" " -P Request IPv6-Prefix (0 = auto)\n" " -c Override client-ID (base-16 encoded)\n" + " -i Use a custom interface identifier for RA handling\n" " -r Options to be requested (comma-separated)\n" " -s