udhcpc6: preparatory patch, no code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2018-01-16 21:35:39 +01:00
parent 688cb3bc19
commit 1e8d79ba12

View File

@@ -1589,44 +1589,44 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
* . . * . .
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
free(client6_data.ia_na); free(client6_data.ia_na);
client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA); client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA);
if (!client6_data.ia_na) { if (!client6_data.ia_na) {
bb_error_msg("no %s option, ignoring packet", "IA_NA"); bb_error_msg("no %s option, ignoring packet", "IA_NA");
continue; continue;
} }
if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) { if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) {
bb_error_msg("IA_NA option is too short:%d bytes", client6_data.ia_na->len); bb_error_msg("IA_NA option is too short:%d bytes", client6_data.ia_na->len);
continue; continue;
} }
iaaddr = d6_find_option(client6_data.ia_na->data + 4 + 4 + 4, iaaddr = d6_find_option(client6_data.ia_na->data + 4 + 4 + 4,
client6_data.ia_na->data + client6_data.ia_na->len, client6_data.ia_na->data + client6_data.ia_na->len,
D6_OPT_IAADDR D6_OPT_IAADDR
); );
if (!iaaddr) { if (!iaaddr) {
bb_error_msg("no %s option, ignoring packet", "IAADDR"); bb_error_msg("no %s option, ignoring packet", "IAADDR");
continue; continue;
} }
if (iaaddr->len < (16 + 4 + 4)) { if (iaaddr->len < (16 + 4 + 4)) {
bb_error_msg("IAADDR option is too short:%d bytes", iaaddr->len); bb_error_msg("IAADDR option is too short:%d bytes", iaaddr->len);
continue; continue;
} }
/* Note: the address is sufficiently aligned for cast: /* Note: the address is sufficiently aligned for cast:
* we _copied_ IA-NA, and copy is always well-aligned. * we _copied_ IA-NA, and copy is always well-aligned.
*/ */
requested_ipv6 = (struct in6_addr*) iaaddr->data; requested_ipv6 = (struct in6_addr*) iaaddr->data;
move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4); move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4);
lease_seconds = ntohl(lease_seconds); lease_seconds = ntohl(lease_seconds);
/* paranoia: must not be too small and not prone to overflows */ /* paranoia: must not be too small and not prone to overflows */
if (lease_seconds < 0x10) if (lease_seconds < 0x10)
lease_seconds = 0x10; lease_seconds = 0x10;
/// TODO: check for 0 lease time? /// TODO: check for 0 lease time?
if (lease_seconds > 0x7fffffff / 1000) if (lease_seconds > 0x7fffffff / 1000)
lease_seconds = 0x7fffffff / 1000; lease_seconds = 0x7fffffff / 1000;
/* enter bound state */ /* enter bound state */
timeout = lease_seconds / 2; timeout = lease_seconds / 2;
bb_error_msg("lease obtained, lease time %u", bb_error_msg("lease obtained, lease time %u",
/*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
d6_run_script(&packet, state == REQUESTING ? "bound" : "renew"); d6_run_script(&packet, state == REQUESTING ? "bound" : "renew");
state = BOUND; state = BOUND;