Gentoo Archives: gentoo-commits

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/netifrc:master commit in: init.d/, doc/, net/
Date: Tue, 02 Jun 2020 21:25:09
Message-Id: 1591133064.d3b5d78c5f3696aaf841d7900e69a37de29cfc25.robbat2@OpenRC
1 commit: d3b5d78c5f3696aaf841d7900e69a37de29cfc25
2 Author: Daniel Solano Gómez <daniel <AT> solanogomez <DOT> org>
3 AuthorDate: Sat Apr 6 00:13:12 2013 +0000
4 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
5 CommitDate: Tue Jun 2 21:24:24 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=d3b5d78c
7
8 dhclientv6: Add DHCPv6 support via dhclient
9
10 This adds DHCPv6 support to OpenRC in Linux using dhclient as outlined
11 by Stuart Longland at <http://stuartl.longlandclan.yi.org/blog/2011/02/15/gentoo-and-dhcpv6/>.
12 The main place where the new support is added is via a modified copy of
13 the dhclient.sh script that:
14
15 - Renames functions using a 'v6' suffix
16 - Uses a different pid file
17 - Uses the '-6' argument when invoking dhclient
18 - Recognizes new DHCPv6-specific configuration variables with a fallback
19 to the DHCP configuration variables.
20
21 Additionally:
22
23 1. The iproute2 and Linux ifconfig scripts have been ammended to be able
24 to return IPv6 addresses using new '_get_inet6_address' and
25 '_get_inet6_addresses' functions.
26
27 2. The 'net.lo' init script now has a '_show_address6' function.
28
29 3. The documentation in the Linux net.example now contains some DHCPv6
30 information.
31
32 Reported-by: Dustin C. Hatch <admiralnemo <AT> gmail.com>
33 X-Gentoo-Bug: 150908
34 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=150908
35 Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
36 (cherry picked from commit bd7bd3a513c8ddc554e211316c990b5f98110982)
37 Closes: https://bugs.gentoo.org/450326
38 Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
39
40 doc/net.example.Linux.in | 35 +++++++++++++++++++++
41 init.d/net.lo.in | 4 +++
42 net/Makefile | 2 +-
43 net/dhclientv6.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++
44 net/ifconfig.sh.Linux.in | 26 +++++++++++++--
45 net/iproute2.sh | 19 +++++++++--
46 6 files changed, 162 insertions(+), 6 deletions(-)
47
48 diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
49 index a2993c0..53d9e84 100644
50 --- a/doc/net.example.Linux.in
51 +++ b/doc/net.example.Linux.in
52 @@ -518,6 +518,41 @@
53 # You can use any combination of the above options - the default is not to
54 # use any of them.
55
56 +#-----------------------------------------------------------------------------
57 +# DHCPv6
58 +# DHCPv6 can be provided by dhclient
59 +#
60 +# dhclient: emerge net-misc/dhcp
61 +#
62 +# If you have more than one DHCP client installed, you should probably
63 +# explicitly use 'dhclient' to use dhclient for both DHCP and DHCPv6,
64 +# otherwise the default DHCP client will be used. dhcpcd has some stateless
65 +# IPv6 autoconfiguration support which may clash with DHCPv6.
66 +#modules="dhclient" # to select dhclient over dhcpcd
67 +
68 +# Regardless of which DHCP client you prefer, you configure them the
69 +# same way using one of following depending on which interface modules
70 +# you're using.
71 +#config_eth0="dhcpv6"
72 +
73 +# You can also use both DHCP and DHCPv6 on a dual-stack network:
74 +#config_eth0="dhcp
75 +#dhcpv6"
76 +
77 +# To pass runtime arguments to dhclient for DHCPv6, you do it similarly to
78 +# setting runtime arguments for DHCP. Note that you can set options for
79 +# DHCPv6 separately or in addition the dhclient arguments for DHCP.
80 +#dhclientv6_eth0="..." # options for DHCPv6 only
81 +#dhclient_eth0='..." # options for DHCP (also for DHCPv6 when no
82 +# # dhclientv6_eth0 is defined)
83 +
84 +# GENERIC DHCPv6 OPTIONS
85 +# Set generic DHCPv6 options just as with generic DHCP options.
86 +#dhcpv6_eth0="release nodns nontp nonis nogateway nosendhost"
87 +
88 +# If no generic DHCPv6 options are set, the default is to fall back to the
89 +# DHCP generic options.
90 +
91 #-----------------------------------------------------------------------------
92 # For APIPA support, emerge net-misc/iputils or net-analyzer/arping
93
94
95 diff --git a/init.d/net.lo.in b/init.d/net.lo.in
96 index a5ac0fe..3ab83b2 100644
97 --- a/init.d/net.lo.in
98 +++ b/init.d/net.lo.in
99 @@ -295,6 +295,10 @@ _get_errorhandler_behavior() {
100 echo "$value" && break
101 fi
102 done
103 +
104 +_show_address6()
105 +{
106 + einfo "received address $(_get_inet6_address "${IFACE}")"
107 }
108
109 # Basically sorts our modules into order and saves the list
110
111 diff --git a/net/Makefile b/net/Makefile
112 index dab94f9..ee48294 100644
113 --- a/net/Makefile
114 +++ b/net/Makefile
115 @@ -14,7 +14,7 @@ INC-Linux= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \
116 ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh \
117 ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \
118 vlan.sh macvlan.sh ip6rd.sh firewalld.sh dummy.sh hsr.sh l2tp.sh \
119 - iw.sh wireguard.sh veth.sh
120 + iw.sh wireguard.sh veth.sh dhclientv6.sh
121
122 SRCS-NetBSD= ifwatchd.sh.in
123 INC-NetBSD= ifwatchd.sh
124
125 diff --git a/net/dhclientv6.sh b/net/dhclientv6.sh
126 new file mode 100644
127 index 0000000..f87ed4d
128 --- /dev/null
129 +++ b/net/dhclientv6.sh
130 @@ -0,0 +1,82 @@
131 +# Copyright (c) 2007-2008 Roy Marples <roy@×××××××.name>
132 +# Released under the 2-clause BSD license.
133 +
134 +dhclientv6_depend()
135 +{
136 + after interface
137 + program start /sbin/dhclient
138 + provide dhcpv6
139 +}
140 +
141 +_config_vars="$_config_vars dhcp dhclient dhcpv6 dhclientv6"
142 +
143 +dhclientv6_start()
144 +{
145 + local args= opt= opts= pidfile="/var/run/dhclientv6-${IFACE}.pid"
146 + local sendhost=true dconf=
147 +
148 + # Get our options
149 + # These options only work in Gentoo, and maybe RedHat
150 + eval args=\$dhclientv6_${IFVAR}
151 + [ -z "${args}" ] && eval args=\$dhclient_${IFVAR}
152 + eval opts=\$dhcpv6_${IFVAR}
153 + [ -z "${opts}" ] && opts=${dhcpv6}
154 + [ -z "${opts}" ] && eval opts=\$dhcp_${IFVAR}
155 + [ -z "${opts}" ] && opts=${dhcp}
156 +
157 + for opt in ${opts}; do
158 + case "${opt}" in
159 + nodns) args="${args} -e PEER_DNS=no";;
160 + nontp) args="${args} -e PEER_NTP=no";;
161 + nogateway) args="${args} -e PEER_ROUTERS=no";;
162 + nosendhost) sendhost=false;;
163 + esac
164 + done
165 +
166 + # Add our route metric
167 + [ "${metric:-0}" != "0" ] && args="${args} -e IF_METRIC=${metric}"
168 +
169 + if ${sendhost}; then
170 + local hname="$(hostname)"
171 + if [ "${hname}" != "(none)" -a "${hname}" != "localhost" ]; then
172 + dhconf="${dhconf} interface \"${IFACE}\" {"
173 + dhconf="${dhconf} send fqdn.fqdn \"${hname}\";"
174 + dhconf="${dhconf} send fqdn.encoded on;"
175 + dhconf="${dhconf} send fqdn.server-update on;"
176 + dhconf="${dhconf} send fqdn.no-client-update on;"
177 + dhconf="${dhconf}}"
178 + fi
179 + fi
180 +
181 + # Bring up DHCP for this interface
182 + ebegin "Running dhclient -6"
183 + echo "${dhconf}" | start-stop-daemon --start --exec /sbin/dhclient \
184 + --pidfile "${pidfile}" \
185 + -- -6 ${args} -q -1 -pf "${pidfile}" "${IFACE}"
186 + eend $? || return 1
187 +
188 + _show_address6
189 + return 0
190 +}
191 +
192 +dhclientv6_stop()
193 +{
194 + local pidfile="/var/run/dhclientv6-${IFACE}.pid" opts=
195 + [ ! -f "${pidfile}" ] && return 0
196 +
197 + # Get our options
198 + if [ -x /sbin/dhclient ]; then
199 + eval opts=\$dhcp_${IFVAR}
200 + [ -z "${opts}" ] && opts=${dhcp}
201 + fi
202 +
203 + ebegin "Stopping dhclient -6 on ${IFACE}"
204 + case " ${opts} " in
205 + *" release "*) dhclient -6 -q -r -pf "${pidfile}" "${IFACE}";;
206 + *)
207 + start-stop-daemon --stop --quiet \
208 + --exec /sbin/dhclient --pidfile "${pidfile}"
209 + ;;
210 + esac
211 + eend $?
212 +}
213
214 diff --git a/net/ifconfig.sh.Linux.in b/net/ifconfig.sh.Linux.in
215 index 09708a9..960b239 100644
216 --- a/net/ifconfig.sh.Linux.in
217 +++ b/net/ifconfig.sh.Linux.in
218 @@ -87,21 +87,41 @@ _get_inet_address()
219 echo "/$(_netmask2cidr "$1")"
220 }
221
222 -_get_inet_addresses()
223 +_get_inet6_address()
224 +{
225 + set -- $(LC_ALL=C ifconfig "${IFACE}" |
226 + sed -n -e 's/.*\(inet6 addr:\|inet6\) \([^ /]*\)\(\/\| *prefixlen \)\([^ ]*\).*/\2\/\4/p')
227 + [ -z "$1" ] && return 1
228 +
229 + echo -n "$1"
230 +}
231 +
232 +_get_addresses_fn()
233 {
234 + local fn="$1"
235 local iface=${IFACE} i=0
236 - local addrs="$(_get_inet_address)"
237 + local addrs="$($fn)"
238
239 while true; do
240 local IFACE="${iface}:${i}"
241 _exists || break
242 - local addr="$(_get_inet_address)"
243 + local addr="$($fn)"
244 [ -n "${addr}" ] && addrs="${addrs}${addrs:+ }${addr}"
245 : $(( i += 1 ))
246 done
247 echo "${addrs}"
248 }
249
250 +_get_inet_addresses()
251 +{
252 + _get_addresses_fn _get_inet_address
253 +}
254 +
255 +_get_inet6_addresses()
256 +{
257 + _get_addresses_fn _get_inet6_address
258 +}
259 +
260 _cidr2netmask()
261 {
262 local cidr="$1" netmask="" done=0 i=0 sum=0 cur=128
263
264 diff --git a/net/iproute2.sh b/net/iproute2.sh
265 index ca6c0f8..d19f79d 100644
266 --- a/net/iproute2.sh
267 +++ b/net/iproute2.sh
268 @@ -92,8 +92,16 @@ _set_mac_address()
269
270 _get_inet_addresses()
271 {
272 - LC_ALL=C ip -family inet addr show "${IFACE}" | \
273 - sed -n -e 's/.*inet \([^ ]*\).*/\1/p'
274 + local family="$1";
275 + if [ -z "$family" ]; then
276 + family="inet"
277 + fi
278 + LC_ALL=C ip -family $family addr show "${IFACE}" | \
279 + sed -n -e 's/.*inet6\? \([^ ]*\).*/\1/p'
280 +}
281 +
282 +_get_inet6_addresses() {
283 + _get_inet_addresses "inet6"
284 }
285
286 _get_inet_address()
287 @@ -103,6 +111,13 @@ _get_inet_address()
288 echo "$1"
289 }
290
291 +_get_inet6_address()
292 +{
293 + set -- $(_get_inet6_addresses)
294 + [ $# = "0" ] && return 1
295 + echo "$1"
296 +}
297 +
298 _add_address()
299 {
300 if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ]; then