1 |
commit: b712a9161f3d51566f44d48909776649d70116d0 |
2 |
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com> |
3 |
AuthorDate: Tue Apr 26 16:05:19 2011 +0000 |
4 |
Commit: William Hubbs <williamh <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Apr 26 20:25:08 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=b712a916 |
7 |
|
8 |
change udhcpc support to busybox udhcpc |
9 |
|
10 |
This updates the udhcpc support to use busybox's udhcpc instead of the |
11 |
stand alone version. |
12 |
|
13 |
I would like to thank jackieku <kjackie <AT> gmail.com> for assisting with |
14 |
this update. |
15 |
|
16 |
X-Gentoo-Bug: 205286 |
17 |
X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=205286 |
18 |
|
19 |
--- |
20 |
doc/net.example.Linux.in | 2 +- |
21 |
net/udhcpc.sh | 37 ++++++++------ |
22 |
sh/.gitignore | 1 + |
23 |
sh/Makefile.Linux | 4 +- |
24 |
sh/udhcpc-hook.sh.in | 117 ++++++++++++++++++++++++++++++++++++++++++++++ |
25 |
5 files changed, 142 insertions(+), 19 deletions(-) |
26 |
|
27 |
diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in |
28 |
index 5d7c49f..952f8eb 100644 |
29 |
--- a/doc/net.example.Linux.in |
30 |
+++ b/doc/net.example.Linux.in |
31 |
@@ -414,7 +414,7 @@ |
32 |
# dhclient: emerge net-misc/dhcp |
33 |
# dhcpcd: emerge net-misc/dhcpcd |
34 |
# pump: emerge net-misc/pump |
35 |
-# udhcpc: emerge net-misc/udhcp |
36 |
+# udhcpc: emerge sys-apps/busybox |
37 |
|
38 |
# If you have more than one DHCP client installed, you need to specify which |
39 |
# one to use - otherwise we default to dhcpcd if available. |
40 |
|
41 |
diff --git a/net/udhcpc.sh b/net/udhcpc.sh |
42 |
index 75cbf09..bb4238a 100644 |
43 |
--- a/net/udhcpc.sh |
44 |
+++ b/net/udhcpc.sh |
45 |
@@ -3,14 +3,13 @@ |
46 |
|
47 |
udhcpc_depend() |
48 |
{ |
49 |
- program start /sbin/udhcpc |
50 |
+ program start /bin/busybox |
51 |
after interface |
52 |
provide dhcp |
53 |
} |
54 |
|
55 |
_config_vars="$_config_vars dhcp udhcpc" |
56 |
|
57 |
-# WARNING:- The relies heavily on Gentoo patches and scripts for udhcpc |
58 |
udhcpc_start() |
59 |
{ |
60 |
local args= opt= opts= pidfile="/var/run/udhcpc-${IFACE}.pid" |
61 |
@@ -22,17 +21,22 @@ udhcpc_start() |
62 |
eval opts=\$dhcp_${IFVAR} |
63 |
[ -z "${opts}" ] && opts=${dhcp} |
64 |
|
65 |
+ # This omits the Gentoo specific patch to busybox, |
66 |
+ # but it creates temporary files. |
67 |
+ # We can move this stuff to udhcpc hook script to avoid that, should we do? |
68 |
+ local conf="/var/run/udhcpc-${IFACE}.conf" |
69 |
+ echo -n >"$conf" |
70 |
# Map some generic options to dhcpcd |
71 |
for opt in ${opts}; do |
72 |
case "${opt}" in |
73 |
- nodns) args="${args} --env PEER_DNS=no";; |
74 |
- nontp) args="${args} --env PEER_NTP=no";; |
75 |
- nogateway) args="${args} --env PEER_ROUTERS=no";; |
76 |
+ nodns) echo "PEER_DNS=no" >>"$conf" ;; |
77 |
+ nontp) echo "PEER_NTP=no" >>"$conf" ;; |
78 |
+ nogateway) echo "PEER_ROUTERS=no" >>"$conf" ;; |
79 |
nosendhost) sendhost=false; |
80 |
esac |
81 |
done |
82 |
|
83 |
- [ "${metric:-0}" != "0" ] && args="${args} --env IF_METRIC=${metric}" |
84 |
+ [ "${metric:-0}" != "0" ] && echo "IF_METRIC=${metric}" >>"$conf" |
85 |
|
86 |
ebegin "Running udhcpc" |
87 |
|
88 |
@@ -51,9 +55,9 @@ udhcpc_start() |
89 |
fi |
90 |
|
91 |
case " ${args} " in |
92 |
- *" --quit "*|*" -q "*) x="/sbin/udhcpc";; |
93 |
- *) x="start-stop-daemon --start --exec /sbin/udhcpc \ |
94 |
- --pidfile \"${pidfile}\" --";; |
95 |
+ *" --quit "*|*" -q "*) x="/bin/busybox udhcpc";; |
96 |
+ *) x="start-stop-daemon --start --exec /bin/busybox \ |
97 |
+ --pidfile \"${pidfile}\" -- udhcpc";; |
98 |
esac |
99 |
|
100 |
case " ${args} " in |
101 |
@@ -68,11 +72,8 @@ udhcpc_start() |
102 |
;; |
103 |
esac |
104 |
|
105 |
- local script="${RC_LIBEXECDIR}"/sh/udhcpc.h |
106 |
- [ -x "${script}" ] || script=/lib/rcscripts/sh/udhcpc.sh |
107 |
- |
108 |
eval "${x}" "${args}" --interface="${IFACE}" --now \ |
109 |
- --script="${script}" \ |
110 |
+ --script="${RC_LIBEXECDIR}/sh/udhcpc-hook.sh" \ |
111 |
--pidfile="${pidfile}" >/dev/null |
112 |
eend $? || return 1 |
113 |
|
114 |
@@ -92,14 +93,18 @@ udhcpc_stop() |
115 |
ebegin "Stopping udhcpc on ${IFACE}" |
116 |
case " ${opts} " in |
117 |
*" release "*) |
118 |
- start-stop-daemon --stop --quiet --oknodo --signal USR2 \ |
119 |
- --exec /sbin/udhcpc --pidfile "${pidfile}" |
120 |
+ start-stop-daemon --stop --quiet --signal USR2 \ |
121 |
+ --exec /bin/busybox --pidfile "${pidfile}" |
122 |
if [ -f /var/cache/udhcpc-"${IFACE}".lease ]; then |
123 |
rm -f /var/cache/udhcpc-"${IFACE}".lease |
124 |
fi |
125 |
;; |
126 |
esac |
127 |
|
128 |
- start-stop-daemon --stop --exec /sbin/udhcpc --pidfile "${pidfile}" |
129 |
+ start-stop-daemon --stop --exec /bin/busybox --pidfile "${pidfile}" |
130 |
eend $? |
131 |
+ |
132 |
+ if [ -e "/var/run/udhcpc-${IFACE}.conf" ]; then |
133 |
+ rm -f "/var/run/udhcpc-${IFACE}.conf" |
134 |
+ fi |
135 |
} |
136 |
|
137 |
diff --git a/sh/.gitignore b/sh/.gitignore |
138 |
index f416d5b..bc5c074 100644 |
139 |
--- a/sh/.gitignore |
140 |
+++ b/sh/.gitignore |
141 |
@@ -7,3 +7,4 @@ init.sh |
142 |
init-early.sh |
143 |
ifwatchd-carrier.sh |
144 |
ifwatchd-nocarrier.sh |
145 |
+udhcpc-hook.sh |
146 |
|
147 |
diff --git a/sh/Makefile.Linux b/sh/Makefile.Linux |
148 |
index bb48f42..fb9208c 100644 |
149 |
--- a/sh/Makefile.Linux |
150 |
+++ b/sh/Makefile.Linux |
151 |
@@ -1,5 +1,5 @@ |
152 |
-SRCS+= init.sh.in init-early.sh.in |
153 |
-BIN+= init-early.sh |
154 |
+SRCS+= init.sh.in init-early.sh.in udhcpc-hook.sh.in |
155 |
+BIN+= init-early.sh udhcpc-hook.sh |
156 |
|
157 |
.SUFFIXES: .sh.Linux.in |
158 |
.sh.Linux.in.sh: |
159 |
|
160 |
diff --git a/sh/udhcpc-hook.sh.in b/sh/udhcpc-hook.sh.in |
161 |
new file mode 100644 |
162 |
index 0000000..a14cac9 |
163 |
--- /dev/null |
164 |
+++ b/sh/udhcpc-hook.sh.in |
165 |
@@ -0,0 +1,117 @@ |
166 |
+#!@SHELL@ |
167 |
+# busybox udhcp setup script |
168 |
+ |
169 |
+PATH=/bin:/usr/bin:/sbin:/usr/sbin |
170 |
+ |
171 |
+peer_var() |
172 |
+{ |
173 |
+ [ -n "$1" ] && [ "$1" != "yes" ] |
174 |
+} |
175 |
+ |
176 |
+update_dns() |
177 |
+{ |
178 |
+ peer_var "${PEER_DNS}" && return |
179 |
+ [ -z "${domain}" ] && [ -z "${dns}" ] && return |
180 |
+ |
181 |
+ conf="# Generated by udhcpc for ${interface}\n" |
182 |
+ [ -n "${domain}" ] && conf="${conf}search ${domain}\n" |
183 |
+ for i in ${dns} ; do |
184 |
+ conf="${conf}nameserver ${i}\n" |
185 |
+ done |
186 |
+ if [ -x /sbin/resolvconf ] ; then |
187 |
+ printf "${conf}" | resolvconf -a ${interface} |
188 |
+ else |
189 |
+ printf "${conf}" > /etc/resolv.conf |
190 |
+ chmod 644 /etc/resolv.conf |
191 |
+ fi |
192 |
+} |
193 |
+ |
194 |
+update_ntp() |
195 |
+{ |
196 |
+ peer_var "${PEER_NTP}" && return |
197 |
+ [ -z "${ntpsrv}" ] && return |
198 |
+ |
199 |
+ conf="# Generated by udhcpc for interface ${interface}\n" |
200 |
+ conf="${conf}restrict default noquery notrust nomodify\n" |
201 |
+ conf="${conf}restrict 127.0.0.1\n" |
202 |
+ for i in ${ntpsrv} ; do |
203 |
+ conf="${conf}restrict ${i} nomodify notrap noquery\n" |
204 |
+ conf="${conf}server ${i}\n" |
205 |
+ done |
206 |
+ conf="${conf}driftfile /var/lib/ntp/ntp.drift\n" |
207 |
+ conf="${conf}logfile /var/log/ntp.log\n" |
208 |
+ printf "${conf}" > /etc/ntp.conf |
209 |
+ chmod 644 /etc/ntp.conf |
210 |
+} |
211 |
+ |
212 |
+update_hostname() |
213 |
+{ |
214 |
+ peer_var "${PEER_HOSTNAME}" && return |
215 |
+ [ -z "${hostname}" ] && return |
216 |
+ |
217 |
+ myhost="$(hostname)" |
218 |
+ [ -z "${myhost}" ] || [ "${myhost}" = "(none)" ] && hostname "${hostname}" |
219 |
+} |
220 |
+ |
221 |
+update_interface() |
222 |
+{ |
223 |
+ [ -n "${broadcast}" ] && broadcast="broadcast ${broadcast}" |
224 |
+ [ -n "${subnet}" ] && netmask="netmask ${subnet}" |
225 |
+ [ -n "${mtu}" ] && mtu="mtu ${mtu}" |
226 |
+ ifconfig "${interface}" ${ip} ${broadcast} ${netmask} ${mtu} |
227 |
+} |
228 |
+ |
229 |
+update_routes() |
230 |
+{ |
231 |
+ peer_var "${PEER_ROUTERS}" && return |
232 |
+ |
233 |
+ if [ -n "${router}" ] ; then |
234 |
+ metric= |
235 |
+ [ -n "${IF_METRIC}" ] && metric="metric ${IF_METRIC}" |
236 |
+ for i in ${router} ; do |
237 |
+ route add default gw "${i}" ${metric} dev "${interface}" |
238 |
+ done |
239 |
+ fi |
240 |
+} |
241 |
+ |
242 |
+deconfig() |
243 |
+{ |
244 |
+ ifconfig "${interface}" 0.0.0.0 |
245 |
+ |
246 |
+ if ! peer_var "${PEER_ROUTERS}" ; then |
247 |
+ while route del default dev "${interface}" >& /dev/null; do |
248 |
+ : |
249 |
+ done |
250 |
+ fi |
251 |
+ |
252 |
+ if ! peer_var "${PEER_DNS}" ; then |
253 |
+ [ -x /sbin/resolvconf ] && resolvconf -d "${interface}" |
254 |
+ fi |
255 |
+} |
256 |
+ |
257 |
+if [ -r "/var/run/udhcpc-${interface}.conf" ]; then |
258 |
+ . "/var/run/udhcpc-${interface}.conf" |
259 |
+fi |
260 |
+ |
261 |
+case "$1" in |
262 |
+ bound|renew) |
263 |
+ update_hostname |
264 |
+ update_interface |
265 |
+ update_routes |
266 |
+ update_dns |
267 |
+ update_ntp |
268 |
+ ;; |
269 |
+ deconfig|leasefail) |
270 |
+ deconfig |
271 |
+ ;; |
272 |
+ nak) |
273 |
+ echo "nak: ${message}" |
274 |
+ ;; |
275 |
+ *) |
276 |
+ echo "unknown option $1" >&2 |
277 |
+ echo "Usage: $0 {bound|deconfig|leasefail|nak|renew}" >&2 |
278 |
+ exit 1 |
279 |
+ ;; |
280 |
+esac |
281 |
+ |
282 |
+exit 0 |