/[baselayout]/branches/baselayout-1_12/net-scripts/net.modules.d/udhcpc.sh
Gentoo

Contents of /branches/baselayout-1_12/net-scripts/net.modules.d/udhcpc.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1963 - (show annotations) (download) (as text)
Fri Apr 7 23:14:23 2006 UTC (8 years ago) by uberlord
File MIME type: text/x-sh
File size: 3904 byte(s)
udhcpc now uses udhcpc's own script
1 # Copyright (c) 2004-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # Contributed by Roy Marples (uberlord@gentoo.org)
4
5 # Fix any potential localisation problems
6 # Note that LC_ALL trumps LC_anything_else according to locale(7)
7 udhcpc() {
8 LC_ALL=C /sbin/udhcpc "$@"
9 }
10
11 # void udhcpc_depend(void)
12 #
13 # Sets up the dependancies for the module
14 udhcpc_depend() {
15 after interface
16 provide dhcp
17 functions interface_exists interface_get_address
18 }
19
20 # void udhcpc_expose(void)
21 #
22 # Expose variables that can be configured
23 udhcpc_expose() {
24 variables udhcpc dhcp
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 # bool udhcpc_stop(char *iface)
37 #
38 # Stops udhcpc running on an interface
39 # Return 1 if we fail to stop udhcpc (if it's running) otherwise 0
40 udhcpc_stop() {
41 local iface="$1" pidfile="/var/run/udhcpc-$1.pid" d
42
43 [[ ! -f ${pidfile} ]] && return 0
44
45 ebegin "Stopping udhcpc on ${iface}"
46 local pid="$(<"${pidfile}")" e=true
47
48 local ifvar="$(bash_variable "${iface}")"
49 d="dhcp_${ifvar}"
50 [[ -z ${!d} ]] && d="dhcp"
51
52 if [[ " ${!d} " == *" release "* ]]; then
53 kill -s USR2 "${pid}" &>/dev/null
54 [[ -f "/var/cache/udhcpc-${iface}.lease" ]] \
55 && rm "/var/cache/udhcpc-${iface}.lease"
56 fi
57
58 start-stop-daemon --stop --exec /sbin/udhcpc --pidfile "${pidfile}"
59 eend $? || return 1
60
61 [[ -e /var/run/udhcpc-"${iface}".conf ]] \
62 && rm -f /var/run/udhcpc-"${iface}".conf
63 return 0
64 }
65
66 # bool udhcpc_start(char *iface)
67 #
68 # Start DHCP on an interface by calling udhcpc $iface $options
69 #
70 # Returns 0 (true) when a DHCP address is obtained, otherwise 1
71 udhcpc_start() {
72 local iface="$1" opts pidfile="/var/run/udhcpc-$1.pid"
73 local cachefile="/var/cache/udhcpc-$1.lease" d
74
75 interface_exists "${iface}" true || return 1
76
77 local ifvar="$(bash_variable "${iface}" )" opts
78 opts="udhcpc_${ifvar}"
79 opts="${!opts}"
80
81 d="dhcp_${ifvar}"
82 [[ -z ${!d} ]] && d="dhcp"
83
84 if [[ " ${!d} " != *" nosendhost "* ]]; then
85 if [[ ! " ${opts}" =~ " -([hH] |-hostname=)" ]]; then
86 local hname="$(hostname)"
87 [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \
88 && opts="${opts} --hostname=${hname}"
89 fi
90 fi
91
92 # Setup options for the udhcpc script
93 # We pass these via a seperate config file so we're nice and fast
94 # maybe oneday, udhcp will accept custom env vars.
95 local conf="/var/run/udhcpc-${iface}.conf"
96 echo "# udhcpc runtime configuration for interface ${iface}" > "${conf}"
97 if [[ " ${!d} " == *" nodns "* ]] ; then
98 #opts="${opts} --env PEER_DNS=no"
99 echo "PEER_DNS=no" >> "${conf}"
100 else
101 #opts="${opts} --env PEER_DNS=yes"
102 echo "PEER_DNS=yes" >> "${conf}"
103 fi
104 if [[ " ${!d} " == *" nontp "* ]] ; then
105 #opts="${opts} --env PEER_NTP=no"
106 echo "PEER_NTP=no" >> "${conf}"
107 else
108 #opts="${opts} --env PEER_NTP=yes"
109 echo "PEER_NTP=yes" >> "${conf}"
110 fi
111 local metric="metric_${ifvar}"
112 if [[ -n ${!metric} ]] ; then
113 #opts="${opts} --env IF_METRIC=${!metric}"
114 echo "IF_METRIC=${!metric}" >> "${conf}"
115 fi
116
117 # Bring up DHCP for this interface (or alias)
118 ebegin "Running udhcpc"
119
120 # Try and load the cache if it exists
121 if [[ -f ${cachefile} ]]; then
122 if [[ " ${opts}" != *" --request="* && " ${opts} " != *" -r "* ]]; then
123 local x="$(<"${cachefile}")"
124 # Check for a valid ip
125 [[ ${x} == *.*.*.* ]] && opts="${opts} --request=${x}"
126 fi
127 fi
128
129 eval start-stop-daemon --start --exec /sbin/udhcpc \
130 --pidfile "${pidfile}" \
131 -- "${opts}" --interface="${iface}" --now \
132 --script=/lib/rcscripts/sh/udhcpc.sh \
133 --pidfile="${pidfile}" >/dev/null
134 eend $? || return 1
135
136 # DHCP succeeded, show address retrieved
137 local addr="$(interface_get_address "${iface}")"
138 einfo "${iface} received address ${addr}"
139
140 return 0
141 }
142
143 # vim: set ts=4 :

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20