// IA states
static int request_prefix = -1;
-static enum odhcp6c_ia_mode na_mode = IA_MODE_NONE;
+static enum odhcp6c_ia_mode na_mode = IA_MODE_NONE, pd_mode = IA_MODE_NONE;
static bool accept_reconfig = false;
// Reconfigure key
}
-void dhcpv6_set_ia_na_mode(enum odhcp6c_ia_mode mode)
+void dhcpv6_set_ia_mode(enum odhcp6c_ia_mode na, enum odhcp6c_ia_mode pd)
{
- na_mode = mode;
+ na_mode = na;
+ pd_mode = pd;
}
.type = htons(DHCPV6_OPT_IA_PREFIX),
.len = htons(25), .prefix = request_prefix
};
- if (request_prefix > 0 && ia_pd_len == 0 &&
- (type == DHCPV6_MSG_SOLICIT ||
- type == DHCPV6_MSG_REQUEST)) {
+ if (request_prefix > 0 && ia_pd_len == 0 && type == DHCPV6_MSG_SOLICIT) {
ia_pd = (uint8_t*)&pref;
ia_pd_len = sizeof(pref);
}
}
// Disable IAs if not used
- if (type != DHCPV6_MSG_REQUEST && type != DHCPV6_MSG_SOLICIT) {
+ if (type != DHCPV6_MSG_SOLICIT) {
iov[5].iov_len = 0;
if (ia_na_len == 0)
iov[7].iov_len = 0;
len = retx->handler_reply(
type, opt, opt_end);
- if (round_end - round_start > 1000)
+ if (len > 0 && round_end - round_start > 1000)
round_end = 1000 + round_start;
}
}
uint16_t olen, otype;
uint8_t *odata;
struct dhcpv6_server_cand cand = {false, false, 0, 0, {0}, NULL, NULL, 0, 0};
+ bool have_na = false, have_pd = false;
dhcpv6_for_each_option(opt, end, otype, olen, odata) {
if (orig == DHCPV6_MSG_SOLICIT &&
if (otype == DHCPV6_OPT_SERVERID && olen <= 130) {
memcpy(cand.duid, odata, olen);
cand.duid_len = olen;
- } else if (otype == DHCPV6_OPT_STATUS && olen >= 2 && !odata[0]
- && odata[1] == DHCPV6_NoAddrsAvail) {
- if (na_mode == IA_MODE_FORCE) {
- return -1;
- } else {
- cand.has_noaddravail = true;
- cand.preference -= 1000;
- }
} else if (otype == DHCPV6_OPT_STATUS && olen >= 2 && !odata[0]
&& odata[1] == DHCPV6_NoPrefixAvail) {
cand.preference -= 2000;
} else if (otype == DHCPV6_OPT_IA_PD && request_prefix) {
struct dhcpv6_ia_hdr *h = (struct dhcpv6_ia_hdr*)&odata[-4];
uint8_t *oend = odata + olen, *d;
- dhcpv6_for_each_option(&h[1], oend, otype, olen, d) {
+ dhcpv6_for_each_option(&h[1], oend, otype, olen, d)
if (otype == DHCPV6_OPT_IA_PREFIX)
- cand.preference += 2000;
- else if (otype == DHCPV6_OPT_STATUS &&
- olen >= 2 && d[0] == 0 &&
- d[1] == DHCPV6_NoPrefixAvail)
- cand.preference -= 2000;
- }
+ have_pd = true;
+ } else if (otype == DHCPV6_OPT_IA_NA) {
+ struct dhcpv6_ia_hdr *h = (struct dhcpv6_ia_hdr*)&odata[-4];
+ uint8_t *oend = odata + olen, *d;
+ dhcpv6_for_each_option(&h[1], oend, otype, olen, d)
+ if (otype == DHCPV6_OPT_IA_ADDR)
+ have_na = true;
}
}
+ if ((!have_na && na_mode == IA_MODE_FORCE) ||
+ (!have_pd && pd_mode == IA_MODE_FORCE))
+ return -1;
+
+ if (na_mode != IA_MODE_NONE && !have_na) {
+ cand.has_noaddravail = true;
+ cand.preference -= 1000;
+ }
+
+ if (pd_mode != IA_MODE_NONE) {
+ if (have_pd)
+ cand.preference += 2000;
+ else
+ cand.preference -= 2000;
+ }
+
if (cand.duid_len > 0) {
cand.ia_na = odhcp6c_move_state(STATE_IA_NA, &cand.ia_na_len);
cand.ia_pd = odhcp6c_move_state(STATE_IA_PD, &cand.ia_pd_len);
char *optpos;
uint16_t opttype;
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;
bool help = false, daemonize = false;
int logopt = LOG_PID;
int c, request_pd = 0;
- while ((c = getopt(argc, argv, "S::N:P:c:i:r:s:khedp:")) != -1) {
+ while ((c = getopt(argc, argv, "S::N:P:Fc:i:r:s:khedp:")) != -1) {
switch (c) {
case 'S':
allow_slaac_only = (optarg) ? atoi(optarg) : -1;
break;
case 'N':
- if (!strcmp(optarg, "force"))
+ if (!strcmp(optarg, "force")) {
ia_na_mode = IA_MODE_FORCE;
- else if (!strcmp(optarg, "none"))
+ allow_slaac_only = -1;
+ } else if (!strcmp(optarg, "none")) {
ia_na_mode = IA_MODE_NONE;
- else if (!strcmp(optarg, "try"))
+ } else if (!strcmp(optarg, "try")) {
ia_na_mode = IA_MODE_TRY;
- else
+ } else{
help = true;
+ }
break;
case 'P':
request_pd = strtoul(optarg, NULL, 10);
if (request_pd == 0)
request_pd = -1;
+
+ ia_pd_mode = IA_MODE_TRY;
+ break;
+
+ case 'F':
+ allow_slaac_only = -1;
+ ia_pd_mode = IA_MODE_FORCE;
break;
case 'c':
odhcp6c_clear_state(STATE_SNTP_FQDN);
odhcp6c_clear_state(STATE_SIP_IP);
odhcp6c_clear_state(STATE_SIP_FQDN);
- dhcpv6_set_ia_na_mode(ia_na_mode);
+ dhcpv6_set_ia_mode(ia_na_mode, ia_pd_mode);
bound = false;
// Server candidates need deep-delete
" -S <time> Wait at least <time> sec for a DHCP-server (0)\n"
" -N <mode> Mode for requesting addresses [try|force|none]\n"
" -P <length> Request IPv6-Prefix (0 = auto)\n"
+ " -F Force IPv6-Prefix\n"
" -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"