diff options
author | 2021-01-12 08:59:03 +0000 | |
---|---|---|
committer | 2021-01-12 08:59:03 +0000 | |
commit | 74206d1286f5f1bfd4887097b26d8432a203c3a6 (patch) | |
tree | b162e9c3d1fbb5e098dc9fc37d2feb82b5c2f609 | |
parent | Check that rule without logopt user has no uid in log entry. (diff) | |
download | wireguard-openbsd-74206d1286f5f1bfd4887097b26d8432a203c3a6.tar.xz wireguard-openbsd-74206d1286f5f1bfd4887097b26d8432a203c3a6.zip |
Totally rework the exabgp integration tests. Instead of a simple shell
script to talk to exabgp api use a small c programm. Use a fifo to
send commands to this program. While exabgp includes a cli tool exactly
for that it is impossible to use.
Use a single config file for multiple sessions and make sure exabgp is
properly killed on exit (pkill exabgp fails since it is a python script).
Introduce a med target to test the route decision process handling med
path. This test currently fails and is not hooked up yet.
11 files changed, 393 insertions, 64 deletions
diff --git a/regress/usr.sbin/bgpd/integrationtests/Makefile b/regress/usr.sbin/bgpd/integrationtests/Makefile index 168bf8226fc..9e617ed6906 100644 --- a/regress/usr.sbin/bgpd/integrationtests/Makefile +++ b/regress/usr.sbin/bgpd/integrationtests/Makefile @@ -1,11 +1,13 @@ -# $OpenBSD: Makefile,v 1.11 2020/01/26 00:54:47 claudio Exp $ +# $OpenBSD: Makefile,v 1.12 2021/01/12 08:59:03 claudio Exp $ REGRESS_TARGETS = network_statement md5 ovs mrt \ maxprefix maxprefixout as0 BGPD ?= /usr/sbin/bgpd -CLEANFILES += *.mrt *.out *.conf *.log +CLEANFILES += *.mrt *.out *.conf *.log *.fifo api-exabgp* + +api-exabgp: api-exabgp.c network_statement: ${SUDO} ksh ${.CURDIR}/$@.sh ${BGPD} ${.CURDIR} 11 12 pair11 pair12 @@ -29,18 +31,26 @@ maxprefixout: as0: # install exabgp from ports for additional tests @echo SKIPPED + +med: + # install exabgp from ports for additional tests + @echo SKIPPED .else .SUFFIXES: .conf .in .in.conf: - sed 's|##BGPDCONFIGDIR##|${.CURDIR}|' ${.IMPSRC} > ${.TARGET} || \ + sed -e 's|##OBJDIR##|${.OBJDIR}|g' \ + ${.IMPSRC} > ${.TARGET} || \ (rm ${.TARGET} && exit 1) -AS0_CONFS = exabgp.as0.test1.conf \ - exabgp.as0.test2.conf exabgp.as0.test2_2.conf exabgp.as0.test2_3.conf +AS0_CONFS = exabgp.as0.test1.conf exabgp.as0.test2.conf -as0: ${AS0_CONFS} +as0: api-exabgp ${AS0_CONFS} ${SUDO} ksh ${.CURDIR}/$@.sh ${BGPD} ${.CURDIR} 11 12 pair11 pair12 + +med: api-exabgp exabgp.med.conf + ${SUDO} ksh ${.CURDIR}/$@.sh ${BGPD} ${.CURDIR} 11 12 pair11 pair12 + .endif .include <bsd.regress.mk> diff --git a/regress/usr.sbin/bgpd/integrationtests/api-exabgp.c b/regress/usr.sbin/bgpd/integrationtests/api-exabgp.c new file mode 100644 index 00000000000..559197706eb --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/api-exabgp.c @@ -0,0 +1,95 @@ +#include <err.h> +#include <fcntl.h> +#include <poll.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + +static void +usage(void) +{ + fprintf(stderr, "usage: api-exabgp [ -t timeout ] fifo\n"); + exit(1); +} + +static int +fifo_open(const char *name) +{ + int fd; + + fd = open(name, O_RDONLY | O_NONBLOCK); + if (fd == -1) + err(1, "open %s", name); + return fd; +} + +int +main(int argc, char **argv) +{ + struct pollfd pfd[2]; + char buf[512]; + const char *errstr, *fifo; + int fd, ch, timeout = 0; + time_t end, now; + ssize_t n; + + while ((ch = getopt(argc, argv, "t:")) != -1) { + switch (ch) { + case 't': + timeout = strtonum(optarg, 0, 120, &errstr); + if (errstr != NULL) + errx(1, "timeout is %s: %s", errstr, optarg); + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argv[0] == NULL) + usage(); + fifo = argv[0]; + + pfd[0].fd = 0; + pfd[0].events = POLLIN; + pfd[1].fd = fd = fifo_open(fifo); + pfd[1].events = POLLIN; + + end = time(NULL) + timeout; + while (1) { + now = time(NULL); + if (timeout != 0 && end < now) { + if (write(1, "shutdown\n", 9) != 9) + errx(1, "bad write to stdout"); + } + if (poll(pfd, 2, 1000) == -1) + err(1, "poll"); + + if (pfd[0].revents & POLLIN) { + n = read(0, buf, sizeof(buf)); + if (n == -1) + err(1, "read stdin"); + if (write(2, buf, n - 1) != n - 1) + errx(1, "bad write to stderr"); + if (n > 8 && strncmp(buf, "shutdown", 8) == 0) + errx(0, "exabgp shutdown"); + } + if (pfd[1].revents & POLLIN) { + n = read(fd, buf, sizeof(buf)); + if (n == -1) + err(1, "read fifo"); + if (n > 0) { + if (write(1, buf, n) != n) + errx(1, "bad write to stdout"); + } + } + if (pfd[1].revents & POLLHUP) { + /* re-open fifo */ + close(fd); + pfd[1].fd = fd = fifo_open(fifo); + } + } +} diff --git a/regress/usr.sbin/bgpd/integrationtests/as0.sh b/regress/usr.sbin/bgpd/integrationtests/as0.sh index 6e87a887d80..81922c2c493 100644 --- a/regress/usr.sbin/bgpd/integrationtests/as0.sh +++ b/regress/usr.sbin/bgpd/integrationtests/as0.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: as0.sh,v 1.1 2019/08/06 15:49:57 claudio Exp $ +# $OpenBSD: as0.sh,v 1.2 2021/01/12 08:59:03 claudio Exp $ set -e @@ -20,7 +20,7 @@ PAIR2IP3=10.12.57.4 error_notify() { echo cleanup pkill -T ${RDOMAIN1} bgpd || true - pkill -T ${RDOMAIN2} exabgp || true + pkill -T ${RDOMAIN2} -f exabgp || true sleep 1 ifconfig ${PAIR2} destroy || true ifconfig ${PAIR1} destroy || true @@ -85,6 +85,7 @@ 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 as0.fifo ] || mkfifo as0.fifo echo run bgpd route -T ${RDOMAIN1} exec ${BGPD} \ @@ -93,11 +94,12 @@ route -T ${RDOMAIN1} exec ${BGPD} \ sleep 1 echo test1 -run_exabgp test1 exabgp.as0.test1.conf > as0.test1.out 2>&1 -grep -q 'error[OPEN message error / Bad Peer AS]' as0.test1.out && echo OK +run_exabgp as0.test1 exabgp.as0.test1.conf > as0.test1.out 2>&1 +grep -q 'error[OPEN message error / Bad Peer AS]' as0.test1.out +echo OK echo test2 -run_exabgp test2 exabgp.as0.test2*.conf > as0.test2.out 2>&1 +run_exabgp as0.test2 exabgp.as0.test2*.conf > as0.test2.out 2>&1 grep 'receive update announced' as0.test2.out | sort | \ diff -u ${BGPDCONFIGDIR}/exabgp.as0.test2.ok /dev/stdin echo OK diff --git a/regress/usr.sbin/bgpd/integrationtests/bgpd.med.conf b/regress/usr.sbin/bgpd/integrationtests/bgpd.med.conf new file mode 100644 index 00000000000..94ad83ad85b --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/bgpd.med.conf @@ -0,0 +1,10 @@ +AS 64500 +router-id 10.12.57.1 +fib-update no + +#rde med compare always + +neighbor 10.12.57.0/29 + +allow from any +allow to any diff --git a/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test1.in b/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test1.in index f81234ecd28..c6c7b2fee4d 100644 --- a/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test1.in +++ b/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test1.in @@ -1,5 +1,5 @@ process reader { - run /bin/sh "##BGPDCONFIGDIR##/api-exabgp.sh"; + run "##OBJDIR##/api-exabgp" -t 10 "##OBJDIR##/as0.fifo"; encoder text; } diff --git a/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2.in b/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2.in index 826b1020985..efbdd06bc2e 100644 --- a/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2.in +++ b/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2.in @@ -1,5 +1,5 @@ process reader { - run /bin/sh "##BGPDCONFIGDIR##/api-exabgp.sh"; + run "##OBJDIR##/api-exabgp" -t 10 "##OBJDIR##/as0.fifo"; encoder text; } @@ -26,3 +26,46 @@ neighbor 10.12.57.1 { } } } + +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.1.0/24 next-hop self ; + route 10.12.2.0/24 next-hop self as-path [ 64502 0 64505 ]; + route 10.12.3.0/24 next-hop self as-path [ 64502 64505 ] aggregator 0:127.0.0.1; + } +} + +neighbor 10.12.57.1 { + router-id 10.12.57.4; + local-address 10.12.57.4; + local-as 64503; + peer-as 64500; + group-updates; + adj-rib-in false; + passive false; + + family { + ipv4 unicast; + } + capability { + asn4 disable; + } + + static { + route 10.13.1.0/24 next-hop self ; + route 10.13.2.0/24 next-hop self attribute [ 0x02 0x40 0x0203fbf75ba0fbf9 ] attribute [ 0x11 0xc0 0x02030000fbf7000000000000fbf9 ]; + route 10.13.3.0/24 next-hop self as-path [ 64503 64505 ] aggregator 23456:127.0.0.1 attribute [ 0x12 0xc0 0x000000007f000001 ]; + } +} diff --git a/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2_2.in b/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2_2.in deleted file mode 100644 index 74f4999dcb7..00000000000 --- a/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2_2.in +++ /dev/null @@ -1,24 +0,0 @@ -process reader { - run /bin/sh "##BGPDCONFIGDIR##/api-exabgp.sh"; - encoder text; -} - -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.1.0/24 next-hop self ; - route 10.12.2.0/24 next-hop self as-path [ 64502 0 64505 ]; - route 10.12.3.0/24 next-hop self as-path [ 64502 64505 ] aggregator 0:127.0.0.1; - } -} diff --git a/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2_3.in b/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2_3.in deleted file mode 100644 index dd5903cf252..00000000000 --- a/regress/usr.sbin/bgpd/integrationtests/exabgp.as0.test2_3.in +++ /dev/null @@ -1,27 +0,0 @@ -process reader { - run /bin/sh "##BGPDCONFIGDIR##/api-exabgp.sh"; - encoder text; -} - -neighbor 10.12.57.1 { - router-id 10.12.57.4; - local-address 10.12.57.4; - local-as 64503; - peer-as 64500; - group-updates; - adj-rib-in false; - passive false; - - family { - ipv4 unicast; - } - capability { - asn4 disable; - } - - static { - route 10.13.1.0/24 next-hop self ; - route 10.13.2.0/24 next-hop self attribute [ 0x02 0x40 0x0203fbf75ba0fbf9 ] attribute [ 0x11 0xc0 0x02030000fbf7000000000000fbf9 ]; - route 10.13.3.0/24 next-hop self as-path [ 64503 64505 ] aggregator 23456:127.0.0.1 attribute [ 0x12 0xc0 0x000000007f000001 ]; - } -} diff --git a/regress/usr.sbin/bgpd/integrationtests/exabgp.med.in b/regress/usr.sbin/bgpd/integrationtests/exabgp.med.in new file mode 100644 index 00000000000..1c6e90a3ebe --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/exabgp.med.in @@ -0,0 +1,61 @@ +process reader { + run "##OBJDIR##/api-exabgp" "##OBJDIR##/med.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; + } +} + +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; + } + + api { + processes [ reader ]; + neighbor-changes; + } +} + +neighbor 10.12.57.1 { + router-id 10.12.57.4; + local-address 10.12.57.4; + local-as 64501; + peer-as 64500; + group-updates; + adj-rib-in false; + passive false; + + family { + ipv4 unicast; + } + + api { + processes [ reader ]; + neighbor-changes; + } +} diff --git a/regress/usr.sbin/bgpd/integrationtests/exabgp.med.ok b/regress/usr.sbin/bgpd/integrationtests/exabgp.med.ok new file mode 100644 index 00000000000..dabf034cbe4 --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/exabgp.med.ok @@ -0,0 +1,9 @@ +flags: * = Valid, > = Selected, I = via IBGP, A = Announced, + S = Stale, E = Error +origin validation state: N = not-found, V = valid, ! = invalid +origin: i = IGP, e = EGP, ? = Incomplete + +flags ovs destination gateway lpref med aspath origin +*> N 10.12.1.0/24 10.12.57.3 100 100 64502 64510 i +* N 10.12.1.0/24 10.12.57.4 100 50 64501 64510 i +* N 10.12.1.0/24 10.12.57.2 100 100 64501 64510 i diff --git a/regress/usr.sbin/bgpd/integrationtests/med.sh b/regress/usr.sbin/bgpd/integrationtests/med.sh new file mode 100644 index 00000000000..43993f4921b --- /dev/null +++ b/regress/usr.sbin/bgpd/integrationtests/med.sh @@ -0,0 +1,150 @@ +#!/bin/ksh +# $OpenBSD: med.sh,v 1.1 2021/01/12 08:59:03 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 +PAIR2IP4=10.12.57.5 + +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 +} + +exacmd() { + echo "${1+"$@"}" > med.fifo + sleep .1 # give exabgp a bit of time +} + +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 ${PAIR2} alias ${PAIR2IP4}/32 +ifconfig ${PAIR1} patch ${PAIR2} +ifconfig lo${RDOMAIN1} inet 127.0.0.1/8 +ifconfig lo${RDOMAIN2} inet 127.0.0.1/8 + +[ -p med.fifo ] || mkfifo med.fifo + +echo run bgpd +route -T ${RDOMAIN1} exec ${BGPD} \ + -v -f ${BGPDCONFIGDIR}/bgpd.med.conf + +sleep 1 + +echo run exabgp +run_exabgp med exabgp.med.conf & +sleep 2 + +echo test 1 + +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.12.1.0/24 next-hop self as-path [ 64501 64510 ] med 100' +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.12.1.0/24 next-hop self as-path [ 64502 64510 ] med 100' +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.4 announce route 10.12.1.0/24 next-hop self as-path [ 64501 64510 ] med 50' + +sleep 5 +route -T ${RDOMAIN1} exec bgpctl sh rib | tee med.out +sleep .2 +diff -u ${BGPDCONFIGDIR}/exabgp.med.ok med.out +echo OK + +exacmd 'clear adj-rib out all peers' + +echo test 2 + +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.4 announce route 10.12.1.0/24 next-hop self as-path [ 64501 64510 ] med 50' +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.12.1.0/24 next-hop self as-path [ 64502 64510 ] med 100' +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.12.1.0/24 next-hop self as-path [ 64501 64510 ] med 100' + +sleep 5 +route -T ${RDOMAIN1} exec bgpctl sh rib | tee med.out +sleep .2 +diff -u ${BGPDCONFIGDIR}/exabgp.med.ok med.out +echo OK + +exacmd 'clear adj-rib out all peers' + +echo test 3 + +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.12.1.0/24 next-hop self as-path [ 64501 64510 ] med 100' +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.4 announce route 10.12.1.0/24 next-hop self as-path [ 64501 64510 ] med 50' +exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.12.1.0/24 next-hop self as-path [ 64502 64510 ] med 100' + +sleep 5 +route -T ${RDOMAIN1} exec bgpctl sh rib | tee med.out +sleep .2 +diff -u ${BGPDCONFIGDIR}/exabgp.med.ok med.out +echo OK + +exacmd 'shutdown' + +exit 0 |