mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-02-06 00:13:37 +01:00
main/openrc: add support for nested network configs
Add support for source and source-directory keywords in network configuration by use ifquery from ifupdown-ng. Use a fallback for busybox ifupdown in case ifquery is not available. Run the `make check` to run unit tests in openrc. Also add some unit tests for the find_ifaces and find_running_ifaces functions in networking.initd. fixes #11562
This commit is contained in:
parent
07f9872c9d
commit
8c8f379f10
@ -2,7 +2,7 @@
|
||||
pkgname=openrc
|
||||
pkgver=0.42.1
|
||||
_ver=${pkgver/_git*/}
|
||||
pkgrel=13
|
||||
pkgrel=14
|
||||
pkgdesc="OpenRC manages the services, startup and shutdown of a host"
|
||||
url="https://github.com/OpenRC/openrc"
|
||||
arch="all"
|
||||
@ -38,6 +38,7 @@ source="$pkgname-$pkgver.tar.gz::https://github.com/OpenRC/openrc/archive/$pkgve
|
||||
sysfsconf.initd
|
||||
firstboot.initd
|
||||
sysctl.initd
|
||||
test-networking.sh
|
||||
"
|
||||
|
||||
prepare() {
|
||||
@ -51,6 +52,14 @@ build() {
|
||||
make LIBEXECDIR=/lib/rc
|
||||
}
|
||||
|
||||
check() {
|
||||
make check
|
||||
|
||||
# run unit tests for networking.initd
|
||||
cd "$srcdir"
|
||||
( set -e; sh test-networking.sh )
|
||||
}
|
||||
|
||||
package() {
|
||||
local i j
|
||||
|
||||
@ -135,8 +144,9 @@ ff9bf2f6e4f55633a9641385398f70a2e591e2b3b56b1903f168a97b07bd56dc5a65d151deeab942
|
||||
c06eac7264f6cc6888563feeae5ca745aae538323077903de1b19102e4f16baa34c18b8c27af5dd5423e7670834e2261e9aa55f2b1ec8d8fdc2be105fe894d55 hwdrivers.initd
|
||||
7113c930f7f5fb5b345b115db175f8e5837e3541b3e022d5cecf1b59067ed4b40b2adea2324a008035b97d653311217ac5cf961b4d0fc8b714a8b2505883cdc6 modules.initd
|
||||
c1615dbeb18e2f988237ecbef830a01fd79970365a799e8704abefab9c716ab45553b3c15f1e3d24320d422fd25d21ab38f519f0edd4ca25cf19846713195ae1 modloop.initd
|
||||
e945859bee6d0ddcfe1897df3af22b80ac1f5a93308bb8dd7b2dafe145bdb16d25b2a9ec627a7b5e8d7a6f458403fcacd914c981c4a38b736c8ffa258a5bfd6b networking.initd
|
||||
7883ed880c49db3f7fb7598c8cc01f9830ccb5f70b64ed620213baf4900289a718d89a5f7bf97dc94593465eb0e1e3ed126b19dfeaaf9d03a7c46e4e7b6c4472 networking.initd
|
||||
80e43ded522e2d48b876131c7c9997debd43f3790e0985801a8c1dd60bc6e09f625b35a127bf225eb45a65eec7808a50d1c08a5e8abceafc61726211e061e0a2 modloop.confd
|
||||
d76c75c58e6f4b0801edac4e081b725ef3d50a9a8c9bbb5692bf4d0f804af7d383bf71a73d5d03ed348a89741ef0b2427eb6a7cbf5a9b9ff60a240639fa6ec88 sysfsconf.initd
|
||||
990855f875513a85c2b737685ac5bfdfa86f8dadacf00c1826a456547f99b69d4ecf1b9a09c0ce002f1df618b44b1febabe53f95a2c0cd02b504d565bccb50c8 firstboot.initd
|
||||
2d5f9f6d41b7c0a8643cfdee1ce3c399bfe4ebff54421f33ab1e74c1c4c1b96a49e54b5cd69f0339a060342e4e5a11067bbff68c39fa487919259d73e8e46ed1 sysctl.initd"
|
||||
2d5f9f6d41b7c0a8643cfdee1ce3c399bfe4ebff54421f33ab1e74c1c4c1b96a49e54b5cd69f0339a060342e4e5a11067bbff68c39fa487919259d73e8e46ed1 sysctl.initd
|
||||
af17947aa3954e317dc06580da829200e0b0f2ddc37ce842c3fc7fc0d8ca2f40220e4f4665f61b4b5ec47c96416db0127e2ed979b9421bf21df89d4c4f998b7f test-networking.sh"
|
||||
|
||||
17
main/openrc/machine-id.initd
Normal file
17
main/openrc/machine-id.initd
Normal file
@ -0,0 +1,17 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
description="Generate machine-id if needed"
|
||||
|
||||
depend() {
|
||||
need root dev
|
||||
}
|
||||
|
||||
start() {
|
||||
if [ -s /etc/hostname ] ; then
|
||||
return 0
|
||||
fi
|
||||
ebegin "Generating machine-id"
|
||||
dd if=/dev/urandom status=none bs=16 count=1 \
|
||||
| md5sum | cut -d' ' -f1 > /etc/machine-id
|
||||
eend $?
|
||||
}
|
||||
@ -4,7 +4,8 @@
|
||||
# /etc/sysctl.conf
|
||||
|
||||
: ${cfgfile:="/etc/network/interfaces"}
|
||||
ifstate=/run/ifstate
|
||||
: ${ifquery:="ifquery"}
|
||||
: ${ifstate:="/run/ifstate"}
|
||||
|
||||
single_iface="${RC_SVCNAME#*.}"
|
||||
if [ "$single_iface" = "$RC_SVCNAME" ]; then
|
||||
@ -23,18 +24,32 @@ depend() {
|
||||
find_ifaces() {
|
||||
if [ -n "$single_iface" ]; then
|
||||
echo $single_iface
|
||||
else
|
||||
awk '$1 == "auto" {for (i = 2; i <= NF; i = i + 1) printf("%s ", $i)}' "$cfgfile"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if command -v "$ifquery" >/dev/null; then
|
||||
$ifquery -i "$cfgfile" --list --auto
|
||||
return
|
||||
fi
|
||||
|
||||
# fallback in case ifquery does not exist
|
||||
awk '$1 == "auto" {for (i = 2; i <= NF; i = i + 1) printf("%s ", $i)}' "$cfgfile"
|
||||
}
|
||||
|
||||
# return the list of interfaces we should try stop
|
||||
find_running_ifaces() {
|
||||
if [ -n "$single_iface" ]; then
|
||||
echo $single_iface
|
||||
else
|
||||
awk -F= '{print $2}' $ifstate
|
||||
return 0
|
||||
fi
|
||||
|
||||
if command -v "$ifquery" >/dev/null; then
|
||||
$ifquery --state-file $ifstate -i "$cfgfile" --running
|
||||
return
|
||||
fi
|
||||
|
||||
# fallback
|
||||
awk -F= '{print $2}' $ifstate
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
65
main/openrc/test-networking.sh
Normal file
65
main/openrc/test-networking.sh
Normal file
@ -0,0 +1,65 @@
|
||||
#!/bin/sh
|
||||
|
||||
# unit tests for find_ifaces and find_running_ifaces in networking.initd
|
||||
|
||||
cfgfile=/tmp/openrc-test-network.$$
|
||||
sourcefile=$cfgfile.source
|
||||
sourcedir=$cfgfile.d
|
||||
ifstate=$cfgfile.state
|
||||
|
||||
cat >$cfgfile<<EOF
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
|
||||
source $sourcefile
|
||||
|
||||
source-directory $sourcedir
|
||||
EOF
|
||||
|
||||
cat >$sourcefile<<EOF
|
||||
auto eth1
|
||||
iface eth1 inet dhcp
|
||||
EOF
|
||||
|
||||
mkdir -p $sourcedir
|
||||
cat >$sourcedir/a<<EOF
|
||||
auto eth2
|
||||
iface eth2 inet dhcp
|
||||
EOF
|
||||
|
||||
cat >$ifstate<<EOF
|
||||
eth4=eth4 1
|
||||
EOF
|
||||
|
||||
errors=0
|
||||
fail() {
|
||||
echo "$@"
|
||||
errors=$(( $errors + 1))
|
||||
}
|
||||
|
||||
# test fallback, when ifquery does not exist
|
||||
ifquery=does-not-exist
|
||||
. ./networking.initd
|
||||
|
||||
find_ifaces | grep -q -w eth0 || fail "Did not find eth0"
|
||||
find_ifaces | grep -q -E '(eth1|eth2)' && fail "Unexpectedly found eth1 or eth2"
|
||||
|
||||
# test that ifquery finds source and source-directory
|
||||
unset ifquery
|
||||
. ./networking.initd
|
||||
for i in eth0 eth1 eth2; do
|
||||
find_ifaces | grep -q -w "$i" || fail "Did not find $i"
|
||||
done
|
||||
|
||||
# test that ifquery picks up the running state file
|
||||
find_running_ifaces | grep -q -w "eth4" || fail "Did not detect eth4 running"
|
||||
|
||||
|
||||
# test /etc/init.d/net.eth5
|
||||
RC_SVCNAME=net.eth5
|
||||
. ./networking.initd
|
||||
find_ifaces | grep -q -w "eth5" || fail "Did not detect eth5"
|
||||
find_running_ifaces | grep -q -w "eth5" || fail "Did not detect eth5 running"
|
||||
|
||||
rm -rf $cfgfile $sourcefile $sourcedir $ifstate
|
||||
exit $errors
|
||||
Loading…
x
Reference in New Issue
Block a user