X-Git-Url: https://git.decadent.org.uk/gitweb/?p=odhcp6c.git;a=blobdiff_plain;f=src%2Fdhcpv6.c;h=013e215c6555d1a0f2ffa7cf794efb5f04799c73;hp=8be70af19797ffde5ed2ddf73646a13a90463280;hb=4ad21618ad863b5f590ed00f2c7677605a98e39f;hpb=e9de72f3fc41466819f8027b6cc7a978c388ed28 diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 8be70af..013e215 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -135,7 +135,8 @@ int init_dhcpv6(const char *ifname, int request_pd) htons(DHCPV6_OPT_DNS_DOMAIN), htons(DHCPV6_OPT_NTP_SERVER), htons(DHCPV6_OPT_SIP_SERVER_A), - htons(DHCPV6_OPT_SIP_SERVER_D)}; + htons(DHCPV6_OPT_PREFIX_CLASS) + }; odhcp6c_add_state(STATE_ORO, oro, sizeof(oro)); @@ -520,7 +521,7 @@ static int dhcpv6_handle_advert(_unused enum dhcpv6_msg orig, cand.preference -= 2000; } else if (otype == DHCPV6_OPT_PREF && olen >= 1 && cand.preference >= 0) { - cand.preference = odata[1]; + cand.preference = odata[0]; } else if (otype == DHCPV6_OPT_RECONF_ACCEPT) { cand.wants_reconfigure = true; } else if (otype == DHCPV6_OPT_IA_PD && request_prefix) { @@ -623,7 +624,7 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, if (t3 < 0) t3 = 0; } else { - t1 = t2 = t3 = 86400; + t1 = t2 = t3 = UINT32_MAX; } if (opt) { @@ -674,6 +675,12 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, if (n < t3) t3 = n; + if (t2 >= t3) + t2 = 8 * t3 / 10; + + if (t1 >= t2) + t1 = 5 * t2 / 8; + } else if (otype == DHCPV6_OPT_DNS_SERVERS) { if (olen % 16 == 0) odhcp6c_add_state(STATE_DNS, odata, olen); @@ -719,11 +726,11 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end) uint16_t otype, olen; uint8_t *odata; - struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, - 0, 0, IN6ADDR_ANY_INIT, 0, 0}; - // Update address IA dhcpv6_for_each_option(opt, end, otype, olen, odata) { + struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, + 0, 0, IN6ADDR_ANY_INIT, 0, 0, 0}; + if (otype == DHCPV6_OPT_IA_PREFIX) { struct dhcpv6_ia_prefix *prefix = (void*)&odata[-4]; if (olen + 4U < sizeof(*prefix)) @@ -737,6 +744,14 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end) entry.length = prefix->prefix; entry.target = prefix->addr; + uint16_t stype, slen; + uint8_t *sdata; + + // Find prefix class, if any + dhcpv6_for_each_option(odata, odata + olen, + stype, slen, sdata) + if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2) + entry.prefix_class = ntohs(*((uint16_t*)sdata)); odhcp6c_update_entry(STATE_IA_PD, &entry); } else if (otype == DHCPV6_OPT_IA_ADDR) {