/[baselayout]/trunk/net-scripts/net.modules.d/dhclient
Gentoo

Contents of /trunk/net-scripts/net.modules.d/dhclient

Parent Directory Parent Directory | Revision Log Revision Log


Revision 872 - (show annotations) (download)
Thu Jan 27 12:37:06 2005 UTC (14 years, 3 months ago) by uberlord
File size: 3459 byte(s)
removed udhcpc-* and dhclient-* helper modules and replaced them with a
generic dhcp module which caters for all interfaces and dhcp clients that
need it.
We now prefer iproute2 over ifconfig if both are installed.

1 # Copyright (c) 2004-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header$
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # Fix any potential localisation problems
8 # Note that LC_ALL trumps LC_anything_else according to locale(7)
9 dhclient() {
10 LC_ALL=C /sbin/dhclient "$@"
11 }
12
13 # char* dhclient_provides(void)
14 #
15 # Returns a string to change module definition for starting up
16 dhclient_provides() {
17 echo "dhcp"
18 }
19
20 # void dhclient_depend(void)
21 #
22 # Sets up the dependancies for the module
23 dhclient_depend() {
24 after interface
25 }
26
27 # bool dhclient_check_installed(void)
28 #
29 # Returns 1 if dhclient is installed, otherwise 0
30 dhclient_check_installed() {
31 [[ -x /sbin/dhclient ]] && return 0
32 ${1:-false} && eerror "For DHCP (dhclient) support, emerge net-misc/dhcp"
33 return 1
34 }
35
36 # bool dhclient_check_depends(void)
37 #
38 # Checks to see if we have the needed functions
39 dhclient_check_depends() {
40 local f
41
42 for f in interface_exists interface_get_address; do
43 [[ $( type -t ${f} ) == "function" ]] && continue
44 eerror "dhclient: missing required function ${f}\n"
45 return 1
46 done
47
48 return 0
49 }
50
51 # char* dhclient_get_vars(char *interface)
52 #
53 # Returns a string spaced with possible user set
54 # configuration variables
55 dhclient_get_vars() {
56 echo "dhclient_${1} dhcp_${1}"
57 }
58
59 # bool dhclient_stop(char *iface)
60 #
61 # Stop dhclient on an interface
62 # Always returns 0
63 dhclient_stop() {
64 local iface=${1} dhcp release ifvar=${1//[![:word:]]/_}
65 local pidfile="/var/run/dhclient-${1}.pid"
66
67 dhclient_check_installed || return 0
68 [[ ! -f ${pidfile} ]] && return 0
69
70 # We check for a dhclient process first as if we attempt to release
71 # an interface for which dhclient has obtained an IP in the past
72 # it causes a "RELEASE" event anyway.
73 local pid=$( cat ${pidfile} )
74
75 eval dhcp=\" \$\{dhcp_${ifvar}\} \"
76
77 ebegin "Stopping dhclient on ${iface}"
78 if [[ ${dhcp} == *' release '* ]]; then
79 local r=$( dhclient -q -r -sf ${MODULES_DIR}/helpers.d/dhclient-wrapper -pf ${pidfile} ${iface} )
80 [[ ${r} == "deconfig" ]]
81 eend $? "dhclient returned a ${r}"
82 [[ -f /var/cache/dhcp-${iface}.lease ]] \
83 && rm -f /var/cache/dhcp-${iface}.lease
84 else
85 kill -s TERM ${pid} 2>/dev/null
86 clean_pidfile ${pidfile}
87 eend 0
88 fi
89
90 return 0
91 }
92
93 # bool dhclient_start(char *iface)
94 #
95 # Start DHCP on an interface by calling dhclient $iface $options
96 #
97 # Returns 0 (true) when a DHCP address is obtained, otherwise 1
98 dhclient_start() {
99 local iface=$1 opts ifvar=${1//[![:word:]]/_}
100 local pidfile="/var/run/dhclient-$1.pid"
101
102 interface_exists ${iface} true || return 1
103
104 # Bring up DHCP for this interface (or alias)
105 ebegin "Running dhclient"
106
107 if ! clean_pidfile ${pidfile} ; then
108 ewarn "dhclient is already running on ${iface}"
109 eend 0
110 return 0
111 fi
112
113 eval opts=\"\$\{dhclient_${ifvar}\}\"
114
115 if [[ ${background} == "yes" ]]; then
116 dhclient ${opts} -sf ${MODULES_DIR}/helpers.d/dhclient-wrapper -pf ${pidfile} -q ${iface} &>/dev/null &
117 eend 0
118 go_background
119 fi
120
121 local x=$( dhclient ${opts} -1 -sf ${MODULES_DIR}/helpers.d/dhclient-wrapper -pf ${pidfile} -q ${iface} )
122 # We just check the last 5 letters
123 [[ ${x:${#x} - 5:5} == "bound" ]]
124 if [[ $? != 0 ]]; then
125 # We need to kill the process if we fail
126 kill -s TERM $( cat ${pidfile} ) 2>/dev/null
127 eend 1
128 return 1
129 fi
130 eend 0
131
132 # DHCP succeeded, show address retrieved
133 local addr=$( interface_get_address ${iface} )
134 einfo "${iface} received address ${addr}"
135
136 return 0
137 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20