From 8bad04acb6dad1edc967e3b14486ed4245251a4f Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Sun, 3 Sep 2023 13:18:01 +0000 Subject: [PATCH] More cleanup and generalizing --- netdev.sh | 161 ++++++++++++++++++++++++++++++++++++------------------ router.sh | 26 ++++----- 2 files changed, 120 insertions(+), 67 deletions(-) diff --git a/netdev.sh b/netdev.sh index 429e590..4a21036 100755 --- a/netdev.sh +++ b/netdev.sh @@ -2,6 +2,8 @@ # # Generate s6 network definitions +# set -x + header_eb() { echo '#!/bin/execlineb -P' } @@ -16,6 +18,11 @@ header_addr() { echo "define ADDR $addr" } +header_fam() { + local fam="${1:?missing family}" + echo "define FAMILY $fam" +} + header_vlan() { local vlan="${1:?missing vlan}" local parent="${2:?missing parent}" @@ -35,22 +42,21 @@ emptyenv -p EOF } -h_if() { - header_eb - header_if "$1" - header_path -} - -h_if_addr() { - header_eb - header_if "$1" - header_addr "$2" - header_path +addrfam() { + # Use ipv6 if cannot autodetect of if no semicolons are present + local addr="$1" + local fam='6' + if which grep >/dev/null 2>&1 && echo "$addr" | grep -v ':'; then + local fam='4' + fi + echo "$fam" } linkdel() { local if="${1:?missing if}" - h_if "$if" + header_eb + header_path + header_if "$if" echo 'ip link del $INTERFACE' } @@ -69,11 +75,15 @@ new_link() { local sname="interface.$if.link" install -Dm644 <( - h_if "$if" + header_eb + header_path + header_if "$if" echo 'ip link set dev $INTERFACE up' ) rc/"$sname"/up install -Dm644 <( - h_if "$if" + header_eb + header_path + header_if "$if" echo 'ip link set dev $INTERFACE down' ) rc/"$sname"/down install -Dm644 <(echo oneshot) rc/"$sname"/type @@ -82,33 +92,38 @@ new_link() { new_forward() { local if="${1:?missing if}" + local fam="${2:-6}" - local sname="sysctl.net-ipv6-conf-$if-forwarding" + local sname="sysctl.net-ipv$fam-conf-$if-forwarding" ifbundle "$if" "$sname" install -Dm644 <( header_eb + header_path header_if "$if" + header_fam "$fam" cat <