X-Git-Url: https://git.decadent.org.uk/gitweb/?p=odhcp6c.git;a=blobdiff_plain;f=src%2Fodhcp6c.c;h=0a46947f4a5e2adc689b9dfd4ebc8ad412d18369;hp=fdfc3278840443e82f0249ca9981a14f0ca41cdb;hb=6c8109e0c77d5a54950ba607d1ec1f83d5efb5b7;hpb=b146f9adc80cc2c2cdf2b04bfeec4c861a2a0e23 diff --git a/src/odhcp6c.c b/src/odhcp6c.c index fdfc327..0a46947 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2012-2013 Steven Barth + * Copyright (C) 2012-2014 Steven Barth * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License v2 as published by @@ -52,6 +52,8 @@ static int urandom_fd = -1, allow_slaac_only = 0; static bool bound = false, release = true; static time_t last_update = 0; +static unsigned int min_update_interval = DEFAULT_MIN_UPDATE_INTERVAL; + int main(_unused int argc, char* const argv[]) { // Allocate ressources @@ -61,8 +63,9 @@ int main(_unused int argc, char* const argv[]) uint8_t buf[134]; char *optpos; uint16_t opttype; + uint16_t optlen; enum odhcp6c_ia_mode ia_na_mode = IA_MODE_TRY; - enum odhcp6c_ia_mode ia_pd_mode = IA_MODE_TRY; + enum odhcp6c_ia_mode ia_pd_mode = IA_MODE_NONE; int ia_pd_iaid_index = 0; static struct in6_addr ifid = IN6ADDR_ANY_INIT; int sol_timeout = DHCPV6_SOL_MAX_RT; @@ -71,10 +74,12 @@ int main(_unused int argc, char* const argv[]) int bfd_interval = 0, bfd_loss = 3; #endif - bool help = false, daemonize = false, strict_options = false; + bool help = false, daemonize = false; int logopt = LOG_PID; int c; - while ((c = getopt(argc, argv, "S::N:P:FB:c:i:r:Rs:kt:hedp:")) != -1) { + unsigned int client_options = DHCPV6_CLIENT_FQDN | DHCPV6_ACCEPT_RECONFIGURE; + + while ((c = getopt(argc, argv, "S::N:V:P:FB:c:i:r:Ru:s:kt:m:hedp:fa")) != -1) { switch (c) { case 'S': allow_slaac_only = (optarg) ? atoi(optarg) : -1; @@ -93,7 +98,18 @@ int main(_unused int argc, char* const argv[]) } break; + case 'V': + l = script_unhexlify(buf, sizeof(buf), optarg); + if (!l) + help=true; + + odhcp6c_add_state(STATE_VENDORCLASS, buf, l); + + break; case 'P': + if (ia_pd_mode == IA_MODE_NONE) + ia_pd_mode = IA_MODE_TRY; + if (allow_slaac_only >= 0 && allow_slaac_only < 10) allow_slaac_only = 10; @@ -102,7 +118,7 @@ int main(_unused int argc, char* const argv[]) int prefix_length = strtoul(optarg, &iaid_begin, 10); - if (*iaid_begin != '\0' && *iaid_begin != ',') { + if (*iaid_begin != '\0' && *iaid_begin != ',' && *iaid_begin != ':') { syslog(LOG_ERR, "invalid argument: '%s'", optarg); return 1; } @@ -111,8 +127,10 @@ int main(_unused int argc, char* const argv[]) if (*iaid_begin == ',' && (iaid_len = strlen(iaid_begin)) > 1) memcpy(&prefix.iaid, iaid_begin + 1, iaid_len > 4 ? 4 : iaid_len); + else if (*iaid_begin == ':') + prefix.iaid = htonl((uint32_t)strtoul(&iaid_begin[1], NULL, 16)); else - prefix.iaid = ++ia_pd_iaid_index; + prefix.iaid = htonl(++ia_pd_iaid_index); odhcp6c_add_state(STATE_IA_PD_INIT, &prefix, sizeof(prefix)); @@ -160,7 +178,13 @@ int main(_unused int argc, char* const argv[]) break; case 'R': - strict_options = true; + client_options |= DHCPV6_STRICT_OPTIONS; + break; + + case 'u': + optlen = htons(strlen(optarg)); + odhcp6c_add_state(STATE_USERCLASS, &optlen, 2); + odhcp6c_add_state(STATE_USERCLASS, optarg, strlen(optarg)); break; case 's': @@ -175,6 +199,10 @@ int main(_unused int argc, char* const argv[]) sol_timeout = atoi(optarg); break; + case 'm': + min_update_interval = atoi(optarg); + break; + case 'e': logopt |= LOG_PERROR; break; @@ -187,6 +215,14 @@ int main(_unused int argc, char* const argv[]) pidfile = optarg; break; + case 'f': + client_options &= ~DHCPV6_CLIENT_FQDN; + break; + + case 'a': + client_options &= ~DHCPV6_ACCEPT_RECONFIGURE; + break; + default: help = true; break; @@ -208,7 +244,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, strict_options, sol_timeout) || + init_dhcpv6(ifname, client_options, sol_timeout) || ra_init(ifname, &ifid) || script_init(script, ifname)) { syslog(LOG_ERR, "failed to initialize: %s", strerror(errno)); return 3; @@ -229,7 +265,7 @@ int main(_unused int argc, char* const argv[]) pidfile = pidbuf; } - int fd = open(pidfile, O_WRONLY | O_CREAT); + int fd = open(pidfile, O_WRONLY | O_CREAT, 0644); if (fd >= 0) { char buf[8]; int len = snprintf(buf, sizeof(buf), "%i\n", getpid()); @@ -355,6 +391,12 @@ int main(_unused int argc, char* const argv[]) odhcp6c_clear_state(STATE_SERVER_ID); // Remove binding + odhcp6c_get_state(STATE_IA_PD, &ia_pd_len); + odhcp6c_get_state(STATE_IA_NA, &ia_na_len); + + if (ia_pd_len == 0 && ia_na_len == 0) + break; + // If we have IAs, try rebind otherwise restart res = dhcpv6_request(DHCPV6_MSG_REBIND); odhcp6c_signal_process(); @@ -404,6 +446,7 @@ static int usage(void) " -N Mode for requesting addresses [try|force|none]\n" " -P Request IPv6-Prefix (0 = auto)\n" " -F Force IPv6-Prefix\n" + " -V Set vendor-class option (base-16 encoded)\n" #ifdef EXT_BFD_PING " -B Enable BFD ping check\n" #endif @@ -412,10 +455,13 @@ static int usage(void) " -r Options to be requested (comma-separated)\n" " -R Do not request any options except those specified with -r\n" " -s