From a96576c0d59f31a4c415a430ccf0358408b51e8d Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 12 Jul 2023 15:34:59 +0000 Subject: [PATCH] Add regress test to check for bad attribute lenght for optional transitive attributes. --- .../usr.sbin/bgpd/integrationtests/Makefile | 12 +- .../usr.sbin/bgpd/integrationtests/attr.sh | 105 ++++++++++++++++++ .../bgpd/integrationtests/bgpd.attr.conf | 8 ++ .../bgpd/integrationtests/exabgp.attr.in | 60 ++++++++++ .../bgpd/integrationtests/exabgp.attr.ok | 15 +++ 5 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 regress/usr.sbin/bgpd/integrationtests/attr.sh create mode 100644 regress/usr.sbin/bgpd/integrationtests/bgpd.attr.conf create mode 100644 regress/usr.sbin/bgpd/integrationtests/exabgp.attr.in create mode 100644 regress/usr.sbin/bgpd/integrationtests/exabgp.attr.ok diff --git a/regress/usr.sbin/bgpd/integrationtests/Makefile b/regress/usr.sbin/bgpd/integrationtests/Makefile index 035e1850f1f..31f32c8df18 100644 --- a/regress/usr.sbin/bgpd/integrationtests/Makefile +++ b/regress/usr.sbin/bgpd/integrationtests/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.20 2022/11/09 14:31:31 claudio Exp $ +# $OpenBSD: Makefile,v 1.21 2023/07/12 15:34:59 claudio Exp $ REGRESS_TARGETS = network_statement md5 ovs mrt pftable \ maxprefix maxprefixout maxcomm \ - as0 med eval_all policy l3vpn + as0 med eval_all policy l3vpn attr BGPD ?= /usr/sbin/bgpd @@ -53,6 +53,11 @@ med: eval_all: # install exabgp from ports for additional tests @echo SKIPPED + +attr: + # install exabgp from ports for additional tests + @echo SKIPPED + .else .SUFFIXES: .conf .in @@ -70,6 +75,9 @@ med: api-exabgp exabgp.med.conf eval_all: api-exabgp exabgp.eval_all.conf ${SUDO} ksh ${.CURDIR}/$@.sh ${BGPD} ${.CURDIR} 11 12 pair11 pair12 +attr: api-exabgp exabgp.attr.conf + ${SUDO} ksh ${.CURDIR}/$@.sh ${BGPD} ${.CURDIR} 11 12 pair11 pair12 + .endif .include diff --git a/regress/usr.sbin/bgpd/integrationtests/attr.sh b/regress/usr.sbin/bgpd/integrationtests/attr.sh new file mode 100644 index 00000000000..6147eaa057f --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/attr.sh @@ -0,0 +1,105 @@ +#!/bin/ksh +# $OpenBSD: attr.sh,v 1.1 2023/07/12 15:34:59 claudio Exp $ + +set -e + +BGPD=$1 +BGPDCONFIGDIR=$2 +RDOMAIN1=$3 +RDOMAIN2=$4 +PAIR1=$5 +PAIR2=$6 + +RDOMAINS="${RDOMAIN1} ${RDOMAIN2}" +PAIRS="${PAIR1} ${PAIR2}" +PAIR1IP=10.12.57.1 +PAIR2IP=10.12.57.2 +PAIR2IP2=10.12.57.3 +PAIR2IP3=10.12.57.4 + +error_notify() { + echo cleanup + pkill -T ${RDOMAIN1} bgpd || true + pkill -T ${RDOMAIN2} -f exabgp || true + sleep 1 + ifconfig ${PAIR2} destroy || true + ifconfig ${PAIR1} destroy || true + route -qn -T ${RDOMAIN1} flush || true + route -qn -T ${RDOMAIN2} flush || true + ifconfig lo${RDOMAIN1} destroy || true + ifconfig lo${RDOMAIN2} destroy || true + if [ $1 -ne 0 ]; then + echo FAILED + exit 1 + else + echo SUCCESS + fi +} + +run_exabgp() { + local _t=$1 + + shift + env exabgp.log.destination=stdout \ + exabgp.log.packets=true \ + exabgp.log.parser=true \ + exabgp.log.level=DEBUG \ + exabgp.api.cli=false \ + exabgp.daemon.user=build \ + route -T ${RDOMAIN2} exec exabgp -1 ${1+"$@"} > ./exabgp.$_t.log +} + +if [ ! -x /usr/local/bin/exabgp ]; then + echo install exabgp from ports for this test >&2 + exit 1 +fi + +if [ "$(id -u)" -ne 0 ]; then + echo need root privileges >&2 + exit 1 +fi + +trap 'error_notify $?' EXIT + +echo check if rdomains are busy +for n in ${RDOMAINS}; do + if /sbin/ifconfig | grep -v "^lo${n}:" | grep " rdomain ${n} "; then + echo routing domain ${n} is already used >&2 + exit 1 + fi +done + +echo check if interfaces are busy +for n in ${PAIRS}; do + /sbin/ifconfig "${n}" >/dev/null 2>&1 && \ + ( echo interface ${n} is already used >&2; exit 1 ) +done + +set -x + +echo setup +ifconfig ${PAIR1} rdomain ${RDOMAIN1} ${PAIR1IP}/29 up +ifconfig ${PAIR2} rdomain ${RDOMAIN2} ${PAIR2IP}/29 up +ifconfig ${PAIR2} alias ${PAIR2IP2}/32 +ifconfig ${PAIR2} alias ${PAIR2IP3}/32 +ifconfig ${PAIR1} patch ${PAIR2} +ifconfig lo${RDOMAIN1} inet 127.0.0.1/8 +ifconfig lo${RDOMAIN2} inet 127.0.0.1/8 +[ -p attr.fifo ] || mkfifo attr.fifo + +echo run bgpd +route -T ${RDOMAIN1} exec ${BGPD} \ + -v -f ${BGPDCONFIGDIR}/bgpd.attr.conf + +sleep 1 + +echo test2 +run_exabgp attr exabgp.attr.conf > exabgp.attr.out 2>&1 & + +sleep 3 +route -T ${RDOMAIN1} exec bgpctl sh rib in | tee attr.out +sleep .2 +diff -u ${BGPDCONFIGDIR}/exabgp.attr.ok attr.out +echo OK + +exit 0 diff --git a/regress/usr.sbin/bgpd/integrationtests/bgpd.attr.conf b/regress/usr.sbin/bgpd/integrationtests/bgpd.attr.conf new file mode 100644 index 00000000000..7678397a2af --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/bgpd.attr.conf @@ -0,0 +1,8 @@ +AS 64500 +router-id 10.12.57.1 +fib-update no + +neighbor 10.12.57.0/29 + +allow from any +allow to any diff --git a/regress/usr.sbin/bgpd/integrationtests/exabgp.attr.in b/regress/usr.sbin/bgpd/integrationtests/exabgp.attr.in new file mode 100644 index 00000000000..14e17368335 --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/exabgp.attr.in @@ -0,0 +1,60 @@ +process reader { + run "##OBJDIR##/api-exabgp" -t 10 "##OBJDIR##/attr.fifo"; + encoder text; +} + +neighbor 10.12.57.1 { + router-id 10.12.57.2; + local-address 10.12.57.2; + local-as 64501; + peer-as 64500; + group-updates; + adj-rib-in false; + passive false; + + family { + ipv4 unicast; + } + + api { + processes [ reader ]; + neighbor-changes; + receive { + parsed; + update; + notification; + } + } +} + +neighbor 10.12.57.1 { + router-id 10.12.57.3; + local-address 10.12.57.3; + local-as 64502; + peer-as 64500; + group-updates; + adj-rib-in false; + passive false; + + family { + ipv4 unicast; + } + + static { + route 10.12.0.0/24 next-hop self; + # aggregator + route 10.12.1.0/24 next-hop self attribute [ 0x07 0xc0 0x02 ]; + # communities + route 10.12.2.0/24 next-hop self attribute [ 0x08 0xc0 0x02 ]; + # ext communities + route 10.12.3.0/24 next-hop self attribute [ 0x10 0xc0 0x02 ]; + # as4-path + route 10.12.4.0/24 next-hop self attribute [ 0x11 0xc0 0x02 ]; + # as4-aggregator + route 10.12.5.0/24 next-hop self attribute [ 0x12 0xc0 0x02 ]; + # large communities + route 10.12.6.0/24 next-hop self attribute [ 0x20 0xc0 0x02 ]; + # OTC + route 10.12.7.0/24 next-hop self attribute [ 0x23 0xc0 0x02 ]; + } +} diff --git a/regress/usr.sbin/bgpd/integrationtests/exabgp.attr.ok b/regress/usr.sbin/bgpd/integrationtests/exabgp.attr.ok new file mode 100644 index 00000000000..d1097d623c7 --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/exabgp.attr.ok @@ -0,0 +1,15 @@ +flags: * = Valid, > = Selected, I = via IBGP, A = Announced, + S = Stale, E = Error +origin validation state: N = not-found, V = valid, ! = invalid +aspa validation state: ? = unknown, V = valid, ! = invalid +origin: i = IGP, e = EGP, ? = Incomplete + +flags vs destination gateway lpref med aspath origin + N-? 10.12.0.0/24 10.12.57.3 100 0 64502 i + N-? 10.12.1.0/24 10.12.57.3 100 0 64502 i +E N-? 10.12.2.0/24 10.12.57.3 100 0 64502 i +E N-? 10.12.3.0/24 10.12.57.3 100 0 64502 i + N-? 10.12.4.0/24 10.12.57.3 100 0 64502 i + N-? 10.12.5.0/24 10.12.57.3 100 0 64502 i +E N-? 10.12.6.0/24 10.12.57.3 100 0 64502 i +E N-? 10.12.7.0/24 10.12.57.3 100 0 64502 i -- 2.20.1