#!/bin/sh # # Generate s6 network definitions set -x header_eb() { echo '#!/bin/execlineb -P' } header_if() { local if="${1:?missing if}" echo "define INTERFACE $if" } header_addr() { local addr="${1:?missing 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}" echo "define VLAN $vlan" echo "define PARENT $parent" } header_vrf() { local vrf="${1:?missing vrf}" echo "define VRF $vrf" } header_path() { cat </dev/null 2>&1 && echo "$addr" | grep -v ':' >/dev/null 2>&1; then local fam='4' fi echo "$fam" } linkdel() { local if="${1:?missing if}" header_eb header_path header_if "$if" echo 'ip link del $INTERFACE' } ifbundle() { local if="${1:?missing if}" [ -r "rc/bundle.interface.$if/type" ] || install -Dm644 <(echo bundle) rc/bundle.interface."$if"/type shift 1 for sname in $@; do install -Dm644 /dev/null rc/bundle.interface."$if"/contents.d/"$sname" done } new_link() { local if="${1:?missing if}" local sname="interface.$if.link" install -Dm644 <( header_eb header_path header_if "$if" echo 'ip link set dev $INTERFACE up' ) rc/"$sname"/up install -Dm644 <( header_eb header_path header_if "$if" echo 'ip link set dev $INTERFACE down' ) rc/"$sname"/down install -Dm644 <(echo oneshot) rc/"$sname"/type install -Dm644 /dev/null rc/"$sname"/dependencies.d/bundle.interface."$if" } new_forward() { local if="${1:?missing if}" local fam="${2:-6}" 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 <