Replace static network config script with iproute2 batch file

A lot simpler than make-shift DSL parsing with bash.

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-08-11 01:37:36 +02:00
parent 0309ede4b8
commit 7ecb124df2
6 changed files with 7 additions and 115 deletions

1
.gitignore vendored
View File

@ -9,7 +9,6 @@ install-sh
missing
reboot
scripts/devfs.sh
scripts/ifcfg.sh
scripts/ifrename.sh
scripts/modules_load.sh
services/devfs

View File

@ -38,7 +38,6 @@ AC_CONFIG_FILES([services/tmpfsvar])
AC_CONFIG_FILES([services/dhcpcd])
AC_CONFIG_FILES([scripts/devfs.sh])
AC_CONFIG_FILES([scripts/ifrename.sh])
AC_CONFIG_FILES([scripts/ifcfg.sh])
AC_CONFIG_FILES([scripts/modules_load.sh])
AC_CONFIG_FILES([crontab/swclock])

View File

@ -34,46 +34,12 @@ Extension cards or external network adapters should be given a different prefix
to avoid changes in the order as they come and go.
## Interface Configuration
## Static Interface and Route Configuration
After interface renaming, for each network interface, the configuration path is
scanned for files with the same name as the interface.
Each successfully found configuration file is processed line by line, top to
bottom. Each line may contain a keyword, followed by multiple arguments.
The following keywords can be used to add IPv4 or IPv6 network addresses to
an interface:
* address
* addr
* ip
* ip6
* ipv6
Those commands are expected to be followed by an IPv4 or IPv6 address and
network mask.
Furthermore, the following commands can be used for configuring interface
parameters:
* `arp {on|off}`
* `multicast {on|off}`
* `mtu <value>`
* `offload [rx {on|off}] [tx {on|off}] [sg {on|off}] [tso {on|off}]`
* `offload [gso {on|off}] [gro {on|off}] [lro {on|off}] [rxvlan {on|off}]`
* `offload [txvlan {on|off}] [ntuple {on|off}] [rxhash {on|off}]`
* `offload [ufo {on|off}]`
## Route Configuration
After interface configuration is done, routes and rules are restored from a
file named `routes` in the same configuration path.
The file may contain lines starting with `route` or `rule`. Everything that
follows is passed on to `ip route add` or `ip rule add` respectively.
After interface renaming, an iproute2 batch script `/etc/netcfg/static` is
executed with the `-force` option is set, i.e. it will plough throug the
entire script without aborting, but the service will be marked as having
failed if any of the batch lines fail.
## Net Filter Tables

View File

@ -1,5 +1,5 @@
helper_SCRIPTS += scripts/devfs.sh scripts/trymount.sh scripts/ifrename.sh
helper_SCRIPTS += scripts/ifcfg.sh scripts/ifdown.sh scripts/modules_load.sh
helper_SCRIPTS += scripts/ifdown.sh scripts/modules_load.sh
helper_SCRIPTS += scripts/setntpdate.sh scripts/overlay.sh
EXTRA_DIST += scripts/trymount.sh scripts/ifdown.sh scripts/setntpdate.sh

View File

@ -1,71 +0,0 @@
#!/bin/sh
CFGPATH="@ETCPATH@/netcfg"
[ -d "$CFGPATH" ] || exit 0
# configure interfaces
for IFPATH in /sys/class/net/*; do
[ "$IFPATH" = "/sys/class/net/lo" ] && continue
IF=`basename $IFPATH`
CFGFILE="$CFGPATH/$IF"
[ -f "$CFGFILE" ] || continue
ip link set dev "$IF" down
while read LINE;
do
trimmed=`echo -- $LINE`
[ ! -z "$trimmed" ] || continue
set $trimmed
case "$1" in
address|addr|ip|ip6|ipv6)
shift
ip address add $@ dev "$IF"
;;
arp|multicast|mtu)
ip link set dev "$IF" $@
;;
offload)
shift
ethtool -K "$IF" $@
;;
*)
;;
esac
done < "$CFGFILE"
done
# configure static routs
if [ -f "$CFGPATH/routes" ]; then
while read LINE;
do
trimmed=`echo -- $LINE`
[ ! -z "$trimmed" ] || continue
set $trimmed
case "$1" in
route)
shift
ip route add $@
;;
rule)
shift
ip rule add $@
;;
*)
;;
esac
done < "$CFGFILE"
fi
# activate interfaces
for IFPATH in /sys/class/net/*; do
[ "$IFPATH" = "/sys/class/net/lo" ] && continue
IF=`basename $IFPATH`
[ ! -f "$CFGPATH/$IF" ] || ip link set dev "$IF" up
done

View File

@ -3,5 +3,4 @@ type wait
target boot
after sysinit ifrename
before network
exec "@SCRIPTDIR@/ifcfg.sh"
exec ip -force -batch "@ETCPATH@/netcfg/static"