X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=src%2Fdhcpv6.c;h=785b57b03aedf1543dea2ff08a08594599873ceb;hb=8e50917e51f7f21c53f9021063670065c8fa06d8;hp=1df31cd1811c585ce35d5aa9d139abfbd2dfc31a;hpb=74ef11cad687fd165457f212cfe15bc5ad7a2cd1;p=odhcp6c.git diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 1df31cd..785b57b 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -145,7 +145,9 @@ int init_dhcpv6(const char *ifname, int request_pd) htons(DHCPV6_OPT_SIP_SERVER_A), htons(DHCPV6_OPT_AFTR_NAME), htons(DHCPV6_OPT_PD_EXCLUDE), +#ifdef EXT_PREFIX_CLASS htons(DHCPV6_OPT_PREFIX_CLASS), +#endif }; odhcp6c_add_state(STATE_ORO, oro, sizeof(oro)); @@ -569,6 +571,13 @@ static int dhcpv6_handle_advert(enum dhcpv6_msg orig, struct dhcpv6_server_cand cand = {false, false, 0, 0, {0}, NULL, NULL, 0, 0}; dhcpv6_for_each_option(opt, end, otype, olen, odata) { + if (orig == DHCPV6_MSG_SOLICIT && + (otype == DHCPV6_OPT_IA_PD || otype == DHCPV6_OPT_IA_NA) && + olen > sizeof(struct dhcpv6_ia_hdr)) { + struct dhcpv6_ia_hdr *ia_hdr = (void*)(&odata[-4]); + dhcpv6_parse_ia(&ia_hdr[1], odata + olen); + } + if (otype == DHCPV6_OPT_SERVERID && olen <= 130) { memcpy(cand.duid, odata, olen); cand.duid_len = olen; @@ -600,13 +609,6 @@ static int dhcpv6_handle_advert(enum dhcpv6_msg orig, cand.preference -= 2000; } } - - if (orig == DHCPV6_MSG_SOLICIT && - (otype == DHCPV6_OPT_IA_PD || otype == DHCPV6_OPT_IA_NA) && - olen > sizeof(struct dhcpv6_ia_hdr)) { - struct dhcpv6_ia_hdr *ia_hdr = (void*)(&odata[-4]); - dhcpv6_parse_ia(&ia_hdr[1], odata + olen); - } } if (cand.duid_len > 0) { @@ -831,8 +833,8 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end) // 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}; + 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]; @@ -850,11 +852,13 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end) uint16_t stype, slen; uint8_t *sdata; +#ifdef EXT_PREFIX_CLASS // Find prefix class, if any dhcpv6_for_each_option(&prefix[1], odata + olen, - stype, slen, sdata) - if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2) - entry.prefix_class = ntohs(*((uint16_t*)sdata)); + stype, slen, sdata) + if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2) + entry.class = sdata[0] << 8 | sdata[1]; +#endif // Parse PD-exclude bool ok = true; @@ -912,18 +916,18 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end) entry.length = 128; entry.target = addr->addr; +#ifdef EXT_PREFIX_CLASS uint16_t stype, slen; uint8_t *sdata; - // Find prefix class, if any dhcpv6_for_each_option(&addr[1], odata + olen, - stype, slen, sdata) - if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2) - entry.prefix_class = ntohs(*((uint16_t*)sdata)); - + stype, slen, sdata) + if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2) + entry.class = sdata[0] << 8 | sdata[1]; +#endif + odhcp6c_update_entry(STATE_IA_NA, &entry); } - if (entry.valid > 0 && timeout > entry.valid) timeout = entry.valid; }