From f5fd41404eb13b077b472349769144860471d3a4 Mon Sep 17 00:00:00 2001 From: benno Date: Mon, 10 Sep 2018 20:51:59 +0000 Subject: [PATCH] check orlonger option of trie_match() --- regress/usr.sbin/bgpd/unittests/Makefile | 4 +- .../bgpd/unittests/rde_trie_test.1.out | 22 +- .../bgpd/unittests/rde_trie_test.2.out | 28 +- .../bgpd/unittests/rde_trie_test.3.out | 286 +++++++++--------- .../usr.sbin/bgpd/unittests/rde_trie_test.c | 36 ++- 5 files changed, 194 insertions(+), 182 deletions(-) diff --git a/regress/usr.sbin/bgpd/unittests/Makefile b/regress/usr.sbin/bgpd/unittests/Makefile index 13bb1c2bb02..2a44d4eb99a 100644 --- a/regress/usr.sbin/bgpd/unittests/Makefile +++ b/regress/usr.sbin/bgpd/unittests/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.2 2018/09/07 16:10:42 claudio Exp $ +# $OpenBSD: Makefile,v 1.3 2018/09/10 20:51:59 benno Exp $ .PATH: ${.CURDIR}/../../../../usr.sbin/bgpd @@ -18,7 +18,7 @@ run-regress-rde_sets_test: rde_sets_test ./rde_sets_test SRCS_rde_trie_test= rde_trie_test.c rde_trie.c util.c rde_sets.c -TRIE_TESTS=1 2 3 +TRIE_TESTS=1 2 3 4 .for n in ${TRIE_TESTS} TRIE_TARGETS+=run-regress-rde_trie_test-${n} diff --git a/regress/usr.sbin/bgpd/unittests/rde_trie_test.1.out b/regress/usr.sbin/bgpd/unittests/rde_trie_test.1.out index fa21570ddfa..0509ef3b266 100644 --- a/regress/usr.sbin/bgpd/unittests/rde_trie_test.1.out +++ b/regress/usr.sbin/bgpd/unittests/rde_trie_test.1.out @@ -1,11 +1,11 @@ -62.48.0.0/19 MATCH -62.48.0.0/18 miss -62.48.0.0/20 miss -62.48.3.0/24 MATCH -62.48.2.0/24 miss -62.48.2.0/25 MATCH -62.48.2.0/26 MATCH -10.0.0.0/8 MATCH -10.0.0.0/24 MATCH -192.168.3.0/24 miss -192.168.3.66/30 MATCH +62.48.0.0/19 MATCH 0 +62.48.0.0/18 miss 0 +62.48.0.0/20 miss 0 +62.48.3.0/24 MATCH 0 +62.48.2.0/24 miss 0 +62.48.2.0/25 MATCH 0 +62.48.2.0/26 MATCH 0 +10.0.0.0/8 MATCH 0 +10.0.0.0/24 MATCH 0 +192.168.3.0/24 miss 0 +192.168.3.66/30 MATCH 0 diff --git a/regress/usr.sbin/bgpd/unittests/rde_trie_test.2.out b/regress/usr.sbin/bgpd/unittests/rde_trie_test.2.out index b7f4a74977f..1351b043764 100644 --- a/regress/usr.sbin/bgpd/unittests/rde_trie_test.2.out +++ b/regress/usr.sbin/bgpd/unittests/rde_trie_test.2.out @@ -1,14 +1,14 @@ -46.21.0.0/20 MATCH -87.253.240.0/20 MATCH -185.108.8.0/22 MATCH -193.41.124.0/23 MATCH -195.110.26.0/23 MATCH -213.135.192.0/21 MATCH -2a01:7f8::/32 MATCH -199.185.136.0/23 miss -199.185.178.0/24 miss -199.185.230.0/23 miss -204.174.115.0/24 miss -204.209.252.0/24 miss -204.209.253.0/24 miss -2620:3d:c000::/48 miss +46.21.0.0/20 MATCH 0 +87.253.240.0/20 MATCH 0 +185.108.8.0/22 MATCH 0 +193.41.124.0/23 MATCH 0 +195.110.26.0/23 MATCH 0 +213.135.192.0/21 MATCH 0 +2a01:7f8::/32 MATCH 0 +199.185.136.0/23 miss 0 +199.185.178.0/24 miss 0 +199.185.230.0/23 miss 0 +204.174.115.0/24 miss 0 +204.209.252.0/24 miss 0 +204.209.253.0/24 miss 0 +2620:3d:c000::/48 miss 0 diff --git a/regress/usr.sbin/bgpd/unittests/rde_trie_test.3.out b/regress/usr.sbin/bgpd/unittests/rde_trie_test.3.out index 047d9a4ce2b..be5da1a3d35 100644 --- a/regress/usr.sbin/bgpd/unittests/rde_trie_test.3.out +++ b/regress/usr.sbin/bgpd/unittests/rde_trie_test.3.out @@ -1,143 +1,143 @@ -82.130.64.0/18 MATCH -86.119.0.0/16 MATCH -89.206.64.0/18 MATCH -128.178.0.0/15 MATCH -129.129.0.0/16 MATCH -129.132.0.0/16 MATCH -129.194.0.0/15 MATCH -130.59.0.0/16 MATCH -130.60.0.0/16 MATCH -130.82.0.0/16 MATCH -130.92.0.0/16 MATCH -130.125.0.0/16 MATCH -130.223.0.0/16 MATCH -131.152.0.0/16 MATCH -134.21.0.0/16 MATCH -138.131.0.0/16 MATCH -141.249.0.0/16 MATCH -144.200.0.0/16 MATCH -146.136.0.0/16 MATCH -147.86.0.0/16 MATCH -147.87.0.0/16 MATCH -147.88.0.0/16 MATCH -148.187.0.0/16 MATCH -148.196.0.0/16 MATCH -152.88.0.0/16 MATCH -152.96.0.0/16 MATCH -153.109.0.0/16 MATCH -155.105.0.0/16 MATCH -155.228.0.0/16 MATCH -156.25.0.0/16 MATCH -156.135.0.0/21 MATCH -156.135.12.0/22 MATCH -156.135.16.0/21 MATCH -156.135.28.0/22 MATCH -156.135.32.0/19 MATCH -156.135.64.0/18 MATCH -156.135.128.0/17 MATCH -157.26.0.0/16 MATCH -160.85.0.0/16 MATCH -160.98.0.0/16 MATCH -161.62.0.0/16 MATCH -185.51.68.0/22 MATCH -185.133.44.0/22 MATCH -185.144.36.0/22 MATCH -185.194.180.0/22 MATCH -185.225.92.0/22 MATCH -192.12.247.0/24 MATCH -192.26.28.0/22 MATCH -192.26.32.0/21 MATCH -192.26.40.0/22 MATCH -192.26.44.0/24 MATCH -192.26.46.0/23 MATCH -192.33.87.0/24 MATCH -192.33.88.0/21 MATCH -192.33.96.0/21 MATCH -192.33.104.0/22 MATCH -192.33.108.0/23 MATCH -192.33.110.0/24 MATCH -192.33.118.0/23 MATCH -192.33.120.0/21 MATCH -192.33.192.0/19 MATCH -192.33.224.0/21 MATCH -192.41.132.0/22 MATCH -192.41.136.0/24 MATCH -192.41.149.0/24 MATCH -192.41.150.0/23 MATCH -192.41.152.0/21 MATCH -192.41.160.0/24 MATCH -192.42.42.0/23 MATCH -192.42.44.0/22 MATCH -192.42.180.0/22 MATCH -192.42.184.0/21 MATCH -192.42.192.0/21 MATCH -192.42.200.0/23 MATCH -192.43.192.0/22 MATCH -192.43.196.0/24 MATCH -192.47.244.0/22 MATCH -192.47.248.0/23 MATCH -192.65.92.0/23 MATCH -192.101.176.0/24 MATCH -192.135.150.0/23 MATCH -192.135.151.0/24 MATCH -192.135.152.0/21 MATCH -192.152.98.0/24 MATCH -193.5.22.0/24 MATCH -193.5.26.0/23 MATCH -193.5.54.0/23 MATCH -193.5.58.0/24 MATCH -193.5.60.0/24 MATCH -193.5.80.0/21 MATCH -193.5.152.0/22 MATCH -193.5.168.0/22 MATCH -193.5.180.0/24 MATCH -193.5.182.0/24 MATCH -193.5.186.0/24 MATCH -193.5.188.0/24 MATCH -193.8.136.0/23 MATCH -193.36.32.0/24 MATCH -193.73.125.0/24 MATCH -193.134.200.0/21 MATCH -193.134.216.0/21 MATCH -193.135.168.0/22 MATCH -193.135.172.0/24 MATCH -193.135.240.0/21 MATCH -193.138.69.0/24 MATCH -193.222.112.0/20 MATCH -193.222.241.0/24 MATCH -193.222.242.0/23 MATCH -193.222.244.0/22 MATCH -193.222.248.0/23 MATCH -193.222.250.0/24 MATCH -193.246.121.0/24 MATCH -193.246.124.0/23 MATCH -193.246.176.0/20 MATCH -193.247.190.0/23 MATCH -193.247.203.0/24 MATCH -193.247.240.0/22 MATCH -193.247.248.0/23 MATCH -193.247.254.0/24 MATCH -194.153.96.0/24 MATCH -195.176.0.0/17 MATCH -195.176.160.0/19 MATCH -195.176.224.0/19 MATCH -198.21.18.0/24 miss -2001:620::/29 MATCH -2001:620::/32 MATCH -2001:678:678::/48 MATCH -2001:67c:10ec::/48 MATCH -2001:67c:13c0::/48 MATCH -2001:67c:16dc::/48 MATCH -2a02:7dc0::/32 MATCH -2a07:290a::/32 MATCH -2a07:3e00::/29 MATCH -2a07:6b40::/29 MATCH -2a0a:4ec0::/29 MATCH -2a0b:2040::/29 MATCH -199.185.136.0/23 miss -199.185.178.0/24 miss -199.185.230.0/23 miss -204.174.115.0/24 miss -204.209.252.0/24 miss -204.209.253.0/24 miss -2620:3d:c000::/48 miss +82.130.64.0/18 MATCH 0 +86.119.0.0/16 MATCH 0 +89.206.64.0/18 MATCH 0 +128.178.0.0/15 MATCH 0 +129.129.0.0/16 MATCH 0 +129.132.0.0/16 MATCH 0 +129.194.0.0/15 MATCH 0 +130.59.0.0/16 MATCH 0 +130.60.0.0/16 MATCH 0 +130.82.0.0/16 MATCH 0 +130.92.0.0/16 MATCH 0 +130.125.0.0/16 MATCH 0 +130.223.0.0/16 MATCH 0 +131.152.0.0/16 MATCH 0 +134.21.0.0/16 MATCH 0 +138.131.0.0/16 MATCH 0 +141.249.0.0/16 MATCH 0 +144.200.0.0/16 MATCH 0 +146.136.0.0/16 MATCH 0 +147.86.0.0/16 MATCH 0 +147.87.0.0/16 MATCH 0 +147.88.0.0/16 MATCH 0 +148.187.0.0/16 MATCH 0 +148.196.0.0/16 MATCH 0 +152.88.0.0/16 MATCH 0 +152.96.0.0/16 MATCH 0 +153.109.0.0/16 MATCH 0 +155.105.0.0/16 MATCH 0 +155.228.0.0/16 MATCH 0 +156.25.0.0/16 MATCH 0 +156.135.0.0/21 MATCH 0 +156.135.12.0/22 MATCH 0 +156.135.16.0/21 MATCH 0 +156.135.28.0/22 MATCH 0 +156.135.32.0/19 MATCH 0 +156.135.64.0/18 MATCH 0 +156.135.128.0/17 MATCH 0 +157.26.0.0/16 MATCH 0 +160.85.0.0/16 MATCH 0 +160.98.0.0/16 MATCH 0 +161.62.0.0/16 MATCH 0 +185.51.68.0/22 MATCH 0 +185.133.44.0/22 MATCH 0 +185.144.36.0/22 MATCH 0 +185.194.180.0/22 MATCH 0 +185.225.92.0/22 MATCH 0 +192.12.247.0/24 MATCH 0 +192.26.28.0/22 MATCH 0 +192.26.32.0/21 MATCH 0 +192.26.40.0/22 MATCH 0 +192.26.44.0/24 MATCH 0 +192.26.46.0/23 MATCH 0 +192.33.87.0/24 MATCH 0 +192.33.88.0/21 MATCH 0 +192.33.96.0/21 MATCH 0 +192.33.104.0/22 MATCH 0 +192.33.108.0/23 MATCH 0 +192.33.110.0/24 MATCH 0 +192.33.118.0/23 MATCH 0 +192.33.120.0/21 MATCH 0 +192.33.192.0/19 MATCH 0 +192.33.224.0/21 MATCH 0 +192.41.132.0/22 MATCH 0 +192.41.136.0/24 MATCH 0 +192.41.149.0/24 MATCH 0 +192.41.150.0/23 MATCH 0 +192.41.152.0/21 MATCH 0 +192.41.160.0/24 MATCH 0 +192.42.42.0/23 MATCH 0 +192.42.44.0/22 MATCH 0 +192.42.180.0/22 MATCH 0 +192.42.184.0/21 MATCH 0 +192.42.192.0/21 MATCH 0 +192.42.200.0/23 MATCH 0 +192.43.192.0/22 MATCH 0 +192.43.196.0/24 MATCH 0 +192.47.244.0/22 MATCH 0 +192.47.248.0/23 MATCH 0 +192.65.92.0/23 MATCH 0 +192.101.176.0/24 MATCH 0 +192.135.150.0/23 MATCH 0 +192.135.151.0/24 MATCH 0 +192.135.152.0/21 MATCH 0 +192.152.98.0/24 MATCH 0 +193.5.22.0/24 MATCH 0 +193.5.26.0/23 MATCH 0 +193.5.54.0/23 MATCH 0 +193.5.58.0/24 MATCH 0 +193.5.60.0/24 MATCH 0 +193.5.80.0/21 MATCH 0 +193.5.152.0/22 MATCH 0 +193.5.168.0/22 MATCH 0 +193.5.180.0/24 MATCH 0 +193.5.182.0/24 MATCH 0 +193.5.186.0/24 MATCH 0 +193.5.188.0/24 MATCH 0 +193.8.136.0/23 MATCH 0 +193.36.32.0/24 MATCH 0 +193.73.125.0/24 MATCH 0 +193.134.200.0/21 MATCH 0 +193.134.216.0/21 MATCH 0 +193.135.168.0/22 MATCH 0 +193.135.172.0/24 MATCH 0 +193.135.240.0/21 MATCH 0 +193.138.69.0/24 MATCH 0 +193.222.112.0/20 MATCH 0 +193.222.241.0/24 MATCH 0 +193.222.242.0/23 MATCH 0 +193.222.244.0/22 MATCH 0 +193.222.248.0/23 MATCH 0 +193.222.250.0/24 MATCH 0 +193.246.121.0/24 MATCH 0 +193.246.124.0/23 MATCH 0 +193.246.176.0/20 MATCH 0 +193.247.190.0/23 MATCH 0 +193.247.203.0/24 MATCH 0 +193.247.240.0/22 MATCH 0 +193.247.248.0/23 MATCH 0 +193.247.254.0/24 MATCH 0 +194.153.96.0/24 MATCH 0 +195.176.0.0/17 MATCH 0 +195.176.160.0/19 MATCH 0 +195.176.224.0/19 MATCH 0 +198.21.18.0/24 miss 0 +2001:620::/29 MATCH 0 +2001:620::/32 MATCH 0 +2001:678:678::/48 MATCH 0 +2001:67c:10ec::/48 MATCH 0 +2001:67c:13c0::/48 MATCH 0 +2001:67c:16dc::/48 MATCH 0 +2a02:7dc0::/32 MATCH 0 +2a07:290a::/32 MATCH 0 +2a07:3e00::/29 MATCH 0 +2a07:6b40::/29 MATCH 0 +2a0a:4ec0::/29 MATCH 0 +2a0b:2040::/29 MATCH 0 +199.185.136.0/23 miss 0 +199.185.178.0/24 miss 0 +199.185.230.0/23 miss 0 +204.174.115.0/24 miss 0 +204.209.252.0/24 miss 0 +204.209.253.0/24 miss 0 +2620:3d:c000::/48 miss 0 diff --git a/regress/usr.sbin/bgpd/unittests/rde_trie_test.c b/regress/usr.sbin/bgpd/unittests/rde_trie_test.c index f4d3fd50f6f..5b5bc368687 100644 --- a/regress/usr.sbin/bgpd/unittests/rde_trie_test.c +++ b/regress/usr.sbin/bgpd/unittests/rde_trie_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_trie_test.c,v 1.2 2018/09/09 12:39:51 claudio Exp $ */ +/* $OpenBSD: rde_trie_test.c,v 1.3 2018/09/10 20:51:59 benno Exp $ */ /* * Copyright (c) 2018 Claudio Jeker @@ -32,7 +32,7 @@ static int -host_v4(const char *s, struct bgpd_addr *h, u_int8_t *len) +host_v4(const char *s, struct bgpd_addr *h, u_int8_t *len, int *orl) { struct in_addr ina = { 0 }; int bits = 32; @@ -52,13 +52,14 @@ host_v4(const char *s, struct bgpd_addr *h, u_int8_t *len) } static int -host_v6(char *s, struct bgpd_addr *h, u_int8_t *len) +host_v6(const char *s, struct bgpd_addr *h, u_int8_t *len, int *orl) { struct addrinfo hints, *res; const char *errstr; char *p; int mask = 128; + memset(h, 0, sizeof(*h)); if ((p = strrchr(s, '/')) != NULL) { mask = strtonum(p + 1, 0, 128, &errstr); if (errstr) @@ -84,11 +85,21 @@ host_v6(char *s, struct bgpd_addr *h, u_int8_t *len) } static int -host_l(char *s, struct bgpd_addr *h, u_int8_t *len) +host_l(char *s, struct bgpd_addr *h, u_int8_t *len, int *orl) { - if (host_v4(s, h, len)) + char *c, *t; + + *orl = 0; + if ((c = strchr(s, '\t')) != NULL) { + if (c[1] == '1') { + *orl = 1; + } + *c = '\0'; + } + + if (host_v4(s, h, len, orl)) return (1); - if (host_v6(s, h, len)) + if (host_v6(s, h, len, orl)) return (1); return (0); } @@ -117,7 +128,7 @@ parse_file(FILE *in, struct trie_head *th) char *line, *s; struct bgpd_addr prefix; u_int8_t plen, min, max, maskmax; - + int foo; while ((line = fparseln(in, NULL, NULL, NULL, FPARSELN_UNESCALL))) { int state = 0; @@ -126,7 +137,7 @@ parse_file(FILE *in, struct trie_head *th) break; switch (state) { case 0: - if (!host_l(s, &prefix, &plen)) + if (!host_l(s, &prefix, &plen, &foo)) errx(1, "could not parse prefix \"%s\"", s); break; @@ -168,15 +179,16 @@ test_file(FILE *in, struct trie_head *th) char *line; struct bgpd_addr prefix; u_int8_t plen; + int orlonger; while ((line = fparseln(in, NULL, NULL, NULL, FPARSELN_UNESCALL))) { - if (!host_l(line, &prefix, &plen)) + if (!host_l(line, &prefix, &plen, &orlonger)) errx(1, "could not parse prefix \"%s\"", line); printf("%s ", line); - if (trie_match(th, &prefix, plen, 0)) - printf("MATCH\n"); + if (trie_match(th, &prefix, plen, orlonger)) + printf("MATCH %i\n", orlonger); else - printf("miss\n"); + printf("miss %i\n", orlonger); free(line); } } -- 2.20.1