DN42 quagga BGP prefix list script

DN42 is a wonderful project that allows you to develop your BGP skills without breaking the product environment, without having to have expensive devices to make a lab to do simulations with GNS3. At the same time, it should not be a purely laboratory environment in which there are no real-world problems. I participate with 1 node in the project for about a year. One of the problems in the project is 1:1 with the real world – when someone announces prefixes that they shouldn't announce. Because I'm lazy and I don't write filters by hand all the time, I solved the problem with an elementary bash script that generates a prefix-list named dn42 and I pour the valid prefixes in it.

#!/bin/bash</pre>
vtysh -c 'conf t' -c "no ip prefix-list dn42"; #drop old prefix list

while read pl
do
vtysh -c 'conf t' -c "$pl"; #insert prefix list row by row
done < <(curl -s https://ca.dn42.us/reg/filter.txt | grep -e ^[0-9] | awk '{ print "ip prefix-list dn42 seq " $1 " " $2 " " $3 " ge " $4 " le " $5}' | sed "s_/\([0-9]\+\) ge \1_/\1_g;s_/\([0-9]\+\) le \1_/\1_g");
vtysh -c 'wr' #write new prefix list

The list of valid prefixes is taken https://ca.dn42.us/reg/filter.txt from where the main pipeline + a few modifications on my part to be able to generate prefix sheets. Commands are executed through vtysh.

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti SPAM *