diff options
-rwxr-xr-x | net-physical | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/net-physical b/net-physical index ecac45f..6b5ac20 100755 --- a/net-physical +++ b/net-physical @@ -1,16 +1,25 @@ #!/bin/sh -links=`dladm show-phys -o link 2>/dev/null| grep -v LINK` +links=`dladm show-phys -p -o link` for link in $links; do - if ipadm "create-if" $link 2>/dev/null; then # create-if is in quotes because ViM goes crazy + if ipadm "create-if" $link; then # create-if is in quotes because ViM goes crazy + timeout=30 + state=`dladm show-phys -p -o state $link` + if [ "$state" != up ]; then + # http://slackware.com/~alien/rc_scripts/rc.inet1 + timeout=7 + fi echo "Trying DHCP for $link ... " >/dev/msglog - if ipadm create-addr -T dhcp -w 7 $link/dhcp 2>/dev/null; then - echo "Configured $link via DHCP" >/dev/msglog - exit 0 - else - echo "DHCP for $link FAILED " >/dev/msglog + if ipadm create-addr -T dhcp -w $timeout $link/dhcp; then + addrstate=`ipadm show-addr -p -o state $link/dhcp` + if [ "$addrstate" = ok ]; then + echo "Configured $link via DHCP" >/dev/msglog + exit 0 + else + ipadm delete-addr $link/dhcp + fi fi fi done |