X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=src%2Fdhcpv6.c;h=c87d289e159687b03aa3fc87f1c9b98b3651c06d;hb=6c8109e0c77d5a54950ba607d1ec1f83d5efb5b7;hp=4b1ba957b21fcbc3d18c0030a0bc2acb915ec07b;hpb=c291def1cadf58c0aa10c18a53c2fc4d2dee1ad6;p=odhcp6c.git diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 4b1ba95..c87d289 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -197,6 +197,23 @@ int init_dhcpv6(const char *ifname, unsigned int options, int sol_timeout) return 0; } +enum { + IOV_HDR=0, + IOV_ORO, + IOV_ORO_REFRESH, + IOV_CL_ID, + IOV_SRV_ID, + IOV_VENDOR_CLASS_HDR, + IOV_VENDOR_CLASS, + IOV_USER_CLASS_HDR, + IOV_USER_CLASS, + IOV_RECONF_ACCEPT, + IOV_FQDN, + IOV_HDR_IA_NA, + IOV_IA_NA, + IOV_IA_PD, + IOV_TOTAL +}; void dhcpv6_set_ia_mode(enum odhcp6c_ia_mode na, enum odhcp6c_ia_mode pd) { @@ -231,7 +248,7 @@ static void dhcpv6_send(enum dhcpv6_msg type, uint8_t trid[3], uint32_t ecs) void *srv_id = odhcp6c_get_state(STATE_SERVER_ID, &srv_id_len); // Build IA_PDs - size_t ia_pd_entries, ia_pd_len = 0; + size_t ia_pd_entries = 0, ia_pd_len = 0; uint8_t *ia_pd; if (type == DHCPV6_MSG_SOLICIT) { @@ -401,47 +418,45 @@ static void dhcpv6_send(enum dhcpv6_msg type, uint8_t trid[3], uint32_t ecs) htons(DHCPV6_OPT_ORO), htons(oro_len), }; - struct iovec iov[] = { - {&hdr, sizeof(hdr)}, - {oro, oro_len}, - {&oro_refresh, 0}, - {cl_id, cl_id_len}, - {srv_id, srv_id_len}, - {&vendor_class_hdr, vendor_class_len ? sizeof(vendor_class_hdr) : 0}, - {vendor_class, vendor_class_len}, - {&user_class_hdr, user_class_len ? sizeof(user_class_hdr) : 0}, - {user_class, user_class_len}, - {&reconf_accept, sizeof(reconf_accept)}, - {&fqdn, fqdn_len}, - {&hdr_ia_na, sizeof(hdr_ia_na)}, - {ia_na, ia_na_len}, - {ia_pd, ia_pd_len}, + struct iovec iov[IOV_TOTAL] = { + [IOV_HDR] = {&hdr, sizeof(hdr)}, + [IOV_ORO] = {oro, oro_len}, + [IOV_ORO_REFRESH] = {&oro_refresh, 0}, + [IOV_CL_ID] = {cl_id, cl_id_len}, + [IOV_SRV_ID] = {srv_id, srv_id_len}, + [IOV_VENDOR_CLASS_HDR] = {&vendor_class_hdr, vendor_class_len ? sizeof(vendor_class_hdr) : 0}, + [IOV_VENDOR_CLASS] = {vendor_class, vendor_class_len}, + [IOV_USER_CLASS_HDR] = {&user_class_hdr, user_class_len ? sizeof(user_class_hdr) : 0}, + [IOV_USER_CLASS] = {user_class, user_class_len}, + [IOV_RECONF_ACCEPT] = {&reconf_accept, sizeof(reconf_accept)}, + [IOV_FQDN] = {&fqdn, fqdn_len}, + [IOV_HDR_IA_NA] = {&hdr_ia_na, sizeof(hdr_ia_na)}, + [IOV_IA_NA] = {ia_na, ia_na_len}, + [IOV_IA_PD] = {ia_pd, ia_pd_len}, }; - size_t cnt = ARRAY_SIZE(iov); + size_t cnt = IOV_TOTAL; if (type == DHCPV6_MSG_INFO_REQ) { cnt = 9; - iov[2].iov_len = sizeof(oro_refresh); + iov[IOV_ORO_REFRESH].iov_len = sizeof(oro_refresh); hdr.oro_len = htons(oro_len + sizeof(oro_refresh)); } else if (!request_prefix) { cnt = 13; } // Disable IAs if not used - if (type != DHCPV6_MSG_SOLICIT) { - iov[7].iov_len = 0; - if (ia_na_len == 0) - iov[9].iov_len = 0; - } + if (type != DHCPV6_MSG_SOLICIT && ia_na_len == 0) + iov[IOV_HDR_IA_NA].iov_len = 0; if (na_mode == IA_MODE_NONE) - iov[9].iov_len = 0; + iov[IOV_HDR_IA_NA].iov_len = 0; - if (!(client_options & DHCPV6_ACCEPT_RECONFIGURE)) - iov[7].iov_len = 0; + if ((type != DHCPV6_MSG_SOLICIT && type != DHCPV6_MSG_REQUEST) || + !(client_options & DHCPV6_ACCEPT_RECONFIGURE)) + iov[IOV_RECONF_ACCEPT].iov_len = 0; if (!(client_options & DHCPV6_CLIENT_FQDN)) - iov[8].iov_len = 0; + iov[IOV_FQDN].iov_len = 0; struct sockaddr_in6 srv = {AF_INET6, htons(DHCPV6_SERVER_PORT), 0, ALL_DHCPV6_RELAYS, ifindex}; @@ -642,10 +657,12 @@ static bool dhcpv6_response_is_valid(const void *buf, ssize_t len, continue; md5_ctx_t md5; - uint8_t serverhash[16], secretbytes[16], hash[16]; + uint8_t serverhash[16], secretbytes[64], hash[16]; memcpy(serverhash, r->key, sizeof(serverhash)); memset(r->key, 0, sizeof(r->key)); - memcpy(secretbytes, reconf_key, sizeof(secretbytes)); + + memset(secretbytes, 0, sizeof(secretbytes)); + memcpy(secretbytes, reconf_key, sizeof(reconf_key)); for (size_t i = 0; i < sizeof(secretbytes); ++i) secretbytes[i] ^= 0x36;