aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-01-21 21:59:26 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-01-21 21:59:26 +0100
commite8f565c1eeba336fa13ce8216464c9daedd36f76 (patch)
tree85a8bba11af1083fc0eacd310e91df05185892ec
parentb40da22357563bf53fa93823342f8ab59899222d (diff)
parentdd169e84683aa7be3604d491f1c34ab657973365 (diff)
downloadbusybox-w32-e8f565c1eeba336fa13ce8216464c9daedd36f76.tar.gz
busybox-w32-e8f565c1eeba336fa13ce8216464c9daedd36f76.tar.bz2
busybox-w32-e8f565c1eeba336fa13ce8216464c9daedd36f76.zip
Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
-rw-r--r--networking/ifplugd.c26
-rw-r--r--networking/route.c71
-rw-r--r--networking/traceroute.c3
-rw-r--r--networking/udhcp/socket.c25
4 files changed, 69 insertions, 56 deletions
diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 58f56dbf1..8dd0a5bd8 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -131,18 +131,21 @@ static int network_ioctl(int request, void* data, const char *errmsg)
131 131
132static smallint detect_link_mii(void) 132static smallint detect_link_mii(void)
133{ 133{
134 struct ifreq ifreq; 134 /* char buffer instead of bona-fide struct avoids aliasing warning */
135 struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data; 135 char buf[sizeof(struct ifreq)];
136 struct ifreq *const ifreq = (void *)buf;
136 137
137 set_ifreq_to_ifname(&ifreq); 138 struct mii_ioctl_data *mii = (void *)&ifreq->ifr_data;
139
140 set_ifreq_to_ifname(ifreq);
138 141
139 if (network_ioctl(SIOCGMIIPHY, &ifreq, "SIOCGMIIPHY") < 0) { 142 if (network_ioctl(SIOCGMIIPHY, ifreq, "SIOCGMIIPHY") < 0) {
140 return IFSTATUS_ERR; 143 return IFSTATUS_ERR;
141 } 144 }
142 145
143 mii->reg_num = 1; 146 mii->reg_num = 1;
144 147
145 if (network_ioctl(SIOCGMIIREG, &ifreq, "SIOCGMIIREG") < 0) { 148 if (network_ioctl(SIOCGMIIREG, ifreq, "SIOCGMIIREG") < 0) {
146 return IFSTATUS_ERR; 149 return IFSTATUS_ERR;
147 } 150 }
148 151
@@ -151,18 +154,21 @@ static smallint detect_link_mii(void)
151 154
152static smallint detect_link_priv(void) 155static smallint detect_link_priv(void)
153{ 156{
154 struct ifreq ifreq; 157 /* char buffer instead of bona-fide struct avoids aliasing warning */
155 struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data; 158 char buf[sizeof(struct ifreq)];
159 struct ifreq *const ifreq = (void *)buf;
156 160
157 set_ifreq_to_ifname(&ifreq); 161 struct mii_ioctl_data *mii = (void *)&ifreq->ifr_data;
162
163 set_ifreq_to_ifname(ifreq);
158 164
159 if (network_ioctl(SIOCDEVPRIVATE, &ifreq, "SIOCDEVPRIVATE") < 0) { 165 if (network_ioctl(SIOCDEVPRIVATE, ifreq, "SIOCDEVPRIVATE") < 0) {
160 return IFSTATUS_ERR; 166 return IFSTATUS_ERR;
161 } 167 }
162 168
163 mii->reg_num = 1; 169 mii->reg_num = 1;
164 170
165 if (network_ioctl(SIOCDEVPRIVATE+1, &ifreq, "SIOCDEVPRIVATE+1") < 0) { 171 if (network_ioctl(SIOCDEVPRIVATE+1, ifreq, "SIOCDEVPRIVATE+1") < 0) {
166 return IFSTATUS_ERR; 172 return IFSTATUS_ERR;
167 } 173 }
168 174
diff --git a/networking/route.c b/networking/route.c
index 98567aaee..b7d08dd63 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -153,7 +153,10 @@ static int kw_lookup(const char *kwtbl, char ***pargs)
153 153
154static NOINLINE void INET_setroute(int action, char **args) 154static NOINLINE void INET_setroute(int action, char **args)
155{ 155{
156 struct rtentry rt; 156 /* char buffer instead of bona-fide struct avoids aliasing warning */
157 char rt_buf[sizeof(struct rtentry)];
158 struct rtentry *const rt = (void *)rt_buf;
159
157 const char *netmask = NULL; 160 const char *netmask = NULL;
158 int skfd, isnet, xflag; 161 int skfd, isnet, xflag;
159 162
@@ -166,7 +169,7 @@ static NOINLINE void INET_setroute(int action, char **args)
166 } 169 }
167 170
168 /* Clean out the RTREQ structure. */ 171 /* Clean out the RTREQ structure. */
169 memset(&rt, 0, sizeof(rt)); 172 memset(rt, 0, sizeof(*rt));
170 173
171 { 174 {
172 const char *target = *args++; 175 const char *target = *args++;
@@ -178,17 +181,17 @@ static NOINLINE void INET_setroute(int action, char **args)
178 int prefix_len; 181 int prefix_len;
179 182
180 prefix_len = xatoul_range(prefix+1, 0, 32); 183 prefix_len = xatoul_range(prefix+1, 0, 32);
181 mask_in_addr(rt) = htonl( ~(0xffffffffUL >> prefix_len)); 184 mask_in_addr(*rt) = htonl( ~(0xffffffffUL >> prefix_len));
182 *prefix = '\0'; 185 *prefix = '\0';
183#if HAVE_NEW_ADDRT 186#if HAVE_NEW_ADDRT
184 rt.rt_genmask.sa_family = AF_INET; 187 rt->rt_genmask.sa_family = AF_INET;
185#endif 188#endif
186 } else { 189 } else {
187 /* Default netmask. */ 190 /* Default netmask. */
188 netmask = "default"; 191 netmask = "default";
189 } 192 }
190 /* Prefer hostname lookup is -host flag (xflag==1) was given. */ 193 /* Prefer hostname lookup is -host flag (xflag==1) was given. */
191 isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst, 194 isnet = INET_resolve(target, (struct sockaddr_in *) &rt->rt_dst,
192 (xflag & HOST_FLAG)); 195 (xflag & HOST_FLAG));
193 if (isnet < 0) { 196 if (isnet < 0) {
194 bb_error_msg_and_die("resolving %s", target); 197 bb_error_msg_and_die("resolving %s", target);
@@ -204,20 +207,20 @@ static NOINLINE void INET_setroute(int action, char **args)
204 } 207 }
205 208
206 /* Fill in the other fields. */ 209 /* Fill in the other fields. */
207 rt.rt_flags = ((isnet) ? RTF_UP : (RTF_UP | RTF_HOST)); 210 rt->rt_flags = ((isnet) ? RTF_UP : (RTF_UP | RTF_HOST));
208 211
209 while (*args) { 212 while (*args) {
210 int k = kw_lookup(tbl_ipvx, &args); 213 int k = kw_lookup(tbl_ipvx, &args);
211 const char *args_m1 = args[-1]; 214 const char *args_m1 = args[-1];
212 215
213 if (k & KW_IPVx_FLAG_ONLY) { 216 if (k & KW_IPVx_FLAG_ONLY) {
214 rt.rt_flags |= flags_ipvx[k & 3]; 217 rt->rt_flags |= flags_ipvx[k & 3];
215 continue; 218 continue;
216 } 219 }
217 220
218#if HAVE_NEW_ADDRT 221#if HAVE_NEW_ADDRT
219 if (k == KW_IPVx_METRIC) { 222 if (k == KW_IPVx_METRIC) {
220 rt.rt_metric = xatoul(args_m1) + 1; 223 rt->rt_metric = xatoul(args_m1) + 1;
221 continue; 224 continue;
222 } 225 }
223#endif 226#endif
@@ -225,7 +228,7 @@ static NOINLINE void INET_setroute(int action, char **args)
225 if (k == KW_IPVx_NETMASK) { 228 if (k == KW_IPVx_NETMASK) {
226 struct sockaddr mask; 229 struct sockaddr mask;
227 230
228 if (mask_in_addr(rt)) { 231 if (mask_in_addr(*rt)) {
229 bb_show_usage(); 232 bb_show_usage();
230 } 233 }
231 234
@@ -234,18 +237,18 @@ static NOINLINE void INET_setroute(int action, char **args)
234 if (isnet < 0) { 237 if (isnet < 0) {
235 bb_error_msg_and_die("resolving %s", netmask); 238 bb_error_msg_and_die("resolving %s", netmask);
236 } 239 }
237 rt.rt_genmask = full_mask(mask); 240 rt->rt_genmask = full_mask(mask);
238 continue; 241 continue;
239 } 242 }
240 243
241 if (k == KW_IPVx_GATEWAY) { 244 if (k == KW_IPVx_GATEWAY) {
242 if (rt.rt_flags & RTF_GATEWAY) { 245 if (rt->rt_flags & RTF_GATEWAY) {
243 bb_show_usage(); 246 bb_show_usage();
244 } 247 }
245 248
246 isnet = INET_resolve(args_m1, 249 isnet = INET_resolve(args_m1,
247 (struct sockaddr_in *) &rt.rt_gateway, 1); 250 (struct sockaddr_in *) &rt->rt_gateway, 1);
248 rt.rt_flags |= RTF_GATEWAY; 251 rt->rt_flags |= RTF_GATEWAY;
249 252
250 if (isnet) { 253 if (isnet) {
251 if (isnet < 0) { 254 if (isnet < 0) {
@@ -257,24 +260,24 @@ static NOINLINE void INET_setroute(int action, char **args)
257 } 260 }
258 261
259 if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */ 262 if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */
260 rt.rt_flags |= RTF_MSS; 263 rt->rt_flags |= RTF_MSS;
261 rt.rt_mss = xatoul_range(args_m1, 64, 32768); 264 rt->rt_mss = xatoul_range(args_m1, 64, 32768);
262 continue; 265 continue;
263 } 266 }
264 267
265 if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */ 268 if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */
266 rt.rt_flags |= RTF_WINDOW; 269 rt->rt_flags |= RTF_WINDOW;
267 rt.rt_window = xatoul_range(args_m1, 128, INT_MAX); 270 rt->rt_window = xatoul_range(args_m1, 128, INT_MAX);
268 continue; 271 continue;
269 } 272 }
270 273
271#ifdef RTF_IRTT 274#ifdef RTF_IRTT
272 if (k == KW_IPVx_IRTT) { 275 if (k == KW_IPVx_IRTT) {
273 rt.rt_flags |= RTF_IRTT; 276 rt->rt_flags |= RTF_IRTT;
274 rt.rt_irtt = xatoul(args_m1); 277 rt->rt_irtt = xatoul(args_m1);
275 rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ 278 rt->rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */
276#if 0 /* FIXME: do we need to check anything of this? */ 279#if 0 /* FIXME: do we need to check anything of this? */
277 if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { 280 if (rt->rt_irtt < 1 || rt->rt_irtt > (120 * HZ)) {
278 bb_error_msg_and_die("bad irtt"); 281 bb_error_msg_and_die("bad irtt");
279 } 282 }
280#endif 283#endif
@@ -284,9 +287,9 @@ static NOINLINE void INET_setroute(int action, char **args)
284 287
285 /* Device is special in that it can be the last arg specified 288 /* Device is special in that it can be the last arg specified
286 * and doesn't requre the dev/device keyword in that case. */ 289 * and doesn't requre the dev/device keyword in that case. */
287 if (!rt.rt_dev && ((k == KW_IPVx_DEVICE) || (!k && !*++args))) { 290 if (!rt->rt_dev && ((k == KW_IPVx_DEVICE) || (!k && !*++args))) {
288 /* Don't use args_m1 here since args may have changed! */ 291 /* Don't use args_m1 here since args may have changed! */
289 rt.rt_dev = args[-1]; 292 rt->rt_dev = args[-1];
290 continue; 293 continue;
291 } 294 }
292 295
@@ -295,41 +298,41 @@ static NOINLINE void INET_setroute(int action, char **args)
295 } 298 }
296 299
297#ifdef RTF_REJECT 300#ifdef RTF_REJECT
298 if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev) { 301 if ((rt->rt_flags & RTF_REJECT) && !rt->rt_dev) {
299 rt.rt_dev = (char*)"lo"; 302 rt->rt_dev = (char*)"lo";
300 } 303 }
301#endif 304#endif
302 305
303 /* sanity checks.. */ 306 /* sanity checks.. */
304 if (mask_in_addr(rt)) { 307 if (mask_in_addr(*rt)) {
305 uint32_t mask = mask_in_addr(rt); 308 uint32_t mask = mask_in_addr(*rt);
306 309
307 mask = ~ntohl(mask); 310 mask = ~ntohl(mask);
308 if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) { 311 if ((rt->rt_flags & RTF_HOST) && mask != 0xffffffff) {
309 bb_error_msg_and_die("netmask %.8x and host route conflict", 312 bb_error_msg_and_die("netmask %.8x and host route conflict",
310 (unsigned int) mask); 313 (unsigned int) mask);
311 } 314 }
312 if (mask & (mask + 1)) { 315 if (mask & (mask + 1)) {
313 bb_error_msg_and_die("bogus netmask %s", netmask); 316 bb_error_msg_and_die("bogus netmask %s", netmask);
314 } 317 }
315 mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr; 318 mask = ((struct sockaddr_in *) &rt->rt_dst)->sin_addr.s_addr;
316 if (mask & ~(uint32_t)mask_in_addr(rt)) { 319 if (mask & ~(uint32_t)mask_in_addr(*rt)) {
317 bb_error_msg_and_die("netmask and route address conflict"); 320 bb_error_msg_and_die("netmask and route address conflict");
318 } 321 }
319 } 322 }
320 323
321 /* Fill out netmask if still unset */ 324 /* Fill out netmask if still unset */
322 if ((action == RTACTION_ADD) && (rt.rt_flags & RTF_HOST)) { 325 if ((action == RTACTION_ADD) && (rt->rt_flags & RTF_HOST)) {
323 mask_in_addr(rt) = 0xffffffff; 326 mask_in_addr(*rt) = 0xffffffff;
324 } 327 }
325 328
326 /* Create a socket to the INET kernel. */ 329 /* Create a socket to the INET kernel. */
327 skfd = xsocket(AF_INET, SOCK_DGRAM, 0); 330 skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
328 331
329 if (action == RTACTION_ADD) 332 if (action == RTACTION_ADD)
330 xioctl(skfd, SIOCADDRT, &rt); 333 xioctl(skfd, SIOCADDRT, rt);
331 else 334 else
332 xioctl(skfd, SIOCDELRT, &rt); 335 xioctl(skfd, SIOCDELRT, rt);
333 336
334 if (ENABLE_FEATURE_CLEAN_UP) close(skfd); 337 if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
335} 338}
diff --git a/networking/traceroute.c b/networking/traceroute.c
index c18fba8d0..82bb0118c 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -751,7 +751,8 @@ print(int read_len, const struct sockaddr *from, const struct sockaddr *to)
751 } else 751 } else
752#endif 752#endif
753 { 753 {
754 read_len -= ((struct ip*)recv_pkt)->ip_hl << 2; 754 struct ip *ip4packet = (struct ip*)recv_pkt;
755 read_len -= ip4packet->ip_hl << 2;
755 } 756 }
756 printf(" %d bytes to %s", read_len, ina); 757 printf(" %d bytes to %s", read_len, ina);
757 free(ina); 758 free(ina);
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index 0ed7ad1c6..39f1cec54 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -36,42 +36,45 @@
36 36
37int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) 37int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac)
38{ 38{
39 /* char buffer instead of bona-fide struct avoids aliasing warning */
40 char ifr_buf[sizeof(struct ifreq)];
41 struct ifreq *const ifr = (void *)ifr_buf;
42
39 int fd; 43 int fd;
40 struct ifreq ifr;
41 struct sockaddr_in *our_ip; 44 struct sockaddr_in *our_ip;
42 45
43 memset(&ifr, 0, sizeof(ifr)); 46 memset(ifr, 0, sizeof(*ifr));
44 fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); 47 fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
45 48
46 ifr.ifr_addr.sa_family = AF_INET; 49 ifr->ifr_addr.sa_family = AF_INET;
47 strncpy_IFNAMSIZ(ifr.ifr_name, interface); 50 strncpy_IFNAMSIZ(ifr->ifr_name, interface);
48 if (nip) { 51 if (nip) {
49 if (ioctl_or_perror(fd, SIOCGIFADDR, &ifr, 52 if (ioctl_or_perror(fd, SIOCGIFADDR, ifr,
50 "is interface %s up and configured?", interface) 53 "is interface %s up and configured?", interface)
51 ) { 54 ) {
52 close(fd); 55 close(fd);
53 return -1; 56 return -1;
54 } 57 }
55 our_ip = (struct sockaddr_in *) &ifr.ifr_addr; 58 our_ip = (struct sockaddr_in *) &ifr->ifr_addr;
56 *nip = our_ip->sin_addr.s_addr; 59 *nip = our_ip->sin_addr.s_addr;
57 log1("IP %s", inet_ntoa(our_ip->sin_addr)); 60 log1("IP %s", inet_ntoa(our_ip->sin_addr));
58 } 61 }
59 62
60 if (ifindex) { 63 if (ifindex) {
61 if (ioctl_or_warn(fd, SIOCGIFINDEX, &ifr) != 0) { 64 if (ioctl_or_warn(fd, SIOCGIFINDEX, ifr) != 0) {
62 close(fd); 65 close(fd);
63 return -1; 66 return -1;
64 } 67 }
65 log1("Adapter index %d", ifr.ifr_ifindex); 68 log1("Adapter index %d", ifr->ifr_ifindex);
66 *ifindex = ifr.ifr_ifindex; 69 *ifindex = ifr->ifr_ifindex;
67 } 70 }
68 71
69 if (mac) { 72 if (mac) {
70 if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) { 73 if (ioctl_or_warn(fd, SIOCGIFHWADDR, ifr) != 0) {
71 close(fd); 74 close(fd);
72 return -1; 75 return -1;
73 } 76 }
74 memcpy(mac, ifr.ifr_hwaddr.sa_data, 6); 77 memcpy(mac, ifr->ifr_hwaddr.sa_data, 6);
75 log1("MAC %02x:%02x:%02x:%02x:%02x:%02x", 78 log1("MAC %02x:%02x:%02x:%02x:%02x:%02x",
76 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 79 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
77 } 80 }