/[baselayout]/branches/rc-scripts-1_6/net-scripts/net.modules.d/udhcpc
Gentoo

Contents of /branches/rc-scripts-1_6/net-scripts/net.modules.d/udhcpc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (show annotations) (download)
Mon Dec 6 15:46:18 2004 UTC (13 years, 8 months ago) by agriffis
File size: 4077 byte(s)
Merge updates from HEAD

1 # udhcpc (net-misc/udhcp) module for net-scripts
2 # Version 1.0.6
3 # Copyright (c) 2004 Gentoo Foundation
4 # Distributed under the terms of the GNU General Public License V2
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 udhcpc() {
10 LC_ALL=C /sbin/udhcpc "$@"
11 }
12
13 # char* udhcpc_provides(void)
14 #
15 # Returns a string to change module definition for starting up
16 udhcpc_provides() {
17 echo "dhcp"
18 }
19
20 # void udhcpc_depend(void)
21 #
22 # Sets up the dependancies for the module
23 udhcpc_depend() {
24 after interface
25 }
26
27 # bool udhcpc_check_installed(void)
28 #
29 # Returns 1 if udhcpc is installed, otherwise 0
30 udhcpc_check_installed() {
31 [[ -x /sbin/udhcpc ]] && return 0
32 ${1:-false} && eerror "For DHCP (udhcpc) support, emerge net-misc/udhcp"
33 return 1
34 }
35
36 # char* udhcpc_get_script(void)
37 #
38 # Returns the filename of the script to run
39 udhcpc_get_script() {
40 local module=$( interface_module )
41 echo "${MODULES_DIR}/helpers.d/udhcpc-${module}"
42 }
43
44 # bool udhcpc_check_depends(void)
45 #
46 # Checks to see if we have the needed functions
47 udhcpc_check_depends() {
48 local f
49
50 for f in interface_variable interface_device interface_is_up interface_get_address interface_module; do
51 [[ $( type -t ${f} ) == function ]] && continue
52 eerror "udhcpc: missing required function ${f}\n"
53 return 1
54 done
55
56 return 0
57 }
58
59 # char* udhcpc_get_vars(char *interface)
60 #
61 # Returns a string spaced with possible user set
62 # configuration variables
63 udhcpc_get_vars() {
64 echo "udhcpc_${1} dhcp_${1}"
65 }
66
67 # bool udhcpc_stop(char *iface)
68 #
69 # Stops udhcpc running on an interface
70 # Always returns 0
71 udhcpc_stop() {
72 local iface=${1} count release pidfile="/var/run/udhcpc-${1}.pid" dhcp
73
74 udhcpc_check_installed || return 0
75 [[ ! -f ${pidfile} ]] && return 0
76
77 ebegin "Stopping udhcpc on ${iface}"
78 local pid=$( cat ${pidfile} ) e=true
79
80 # Release the lease if told to
81 eval dhcp=\" \$\{dhcp_${ifvar}\} \"
82 if [[ ${dhcp} == *' release '* ]]; then
83 kill -s USR2 ${pid} &>/dev/null
84 rm /var/cache/udhcpc-${iface}.cache
85 fi
86
87 kill -s TERM ${pid} &>/dev/null
88
89 # udhcp-0.9.8-r3 and earlier do not process signals correctly
90 # so we need to kill them off
91 if ps -p ${pid} &>/dev/null ; then
92 kill -s KILL ${pid} &>/dev/null
93 ps -p ${pid} &>/dev/null && e=false
94 fi
95
96 ${e}
97 eend $?
98
99 return 0
100 }
101
102 # bool udhcpc_start(char *iface)
103 #
104 # Start DHCP on an interface by calling udhcpc $iface $options
105 #
106 # Returns 0 (true) when a DHCP address is obtained, otherwise 1
107 udhcpc_start() {
108 local iface=${1} opts hostname pidfile="/var/run/udhcpc-${1}.pid"
109 local cachefile="/var/cache/udhcpc-${1}.cache" x
110
111 interface_exists ${iface} true || return 1
112
113 # Check that iface was not brought up by the kernel ...
114 local check=$( interface_device ${iface} )
115 if [[ ${check} == ${iface} ]] && interface_is_up ${iface} true ; then
116 einfo "Keeping kernel configuration for ${iface}"
117 return 0
118 fi
119
120 local ifvar=$( interface_variable ${iface} )
121 local script=$( udhcpc_get_script ) opts hostname=$( hostname )
122 eval opts=\"\$\{udhcpc_${ifvar}\}\"
123
124 if [[ ${opts} != *'--hostname=' ]]; then
125 hostname=$( hostname )
126 [[ -n ${hostname} && ${hostname} != "(none)" ]] && hostname="--hostname=${hostname}"
127 fi
128
129 # Bring up DHCP for this interface (or alias)
130 ebegin "Running udhcpc"
131
132 if ! clean_pidfile ${pidfile} ; then
133 ewarn "udhcpc is already running on ${iface}"
134 eend 0
135 return 0
136 fi
137
138 # Try and load the cache if it exists
139 if [[ -f ${cachefile} && ${opts} != *'--request='* && ${opts} != *'-r '* ]]; then
140 x=$( cat ${cachefile} )
141 [[ -n ${x} ]] && opts="${opts} --request=${x}"
142 fi
143
144 x=$( udhcpc ${hostname} ${opts} --script=${script} --now --pidfile=${pidfile} --interface=${iface} )
145 # We just check the last 5 letters
146 [[ ${x:((${#x} - 5)):5} == bound ]]
147 eend $? || return 1
148
149 # DHCP succeeded, show address retrieved
150 local addr=$( interface_get_address ${iface} )
151 einfo "${iface} received address ${addr}"
152
153 # Store the address in a cache for future usage
154 echo ${addr} > ${cachefile}
155 chmod 600 ${cachefile}
156
157 return 0
158 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20