diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-20 11:29:00 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-20 11:29:00 +0100 |
commit | b3b6c8bdf23d30c57d92458f1aac93ce84bf81a7 (patch) | |
tree | 09f864fc85a6743e218d7cb61496d4dfeb946050 /networking/route.c | |
parent | 53f30b41ec252d9973719b349a644477e72e1a09 (diff) | |
download | busybox-w32-b3b6c8bdf23d30c57d92458f1aac93ce84bf81a7.tar.gz busybox-w32-b3b6c8bdf23d30c57d92458f1aac93ce84bf81a7.tar.bz2 busybox-w32-b3b6c8bdf23d30c57d92458f1aac93ce84bf81a7.zip |
eliminate aliasing warning in networking/route.c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/route.c')
-rw-r--r-- | networking/route.c | 71 |
1 files changed, 37 insertions, 34 deletions
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 | ||
154 | static NOINLINE void INET_setroute(int action, char **args) | 154 | static 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 | } |