| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# This file is part of the FreeWRT project. FreeWRT is copyrighted |
| 4 |
# material, please see the LICENCE file in the top-level directory |
| 5 |
# or at http://www.freewrt.org/licence for details. |
| 6 |
# |
| 7 |
# Christian Fischer <spaetzle@freewrt.org> |
| 8 |
# |
| 9 |
|
| 10 |
dhcp_up() { |
| 11 |
local err |
| 12 |
|
| 13 |
if ! err=$(ip link set up dev $IFACE 2>&1 1>&-); then |
| 14 |
mprint -s "dhcp_up: $err" |
| 15 |
return 1 |
| 16 |
fi |
| 17 |
|
| 18 |
mkdir -p /var/run/dhcpc |
| 19 |
|
| 20 |
if [[ -n $IF_DHCPCLIENT ]]; then |
| 21 |
if [[ -x $(whence -p $IF_DHCPCLIENT) ]]; then |
| 22 |
$IF_DHCPCLIENT $IF_DHCPCLIENT_OPTS 2>&- 1>&- & |
| 23 |
if [[ -n $! ]]; then |
| 24 |
echo $! >/var/run/dhcpc/${IF_DHCPCLIENT}.${IFACE}.pid |
| 25 |
return 0 |
| 26 |
else |
| 27 |
mprint -s "dhcp_up: dhcp client failed to start" |
| 28 |
return 1 |
| 29 |
fi |
| 30 |
fi |
| 31 |
mprint -s "dhcp_up: $IF_DHCPCLIENT not found, using built-in udhcpcd" |
| 32 |
fi |
| 33 |
|
| 34 |
err=$(udhcpc -b -t 1 -p /var/run/dhcpc/udhcpc.${IFACE}.pid -i $IFACE \ |
| 35 |
${IF_HOSTNAME:+"-H $IF_HOSTNAME"} ${IF_CLIENTID:+"-c $IF_CLIENTID"} \ |
| 36 |
${IF_SCRIPT:+"-s $IF_SCRIPT"} 2>&1 1>&-) && return |
| 37 |
|
| 38 |
mprint -s "dhcp_up: $err" |
| 39 |
return 1 |
| 40 |
} |
| 41 |
|
| 42 |
dhcp_down() { |
| 43 |
local err pid |
| 44 |
|
| 45 |
for pidfile in /var/run/dhcpc/*; do |
| 46 |
echo $pidfile | grep -q .${IFACE}. || continue |
| 47 |
pid=$(<$pidfile) |
| 48 |
[[ -n $pid && -d /proc/$pid ]] || continue |
| 49 |
err=$(kill -TERM $pid 2>&1 1>&-) || mprint -s "dhcp_down: $err" |
| 50 |
rm -f $pidfile |
| 51 |
done |
| 52 |
|
| 53 |
is_up || return 0 |
| 54 |
err=$(ip addr flush dev $IFACE 2>&1 1>&-) || mprint -s "dhcp_down: $err" |
| 55 |
err=$(ip link set down dev $IFACE 2>&1 1>&-) || mprint -s "dhcp_down: $err" |
| 56 |
} |
| 57 |
|
| 58 |
# vim:ts=4 |