aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-01-16 21:47:10 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-01-16 21:47:10 +0100
commit14f13205efda0d1dc09d97ffab036162c13b94d1 (patch)
tree6e4c1929b8ca94e8fe46cb9172bbdbd5a187b038 /networking/udhcp
parentef5207f093216fe6cf6f1bc7a098bcab5f435a98 (diff)
downloadbusybox-w32-14f13205efda0d1dc09d97ffab036162c13b94d1.tar.gz
busybox-w32-14f13205efda0d1dc09d97ffab036162c13b94d1.tar.bz2
busybox-w32-14f13205efda0d1dc09d97ffab036162c13b94d1.zip
udhcpc6: code shrink
function old new delta udhcpc6_main 2723 2727 +4 .rodata 128695 128561 -134 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/d6_dhcpc.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index cfb2dcc5a..3e200eb21 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -1501,10 +1501,12 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1501 case REBINDING: 1501 case REBINDING:
1502 if (packet.d6_msg_type == D6_MSG_REPLY) { 1502 if (packet.d6_msg_type == D6_MSG_REPLY) {
1503 uint32_t lease_seconds; 1503 uint32_t lease_seconds;
1504 struct d6_option *option, *iaaddr; 1504 struct d6_option *option;
1505 int address_timeout = 0; 1505 int address_timeout;
1506 int prefix_timeout = 0; 1506 int prefix_timeout;
1507 type_is_ok: 1507 type_is_ok:
1508 address_timeout = 0;
1509 prefix_timeout = 0;
1508 option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE); 1510 option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE);
1509 if (option && (option->data[0] | option->data[1]) != 0) { 1511 if (option && (option->data[0] | option->data[1]) != 0) {
1510 /* return to init state */ 1512 /* return to init state */
@@ -1628,6 +1630,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1628 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1630 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1629 */ 1631 */
1630 if (option_mask32 & OPT_r) { 1632 if (option_mask32 & OPT_r) {
1633 struct d6_option *iaaddr;
1634
1631 free(client6_data.ia_na); 1635 free(client6_data.ia_na);
1632 client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA); 1636 client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA);
1633 if (!client6_data.ia_na) { 1637 if (!client6_data.ia_na) {
@@ -1635,7 +1639,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1635 continue; 1639 continue;
1636 } 1640 }
1637 if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) { 1641 if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) {
1638 bb_error_msg("IA_NA option is too short:%d bytes", client6_data.ia_na->len); 1642 bb_error_msg("%s option is too short:%d bytes",
1643 "IA_NA", client6_data.ia_na->len);
1639 continue; 1644 continue;
1640 } 1645 }
1641 iaaddr = d6_find_option(client6_data.ia_na->data + 4 + 4 + 4, 1646 iaaddr = d6_find_option(client6_data.ia_na->data + 4 + 4 + 4,
@@ -1647,7 +1652,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1647 continue; 1652 continue;
1648 } 1653 }
1649 if (iaaddr->len < (16 + 4 + 4)) { 1654 if (iaaddr->len < (16 + 4 + 4)) {
1650 bb_error_msg("IAADDR option is too short:%d bytes", iaaddr->len); 1655 bb_error_msg("%s option is too short:%d bytes",
1656 "IAADDR", iaaddr->len);
1651 continue; 1657 continue;
1652 } 1658 }
1653 /* Note: the address is sufficiently aligned for cast: 1659 /* Note: the address is sufficiently aligned for cast:
@@ -1656,16 +1662,13 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1656 requested_ipv6 = (struct in6_addr*) iaaddr->data; 1662 requested_ipv6 = (struct in6_addr*) iaaddr->data;
1657 move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4); 1663 move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4);
1658 lease_seconds = ntohl(lease_seconds); 1664 lease_seconds = ntohl(lease_seconds);
1659 /* paranoia: must not be too small and not prone to overflows */
1660 if (lease_seconds < 0x10)
1661 lease_seconds = 0x10;
1662/// TODO: check for 0 lease time? 1665/// TODO: check for 0 lease time?
1666 /* paranoia: must not be prone to overflows */
1663 if (lease_seconds > 0x7fffffff / 1000) 1667 if (lease_seconds > 0x7fffffff / 1000)
1664 lease_seconds = 0x7fffffff / 1000; 1668 lease_seconds = 0x7fffffff / 1000;
1665 /* enter bound state */
1666 address_timeout = lease_seconds / 2; 1669 address_timeout = lease_seconds / 2;
1667 bb_error_msg("lease obtained, lease time %u", 1670 bb_error_msg("%s obtained, lease time %u",
1668 /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); 1671 "IPv6", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
1669 } 1672 }
1670 if (option_mask32 & OPT_d) { 1673 if (option_mask32 & OPT_d) {
1671 struct d6_option *iaprefix; 1674 struct d6_option *iaprefix;
@@ -1677,7 +1680,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1677 continue; 1680 continue;
1678 } 1681 }
1679 if (client6_data.ia_pd->len < (4 + 4 + 4) + (2 + 2 + 4 + 4 + 1 + 16)) { 1682 if (client6_data.ia_pd->len < (4 + 4 + 4) + (2 + 2 + 4 + 4 + 1 + 16)) {
1680 bb_error_msg("IA_PD option is too short:%d bytes", client6_data.ia_pd->len); 1683 bb_error_msg("%s option is too short:%d bytes",
1684 "IA_PD", client6_data.ia_pd->len);
1681 continue; 1685 continue;
1682 } 1686 }
1683 iaprefix = d6_find_option(client6_data.ia_pd->data + 4 + 4 + 4, 1687 iaprefix = d6_find_option(client6_data.ia_pd->data + 4 + 4 + 4,
@@ -1689,22 +1693,24 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1689 continue; 1693 continue;
1690 } 1694 }
1691 if (iaprefix->len < (4 + 4 + 1 + 16)) { 1695 if (iaprefix->len < (4 + 4 + 1 + 16)) {
1692 bb_error_msg("IAPREFIX option is too short:%d bytes", iaprefix->len); 1696 bb_error_msg("%s option is too short:%d bytes",
1697 "IAPREFIX", iaprefix->len);
1693 continue; 1698 continue;
1694 } 1699 }
1695 move_from_unaligned32(lease_seconds, iaprefix->data + 4); 1700 move_from_unaligned32(lease_seconds, iaprefix->data + 4);
1696 lease_seconds = ntohl(lease_seconds); 1701 lease_seconds = ntohl(lease_seconds);
1697 /* paranoia: must not be too small and not prone to overflows */ 1702 /* paranoia: must not be prone to overflows */
1698 if (lease_seconds < 0x10)
1699 lease_seconds = 0x10;
1700 if (lease_seconds > 0x7fffffff / 1000) 1703 if (lease_seconds > 0x7fffffff / 1000)
1701 lease_seconds = 0x7fffffff / 1000; 1704 lease_seconds = 0x7fffffff / 1000;
1702 /* enter bound state */
1703 prefix_timeout = lease_seconds / 2; 1705 prefix_timeout = lease_seconds / 2;
1704 bb_error_msg("prefix obtained, lease time %u", 1706 bb_error_msg("%s obtained, lease time %u",
1705 /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); 1707 "prefix", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
1706 } 1708 }
1707 timeout = address_timeout > prefix_timeout ? prefix_timeout : address_timeout; 1709 timeout = address_timeout > prefix_timeout ? prefix_timeout : address_timeout;
1710 /* paranoia: must not be too small */
1711 if (timeout < 0x10)
1712 timeout = 0x10;
1713 /* enter bound state */
1708 d6_run_script(&packet, state == REQUESTING ? "bound" : "renew"); 1714 d6_run_script(&packet, state == REQUESTING ? "bound" : "renew");
1709 1715
1710 state = BOUND; 1716 state = BOUND;