diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2019-06-17 13:13:04 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2019-06-17 13:13:04 +0000 |
commit | 9571b84f0523691e47de11c4ad6906fe6e791418 (patch) | |
tree | b5e6a4c91f9bb887015558d36b9ce09789b103e3 /regress | |
parent | 0d1055153c82cdd73785c1db1d033dc8be551259 (diff) |
Add unit test for new community functions. Should cover the basics.
Diffstat (limited to 'regress')
-rw-r--r-- | regress/usr.sbin/bgpd/unittests/Makefile | 7 | ||||
-rw-r--r-- | regress/usr.sbin/bgpd/unittests/rde_community_test.c | 232 | ||||
-rw-r--r-- | regress/usr.sbin/bgpd/unittests/rde_community_test.h | 522 |
3 files changed, 760 insertions, 1 deletions
diff --git a/regress/usr.sbin/bgpd/unittests/Makefile b/regress/usr.sbin/bgpd/unittests/Makefile index 4dd5071a678..a1184812b9c 100644 --- a/regress/usr.sbin/bgpd/unittests/Makefile +++ b/regress/usr.sbin/bgpd/unittests/Makefile @@ -1,9 +1,10 @@ -# $OpenBSD: Makefile,v 1.4 2018/09/18 15:15:32 claudio Exp $ +# $OpenBSD: Makefile,v 1.5 2019/06/17 13:13:03 claudio Exp $ .PATH: ${.CURDIR}/../../../../usr.sbin/bgpd PROGS += rde_sets_test PROGS += rde_trie_test +PROGS += rde_community_test . for p in ${PROGS} REGRESS_TARGETS += run-regress-$p @@ -33,4 +34,8 @@ run-regress-rde_trie_test-${n}: rde_trie_test run-regress-rde_trie_test: ${TRIE_TARGETS} +SRCS_rde_community_test= rde_community_test.c rde_community.c +run-regress-rde_community_test: rde_community_test + ./rde_community_test + .include <bsd.regress.mk> diff --git a/regress/usr.sbin/bgpd/unittests/rde_community_test.c b/regress/usr.sbin/bgpd/unittests/rde_community_test.c new file mode 100644 index 00000000000..94092822a58 --- /dev/null +++ b/regress/usr.sbin/bgpd/unittests/rde_community_test.c @@ -0,0 +1,232 @@ +/* $OpenBSD: rde_community_test.c,v 1.1 2019/06/17 13:13:03 claudio Exp $ */ + +/* + * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "rde.h" +#include "log.h" + +#include "rde_community_test.h" + +struct rde_memstats rdemem; +struct rde_community comm; +struct rde_peer peer = { + .conf.remote_as = 22512, + .conf.local_as = 42, +}; + +static void +dump(uint8_t *b, size_t len) +{ + size_t l; + + printf("\n\t{\n\t\t.data = \""); + for (l = 0; l < len; l++) { + printf("\\x%02x", b[l]); + if (l % 12 == 0 && l != 0) + printf("\"\n\t\t \""); + } + printf("\",\n\t\t.size = %zu\n\t},\n", len); +} + +static int +test_parsing(size_t num, uint8_t *in, size_t inlen) +{ + const char *func = "community"; + uint8_t flags, type, attr[256]; + size_t skip = 2; + uint16_t attr_len; + int r; + + communities_clean(&comm); + + flags = in[0]; + type = in[1]; + if (flags & ATTR_EXTLEN) { + memcpy(&attr_len, in + 2, sizeof(attr_len)); + attr_len = ntohs(attr_len); + skip += 2; + } else { + attr_len = in[2]; + skip += 1; + } + + switch (type) { + case ATTR_COMMUNITIES: + r = community_add(&comm, flags, in + skip, attr_len); + break; + case ATTR_EXT_COMMUNITIES: + r = community_ext_add(&comm, flags, in + skip, attr_len); + break; + case ATTR_LARGE_COMMUNITIES: + r = community_large_add(&comm, flags, in + skip, attr_len); + break; + } + if (r == -1) { + printf("Test %zu: %s_add failed\n", num, func); + return -1; + } + + switch (type) { + case ATTR_COMMUNITIES: + r = community_write(&comm, attr, sizeof(attr)); + break; + case ATTR_EXT_COMMUNITIES: + r = community_ext_write(&comm, 0, attr, sizeof(attr)); + break; + case ATTR_LARGE_COMMUNITIES: + r = community_large_write(&comm, attr, sizeof(attr)); + break; + } + + if (r != inlen) { + printf("Test %zu: %s_write return value %d != %zd\n", + num, func, r, inlen); + return -1; + } + if (r != -1 && memcmp(attr, in, inlen) != 0) { + printf("Test %zu: %s_write unexpected encoding: ", num, func); + dump(attr, inlen); + printf("expected: "); + dump(in, inlen); + return -1; + } + + return 0; +} + +static int +test_filter(size_t num, struct testfilter *f) +{ + size_t l; + int r; + + communities_clean(&comm); + for (l = 0; f->in[l] != -1; l++) { + r = community_set(&comm, &filters[f->in[l]], &peer); + if (r != 1) { + printf("Test %zu: community_set %zu " + "unexpected return %d != 1\n", + num, l, r); + return -1; + } + } + + r = community_match(&comm, &filters[f->match], &peer); + if (r != f->mout) { + printf("Test %zu: community_match " + "unexpected return %d != %d\n", num, r, f->mout); + return -1; + } + + if (f->delete == -1) + return 0; + + community_delete(&comm, &filters[f->delete], &peer); + + if (community_match(&comm, &filters[f->delete], &peer) != 0) { + printf("Test %zu: community_delete still around\n", num); + return -1; + } + + return 0; +} + +int +main(int argc, char *argv[]) +{ + size_t t; + int error = 0; + + for (t = 0; t < sizeof(vectors) / sizeof(*vectors); t++) { + if (test_parsing(t, vectors[t].data, vectors[t].size) == -1) + error = 1; + } + + for (t = 0; t < sizeof(testfilters) / sizeof(*testfilters); t++) { + if (test_filter(t, &testfilters[t]) == -1) + error = 1; + } + + if (!error) + printf("OK\n"); + return error; +} + +__dead void +fatalx(const char *emsg, ...) +{ + va_list ap; + va_start(ap, emsg); + verrx(2, emsg, ap); +} + +__dead void +fatal(const char *emsg, ...) +{ + va_list ap; + va_start(ap, emsg); + verr(2, emsg, ap); +} + +void +log_warnx(const char *emsg, ...) +{ + va_list ap; + va_start(ap, emsg); + vwarnx(emsg, ap); + va_end(ap); +} + +int +attr_write(void *p, u_int16_t p_len, u_int8_t flags, u_int8_t type, + void *data, u_int16_t data_len) +{ + u_char *b = p; + u_int16_t tmp, tot_len = 2; /* attribute header (without len) */ + + flags &= ~ATTR_DEFMASK; + if (data_len > 255) { + tot_len += 2 + data_len; + flags |= ATTR_EXTLEN; + } else { + tot_len += 1 + data_len; + } + + if (tot_len > p_len) + return (-1); + + *b++ = flags; + *b++ = type; + if (data_len > 255) { + tmp = htons(data_len); + memcpy(b, &tmp, sizeof(tmp)); + b += 2; + } else + *b++ = (u_char)data_len; + + if (data == NULL) + return (tot_len - data_len); + + if (data_len != 0) + memcpy(b, data, data_len); + + return (tot_len); +} diff --git a/regress/usr.sbin/bgpd/unittests/rde_community_test.h b/regress/usr.sbin/bgpd/unittests/rde_community_test.h new file mode 100644 index 00000000000..cd575fdc529 --- /dev/null +++ b/regress/usr.sbin/bgpd/unittests/rde_community_test.h @@ -0,0 +1,522 @@ +struct vector { + uint8_t *data; + size_t size; +} vectors[] = { + + { + .data = "\xc0\x08\x04\x00\x00\x48\xce", + .size = 7 + }, + { + .data = "\xc0\x08\x04\x0f\x10\xc8\x02", + .size = 7 + }, + { + .data = "\xc0\x08\x04\x3b\xc0\x00\xc9", + .size = 7 + }, + { + .data = "\xe0\x08\x04\x4e\x97\x00\x03", + .size = 7 + }, + { + .data = "\xe0\x08\x08\x3b\xc0\x00\xc9\x3b\xc0\x00\xcb", + .size = 11 + }, + { + .data = "\xc0\x08\x08\x9e\x19\x7a\x44\x9e\x19\x7a\x45", + .size = 11 + }, + { + .data = "\xc0\x08\x14\x00\x00\x0b\x5a\x00\x00\x3f\x89\x00\x00" + "\x3f\x94\x00\x00\x48\xce\x00\x00\xa2\xda", + .size = 23 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x00\x40", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x00\x42", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x00\xb2", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x00\xd3", + .size = 11 + }, + { + .data = "\xe0\x10\x08\x00\x02\xfc\x00\x00\x00\x01\x10", + .size = 11 + }, + { + .data = "\xe0\x10\x08\x00\x02\xfc\x00\x00\x00\x01\x1e", + .size = 11 + }, + { + .data = "\xe0\x10\x08\x00\x02\xfc\x00\x00\x00\x01\x29", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x01\xb6", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x01\xe0", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x02\x8b", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x02\xc5", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x03\xc2", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x04\x09", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x04\xe4", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x05\x57", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfc\x00\x00\x00\x05\x92", + .size = 11 + }, + { + .data = "\xc0\x10\x08\x00\x02\xfd\xe8\x00\x00\x2a\xf8", + .size = 11 + }, + { + .data = "\xc0\x20\x18\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03", + .size = 27 + }, + { + .data = "\xe0\x20\x24\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x00\xed\x5f\x00\x00\xed\x5f\x00\x00" + "\xed\x5f", + .size = 39 + }, + { + .data = "\xe0\x20\x24\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x16\x49\x00\x03\x16\x49\x00\x00" + "\x00\x64", + .size = 39 + }, + { + .data = "\xe0\x20\x24\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x16\xa9\x00\x03\x16\xa9\x00\x00" + "\x00\x00", + .size = 39 + }, + { + .data = "\xe0\x20\x24\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x24\x92\x00\x00\x00\x03\x00\x00" + "\x00\x01", + .size = 39 + }, + { + .data = "\xe0\x20\x24\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x25\x4b\x00\x00\x00\xc8\x00\x00" + "\x00\x00", + .size = 39 + }, + { + .data = "\xe0\x20\x24\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x26\x8f\x00\x00\x01\x2c\x00\x00" + "\x00\x00", + .size = 39 + }, + { + .data = "\xe0\x20\x24\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x26\xa3\x00\x00\x02\x58\x00\x03" + "\x26\xa3", + .size = 39 + }, + { + .data = "\xe0\x20\x24\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x33\xc8\x00\x00\x07\xd0\x00\x00" + "\x00\x1e", + .size = 39 + }, + { + .data = "\xe0\x20\x30\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x00\xdf\x1e\x00\x00\x00\x1e\x00\x00" + "\x00\x00\x00\x00\xdf\x1e\x00\x00\x00\x1e\x00\x00" + "\x00\x0a", + .size = 51 + }, + { + .data = "\xe0\x20\x30\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x1c\xe3\x00\x00\x00\x01\x00\x00" + "\x00\x00\x00\x03\x1c\xe3\x00\x00\x00\x01\x00\x00" + "\x00\x02", + .size = 51 + }, + { + .data = "\xe0\x20\x30\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x26\xa3\x00\x00\x02\x58\x00\x03" + "\x26\xa3\x00\x03\x26\xa3\x00\x03\x26\xa3\x00\x00" + "\x00\xc8", + .size = 51 + }, + { + .data = "\xe0\x20\x30\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x27\xdd\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x03\x27\xdd\x00\x00\x00\x00\x00\x00" + "\x23\x49", + .size = 51 + }, + { + .data = "\xe0\x20\x30\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x27\xdd\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x03\x27\xdd\x00\x00\x00\x00\x00\x00" + "\xc2\x51", + .size = 51 + }, + { + .data = "\xe0\x20\x30\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x28\xe8\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x03\x28\xe8\x00\x00\x00\x01\x00\x00" + "\x00\x00", + .size = 51 + }, + { + .data = "\xe0\x20\x3c\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x02\x1a\xcd\x00\x00\xfc\x00\x00\x00" + "\x00\x0b\x00\x02\x1a\xcd\x00\x00\xfc\x00\x00\x00" + "\x00\x15\x00\x02\x1a\xcd\x00\x00\xff\xed\x00\x00" + "\x00\x01", + .size = 63 + }, + { + .data = "\xe0\x20\x3c\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x16\xa9\x00\x00\x00\x00\x00\x03" + "\x35\x3a\x00\x03\x16\xa9\x00\x03\x16\xa9\x00\x00" + "\x00\x00\x00\x03\x26\xa3\x00\x03\x26\xa3\x00\x00" + "\x03\x84", + .size = 63 + }, + { + .data = "\xe0\x20\x3c\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x16\xa9\x00\x03\x16\xa9\x00\x03" + "\x16\xa9\x00\x03\x26\xa3\x00\x00\x01\x2c\x00\x00" + "\x03\xe7\x00\x03\x26\xa3\x00\x00\x02\x58\x00\x03" + "\x26\xa3", + .size = 63 + }, + { + .data = "\xe0\x20\xb4\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x01\x00\x00\xd0\x5b\x00\x00\x00\x0b\x00\x00" + "\x00\x03\x00\x03\x22\xd3\x00\x00\x00\x0a\x00\x00" + "\x00\x0a\x00\x03\x22\xd3\x00\x00\x00\x0a\x00\x00" + "\x00\xc9\x00\x03\x22\xd3\x00\x00\x00\x0a\x00\x00" + "\x00\xca\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\x0b\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\x64\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\x65\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\x66\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\x67\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\x68\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\xc8\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\xcf\x00\x03\x22\xd3\x00\x00\x00\x14\x00\x00" + "\x00\xd0\x00\x03\x22\xd3\x00\x00\x00\x79\x00\x00" + "\x00\x00", + .size = 183 + } +}; + +struct community filters[] = { + { /* 0 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = COMMUNITY_WELLKNOWN, + .data2 = COMMUNITY_NO_ADVERTISE + }, + { /* 1 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = COMMUNITY_WELLKNOWN, + .data2 = COMMUNITY_NO_EXPORT + }, + { /* 2 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = COMMUNITY_WELLKNOWN, + .data2 = COMMUNITY_NO_EXPSUBCONFED + }, + { /* 3 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = 22512, + .data2 = 1 + }, + { /* 4 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = 22512, + .data2 = 42 + }, + { /* 5 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = 22512, + .data2 = 65366 + }, + { /* 6 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = 1, + .data2 = 22512 + }, + { /* 7 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = 42, + .data2 = 22512 + }, + { /* 8 */ + .flags = COMMUNITY_TYPE_BASIC, + .data1 = 65366, + .data2 = 22512 + }, + { /* 9 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 22512, + .data2 = 22512, + .data3 = 22512 + }, + { /* 10 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 22512, + .data2 = 42, + .data3 = 22512 + }, + { /* 11 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 22512, + .data2 = 42, + .data3 = 42 + }, + { /* 12 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 42, + .data2 = 22512, + .data3 = 22512 + }, + { /* 13 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 42, + .data2 = 42, + .data3 = 22512 + }, + { /* 14 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 42, + .data2 = 22512, + .data3 = 42 + }, + { /* 15 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 65366, + .data2 = 22512, + .data3 = 22512 + }, + { /* 16 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 22512, + .data2 = 65366, + .data3 = 22512 + }, + { /* 17 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 22512, + .data2 = 65366, + .data3 = 65366 + }, + { /* 18 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 42, + .data2 = 42, + .data3 = 42 + }, + { /* 19 */ + .flags = COMMUNITY_TYPE_LARGE, + .data1 = 65366, + .data2 = 65366, + .data3 = 65366 + }, + { /* 20 */ + .flags = COMMUNITY_TYPE_BASIC | (COMMUNITY_ANY << 16), + .data1 = COMMUNITY_WELLKNOWN, + }, + { /* 21 */ + .flags = COMMUNITY_TYPE_BASIC | (COMMUNITY_ANY << 16), + .data1 = 22512, + }, + { /* 22 */ + .flags = COMMUNITY_TYPE_BASIC | (COMMUNITY_ANY << 8), + .data2 = 22512 + }, + { /* 23 */ + .flags = COMMUNITY_TYPE_LARGE | (COMMUNITY_ANY << 8) | + (COMMUNITY_ANY << 16) | (COMMUNITY_ANY << 24), + }, + { /* 24 */ + .flags = COMMUNITY_TYPE_LARGE | (COMMUNITY_ANY << 16) | + (COMMUNITY_ANY << 24), + .data1 = 22512, + }, + { /* 25 */ + .flags = COMMUNITY_TYPE_EXT, + .data3 = EXT_COMMUNITY_TRANS_TWO_AS << 8 | 0x02, + .data1 = 22512, + .data2 = 42, + }, + { /* 26 */ + .flags = COMMUNITY_TYPE_EXT, + .data3 = EXT_COMMUNITY_TRANS_FOUR_AS << 8 | 0x02, + .data1 = 22512, + .data2 = 42, + }, + { /* 27 */ + .flags = COMMUNITY_TYPE_EXT, + .data3 = EXT_COMMUNITY_TRANS_FOUR_AS << 8 | 0x02, + .data1 = 22512, + .data2 = 15, + }, +}; + +struct testfilter { + ssize_t in[8]; + ssize_t delete; + ssize_t match; + int mout; +} testfilters[] = { + { + .in = { 1, 2, -1 }, + .match = 1, + .mout = 1, + .delete = 1, + }, + { + .in = { 1, 2, -1 }, + .match = 2, + .mout = 1, + .delete = 2, + }, + { + .in = { 1, 2, -1 }, + .match = 20, + .mout = 1, + .delete = 20, + }, + { + .in = { 1, 2, 1, 2, -1 }, + .match = 5, + .mout = 0, + .delete = 5, + }, + { + .in = { 3, 4, 5, 6, 7, 8, -1 }, + .match = 5, + .mout = 1, + .delete = 5, + }, + { /* 5 */ + .in = { 3, 4, 5, 6, 7, 8, -1 }, + .match = 20, + .mout = 0, + .delete = -1, + }, + { + .in = { 3, 4, 5, 6, 7, 8, -1 }, + .match = 21, + .mout = 1, + .delete = 21, + }, + { + .in = { 3, 4, 5, 6, 7, 8, -1 }, + .match = 22, + .mout = 1, + .delete = 22, + }, + { + .in = { 17, 18, 19, -1 }, + .match = 22, + .mout = 0, + .delete = 17, + }, + { + .in = { 17, 18, 19, 7, 8, -1 }, + .match = 18, + .mout = 1, + .delete = 19, + }, + { /* 10 */ + .in = { 1, 3, 5, -1 }, + .match = 23, + .mout = 0, + .delete = -1, + }, + { + .in = { 1, 3, 5, 17, -1 }, + .match = 23, + .mout = 1, + .delete = 23, + }, + { + .in = { 1, 3, 5, 19, -1 }, + .match = 24, + .mout = 0, + .delete = -1, + }, + { + .in = { 19, 18, 17, -1 }, + .match = 24, + .mout = 1, + .delete = 24, + }, + { + .in = { 25, 26, -1 }, + .match = 25, + .mout = 1, + .delete = 25, + }, + { /* 15 */ + .in = { 25, 26, -1 }, + .match = 26, + .mout = 1, + .delete = 26, + }, + { + .in = { 17, 0, -1 }, + .match = 0, + .mout = 1, + .delete = 0, + }, +}; |