diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-08 22:56:18 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-08 22:56:18 +0000 |
commit | efb545b9bdd3934dcdbf9bc0890a42081b330049 (patch) | |
tree | 4dc9212e49a5dae9890bd324bcc9bf4941e2321d /networking/udhcp | |
parent | d1a84a2880073f6cc5e2f9f4e5f236cd110f01a0 (diff) | |
download | busybox-w32-efb545b9bdd3934dcdbf9bc0890a42081b330049.tar.gz busybox-w32-efb545b9bdd3934dcdbf9bc0890a42081b330049.tar.bz2 busybox-w32-efb545b9bdd3934dcdbf9bc0890a42081b330049.zip |
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.c | 4 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 25 | ||||
-rw-r--r-- | networking/udhcp/options.c | 5 | ||||
-rw-r--r-- | networking/udhcp/script.c | 10 | ||||
-rw-r--r-- | networking/udhcp/serverpacket.c | 37 |
5 files changed, 43 insertions, 38 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 2d48980d9..e2e5b0a82 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -503,7 +503,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
503 | /* still selecting - this server looks bad */ | 503 | /* still selecting - this server looks bad */ |
504 | } | 504 | } |
505 | /* it IS unaligned sometimes, don't "optimize" */ | 505 | /* it IS unaligned sometimes, don't "optimize" */ |
506 | server_addr = get_unaligned_u32p((uint32_t*)temp); | 506 | move_from_unaligned32(server_addr, temp); |
507 | xid = packet.xid; | 507 | xid = packet.xid; |
508 | requested_ip = packet.yiaddr; | 508 | requested_ip = packet.yiaddr; |
509 | 509 | ||
@@ -525,7 +525,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
525 | lease_seconds = 60 * 60; | 525 | lease_seconds = 60 * 60; |
526 | } else { | 526 | } else { |
527 | /* it IS unaligned sometimes, don't "optimize" */ | 527 | /* it IS unaligned sometimes, don't "optimize" */ |
528 | lease_seconds = get_unaligned_u32p((uint32_t*)temp); | 528 | move_from_unaligned32(lease_seconds, temp); |
529 | lease_seconds = ntohl(lease_seconds); | 529 | lease_seconds = ntohl(lease_seconds); |
530 | lease_seconds &= 0x0fffffff; /* paranoia: must not be prone to overflows */ | 530 | lease_seconds &= 0x0fffffff; /* paranoia: must not be prone to overflows */ |
531 | if (lease_seconds < 10) /* and not too small */ | 531 | if (lease_seconds < 10) /* and not too small */ |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index b512c45ee..7b4596895 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -30,7 +30,9 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
30 | int server_socket = -1, bytes, retval, max_sock; | 30 | int server_socket = -1, bytes, retval, max_sock; |
31 | struct dhcpMessage packet; | 31 | struct dhcpMessage packet; |
32 | uint8_t *state, *server_id, *requested; | 32 | uint8_t *state, *server_id, *requested; |
33 | uint32_t server_id_align, requested_align, static_lease_ip; | 33 | uint32_t server_id_aligned = server_id_aligned; /* for compiler */ |
34 | uint32_t requested_aligned = requested_aligned; | ||
35 | uint32_t static_lease_ip; | ||
34 | unsigned timeout_end; | 36 | unsigned timeout_end; |
35 | unsigned num_ips; | 37 | unsigned num_ips; |
36 | unsigned opt; | 38 | unsigned opt; |
@@ -79,7 +81,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
79 | option = find_option(server_config.options, DHCP_LEASE_TIME); | 81 | option = find_option(server_config.options, DHCP_LEASE_TIME); |
80 | server_config.lease = LEASE_TIME; | 82 | server_config.lease = LEASE_TIME; |
81 | if (option) { | 83 | if (option) { |
82 | memcpy(&server_config.lease, option->data + 2, 4); | 84 | move_from_unaligned32(server_config.lease, option->data + 2); |
83 | server_config.lease = ntohl(server_config.lease); | 85 | server_config.lease = ntohl(server_config.lease); |
84 | } | 86 | } |
85 | 87 | ||
@@ -190,21 +192,24 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
190 | requested = get_option(&packet, DHCP_REQUESTED_IP); | 192 | requested = get_option(&packet, DHCP_REQUESTED_IP); |
191 | server_id = get_option(&packet, DHCP_SERVER_ID); | 193 | server_id = get_option(&packet, DHCP_SERVER_ID); |
192 | 194 | ||
193 | if (requested) memcpy(&requested_align, requested, 4); | 195 | if (requested) |
194 | if (server_id) memcpy(&server_id_align, server_id, 4); | 196 | move_from_unaligned32(requested_aligned, requested); |
197 | if (server_id) | ||
198 | move_from_unaligned32(server_id_aligned, server_id); | ||
195 | 199 | ||
196 | if (lease) { | 200 | if (lease) { |
197 | if (server_id) { | 201 | if (server_id) { |
198 | /* SELECTING State */ | 202 | /* SELECTING State */ |
199 | DEBUG("server_id = %08x", ntohl(server_id_align)); | 203 | DEBUG("server_id = %08x", ntohl(server_id_aligned)); |
200 | if (server_id_align == server_config.server && requested | 204 | if (server_id_aligned == server_config.server |
201 | && requested_align == lease->yiaddr | 205 | && requested |
206 | && requested_aligned == lease->yiaddr | ||
202 | ) { | 207 | ) { |
203 | send_ACK(&packet, lease->yiaddr); | 208 | send_ACK(&packet, lease->yiaddr); |
204 | } | 209 | } |
205 | } else if (requested) { | 210 | } else if (requested) { |
206 | /* INIT-REBOOT State */ | 211 | /* INIT-REBOOT State */ |
207 | if (lease->yiaddr == requested_align) | 212 | if (lease->yiaddr == requested_aligned) |
208 | send_ACK(&packet, lease->yiaddr); | 213 | send_ACK(&packet, lease->yiaddr); |
209 | else | 214 | else |
210 | send_NAK(&packet); | 215 | send_NAK(&packet); |
@@ -221,7 +226,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
221 | 226 | ||
222 | } else if (requested) { | 227 | } else if (requested) { |
223 | /* INIT-REBOOT State */ | 228 | /* INIT-REBOOT State */ |
224 | lease = find_lease_by_yiaddr(requested_align); | 229 | lease = find_lease_by_yiaddr(requested_aligned); |
225 | if (lease) { | 230 | if (lease) { |
226 | if (lease_expired(lease)) { | 231 | if (lease_expired(lease)) { |
227 | /* probably best if we drop this lease */ | 232 | /* probably best if we drop this lease */ |
@@ -230,7 +235,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
230 | } else | 235 | } else |
231 | send_NAK(&packet); | 236 | send_NAK(&packet); |
232 | } else { | 237 | } else { |
233 | uint32_t r = ntohl(requested_align); | 238 | uint32_t r = ntohl(requested_aligned); |
234 | if (r < server_config.start_ip | 239 | if (r < server_config.start_ip |
235 | || r > server_config.end_ip | 240 | || r > server_config.end_ip |
236 | ) { | 241 | ) { |
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c index 2c27e7033..581a7b671 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) | |||
224 | option[OPT_LEN] = len; | 224 | option[OPT_LEN] = len; |
225 | if (BB_BIG_ENDIAN) | 225 | if (BB_BIG_ENDIAN) |
226 | data <<= 8 * (4 - len); | 226 | data <<= 8 * (4 - len); |
227 | /* This memcpy is for processors which can't | 227 | /* Assignment is unaligned! */ |
228 | * handle a simple unaligned 32-bit assignment */ | 228 | move_to_unaligned32(&option[OPT_DATA], data); |
229 | memcpy(&option[OPT_DATA], &data, 4); | ||
230 | return add_option_string(optionptr, option); | 229 | return add_option_string(optionptr, option); |
231 | } | 230 | } |
232 | } | 231 | } |
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index 8dff9b700..4ae17fb8d 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, | |||
90 | dest += sprintf(dest, "%u", *option); | 90 | dest += sprintf(dest, "%u", *option); |
91 | break; | 91 | break; |
92 | case OPTION_U16: | 92 | case OPTION_U16: |
93 | memcpy(&val_u16, option, 2); | 93 | move_from_unaligned16(val_u16, option); |
94 | dest += sprintf(dest, "%u", ntohs(val_u16)); | 94 | dest += sprintf(dest, "%u", ntohs(val_u16)); |
95 | break; | 95 | break; |
96 | case OPTION_S16: | 96 | case OPTION_S16: |
97 | memcpy(&val_s16, option, 2); | 97 | move_from_unaligned16(val_s16, option); |
98 | dest += sprintf(dest, "%d", ntohs(val_s16)); | 98 | dest += sprintf(dest, "%d", ntohs(val_s16)); |
99 | break; | 99 | break; |
100 | case OPTION_U32: | 100 | case OPTION_U32: |
101 | memcpy(&val_u32, option, 4); | 101 | move_from_unaligned32(val_u32, option); |
102 | dest += sprintf(dest, "%lu", (unsigned long) ntohl(val_u32)); | 102 | dest += sprintf(dest, "%lu", (unsigned long) ntohl(val_u32)); |
103 | break; | 103 | break; |
104 | case OPTION_S32: | 104 | case OPTION_S32: |
105 | memcpy(&val_s32, option, 4); | 105 | move_from_unaligned32(val_s32, option); |
106 | dest += sprintf(dest, "%ld", (long) ntohl(val_s32)); | 106 | dest += sprintf(dest, "%ld", (long) ntohl(val_s32)); |
107 | break; | 107 | break; |
108 | case OPTION_STRING: | 108 | case OPTION_STRING: |
@@ -183,7 +183,7 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
183 | /* Fill in a subnet bits option for things like /24 */ | 183 | /* Fill in a subnet bits option for things like /24 */ |
184 | if (dhcp_options[i].code == DHCP_SUBNET) { | 184 | if (dhcp_options[i].code == DHCP_SUBNET) { |
185 | uint32_t subnet; | 185 | uint32_t subnet; |
186 | memcpy(&subnet, temp, 4); | 186 | move_from_unaligned32(subnet, temp); |
187 | envp[j++] = xasprintf("mask=%d", mton(subnet)); | 187 | envp[j++] = xasprintf("mask=%d", mton(subnet)); |
188 | } | 188 | } |
189 | next: | 189 | next: |
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index dcc234c7d..fca685dd1 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c | |||
@@ -103,7 +103,8 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket) | |||
103 | { | 103 | { |
104 | struct dhcpMessage packet; | 104 | struct dhcpMessage packet; |
105 | struct dhcpOfferedAddr *lease = NULL; | 105 | struct dhcpOfferedAddr *lease = NULL; |
106 | uint32_t req_align, lease_time_align = server_config.lease; | 106 | uint32_t req_align; |
107 | uint32_t lease_time_aligned = server_config.lease; | ||
107 | uint8_t *req, *lease_time; | 108 | uint8_t *req, *lease_time; |
108 | struct option_set *curr; | 109 | struct option_set *curr; |
109 | struct in_addr addr; | 110 | struct in_addr addr; |
@@ -120,7 +121,7 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket) | |||
120 | lease = find_lease_by_chaddr(oldpacket->chaddr); | 121 | lease = find_lease_by_chaddr(oldpacket->chaddr); |
121 | if (lease) { | 122 | if (lease) { |
122 | if (!lease_expired(lease)) | 123 | if (!lease_expired(lease)) |
123 | lease_time_align = lease->expires - time(0); | 124 | lease_time_aligned = lease->expires - time(0); |
124 | packet.yiaddr = lease->yiaddr; | 125 | packet.yiaddr = lease->yiaddr; |
125 | /* Or the client has a requested ip */ | 126 | /* Or the client has a requested ip */ |
126 | } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) | 127 | } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) |
@@ -155,22 +156,22 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket) | |||
155 | } | 156 | } |
156 | lease_time = get_option(oldpacket, DHCP_LEASE_TIME); | 157 | lease_time = get_option(oldpacket, DHCP_LEASE_TIME); |
157 | if (lease_time) { | 158 | if (lease_time) { |
158 | memcpy(&lease_time_align, lease_time, 4); | 159 | move_from_unaligned32(lease_time_aligned, lease_time); |
159 | lease_time_align = ntohl(lease_time_align); | 160 | lease_time_aligned = ntohl(lease_time_aligned); |
160 | if (lease_time_align > server_config.lease) | 161 | if (lease_time_aligned > server_config.lease) |
161 | lease_time_align = server_config.lease; | 162 | lease_time_aligned = server_config.lease; |
162 | } | 163 | } |
163 | 164 | ||
164 | /* Make sure we aren't just using the lease time from the previous offer */ | 165 | /* Make sure we aren't just using the lease time from the previous offer */ |
165 | if (lease_time_align < server_config.min_lease) | 166 | if (lease_time_aligned < server_config.min_lease) |
166 | lease_time_align = server_config.lease; | 167 | lease_time_aligned = server_config.lease; |
167 | /* ADDME: end of short circuit */ | 168 | /* ADDME: end of short circuit */ |
168 | } else { | 169 | } else { |
169 | /* It is a static lease... use it */ | 170 | /* It is a static lease... use it */ |
170 | packet.yiaddr = static_lease_ip; | 171 | packet.yiaddr = static_lease_ip; |
171 | } | 172 | } |
172 | 173 | ||
173 | add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align)); | 174 | add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_aligned)); |
174 | 175 | ||
175 | curr = server_config.options; | 176 | curr = server_config.options; |
176 | while (curr) { | 177 | while (curr) { |
@@ -203,7 +204,7 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) | |||
203 | struct dhcpMessage packet; | 204 | struct dhcpMessage packet; |
204 | struct option_set *curr; | 205 | struct option_set *curr; |
205 | uint8_t *lease_time; | 206 | uint8_t *lease_time; |
206 | uint32_t lease_time_align = server_config.lease; | 207 | uint32_t lease_time_aligned = server_config.lease; |
207 | struct in_addr addr; | 208 | struct in_addr addr; |
208 | 209 | ||
209 | init_packet(&packet, oldpacket, DHCPACK); | 210 | init_packet(&packet, oldpacket, DHCPACK); |
@@ -211,15 +212,15 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) | |||
211 | 212 | ||
212 | lease_time = get_option(oldpacket, DHCP_LEASE_TIME); | 213 | lease_time = get_option(oldpacket, DHCP_LEASE_TIME); |
213 | if (lease_time) { | 214 | if (lease_time) { |
214 | memcpy(&lease_time_align, lease_time, 4); | 215 | move_from_unaligned32(lease_time_aligned, lease_time); |
215 | lease_time_align = ntohl(lease_time_align); | 216 | lease_time_aligned = ntohl(lease_time_aligned); |
216 | if (lease_time_align > server_config.lease) | 217 | if (lease_time_aligned > server_config.lease) |
217 | lease_time_align = server_config.lease; | 218 | lease_time_aligned = server_config.lease; |
218 | else if (lease_time_align < server_config.min_lease) | 219 | else if (lease_time_aligned < server_config.min_lease) |
219 | lease_time_align = server_config.lease; | 220 | lease_time_aligned = server_config.lease; |
220 | } | 221 | } |
221 | 222 | ||
222 | add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align)); | 223 | add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_aligned)); |
223 | 224 | ||
224 | curr = server_config.options; | 225 | curr = server_config.options; |
225 | while (curr) { | 226 | while (curr) { |
@@ -236,7 +237,7 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) | |||
236 | if (send_packet(&packet, 0) < 0) | 237 | if (send_packet(&packet, 0) < 0) |
237 | return -1; | 238 | return -1; |
238 | 239 | ||
239 | add_lease(packet.chaddr, packet.yiaddr, lease_time_align); | 240 | add_lease(packet.chaddr, packet.yiaddr, lease_time_aligned); |
240 | if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) { | 241 | if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) { |
241 | /* rewrite the file with leases at every new acceptance */ | 242 | /* rewrite the file with leases at every new acceptance */ |
242 | write_leases(); | 243 | write_leases(); |