summaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorDenis Vlasenko2008-12-08 22:56:18 +0000
committerDenis Vlasenko2008-12-08 22:56:18 +0000
commitefb545b9bdd3934dcdbf9bc0890a42081b330049 (patch)
tree4dc9212e49a5dae9890bd324bcc9bf4941e2321d /networking/udhcp
parentd1a84a2880073f6cc5e2f9f4e5f236cd110f01a0 (diff)
downloadbusybox-efb545b9bdd3934dcdbf9bc0890a42081b330049.zip
busybox-efb545b9bdd3934dcdbf9bc0890a42081b330049.tar.gz
optimize 16- and 32-bit moves
function old new delta udhcpd_main 1239 1257 +18 udhcp_add_simple_option 93 92 -1 buffer_read_le_u32 19 18 -1 unpack_gz_stream_with_info 526 520 -6 dnsd_main 1470 1463 -7 udhcp_run_script 1208 1186 -22 send_ACK 255 229 -26 arping_main 1661 1623 -38 send_offer 470 428 -42 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/8 up/down: 18/-143) Total: -125 bytes
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/dhcpc.c4
-rw-r--r--networking/udhcp/dhcpd.c25
-rw-r--r--networking/udhcp/options.c5
-rw-r--r--networking/udhcp/script.c10
-rw-r--r--networking/udhcp/serverpacket.c37
5 files changed, 43 insertions, 38 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 2d48980..e2e5b0a 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -503,7 +503,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* still selecting - this server looks bad */
}
/* it IS unaligned sometimes, don't "optimize" */
- server_addr = get_unaligned_u32p((uint32_t*)temp);
+ move_from_unaligned32(server_addr, temp);
xid = packet.xid;
requested_ip = packet.yiaddr;
@@ -525,7 +525,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
lease_seconds = 60 * 60;
} else {
/* it IS unaligned sometimes, don't "optimize" */
- lease_seconds = get_unaligned_u32p((uint32_t*)temp);
+ move_from_unaligned32(lease_seconds, temp);
lease_seconds = ntohl(lease_seconds);
lease_seconds &= 0x0fffffff; /* paranoia: must not be prone to overflows */
if (lease_seconds < 10) /* and not too small */
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index b512c45..7b45968 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -30,7 +30,9 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
int server_socket = -1, bytes, retval, max_sock;
struct dhcpMessage packet;
uint8_t *state, *server_id, *requested;
- uint32_t server_id_align, requested_align, static_lease_ip;
+ uint32_t server_id_aligned = server_id_aligned; /* for compiler */
+ uint32_t requested_aligned = requested_aligned;
+ uint32_t static_lease_ip;
unsigned timeout_end;
unsigned num_ips;
unsigned opt;
@@ -79,7 +81,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
option = find_option(server_config.options, DHCP_LEASE_TIME);
server_config.lease = LEASE_TIME;
if (option) {
- memcpy(&server_config.lease, option->data + 2, 4);
+ move_from_unaligned32(server_config.lease, option->data + 2);
server_config.lease = ntohl(server_config.lease);
}
@@ -190,21 +192,24 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
requested = get_option(&packet, DHCP_REQUESTED_IP);
server_id = get_option(&packet, DHCP_SERVER_ID);
- if (requested) memcpy(&requested_align, requested, 4);
- if (server_id) memcpy(&server_id_align, server_id, 4);
+ if (requested)
+ move_from_unaligned32(requested_aligned, requested);
+ if (server_id)
+ move_from_unaligned32(server_id_aligned, server_id);
if (lease) {
if (server_id) {
/* SELECTING State */
- DEBUG("server_id = %08x", ntohl(server_id_align));
- if (server_id_align == server_config.server && requested
- && requested_align == lease->yiaddr
+ DEBUG("server_id = %08x", ntohl(server_id_aligned));
+ if (server_id_aligned == server_config.server
+ && requested
+ && requested_aligned == lease->yiaddr
) {
send_ACK(&packet, lease->yiaddr);
}
} else if (requested) {
/* INIT-REBOOT State */
- if (lease->yiaddr == requested_align)
+ if (lease->yiaddr == requested_aligned)
send_ACK(&packet, lease->yiaddr);
else
send_NAK(&packet);
@@ -221,7 +226,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
} else if (requested) {
/* INIT-REBOOT State */
- lease = find_lease_by_yiaddr(requested_align);
+ lease = find_lease_by_yiaddr(requested_aligned);
if (lease) {
if (lease_expired(lease)) {
/* probably best if we drop this lease */
@@ -230,7 +235,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
} else
send_NAK(&packet);
} else {
- uint32_t r = ntohl(requested_align);
+ uint32_t r = ntohl(requested_aligned);
if (r < server_config.start_ip
|| r > server_config.end_ip
) {
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 2c27e70..581a7b6 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -224,9 +224,8 @@ int FAST_FUNC add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
option[OPT_LEN] = len;
if (BB_BIG_ENDIAN)
data <<= 8 * (4 - len);
- /* This memcpy is for processors which can't
- * handle a simple unaligned 32-bit assignment */
- memcpy(&option[OPT_DATA], &data, 4);
+ /* Assignment is unaligned! */
+ move_to_unaligned32(&option[OPT_DATA], data);
return add_option_string(optionptr, option);
}
}
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 8dff9b7..4ae17fb 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -90,19 +90,19 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p,
dest += sprintf(dest, "%u", *option);
break;
case OPTION_U16:
- memcpy(&val_u16, option, 2);
+ move_from_unaligned16(val_u16, option);
dest += sprintf(dest, "%u", ntohs(val_u16));
break;
case OPTION_S16:
- memcpy(&val_s16, option, 2);
+ move_from_unaligned16(val_s16, option);
dest += sprintf(dest, "%d", ntohs(val_s16));
break;
case OPTION_U32:
- memcpy(&val_u32, option, 4);
+ move_from_unaligned32(val_u32, option);
dest += sprintf(dest, "%lu", (unsigned long) ntohl(val_u32));
break;
case OPTION_S32:
- memcpy(&val_s32, option, 4);
+ move_from_unaligned32(val_s32, option);
dest += sprintf(dest, "%ld", (long) ntohl(val_s32));
break;
case OPTION_STRING:
@@ -183,7 +183,7 @@ static char **fill_envp(struct dhcpMessage *packet)
/* Fill in a subnet bits option for things like /24 */
if (dhcp_options[i].code == DHCP_SUBNET) {
uint32_t subnet;
- memcpy(&subnet, temp, 4);
+ move_from_unaligned32(subnet, temp);
envp[j++] = xasprintf("mask=%d", mton(subnet));
}
next:
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index dcc234c..fca685d 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -103,7 +103,8 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
{
struct dhcpMessage packet;
struct dhcpOfferedAddr *lease = NULL;
- uint32_t req_align, lease_time_align = server_config.lease;
+ uint32_t req_align;
+ uint32_t lease_time_aligned = server_config.lease;
uint8_t *req, *lease_time;
struct option_set *curr;
struct in_addr addr;
@@ -120,7 +121,7 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
lease = find_lease_by_chaddr(oldpacket->chaddr);
if (lease) {
if (!lease_expired(lease))
- lease_time_align = lease->expires - time(0);
+ lease_time_aligned = lease->expires - time(0);
packet.yiaddr = lease->yiaddr;
/* Or the client has a requested ip */
} else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP))
@@ -155,22 +156,22 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
}
lease_time = get_option(oldpacket, DHCP_LEASE_TIME);
if (lease_time) {
- memcpy(&lease_time_align, lease_time, 4);
- lease_time_align = ntohl(lease_time_align);
- if (lease_time_align > server_config.lease)
- lease_time_align = server_config.lease;
+ move_from_unaligned32(lease_time_aligned, lease_time);
+ lease_time_aligned = ntohl(lease_time_aligned);
+ if (lease_time_aligned > server_config.lease)
+ lease_time_aligned = server_config.lease;
}
/* Make sure we aren't just using the lease time from the previous offer */
- if (lease_time_align < server_config.min_lease)
- lease_time_align = server_config.lease;
+ if (lease_time_aligned < server_config.min_lease)
+ lease_time_aligned = server_config.lease;
/* ADDME: end of short circuit */
} else {
/* It is a static lease... use it */
packet.yiaddr = static_lease_ip;
}
- add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
+ add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_aligned));
curr = server_config.options;
while (curr) {
@@ -203,7 +204,7 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
struct dhcpMessage packet;
struct option_set *curr;
uint8_t *lease_time;
- uint32_t lease_time_align = server_config.lease;
+ uint32_t lease_time_aligned = server_config.lease;
struct in_addr addr;
init_packet(&packet, oldpacket, DHCPACK);
@@ -211,15 +212,15 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
lease_time = get_option(oldpacket, DHCP_LEASE_TIME);
if (lease_time) {
- memcpy(&lease_time_align, lease_time, 4);
- lease_time_align = ntohl(lease_time_align);
- if (lease_time_align > server_config.lease)
- lease_time_align = server_config.lease;
- else if (lease_time_align < server_config.min_lease)
- lease_time_align = server_config.lease;
+ move_from_unaligned32(lease_time_aligned, lease_time);
+ lease_time_aligned = ntohl(lease_time_aligned);
+ if (lease_time_aligned > server_config.lease)
+ lease_time_aligned = server_config.lease;
+ else if (lease_time_aligned < server_config.min_lease)
+ lease_time_aligned = server_config.lease;
}
- add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
+ add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_aligned));
curr = server_config.options;
while (curr) {
@@ -236,7 +237,7 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
if (send_packet(&packet, 0) < 0)
return -1;
- add_lease(packet.chaddr, packet.yiaddr, lease_time_align);
+ add_lease(packet.chaddr, packet.yiaddr, lease_time_aligned);
if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) {
/* rewrite the file with leases at every new acceptance */
write_leases();