diff options
Diffstat (limited to 'bin/mkbirdconfig.sh')
-rwxr-xr-x | bin/mkbirdconfig.sh | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/bin/mkbirdconfig.sh b/bin/mkbirdconfig.sh new file mode 100755 index 0000000..bf5c1f3 --- /dev/null +++ b/bin/mkbirdconfig.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +. /var/lib/inet2/inet2.sh + +escapebird() { + sed -e 's/\\/\\\\/g;s/"/\\"/g' +} + +step "Creating Bird configuration" + +touch /var/log/bird.log +chown bird:bird /var/log/bird.log + +interfacelist=$( + echo " interface \"lo\" { stub; };" + getval interface | while read -r inter; do + val="$(getval "interface $inter" OSPF)" + if [ "$?" = "0" ]; then + echo " interface \"$(printf "%s" "$inter" | escapebird)\" {" + echo " type ptp;" + if [ -n "$val" ]; then + echo " $val;"; + fi + echo " };" + fi + done +) + +filter4=$(getval "Subnet" | grep -v ':' | while read -r line; do printf "%s+," "$line"; done | sed 's/,$//') +filter6=$(getval "Subnet" | grep ':' | while read -r line; do printf "%s+," "$line"; done | sed 's/,$//') + +(cat <<EOF +log "/var/log/bird.log" all; + +$(getval RouterID | while read -r line; do echo "router id $line;"; done) + +protocol kernel { + ipv4 { export filter { if net ~ [$filter4] then accept; else reject; }; }; +} + +protocol kernel { + ipv6 { export filter { if net ~ [$filter6] then accept; else reject; }; }; +} + +protocol device { +} + +protocol direct { + ipv4; + ipv6; +} + +protocol static { + ipv4; +} + +EOF + +cat <<EOF +protocol ospf v3 ospf4 { + ipv4 { + import all; + export filter { if source ~ [RTS_DEVICE, RTS_INHERIT] && net ~ [$filter4] then accept; else reject; }; + }; + area 0 { +$(getval "Stubnet" | grep -v ':' | while read -r net; do echo " stubnet $net {};"; done) +$interfacelist + }; +} +protocol ospf v3 ospf6 { + ipv6 { + import all; + export filter { if source ~ [RTS_DEVICE, RTS_INHERIT] && net ~ [$filter6] then accept; else reject; }; + }; + area 0 { +$(getval "Stubnet" | grep ':' | while read -r net; do echo " stubnet $net {};"; done) +$interfacelist + }; +} +EOF +) > /etc/bird.conf + +chown root:bird /etc/bird.conf +chmod 640 /etc/bird.conf |