1#!/bin/ksh 2# $OpenBSD: mrt.sh,v 1.4 2021/04/13 07:38:23 claudio Exp $ 3 4set -e 5 6BGPD=$1 7BGPDCONFIGDIR=$2 8RDOMAIN1=$3 9 10error_notify() { 11 pkill -T ${RDOMAIN1} bgpd || true 12 sleep 1 13 route -qn -T ${RDOMAIN1} flush || true 14 ifconfig mpe${RDOMAIN1} destroy || true 15 ifconfig lo${RDOMAIN1} destroy || true 16 if [ $1 -ne 0 ]; then 17 echo FAILED 18 exit 1 19 else 20 echo SUCCESS 21 fi 22} 23 24if [ "$(id -u)" -ne 0 ]; then 25 echo need root privileges >&2 26 exit 1 27fi 28 29trap 'error_notify $?' EXIT 30 31echo check if rdomains are busy 32if /sbin/ifconfig lo${RDOMAIN1} > /dev/null 2>&1; then 33 echo routing domain ${RDOMAIN1} is already used >&2 34 exit 1 35fi 36 37set -x 38 39echo setup 40ifconfig mpe${RDOMAIN1} rdomain ${RDOMAIN1} mplslabel 42 41ifconfig lo${RDOMAIN1} inet 127.0.0.1/8 42 43route -T ${RDOMAIN1} exec ${BGPD} \ 44 -v -f ${BGPDCONFIGDIR}/bgpd.mrt.conf 45 46sleep 2 47 48pkill -USR1 -T ${RDOMAIN1} -u 0 bgpd 49 50sleep 2 51 52for i in table-v2 table-mp table; do 53 echo test $i 54 bgpctl show mrt detail file mrt-$i.mrt | \ 55 grep -v 'Last update:' | tee mrt-$i.out 56 diff -u ${BGPDCONFIGDIR}/mrt-$i.ok mrt-$i.out 57done 58 59exit 0 60