Add another special return code, 3, which means 'subsystem is not
[dragonfly.git] / etc / rc.d / dhclient
1 #!/bin/sh
2 #
3 # $NetBSD: dhclient,v 1.8 2002/03/22 04:33:58 thorpej Exp $
4 # $FreeBSD: src/etc/rc.d/dhclient,v 1.6 2003/06/29 05:34:41 mtm Exp $
5 # $DragonFly: src/etc/rc.d/dhclient,v 1.3 2003/12/12 19:49:04 dillon Exp $
6 #
7
8 # PROVIDE: dhclient
9 # REQUIRE: network netif mountcritlocal
10 # BEFORE:  NETWORKING
11 # KEYWORD: DragonFly FreeBSD NetBSD
12 #
13 #       Note that there no syslog logging of dhclient messages at boot because
14 #       dhclient needs to start before services that syslog depends upon do.
15 #
16
17 . /etc/rc.subr
18 . /etc/network.subr
19
20 name="dhclient"
21 pidfile="/var/run/${name}.pid"
22 case "${OSTYPE}" in
23 DragonFly)
24         rcvar=
25         start_precmd="dhclient_prestart"
26         start_postcmd="dhclient_poststart"
27         stop_cmd="dhclient_stop"
28         stop_precmd="dhclient_prestop"
29         stop_postcmd="dhclient_poststop"
30         ;;
31
32 FreeBSD)
33         rcvar=
34         start_precmd="dhclient_prestart"
35         start_postcmd="dhclient_poststart"
36         stop_cmd="dhclient_stop"
37         stop_precmd="dhclient_prestop"
38         stop_postcmd="dhclient_poststop"
39         ;;
40 NetBSD)
41         rcvar=$name
42         command="/sbin/${name}"
43         ;;
44 esac
45
46 dhclient_common()
47 {
48         dhcp_list="`list_net_interfaces dhcp`"
49         if [ -z "$dhcp_list" ]; then
50                 return 3
51         fi
52
53         # Determine the scope of the command
54         #
55         _cooked_list="$dhcp_list"
56         if [ -n "$_cmdifn" ]; then
57                 eval _cooked_list=\"`expr "$dhcp_list" : ".*\($_cmdifn\).*"`\"
58                 if [ -z "$_cooked_list" ]; then
59                         err "No such network interface: $_cmdifn"
60                         return 1
61                 fi
62         fi
63 }
64
65 dhclient_prestart()
66 {
67         dhclient_common || return $?
68
69         for ifn in ${_cooked_list}; do
70                 ifscript_up ${ifn}
71         done
72
73         rc_flags="${rc_flags} ${_cooked_list}"
74         return 0
75 }
76
77 dhclient_poststart()
78 {
79         for ifn in ${_cooked_list}; do
80                 ifalias_up ${ifn}
81                 ipx_up ${ifn}
82                 ifconfig ${ifn}
83         done
84 }
85
86 dhclient_stop()
87 {
88         echo -n "Releasing DHCP leases:"
89         for ifn in $_cooked_list ; do
90                 ${command} -r $ifn
91                 if [ $? -eq 0 ]; then
92                         echo -n " $ifn"
93                 else
94                         _fail="$_fail $ifn"
95                 fi
96         done
97         echo '.'
98         debug "The following leases failed to release: $_fail"
99 }
100
101 dhclient_prestop()
102 {
103         dhclient_common || return $?
104
105         for ifn in ${_cooked_list}; do
106                 ipx_down ${ifn}
107                 ifalias_down ${ifn}
108         done
109 }
110
111 dhclient_poststop()
112 {
113         for ifn in ${_cooked_list}; do
114                 ifscript_down ${ifn}
115         done
116 }
117
118 if [ -n "$2" ]; then
119         _cmdifn="$2"
120 fi
121
122 load_rc_config $name
123
124 run_rc_command "$1"