diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-01-13 21:40:38 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-01-13 21:40:38 +0000 |
commit | d66370cd7329d7d1022644c0a8213147adf8e016 (patch) | |
tree | f1a7c4ebd489ebeb90f63ed87ef671ec22e061eb /networking/ifupdown.c | |
parent | 4e486a5d00830990cdfda68eb5dceefab43635f5 (diff) | |
download | busybox-w32-d66370cd7329d7d1022644c0a8213147adf8e016.tar.gz busybox-w32-d66370cd7329d7d1022644c0a8213147adf8e016.tar.bz2 busybox-w32-d66370cd7329d7d1022644c0a8213147adf8e016.zip |
Option to allow ifupdown use ip commands instead of ifconfig, add flush
command to ipaddr, patch by Bastian Blank
Diffstat (limited to 'networking/ifupdown.c')
-rw-r--r-- | networking/ifupdown.c | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 37185327b..665e527cc 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -307,22 +307,40 @@ address_family_t addr_ipx = { | |||
307 | #ifdef CONFIG_FEATURE_IFUPDOWN_IPV6 | 307 | #ifdef CONFIG_FEATURE_IFUPDOWN_IPV6 |
308 | static int loopback_up6(interface_defn_t *ifd, execfn *exec) | 308 | static int loopback_up6(interface_defn_t *ifd, execfn *exec) |
309 | { | 309 | { |
310 | if (!execute("ifconfig %iface% add ::1", ifd, exec)) { | 310 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP |
311 | if (!execute("ip link set %iface% up", ifd, exec)) | ||
311 | return(0); | 312 | return(0); |
312 | } | 313 | if (!execute("ip addr add ::1 dev %iface%", ifd, exec)) |
314 | return(0); | ||
315 | #else | ||
316 | if (!execute("ifconfig %iface% add ::1", ifd, exec)) | ||
317 | return(0); | ||
318 | #endif | ||
313 | return(1); | 319 | return(1); |
314 | } | 320 | } |
315 | 321 | ||
316 | static int loopback_down6(interface_defn_t *ifd, execfn *exec) | 322 | static int loopback_down6(interface_defn_t *ifd, execfn *exec) |
317 | { | 323 | { |
318 | if (!execute("ifconfig %iface% del ::1", ifd, exec)) { | 324 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP |
325 | if (!execute("ip link set %iface% down", ifd, exec)) | ||
319 | return(0); | 326 | return(0); |
320 | } | 327 | #else |
328 | if (!execute("ifconfig %iface% del ::1", ifd, exec)) | ||
329 | return(0); | ||
330 | #endif | ||
321 | return(1); | 331 | return(1); |
322 | } | 332 | } |
323 | 333 | ||
324 | static int static_up6(interface_defn_t *ifd, execfn *exec) | 334 | static int static_up6(interface_defn_t *ifd, execfn *exec) |
325 | { | 335 | { |
336 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP | ||
337 | if (!execute("ip link set %iface% up", ifd, exec)) | ||
338 | return(0); | ||
339 | if (!execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec)) | ||
340 | return(0); | ||
341 | if (!execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec)) | ||
342 | return(0); | ||
343 | #else | ||
326 | if (!execute("ifconfig %iface% [[media %media%]] [[hw %hwaddress%]] [[mtu %mtu%]] up", ifd, exec)) { | 344 | if (!execute("ifconfig %iface% [[media %media%]] [[hw %hwaddress%]] [[mtu %mtu%]] up", ifd, exec)) { |
327 | return(0); | 345 | return(0); |
328 | } | 346 | } |
@@ -332,17 +350,24 @@ static int static_up6(interface_defn_t *ifd, execfn *exec) | |||
332 | if (!execute("[[ route -A inet6 add ::/0 gw %gateway% ]]", ifd, exec)) { | 350 | if (!execute("[[ route -A inet6 add ::/0 gw %gateway% ]]", ifd, exec)) { |
333 | return(0); | 351 | return(0); |
334 | } | 352 | } |
353 | #endif | ||
335 | return(1); | 354 | return(1); |
336 | } | 355 | } |
337 | 356 | ||
338 | static int static_down6(interface_defn_t *ifd, execfn *exec) | 357 | static int static_down6(interface_defn_t *ifd, execfn *exec) |
339 | { | 358 | { |
359 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP | ||
360 | if (!execute("ip link set %iface% down", ifd, exec)) | ||
361 | return(0); | ||
362 | #else | ||
340 | if (!execute("ifconfig %iface% down", ifd, exec)) { | 363 | if (!execute("ifconfig %iface% down", ifd, exec)) { |
341 | return(0); | 364 | return(0); |
342 | } | 365 | } |
366 | #endif | ||
343 | return(1); | 367 | return(1); |
344 | } | 368 | } |
345 | 369 | ||
370 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP | ||
346 | static int v4tunnel_up(interface_defn_t *ifd, execfn *exec) | 371 | static int v4tunnel_up(interface_defn_t *ifd, execfn *exec) |
347 | { | 372 | { |
348 | if (!execute("ip tunnel add %iface% mode sit remote %endpoint% [[local %local%]] [[ttl %ttl%]]", ifd, exec)) { | 373 | if (!execute("ip tunnel add %iface% mode sit remote %endpoint% [[local %local%]] [[ttl %ttl%]]", ifd, exec)) { |
@@ -367,9 +392,12 @@ static int v4tunnel_down(interface_defn_t * ifd, execfn * exec) | |||
367 | } | 392 | } |
368 | return(1); | 393 | return(1); |
369 | } | 394 | } |
395 | #endif | ||
370 | 396 | ||
371 | static method_t methods6[] = { | 397 | static method_t methods6[] = { |
398 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP | ||
372 | { "v4tunnel", v4tunnel_up, v4tunnel_down, }, | 399 | { "v4tunnel", v4tunnel_up, v4tunnel_down, }, |
400 | #endif | ||
373 | { "static", static_up6, static_down6, }, | 401 | { "static", static_up6, static_down6, }, |
374 | { "loopback", loopback_up6, loopback_down6, }, | 402 | { "loopback", loopback_up6, loopback_down6, }, |
375 | }; | 403 | }; |
@@ -384,22 +412,44 @@ address_family_t addr_inet6 = { | |||
384 | #ifdef CONFIG_FEATURE_IFUPDOWN_IPV4 | 412 | #ifdef CONFIG_FEATURE_IFUPDOWN_IPV4 |
385 | static int loopback_up(interface_defn_t *ifd, execfn *exec) | 413 | static int loopback_up(interface_defn_t *ifd, execfn *exec) |
386 | { | 414 | { |
415 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP | ||
416 | if (!execute("ip link set %iface% up", ifd, exec)) | ||
417 | return(0); | ||
418 | if (!execute("ip addr add 127.0.0.1 dev %iface%", ifd, exec)) | ||
419 | return(0); | ||
420 | #else | ||
387 | if (!execute("ifconfig %iface% 127.0.0.1 up", ifd, exec)) { | 421 | if (!execute("ifconfig %iface% 127.0.0.1 up", ifd, exec)) { |
388 | return(0); | 422 | return(0); |
389 | } | 423 | } |
424 | #endif | ||
390 | return(1); | 425 | return(1); |
391 | } | 426 | } |
392 | 427 | ||
393 | static int loopback_down(interface_defn_t *ifd, execfn *exec) | 428 | static int loopback_down(interface_defn_t *ifd, execfn *exec) |
394 | { | 429 | { |
430 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP | ||
431 | if (!execute("ip -f inet addr flush dev %iface%", ifd, exec)) | ||
432 | return(0); | ||
433 | if (!execute("ip link set %iface% down", ifd, exec)) | ||
434 | return(0); | ||
435 | #else | ||
395 | if (!execute("ifconfig %iface% 127.0.0.1 down", ifd, exec)) { | 436 | if (!execute("ifconfig %iface% 127.0.0.1 down", ifd, exec)) { |
396 | return(0); | 437 | return(0); |
397 | } | 438 | } |
439 | #endif | ||
398 | return(1); | 440 | return(1); |
399 | } | 441 | } |
400 | 442 | ||
401 | static int static_up(interface_defn_t *ifd, execfn *exec) | 443 | static int static_up(interface_defn_t *ifd, execfn *exec) |
402 | { | 444 | { |
445 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP | ||
446 | if (!execute("ip link set %iface% up", ifd, exec)) | ||
447 | return(0); | ||
448 | if (!execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec)) | ||
449 | return(0); | ||
450 | if (!execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec)) | ||
451 | return(0); | ||
452 | #else | ||
403 | if (!execute("ifconfig %iface% %address% netmask %netmask% [[broadcast %broadcast%]] [[pointopoint %pointopoint%]] [[media %media%]] [[mtu %mtu%]] [[hw %hwaddress%]] up", | 453 | if (!execute("ifconfig %iface% %address% netmask %netmask% [[broadcast %broadcast%]] [[pointopoint %pointopoint%]] [[media %media%]] [[mtu %mtu%]] [[hw %hwaddress%]] up", |
404 | ifd, exec)) { | 454 | ifd, exec)) { |
405 | return(0); | 455 | return(0); |
@@ -407,17 +457,27 @@ static int static_up(interface_defn_t *ifd, execfn *exec) | |||
407 | if (!execute("[[ route add default gw %gateway% %iface% ]]", ifd, exec)) { | 457 | if (!execute("[[ route add default gw %gateway% %iface% ]]", ifd, exec)) { |
408 | return(0); | 458 | return(0); |
409 | } | 459 | } |
460 | #endif | ||
410 | return(1); | 461 | return(1); |
411 | } | 462 | } |
412 | 463 | ||
413 | static int static_down(interface_defn_t *ifd, execfn *exec) | 464 | static int static_down(interface_defn_t *ifd, execfn *exec) |
414 | { | 465 | { |
466 | #ifdef CONFIG_FEATURE_IFUPDOWN_IP | ||
467 | if (!execute("[[ ip route del default via %gateway% dev %iface% ]]", ifd, exec)) | ||
468 | return(0); | ||
469 | if (!execute("ip -f inet addr flush dev %iface%", ifd, exec)) | ||
470 | return(0); | ||
471 | if (!execute("ip link set %iface% down", ifd, exec)) | ||
472 | return(0); | ||
473 | #else | ||
415 | if (!execute("[[ route del default gw %gateway% %iface% ]]", ifd, exec)) { | 474 | if (!execute("[[ route del default gw %gateway% %iface% ]]", ifd, exec)) { |
416 | return(0); | 475 | return(0); |
417 | } | 476 | } |
418 | if (!execute("ifconfig %iface% down", ifd, exec)) { | 477 | if (!execute("ifconfig %iface% down", ifd, exec)) { |
419 | return(0); | 478 | return(0); |
420 | } | 479 | } |
480 | #endif | ||
421 | return(1); | 481 | return(1); |
422 | } | 482 | } |
423 | 483 | ||
@@ -936,7 +996,6 @@ static int doit(char *str) | |||
936 | case 0: /* child */ | 996 | case 0: /* child */ |
937 | execle("/bin/sh", "/bin/sh", "-c", str, NULL, environ); | 997 | execle("/bin/sh", "/bin/sh", "-c", str, NULL, environ); |
938 | exit(127); | 998 | exit(127); |
939 | default: /* parent */ | ||
940 | } | 999 | } |
941 | waitpid(child, &status, 0); | 1000 | waitpid(child, &status, 0); |
942 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { | 1001 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |