Add argument checks and allow lladdrs and stp to be set

This commit is contained in:
Alex D. 2023-08-16 06:52:45 +00:00
parent 79cb1609e7
commit f8856c5b33
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 75 additions and 25 deletions

View File

@ -7,20 +7,25 @@ header_eb() {
}
header_if() {
echo "define INTERFACE $1"
local if="${1:?missing if}"
echo "define INTERFACE $if"
}
header_addr() {
echo "define ADDR $1"
local addr="${1:?missing addr}"
echo "define ADDR $addr"
}
header_vlan() {
echo "define VLAN $1"
echo "define PARENT $2"
local vlan="${1:?missing vlan}"
local parent="${2:?missing parent}"
echo "define VLAN $vlan"
echo "define PARENT $parent"
}
header_vrf() {
echo "define VRF $1"
local vrf="${1:?missing vrf}"
echo "define VRF $vrf"
}
header_path() {
@ -44,12 +49,13 @@ h_if_addr() {
}
linkdel() {
h_if "$1"
local if="${1:?missing if}"
h_if "$if"
echo 'ip link del $INTERFACE'
}
ifbundle() {
local if="$1"
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
@ -58,7 +64,7 @@ ifbundle() {
}
new_link() {
local if="$1"
local if="${1:?missing if}"
local sname="interface.$if.link"
@ -75,7 +81,7 @@ new_link() {
}
new_forward() {
local if="$1"
local if="${1:?missing if}"
local sname="sysctl.net-ipv6-conf-$if-forwarding"
ifbundle "$if" "$sname"
@ -106,8 +112,8 @@ EOF
}
new_if_slave() {
local master="$1"
local slave="$2"
local master="${1:?missing master}"
local slave="${2:?missing slave}"
local sname="interface.$master.slave.$slave"
ifbundle "$master" "$sname"
@ -135,7 +141,7 @@ EOF
}
new_if_bridge() {
local if="$1"
local if="${1:?missing if}"
local sname="interface.$if.create"
ifbundle "$if" "$sname"
@ -151,8 +157,46 @@ new_if_bridge() {
new_link "$if"
}
bridge_stp() {
local if="${1:?missing if}"
local state="${2:-1}"
local sname="interface.$if.stp"
ifbundle "$if" "$sname"
install -Dm644 <(
h_if "$if"
cat <<EOF
define STATE $state
EOF
echo 'ip link set $INTERFACE type bridge stp_state $STATE'
) rc/"$sname"/up
install -Dm644 <(
h_if "$if"
echo 'ip link set $INTERFACE type bridge stp_state 0'
) rc/"$sname"/down
install -Dm644 <(echo oneshot) rc/"$sname"/type
install -Dm644 /dev/null rc/"$sname"/dependencies.d/module.stp
install -Dm644 /dev/null rc/"$sname"/dependencies.d/interface."$if".create
}
if_lladdress() {
local if="${1:?missing if}"
local addr="${2:?missing addr}"
local sname="interface.$if.lladdr"
ifbundle "$if" "$sname"
install -Dm644 <(
h_if_addr "$if" "$addr"
echo 'ip link set $INTERFACE address $ADDR'
) rc/"$sname"/up
install -Dm644 <(echo oneshot) rc/"$sname"/type
install -Dm644 /dev/null rc/"$sname"/dependencies.d/interface."$if".create
}
new_if_phys() {
local if="$1"
local if="${1:?missing if}"
local sname="interface.$if.create"
ifbundle "$if" "$sname"
@ -168,7 +212,7 @@ new_if_phys() {
}
new_if_wg() {
local if="$1"
local if="${1:?missing if}"
# Main service for creating interface
local sname="interface.$if.create"
@ -189,7 +233,7 @@ new_if_wg() {
}
wgconf() {
local if="$1"
local if="${1:?missing if}"
local sname="interface.$if.wg-config"
ifbundle "$if" "$sname"
@ -210,8 +254,8 @@ EOF
}
new_if_vrf() {
local if="$1"
local table="$2"
local if="${1:?missing if}"
local table="${2:?missing table}"
local sname="interface.$if.create"
ifbundle "$if" "$sname"
@ -236,7 +280,7 @@ EOF
}
new_if_vlan() {
local if="$1"
local if="${1:?missing if}"
local vlan="$(echo $if | cut -d'-' -f2)"
local parent="$(echo $if | cut -d'-' -f1)"
@ -259,8 +303,8 @@ new_if_vlan() {
}
addr_v6_static_if() {
local if="$1"
local addr="$2"
local if="${1:?missing if}"
local addr="${2:?missing addr}"
local addrn="$(echo "$addr" | sed 's/\//_/g')"
local sname="interface.$if.static.addr.6.$addrn"
@ -279,8 +323,8 @@ addr_v6_static_if() {
}
route_v6_vrf_default_if() {
local vrf="$1"
local if="$2"
local vrf="${1:?missing vrf}"
local if="${2:?missing if}"
local sname="interface.$vrf.route.6.default"
ifbundle "$vrf" "$sname"
@ -301,7 +345,7 @@ route_v6_vrf_default_if() {
}
route_v6_vrf_default_unreach() {
local if="$1"
local if="${1:?missing if}"
local sname="interface.$if.route.6.unreach"
ifbundle "$if" "$sname"
@ -319,8 +363,8 @@ route_v6_vrf_default_unreach() {
}
route_v6_vrf_sink_unreach() {
local if="$1"
local addr="$2"
local if="${1:?missing if}"
local addr="${2:?missing addr}"
local addrn="$(echo "$addr" | sed 's/\//_/g')"
local sname="interface.$if.route.6.sink.$addrn"

View File

@ -29,16 +29,22 @@ new_if_bridge "br-dn42"
new_if_slave "br-dn42" "phys2-42"
new_if_bridge "f33d"
bridge_stp "f33d"
if_lladdress "f33d" '02:00:00:00:f3:3d'
addr_v6_static_if "f33d" "2a04:5b81:2060:f33d::1/64"
new_if_slave "f33d" "vnet2"
new_if_bridge "b00b"
bridge_stp "b00b"
if_lladdress "b00b" '02:00:00:00:b0:0b'
addr_v6_static_if "b00b" "2a04:5b81:2060:b00b::1/64"
new_if_slave "b00b" "vnet0"
new_if_slave "b00b" "vnet4"
new_if_slave "b00b" "phys2-66"
new_if_bridge "d00d"
bridge_stp "d00d"
if_lladdress "d00d" '02:00:00:00:d0:0d'
addr_v6_static_if "d00d" "2a04:5b81:2060:d00d::1/64"
new_if_slave "d00d" "vnet3"