mirror of
https://github.com/quantum5/bird-filter.git
synced 2025-04-24 09:01:57 -04:00
29 lines
729 B
Bash
Executable file
29 lines
729 B
Bash
Executable file
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
FILTER_SOURCE=/etc/bird/irr-filters
|
|
FILTER_OUTPUT=/etc/bird/filter_irr.conf
|
|
|
|
tmpfile="$(mktemp /tmp/bird-filter.XXXXXX)"
|
|
cleanup() {
|
|
rm -f "$tmpfile"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
grep -v '^#' "$FILTER_SOURCE" | while IFS=$'\t ' read -r -a line; do
|
|
name="${line[0]:-}"
|
|
asset="${line[1]:-}"
|
|
protocol="${line[2]:-}"
|
|
if [ -z "$name" ] || [ -z "$asset" ]; then
|
|
echo "Malformed line found" 1>&2
|
|
continue
|
|
fi
|
|
|
|
[ "$protocol" != v6 ] && bgpq4 -4Ab -m24 "$asset" -l "define IRR_${name}_V4"
|
|
[ "$protocol" != v4 ] && bgpq4 -6Ab -m48 "$asset" -l "define IRR_${name}_V6"
|
|
bgpq4 -tb "$asset" -l "define IRR_${name}_ASN"
|
|
done > "$tmpfile"
|
|
|
|
mv "$tmpfile" "$FILTER_OUTPUT"
|
|
chmod a+r "$FILTER_OUTPUT"
|