aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-08 22:56:18 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-08 22:56:18 +0000
commitefb545b9bdd3934dcdbf9bc0890a42081b330049 (patch)
tree4dc9212e49a5dae9890bd324bcc9bf4941e2321d
parentd1a84a2880073f6cc5e2f9f4e5f236cd110f01a0 (diff)
downloadbusybox-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
-rw-r--r--archival/libunarchive/decompress_unzip.c5
-rw-r--r--include/platform.h12
-rw-r--r--networking/arping.c23
-rw-r--r--networking/dnsd.c2
-rw-r--r--networking/libiproute/libnetlink.c4
-rw-r--r--networking/libiproute/ll_addr.c38
-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
-rw-r--r--networking/zcip.c3
-rw-r--r--util-linux/volume_id/linux_raid.c2
13 files changed, 95 insertions, 75 deletions
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index e83cd4f45..86969251e 100644
--- a/archival/libunarchive/decompress_unzip.c
+++ b/archival/libunarchive/decompress_unzip.c
@@ -1083,8 +1083,7 @@ static uint16_t buffer_read_le_u16(STATE_PARAM_ONLY)
1083{ 1083{
1084 uint16_t res; 1084 uint16_t res;
1085#if BB_LITTLE_ENDIAN 1085#if BB_LITTLE_ENDIAN
1086 /* gcc 4.2.1 is very clever */ 1086 move_from_unaligned16(res, &bytebuffer[bytebuffer_offset]);
1087 memcpy(&res, &bytebuffer[bytebuffer_offset], 2);
1088#else 1087#else
1089 res = bytebuffer[bytebuffer_offset]; 1088 res = bytebuffer[bytebuffer_offset];
1090 res |= bytebuffer[bytebuffer_offset + 1] << 8; 1089 res |= bytebuffer[bytebuffer_offset + 1] << 8;
@@ -1097,7 +1096,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
1097{ 1096{
1098 uint32_t res; 1097 uint32_t res;
1099#if BB_LITTLE_ENDIAN 1098#if BB_LITTLE_ENDIAN
1100 memcpy(&res, &bytebuffer[bytebuffer_offset], 4); 1099 move_from_unaligned32(res, &bytebuffer[bytebuffer_offset]);
1101#else 1100#else
1102 res = bytebuffer[bytebuffer_offset]; 1101 res = bytebuffer[bytebuffer_offset];
1103 res |= bytebuffer[bytebuffer_offset + 1] << 8; 1102 res |= bytebuffer[bytebuffer_offset + 1] << 8;
diff --git a/include/platform.h b/include/platform.h
index b8c85dba0..5d6a18107 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -151,13 +151,19 @@
151 151
152/* ---- Unaligned access ------------------------------------ */ 152/* ---- Unaligned access ------------------------------------ */
153 153
154/* parameter is supposed to be an uint32_t* ptr */ 154/* NB: unaligned parameter should be a pointer, aligned one -
155 * a lvalue. This makes it more likely to not swap them by mistake
156 */
155#if defined(i386) || defined(__x86_64__) 157#if defined(i386) || defined(__x86_64__)
156#define get_unaligned_u32p(u32p) (*(u32p)) 158#define move_from_unaligned16(v, u16p) ((v) = *(uint16_t*)(u16p))
159#define move_from_unaligned32(v, u32p) ((v) = *(uint32_t*)(u32p))
160#define move_to_unaligned32(u32p, v) (*(uint32_t*)(u32p) = (v))
157/* #elif ... - add your favorite arch today! */ 161/* #elif ... - add your favorite arch today! */
158#else 162#else
159/* performs reasonably well (gcc usually inlines memcpy here) */ 163/* performs reasonably well (gcc usually inlines memcpy here) */
160#define get_unaligned_u32p(u32p) ({ uint32_t __t; memcpy(&__t, (u32p), 4); __t; }) 164#define move_from_unaligned16(v, u16p) (memcpy(&(v), (u16p), 2))
165#define move_from_unaligned32(v, u32p) (memcpy(&(v), (u32p), 4))
166#define move_to_unaligned32(u32p, v) (memcpy((u32p), &(v), 4))
161#endif 167#endif
162 168
163/* ---- Networking ------------------------------------------ */ 169/* ---- Networking ------------------------------------------ */
diff --git a/networking/arping.c b/networking/arping.c
index e4429973b..e7b842f5b 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -153,6 +153,15 @@ static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
153 struct arphdr *ah = (struct arphdr *) buf; 153 struct arphdr *ah = (struct arphdr *) buf;
154 unsigned char *p = (unsigned char *) (ah + 1); 154 unsigned char *p = (unsigned char *) (ah + 1);
155 struct in_addr src_ip, dst_ip; 155 struct in_addr src_ip, dst_ip;
156 /* moves below assume in_addr is 4 bytes big, ensure that */
157 struct BUG_in_addr_must_be_4 {
158 char BUG_in_addr_must_be_4[
159 sizeof(struct in_addr) == 4 ? 1 : -1
160 ];
161 char BUG_s_addr_must_be_4[
162 sizeof(src_ip.s_addr) == 4 ? 1 : -1
163 ];
164 };
156 165
157 /* Filter out wild packets */ 166 /* Filter out wild packets */
158 if (FROM->sll_pkttype != PACKET_HOST 167 if (FROM->sll_pkttype != PACKET_HOST
@@ -171,13 +180,13 @@ static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
171 180
172 /* Protocol must be IP. */ 181 /* Protocol must be IP. */
173 if (ah->ar_pro != htons(ETH_P_IP) 182 if (ah->ar_pro != htons(ETH_P_IP)
174 || (ah->ar_pln != 4) 183 || (ah->ar_pln != 4)
175 || (ah->ar_hln != me.sll_halen) 184 || (ah->ar_hln != me.sll_halen)
176 || (len < (int)(sizeof(*ah) + 2 * (4 + ah->ar_hln)))) 185 || (len < (int)(sizeof(*ah) + 2 * (4 + ah->ar_hln))))
177 return false; 186 return false;
178 187
179 memcpy(&src_ip, p + ah->ar_hln, 4); 188 move_from_unaligned32(src_ip.s_addr, p + ah->ar_hln);
180 memcpy(&dst_ip, p + ah->ar_hln + 4 + ah->ar_hln, 4); 189 move_from_unaligned32(dst_ip.s_addr, p + ah->ar_hln + 4 + ah->ar_hln);
181 190
182 if (dst.s_addr != src_ip.s_addr) 191 if (dst.s_addr != src_ip.s_addr)
183 return false; 192 return false;
@@ -200,7 +209,7 @@ static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
200 dst_ip/dst_hw do not matter. 209 dst_ip/dst_hw do not matter.
201 */ 210 */
202 if ((memcmp(p, &me.sll_addr, me.sll_halen) == 0) 211 if ((memcmp(p, &me.sll_addr, me.sll_halen) == 0)
203 || (src.s_addr && src.s_addr != dst_ip.s_addr)) 212 || (src.s_addr && src.s_addr != dst_ip.s_addr))
204 return false; 213 return false;
205 } 214 }
206 if (!(option_mask32 & QUIET)) { 215 if (!(option_mask32 & QUIET)) {
@@ -306,7 +315,7 @@ int arping_main(int argc UNUSED_PARAM, char **argv)
306 /* if (!inet_aton(target, &dst)) - not needed */ { 315 /* if (!inet_aton(target, &dst)) - not needed */ {
307 len_and_sockaddr *lsa; 316 len_and_sockaddr *lsa;
308 lsa = xhost_and_af2sockaddr(target, 0, AF_INET); 317 lsa = xhost_and_af2sockaddr(target, 0, AF_INET);
309 memcpy(&dst, &lsa->u.sin.sin_addr.s_addr, 4); 318 dst = lsa->u.sin.sin_addr;
310 if (ENABLE_FEATURE_CLEAN_UP) 319 if (ENABLE_FEATURE_CLEAN_UP)
311 free(lsa); 320 free(lsa);
312 } 321 }
diff --git a/networking/dnsd.c b/networking/dnsd.c
index e8dcb404b..434903fe1 100644
--- a/networking/dnsd.c
+++ b/networking/dnsd.c
@@ -253,7 +253,7 @@ static int process_packet(uint8_t *buf)
253 goto empty_packet; 253 goto empty_packet;
254 } 254 }
255 v32 = a.s_addr; /* in case long != int */ 255 v32 = a.s_addr; /* in case long != int */
256 memcpy(answstr, &v32, 4); 256 move_to_unaligned32(answstr, v32);
257 outr_rlen = 4; // uint32_t IP 257 outr_rlen = 4; // uint32_t IP
258 } else 258 } else
259 outr_rlen = strlen((char *)answstr) + 1; // a host name 259 outr_rlen = strlen((char *)answstr) + 1; // a host name
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c
index 01454fbf5..6d51d8deb 100644
--- a/networking/libiproute/libnetlink.c
+++ b/networking/libiproute/libnetlink.c
@@ -341,7 +341,7 @@ int FAST_FUNC addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
341 rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); 341 rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
342 rta->rta_type = type; 342 rta->rta_type = type;
343 rta->rta_len = len; 343 rta->rta_len = len;
344 memcpy(RTA_DATA(rta), &data, 4); 344 move_to_unaligned32(RTA_DATA(rta), data);
345 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; 345 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
346 return 0; 346 return 0;
347} 347}
@@ -372,7 +372,7 @@ int FAST_FUNC rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t d
372 subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len)); 372 subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
373 subrta->rta_type = type; 373 subrta->rta_type = type;
374 subrta->rta_len = len; 374 subrta->rta_len = len;
375 memcpy(RTA_DATA(subrta), &data, 4); 375 move_to_unaligned32(RTA_DATA(subrta), data);
376 rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len; 376 rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
377 return 0; 377 return 0;
378} 378}
diff --git a/networking/libiproute/ll_addr.c b/networking/libiproute/ll_addr.c
index e732efdb2..f50e37193 100644
--- a/networking/libiproute/ll_addr.c
+++ b/networking/libiproute/ll_addr.c
@@ -43,6 +43,8 @@ const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int
43 43
44int ll_addr_a2n(unsigned char *lladdr, int len, char *arg) 44int ll_addr_a2n(unsigned char *lladdr, int len, char *arg)
45{ 45{
46 int i;
47
46 if (strchr(arg, '.')) { 48 if (strchr(arg, '.')) {
47 inet_prefix pfx; 49 inet_prefix pfx;
48 if (get_addr_1(&pfx, arg, AF_INET)) { 50 if (get_addr_1(&pfx, arg, AF_INET)) {
@@ -54,26 +56,24 @@ int ll_addr_a2n(unsigned char *lladdr, int len, char *arg)
54 } 56 }
55 memcpy(lladdr, pfx.data, 4); 57 memcpy(lladdr, pfx.data, 4);
56 return 4; 58 return 4;
57 } else { 59 }
58 int i;
59 60
60 for (i=0; i<len; i++) { 61 for (i = 0; i < len; i++) {
61 int temp; 62 int temp;
62 char *cp = strchr(arg, ':'); 63 char *cp = strchr(arg, ':');
63 if (cp) { 64 if (cp) {
64 *cp = 0; 65 *cp = 0;
65 cp++; 66 cp++;
66 } 67 }
67 if (sscanf(arg, "%x", &temp) != 1 || (temp < 0 || temp > 255)) { 68 if (sscanf(arg, "%x", &temp) != 1 || (temp < 0 || temp > 255)) {
68 bb_error_msg("\"%s\" is invalid lladdr", arg); 69 bb_error_msg("\"%s\" is invalid lladdr", arg);
69 return -1; 70 return -1;
70 } 71 }
71 lladdr[i] = temp; 72 lladdr[i] = temp;
72 if (!cp) { 73 if (!cp) {
73 break; 74 break;
74 }
75 arg = cp;
76 } 75 }
77 return i+1; 76 arg = cp;
78 } 77 }
78 return i+1;
79} 79}
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();
diff --git a/networking/zcip.c b/networking/zcip.c
index 3a349a5af..df4c0ec2d 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -279,7 +279,8 @@ int zcip_main(int argc, char **argv)
279 // NOTE: the sequence of addresses we try changes only 279 // NOTE: the sequence of addresses we try changes only
280 // depending on when we detect conflicts. 280 // depending on when we detect conflicts.
281 { 281 {
282 uint32_t t = get_unaligned_u32p((uint32_t *) ((char *)&eth_addr + 2)); 282 uint32_t t;
283 move_from_unaligned32(t, ((char *)&eth_addr + 2));
283 srand(t); 284 srand(t);
284 } 285 }
285 if (ip.s_addr == 0) 286 if (ip.s_addr == 0)
diff --git a/util-linux/volume_id/linux_raid.c b/util-linux/volume_id/linux_raid.c
index a1130606f..0877b8ad2 100644
--- a/util-linux/volume_id/linux_raid.c
+++ b/util-linux/volume_id/linux_raid.c
@@ -62,7 +62,7 @@ int volume_id_probe_linux_raid(struct volume_id *id, uint64_t off, uint64_t size
62 if (mdp->md_magic != cpu_to_le32(MD_MAGIC)) 62 if (mdp->md_magic != cpu_to_le32(MD_MAGIC))
63 return -1; 63 return -1;
64 64
65 memcpy(uuid, &mdp->set_uuid0, 4); 65 *(uint32_t*)uuid = mdp->set_uuid0;
66 memcpy(&uuid[4], &mdp->set_uuid1, 12); 66 memcpy(&uuid[4], &mdp->set_uuid1, 12);
67 volume_id_set_uuid(id, uuid, UUID_DCE); 67 volume_id_set_uuid(id, uuid, UUID_DCE);
68 68