freyanet/bin/mkbirdconfig.sh

85 lines
1.8 KiB
Bash
Raw Normal View History

2023-12-30 20:23:30 +00:00
#!/bin/sh
2024-11-17 04:01:08 +00:00
. ${INET2_PREFIX}/share/inet2/inet2.sh
2023-12-30 20:23:30 +00:00
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