X-Git-Url: https://git.decadent.org.uk/gitweb/?p=odhcp6c.git;a=blobdiff_plain;f=src%2Fodhcp6c.c;h=dbba60512c171ef8f5782ecd524d07baacfabc87;hp=c8d40f63b84641d85abbb0bec40d096c68e94c0e;hb=c98181c4a48c57e405effd1dc9046aaaee6d480f;hpb=3d85fddacbbb0eebd33997382997af442b408b04 diff --git a/src/odhcp6c.c b/src/odhcp6c.c index c8d40f6..dbba605 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -23,14 +22,12 @@ #include #include #include -#include #include #include #include #include #include -#include #include "odhcp6c.h" #include "ra.h" @@ -39,11 +36,6 @@ #include "bfd.h" #endif -#ifndef IN6_IS_ADDR_UNIQUELOCAL -#define IN6_IS_ADDR_UNIQUELOCAL(a) \ - ((((__const uint32_t *) (a))[0] & htonl (0xfe000000)) \ - == htonl (0xfc000000)) -#endif static void sighandler(int signal); static int usage(void); @@ -55,7 +47,7 @@ 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; -static char *ifname = NULL; + int main(_unused int argc, char* const argv[]) { @@ -69,7 +61,7 @@ int main(_unused int argc, char* const argv[]) enum odhcp6c_ia_mode ia_na_mode = IA_MODE_TRY; enum odhcp6c_ia_mode ia_pd_mode = IA_MODE_TRY; static struct in6_addr ifid = IN6ADDR_ANY_INIT; - int sol_timeout = 120; + int sol_timeout = DHCPV6_SOL_MAX_RT; #ifdef EXT_BFD_PING int bfd_interval = 0, bfd_loss = 3; @@ -179,7 +171,7 @@ int main(_unused int argc, char* const argv[]) } openlog("odhcp6c", logopt, LOG_DAEMON); - ifname = argv[optind]; + const char *ifname = argv[optind]; if (help || !ifname) return usage(); @@ -318,8 +310,17 @@ int main(_unused int argc, char* const argv[]) else if (do_signal > 0) break; // Other signal type + // Send renew as T1 expired + size_t ia_pd_len, ia_na_len; + odhcp6c_get_state(STATE_IA_PD, &ia_pd_len); + odhcp6c_get_state(STATE_IA_NA, &ia_na_len); + // If we have any IAs, send renew, otherwise request - res = dhcpv6_request(DHCPV6_MSG_RENEW); + if (ia_pd_len == 0 && ia_na_len == 0) + res = dhcpv6_request(DHCPV6_MSG_REQUEST); + else + res = dhcpv6_request(DHCPV6_MSG_RENEW); + odhcp6c_signal_process(); if (res > 0) { // Renew was succesfull // Publish updates @@ -613,64 +614,11 @@ void odhcp6c_random(void *buf, size_t len) read(urandom_fd, buf, len); } - bool odhcp6c_is_bound(void) { return bound; } - -bool odhcp6c_addr_in_scope(const struct in6_addr *addr) -{ - FILE *fd = fopen("/proc/net/if_inet6", "r"); - int len; - char buf[256]; - - if (fd == NULL) - return false; - - while (fgets(buf, sizeof(buf), fd)) { - struct in6_addr inet6_addr; - uint32_t flags, dummy; - unsigned int i; - char name[8], addr_buf[32]; - - len = strlen(buf); - - if ((len <= 0) || buf[len - 1] != '\n') - return false; - - buf[--len] = '\0'; - - if (sscanf(buf, "%s %x %x %x %x %s", - addr_buf, &dummy, &dummy, &dummy, &flags, name) != 6) - return false; - - if (strcmp(name, ifname) || - (flags & (IFA_F_DADFAILED | IFA_F_TENTATIVE | IFA_F_DEPRECATED))) - continue; - - for (i = 0; i < sizeof(addr_buf); i++) { - if (!isxdigit(addr_buf[i]) || isupper(addr_buf[i])) - return false; - } - - memset(&inet6_addr, 0, sizeof(inet6_addr)); - for (i = 0; i < (sizeof(addr_buf) / 2); i++) { - unsigned char byte; - static const char hex[] = "0123456789abcdef"; - byte = ((index(hex, addr_buf[i * 2]) - hex) << 4) | - (index(hex, addr_buf[i * 2 + 1]) - hex); - inet6_addr.s6_addr[i] = byte; - } - - if ((IN6_IS_ADDR_LINKLOCAL(&inet6_addr) == IN6_IS_ADDR_LINKLOCAL(addr)) && - (IN6_IS_ADDR_UNIQUELOCAL(&inet6_addr) == IN6_IS_ADDR_UNIQUELOCAL(addr))) - return true; - } - return false; -} - static void sighandler(int signal) { if (signal == SIGCHLD)