diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bgp_capability_test.c | 143 | ||||
-rw-r--r-- | tests/bgp_mp_attr_test.c | 139 | ||||
-rw-r--r-- | tests/ecommunity_test.c | 23 | ||||
-rw-r--r-- | tests/heavy-thread.c | 26 | ||||
-rw-r--r-- | tests/heavy-wq.c | 36 | ||||
-rw-r--r-- | tests/heavy.c | 26 | ||||
-rw-r--r-- | tests/main.c | 34 | ||||
-rw-r--r-- | tests/test-checksum.c | 97 | ||||
-rw-r--r-- | tests/test-sig.c | 10 |
9 files changed, 277 insertions, 257 deletions
diff --git a/tests/bgp_capability_test.c b/tests/bgp_capability_test.c index 0dbf4fb9..78142009 100644 --- a/tests/bgp_capability_test.c +++ b/tests/bgp_capability_test.c @@ -1,4 +1,5 @@ #include <zebra.h> +#include "miyagi.h" #include "vty.h" #include "stream.h" @@ -36,7 +37,7 @@ static struct test_segment { #define SHOULD_ERR -1 int parses; /* whether it should parse or not */ int peek_for; /* what peek_for_as4_capability should say */ - + /* AFI/SAFI validation */ int validate_afi; afi_t afi; @@ -44,10 +45,10 @@ static struct test_segment { #define VALID_AFI 1 #define INVALID_AFI 0 int afi_valid; -} test_segments [] = +} test_segments [] = { /* 0 */ - { "caphdr", + { "caphdr", "capability header, and no more", { CAPABILITY_CODE_REFRESH, 0x0 }, 2, SHOULD_PARSE, @@ -114,7 +115,7 @@ static struct test_segment mp_segments[] = { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80 }, 6, SHOULD_PARSE, 0, 1, AFI_IP, BGP_SAFI_VPNV4, VALID_AFI, - }, + }, /* 9 */ { "MP7", "MP IP4/VPNv6", @@ -150,9 +151,9 @@ static struct test_segment misc_segments[] = /* 13 */ { "ORF", "ORF, simple, single entry, single tuple", - { /* hdr */ CAPABILITY_CODE_ORF, 0x7, - /* mpc */ 0x0, 0x1, 0x0, 0x1, - /* num */ 0x1, + { /* hdr */ CAPABILITY_CODE_ORF, 0x7, + /* mpc */ 0x0, 0x1, 0x0, 0x1, + /* num */ 0x1, /* tuples */ 0x40, 0x3 }, 9, SHOULD_PARSE, @@ -161,18 +162,18 @@ static struct test_segment misc_segments[] = { "ORF-many", "ORF, multi entry/tuple", { /* hdr */ CAPABILITY_CODE_ORF, 0x21, - /* mpc */ 0x0, 0x1, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x1, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, ORF_MODE_BOTH, 0x80, ORF_MODE_RECEIVE, 0x80, ORF_MODE_SEND, - /* mpc */ 0x0, 0x2, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x2, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, ORF_MODE_BOTH, 0x80, ORF_MODE_RECEIVE, 0x80, ORF_MODE_SEND, /* mpc */ 0x0, 0x2, 0x0, 0x2, - /* num */ 0x3, + /* num */ 0x3, /* tuples */ 0x40, ORF_MODE_RECEIVE, 0x80, ORF_MODE_SEND, 0x80, ORF_MODE_BOTH, @@ -183,18 +184,18 @@ static struct test_segment misc_segments[] = { "ORFlo", "ORF, multi entry/tuple, hdr length too short", { /* hdr */ CAPABILITY_CODE_ORF, 0x15, - /* mpc */ 0x0, 0x1, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x1, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, - /* mpc */ 0x0, 0x1, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x1, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, /* mpc */ 0x0, 0x2, 0x0, 0x2, - /* num */ 0x3, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, @@ -205,18 +206,18 @@ static struct test_segment misc_segments[] = { "ORFlu", "ORF, multi entry/tuple, length too long", { /* hdr */ 0x3, 0x22, - /* mpc */ 0x0, 0x1, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x1, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, - /* mpc */ 0x0, 0x2, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x2, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, /* mpc */ 0x0, 0x2, 0x0, 0x2, - /* num */ 0x3, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, @@ -227,18 +228,18 @@ static struct test_segment misc_segments[] = { "ORFnu", "ORF, multi entry/tuple, entry number too long", { /* hdr */ 0x3, 0x21, - /* mpc */ 0x0, 0x1, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x1, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, - /* mpc */ 0x0, 0x2, 0x0, 0x1, - /* num */ 0x4, + /* mpc */ 0x0, 0x2, 0x0, 0x1, + /* num */ 0x4, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, /* mpc */ 0x0, 0x2, 0x0, 0x2, - /* num */ 0x3, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, @@ -249,13 +250,13 @@ static struct test_segment misc_segments[] = { "ORFno", "ORF, multi entry/tuple, entry number too short", { /* hdr */ 0x3, 0x21, - /* mpc */ 0x0, 0x1, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x1, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, - /* mpc */ 0x0, 0x2, 0x0, 0x1, - /* num */ 0x1, + /* mpc */ 0x0, 0x2, 0x0, 0x1, + /* num */ 0x1, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, @@ -271,18 +272,18 @@ static struct test_segment misc_segments[] = { "ORFpad", "ORF, multi entry/tuple, padded to align", { /* hdr */ 0x3, 0x22, - /* mpc */ 0x0, 0x1, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x1, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, - /* mpc */ 0x0, 0x2, 0x0, 0x1, - /* num */ 0x3, + /* mpc */ 0x0, 0x2, 0x0, 0x1, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, /* mpc */ 0x0, 0x2, 0x0, 0x2, - /* num */ 0x3, + /* num */ 0x3, /* tuples */ 0x40, 0x3, 0x80, 0x1, 0x80, 0x2, @@ -401,7 +402,7 @@ static struct test_segment misc_segments[] = }; /* DYNAMIC message */ -struct test_segment dynamic_cap_msgs[] = +struct test_segment dynamic_cap_msgs[] = { { "DynCap", "Dynamic Capability Message, IP/Multicast", @@ -439,7 +440,7 @@ struct test_segment opt_params[] = { 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */ 0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */ 0x02, 0x02, 0x80, 0x00, /* RR (old) */ - 0x02, 0x02, 0x02, 0x00, /* RR */ + 0x02, 0x02, 0x02, 0x00, /* RR */ }, 24, SHOULD_PARSE, }, @@ -449,7 +450,7 @@ struct test_segment opt_params[] = 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */ 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */ 0x80, 0x00, /* RR (old) */ - 0x02, 0x00, /* RR */ + 0x02, 0x00, /* RR */ }, 18, SHOULD_PARSE, }, @@ -469,7 +470,7 @@ struct test_segment opt_params[] = 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */ 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */ 0x80, 0x00, /* RR (old) */ - 0x02, 0x00, /* RR */ + 0x02, 0x00, /* RR */ 0x41, 0x04, 0x00, 0x03, 0x00, 0x06 /* AS4: 1996614 */ }, 24, SHOULD_PARSE, 196614, @@ -503,6 +504,8 @@ struct test_segment opt_params[] = { NULL, NULL, {0}, 0, 0} }; +extern int bgp_capability_receive(struct peer*, bgp_size_t) ; + /* basic parsing test */ static void parse_test (struct peer *peer, struct test_segment *t, int type) @@ -513,11 +516,11 @@ parse_test (struct peer *peer, struct test_segment *t, int type) int oldfailed = failed; int len = t->len; #define RANDOM_FUZZ 35 - + stream_reset (peer->ibuf); stream_put (peer->ibuf, NULL, RANDOM_FUZZ); stream_set_getp (peer->ibuf, RANDOM_FUZZ); - + switch (type) { case CAPABILITY: @@ -532,7 +535,7 @@ parse_test (struct peer *peer, struct test_segment *t, int type) break; } stream_write (peer->ibuf, t->data, t->len); - + printf ("%s: %s\n", t->name, t->desc); switch (type) @@ -546,7 +549,7 @@ parse_test (struct peer *peer, struct test_segment *t, int type) printf ("peek_for_as4: as4 is %u\n", as4); /* and it should leave getp as it found it */ assert (stream_get_getp (peer->ibuf) == RANDOM_FUZZ); - + ret = bgp_open_option_parse (peer, len, &capability); break; case DYNCAP: @@ -556,49 +559,49 @@ parse_test (struct peer *peer, struct test_segment *t, int type) printf ("unknown type %u\n", type); exit(1); } - + if (!ret && t->validate_afi) { safi_t safi = t->safi; - + if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid) failed++; - + printf ("MP: %u/%u (%u): recv %u, nego %u\n", t->afi, t->safi, safi, peer->afc_recv[t->afi][safi], peer->afc_nego[t->afi][safi]); - + if (t->afi_valid == VALID_AFI) { - + if (!peer->afc_recv[t->afi][safi]) failed++; if (!peer->afc_nego[t->afi][safi]) failed++; } } - - if (as4 != t->peek_for) + + if (as4 != (uint32_t)t->peek_for) { printf ("as4 %u != %u\n", as4, t->peek_for); failed++; } - + printf ("parsed?: %s\n", ret ? "no" : "yes"); - + if (ret != t->parses) failed++; - + if (tty) - printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET + printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET : VT100_GREEN "OK" VT100_RESET); else printf ("%s", (failed > oldfailed) ? "failed!" : "OK" ); - + if (failed) printf (" (%u)", failed); - + printf ("\n\n"); } @@ -610,7 +613,7 @@ main (void) { struct peer *peer; int i, j; - + conf_bgp_debug_fsm = -1UL; conf_bgp_debug_events = -1UL; conf_bgp_debug_packet = -1UL; @@ -621,26 +624,26 @@ main (void) term_bgp_debug_packet = -1UL; term_bgp_debug_normal = -1UL; term_bgp_debug_as4 = -1UL; - + master = thread_master_create (); bgp_master_init (); - - if (fileno (stdout) >= 0) + + if (fileno (stdout) >= 0) tty = isatty (fileno (stdout)); - + if (bgp_get (&bgp, &asn, NULL)) return -1; - + peer = peer_create_accept (bgp); - peer->host = "foo"; - + peer->host = miyagi("foo"); + for (i = AFI_IP; i < AFI_MAX; i++) for (j = SAFI_UNICAST; j < SAFI_MAX; j++) { peer->afc[i][j] = 1; peer->afc_adv[i][j] = 1; } - + i = 0; while (mp_segments[i].name) parse_test (peer, &mp_segments[i++], CAPABILITY); @@ -649,9 +652,9 @@ main (void) * one of the afc_nego's */ i = 0; - while (test_segments[i].name) + while (test_segments[i].name) parse_test (peer, &test_segments[i++], CAPABILITY); - + i = 0; while (misc_segments[i].name) parse_test (peer, &misc_segments[i++], CAPABILITY); @@ -662,11 +665,11 @@ main (void) SET_FLAG (peer->cap, PEER_CAP_DYNAMIC_ADV); peer->status = Established; - + i = 0; while (dynamic_cap_msgs[i].name) parse_test (peer, &dynamic_cap_msgs[i++], DYNCAP); - + printf ("failures: %d\n", failed); return failed; } diff --git a/tests/bgp_mp_attr_test.c b/tests/bgp_mp_attr_test.c index dde0df2f..6a445acf 100644 --- a/tests/bgp_mp_attr_test.c +++ b/tests/bgp_mp_attr_test.c @@ -1,4 +1,5 @@ #include <zebra.h> +#include "miyagi.h" #include "vty.h" #include "stream.h" @@ -36,17 +37,17 @@ static struct test_segment { #define SHOULD_PARSE 0 #define SHOULD_ERR -1 int parses; /* whether it should parse or not */ - + /* AFI/SAFI validation */ afi_t afi; safi_t safi; #define VALID_AFI 1 #define INVALID_AFI 0 int afi_valid; -} mp_reach_segments [] = +} mp_reach_segments [] = { { "IPv6", - "IPV6 MP Reach, global nexthop, 1 NLRI", + "IPV6 MP Reach, global nexthop, 1 NLRI", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 16, @@ -57,12 +58,12 @@ static struct test_segment { /* SNPA (defunct, MBZ) */ 0x0, /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ }, - (4 + 16 + 1 + 5), + (4 + 16 + 1 + 5), SHOULD_PARSE, AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-2", - "IPV6 MP Reach, global nexthop, 2 NLRIs", + "IPV6 MP Reach, global nexthop, 2 NLRIs", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 16, @@ -71,18 +72,18 @@ static struct test_segment { 0x3, 0x4, 0x5, 0x6, 0xa1, 0xa2, 0xa3, 0xa4, /* SNPA (defunct, MBZ) */ 0x0, - /* NLRI tuples */ 32, + /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ 0x0, 0x2, 0x0, 0x3, }, - (4 + 16 + 1 + 5 + 9), + (4 + 16 + 1 + 5 + 9), SHOULD_PARSE, AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-default", - "IPV6 MP Reach, global nexthop, 2 NLRIs + default", + "IPV6 MP Reach, global nexthop, 2 NLRIs + default", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 16, @@ -91,7 +92,7 @@ static struct test_segment { 0x3, 0x4, 0x5, 0x6, 0xa1, 0xa2, 0xa3, 0xa4, /* SNPA (defunct, MBZ) */ 0x0, - /* NLRI tuples */ 32, + /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ @@ -103,7 +104,7 @@ static struct test_segment { AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-lnh", - "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default", + "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 32, @@ -116,7 +117,7 @@ static struct test_segment { 0x2, 0x10, 0x2, 0xff, 0x1, 0x2, 0x3, 0x4, /* SNPA (defunct, MBZ) */ 0x0, - /* NLRI tuples */ 32, + /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ @@ -128,7 +129,7 @@ static struct test_segment { AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-nhlen", - "IPV6 MP Reach, inappropriate nexthop length", + "IPV6 MP Reach, inappropriate nexthop length", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 4, @@ -141,7 +142,7 @@ static struct test_segment { 0x2, 0x10, 0x2, 0xff, 0x1, 0x2, 0x3, 0x4, /* SNPA (defunct, MBZ) */ 0x0, - /* NLRI tuples */ 32, + /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ @@ -153,7 +154,7 @@ static struct test_segment { AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-nhlen2", - "IPV6 MP Reach, invalid nexthop length", + "IPV6 MP Reach, invalid nexthop length", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 5, @@ -166,7 +167,7 @@ static struct test_segment { 0x2, 0x10, 0x2, 0xff, 0x1, 0x2, 0x3, 0x4, /* SNPA (defunct, MBZ) */ 0x0, - /* NLRI tuples */ 32, + /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ @@ -178,7 +179,7 @@ static struct test_segment { AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-nhlen3", - "IPV6 MP Reach, nexthop length overflow", + "IPV6 MP Reach, nexthop length overflow", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 32, @@ -192,7 +193,7 @@ static struct test_segment { AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-nhlen4", - "IPV6 MP Reach, nexthop length short", + "IPV6 MP Reach, nexthop length short", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 16, @@ -205,7 +206,7 @@ static struct test_segment { 0x2, 0x10, 0x2, 0xff, 0x1, 0x2, 0x3, 0x4, /* SNPA (defunct, MBZ) */ 0x0, - /* NLRI tuples */ 32, + /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ @@ -217,7 +218,7 @@ static struct test_segment { AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-nlri", - "IPV6 MP Reach, NLRI bitlen overflow", + "IPV6 MP Reach, NLRI bitlen overflow", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* nexthop bytes */ 32, @@ -230,7 +231,7 @@ static struct test_segment { 0x2, 0x10, 0x2, 0xff, 0x1, 0x2, 0x3, 0x4, /* SNPA (defunct, MBZ) */ 0x0, - /* NLRI tuples */ 120, + /* NLRI tuples */ 120, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ @@ -242,11 +243,11 @@ static struct test_segment { AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv4", - "IPv4 MP Reach, 2 NLRIs + default", + "IPv4 MP Reach, 2 NLRIs + default", { /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, /* nexthop bytes */ 4, - /* Nexthop */ 192, 168, 0, 1, + /* Nexthop */ 192, 168, 0, 1, /* SNPA (defunct, MBZ) */ 0x0, /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ 17, 10, 2, 3, /* 10.2.3/17 */ @@ -257,11 +258,11 @@ static struct test_segment { AFI_IP, SAFI_UNICAST, VALID_AFI, }, { "IPv4-nhlen", - "IPv4 MP Reach, nexthop lenth overflow", + "IPv4 MP Reach, nexthop lenth overflow", { /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, /* nexthop bytes */ 32, - /* Nexthop */ 192, 168, 0, 1, + /* Nexthop */ 192, 168, 0, 1, /* SNPA (defunct, MBZ) */ 0x0, /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ 17, 10, 2, 3, /* 10.2.3/17 */ @@ -272,14 +273,14 @@ static struct test_segment { AFI_IP, SAFI_UNICAST, VALID_AFI, }, { "IPv4-nlrilen", - "IPv4 MP Reach, nlri lenth overflow", + "IPv4 MP Reach, nlri lenth overflow", { /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, /* nexthop bytes */ 4, - /* Nexthop */ 192, 168, 0, 1, + /* Nexthop */ 192, 168, 0, 1, /* SNPA (defunct, MBZ) */ 0x0, /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ - 30, 10, + 30, 10, 0, /* 0/0 */ }, (4 + 4 + 1 + 3 + 2 + 1), @@ -287,13 +288,13 @@ static struct test_segment { AFI_IP, SAFI_UNICAST, VALID_AFI, }, { "IPv4-vpnv4", - "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs", + "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs", { /* AFI / SAFI */ 0x0, AFI_IP, BGP_SAFI_VPNV4, /* nexthop bytes */ 12, /* RD */ 0, 0, 1, 2, 0, 0xff, 3, 4, - /* Nexthop */ 192, 168, 0, 1, + /* Nexthop */ 192, 168, 0, 1, /* SNPA (defunct, MBZ) */ 0x0, /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ 17, 10, 2, 3, /* 10.2.3/17 */ @@ -305,17 +306,17 @@ static struct test_segment { }, /* From bug #385 */ { "IPv6-bug", - "IPv6, global nexthop, 1 default NLRI", + "IPv6, global nexthop, 1 default NLRI", { /* AFI / SAFI */ 0x0, 0x2, 0x1, /* nexthop bytes */ 0x20, - /* Nexthop (global) */ 0x20, 0x01, 0x04, 0x70, + /* Nexthop (global) */ 0x20, 0x01, 0x04, 0x70, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - /* Nexthop (local) */ 0xfe, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + /* Nexthop (local) */ 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x0c, 0xdb, 0xff, + 0x02, 0x0c, 0xdb, 0xff, 0xfe, 0xfe, 0xeb, 0x00, /* SNPA (defunct, MBZ) */ 0, /* NLRI tuples */ /* Should have 0 here for ::/0, but dont */ @@ -324,7 +325,7 @@ static struct test_segment { SHOULD_ERR, AFI_IP6, SAFI_UNICAST, VALID_AFI, }, - + { NULL, NULL, {0}, 0, 0} }; @@ -332,34 +333,34 @@ static struct test_segment { static struct test_segment mp_unreach_segments [] = { { "IPv6-unreach", - "IPV6 MP Unreach, 1 NLRI", + "IPV6 MP Unreach, 1 NLRI", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ }, - (3 + 5), + (3 + 5), SHOULD_PARSE, AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-unreach2", - "IPV6 MP Unreach, 2 NLRIs", + "IPV6 MP Unreach, 2 NLRIs", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, - /* NLRI tuples */ 32, + /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ 0x0, 0x2, 0x0, 0x3, }, - (3 + 5 + 9), + (3 + 5 + 9), SHOULD_PARSE, AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-unreach-default", - "IPV6 MP Unreach, 2 NLRIs + default", + "IPV6 MP Unreach, 2 NLRIs + default", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, - /* NLRI tuples */ 32, + /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ @@ -371,10 +372,10 @@ static struct test_segment mp_unreach_segments [] = AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv6-unreach-nlri", - "IPV6 MP Unreach, NLRI bitlen overflow", + "IPV6 MP Unreach, NLRI bitlen overflow", { /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, - /* NLRI tuples */ 120, + /* NLRI tuples */ 120, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ 64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ @@ -386,7 +387,7 @@ static struct test_segment mp_unreach_segments [] = AFI_IP6, SAFI_UNICAST, VALID_AFI, }, { "IPv4-unreach", - "IPv4 MP Unreach, 2 NLRIs + default", + "IPv4 MP Unreach, 2 NLRIs + default", { /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ @@ -398,11 +399,11 @@ static struct test_segment mp_unreach_segments [] = AFI_IP, SAFI_UNICAST, VALID_AFI, }, { "IPv4-unreach-nlrilen", - "IPv4 MP Unreach, nlri length overflow", + "IPv4 MP Unreach, nlri length overflow", { /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ - 30, 10, + 30, 10, 0, /* 0/0 */ }, (3 + 3 + 2 + 1), @@ -410,13 +411,13 @@ static struct test_segment mp_unreach_segments [] = AFI_IP, SAFI_UNICAST, VALID_AFI, }, { "IPv4-unreach-vpnv4", - "IPv4/VPNv4 MP Unreach, RD, 3 NLRIs", + "IPv4/VPNv4 MP Unreach, RD, 3 NLRIs", { /* AFI / SAFI */ 0x0, AFI_IP, BGP_SAFI_VPNV4, /* nexthop bytes */ 12, /* RD */ 0, 0, 1, 2, 0, 0xff, 3, 4, - /* Nexthop */ 192, 168, 0, 1, + /* Nexthop */ 192, 168, 0, 1, /* SNPA (defunct, MBZ) */ 0x0, /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ 17, 10, 2, 3, /* 10.2.3/17 */ @@ -439,13 +440,13 @@ parse_test (struct peer *peer, struct test_segment *t, int type) struct attr attr; struct bgp_nlri nlri; #define RANDOM_FUZZ 35 - + stream_reset (peer->ibuf); stream_put (peer->ibuf, NULL, RANDOM_FUZZ); stream_set_getp (peer->ibuf, RANDOM_FUZZ); - + stream_write (peer->ibuf, t->data, t->len); - + printf ("%s: %s\n", t->name, t->desc); if (type == BGP_ATTR_MP_REACH_NLRI) @@ -456,30 +457,30 @@ parse_test (struct peer *peer, struct test_segment *t, int type) if (!ret) { safi_t safi = t->safi; - + if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid) failed++; - + printf ("MP: %u/%u (%u): recv %u, nego %u\n", t->afi, t->safi, safi, peer->afc_recv[t->afi][safi], peer->afc_nego[t->afi][safi]); } - + printf ("parsed?: %s\n", ret ? "no" : "yes"); - + if (ret != t->parses) failed++; - + if (tty) - printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET + printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET : VT100_GREEN "OK" VT100_RESET); else printf ("%s", (failed > oldfailed) ? "failed!" : "OK" ); - + if (failed) printf (" (%u)", failed); - + printf ("\n\n"); } @@ -491,7 +492,7 @@ main (void) { struct peer *peer; int i, j; - + conf_bgp_debug_fsm = -1UL; conf_bgp_debug_events = -1UL; conf_bgp_debug_packet = -1UL; @@ -502,26 +503,26 @@ main (void) term_bgp_debug_packet = -1UL; term_bgp_debug_normal = -1UL; term_bgp_debug_as4 = -1UL; - + master = thread_master_create (); bgp_master_init (); - - if (fileno (stdout) >= 0) + + if (fileno (stdout) >= 0) tty = isatty (fileno (stdout)); - + if (bgp_get (&bgp, &asn, NULL)) return -1; - + peer = peer_create_accept (bgp); - peer->host = "foo"; - + peer->host = miyagi("foo") ; + for (i = AFI_IP; i < AFI_MAX; i++) for (j = SAFI_UNICAST; j < SAFI_MAX; j++) { peer->afc[i][j] = 1; peer->afc_adv[i][j] = 1; } - + i = 0; while (mp_reach_segments[i].name) parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI); diff --git a/tests/ecommunity_test.c b/tests/ecommunity_test.c index 418f659f..da48865c 100644 --- a/tests/ecommunity_test.c +++ b/tests/ecommunity_test.c @@ -1,4 +1,5 @@ #include <zebra.h> +#include "miyagi.h" #include "vty.h" #include "stream.h" @@ -15,7 +16,7 @@ struct thread_master *master = NULL; static int failed = 0; /* specification for a test - what the results should be */ -struct test_spec +struct test_spec { const char *shouldbe; /* the string the path should parse to */ }; @@ -28,7 +29,7 @@ static struct test_segment { const u_char data[1024]; int len; struct test_spec sp; -} test_segments [] = +} test_segments [] = { { /* 0 */ "ipaddr", @@ -73,7 +74,7 @@ validate (struct ecommunity *ecom, const struct test_spec *sp) int fails = 0; struct ecommunity *etmp; char *str1, *str2; - + printf ("got:\n %s\n", ecommunity_str (ecom)); str1 = ecommunity_ecom2str (ecom, ECOMMUNITY_FORMAT_COMMUNITY_LIST); etmp = ecommunity_str2com (str1, 0, 1); @@ -81,7 +82,7 @@ validate (struct ecommunity *ecom, const struct test_spec *sp) str2 = ecommunity_ecom2str (etmp, ECOMMUNITY_FORMAT_COMMUNITY_LIST); else str2 = NULL; - + if (strcmp (sp->shouldbe, str1)) { failed++; @@ -94,13 +95,13 @@ validate (struct ecommunity *ecom, const struct test_spec *sp) fails++; printf ("dogfood: in %s\n" " in->out %s\n", - str1, + str1, (etmp && str2) ? str2 : "NULL"); } ecommunity_free (etmp); XFREE (MTYPE_ECOMMUNITY_STR, str1); XFREE (MTYPE_ECOMMUNITY_STR, str2); - + return fails; } @@ -109,10 +110,10 @@ static void parse_test (struct test_segment *t) { struct ecommunity *ecom; - + printf ("%s: %s\n", t->name, t->desc); - ecom = ecommunity_parse (t->data, t->len); + ecom = ecommunity_parse (miyagi(t->data), t->len); printf ("ecom: %s\nvalidating...:\n", ecommunity_str (ecom)); @@ -120,12 +121,12 @@ parse_test (struct test_segment *t) printf ("OK\n"); else printf ("failed\n"); - + printf ("\n"); ecommunity_unintern (ecom); } - + int main (void) { @@ -133,7 +134,7 @@ main (void) ecommunity_init(); while (test_segments[i].name) parse_test (&test_segments[i++]); - + printf ("failures: %d\n", failed); //printf ("aspath count: %ld\n", aspath_count()); return failed; diff --git a/tests/heavy-thread.c b/tests/heavy-thread.c index cd3a3b9d..f7a99cc5 100644 --- a/tests/heavy-thread.c +++ b/tests/heavy-thread.c @@ -59,17 +59,17 @@ slow_func (struct vty *vty, const char *str, const int i) { double x = 1; int j; - + for (j = 0; j < 300; j++) x += sin(x)*j; - + if ((i % ITERS_LATER) == 0) printf ("%s: %d, temporary error, save this somehow and do it later..\n", __func__, i); - + if ((i % ITERS_ERR) == 0) printf ("%s: hard error\n", __func__); - + if ((i % ITERS_PRINT) == 0) printf ("%s did %d, x = %g\n", str, i, x); } @@ -78,8 +78,8 @@ static int clear_something (struct thread *thread) { struct work_state *ws = THREAD_ARG(thread); - - /* this could be like iterating through 150k of route_table + + /* this could be like iterating through 150k of route_table * or worse, iterating through a list of peers, to bgp_stop them with * each having 150k route tables to process... */ @@ -93,7 +93,7 @@ clear_something (struct thread *thread) return 0; } } - + /* All done! */ XFREE (MTYPE_TMP, ws->str); XFREE (MTYPE_TMP, ws); @@ -114,22 +114,22 @@ DEFUN (clear_foo, vty_out (vty, "%% string argument required%s", VTY_NEWLINE); return CMD_WARNING; } - + str = argv_concat (argv, argc, 0); - + if ((ws = XMALLOC(MTYPE_TMP, sizeof(*ws))) == NULL) { zlog_err ("%s: unable to allocate work_state", __func__); return CMD_WARNING; } - + if (!(ws->str = XSTRDUP (MTYPE_TMP, str))) { zlog_err ("%s: unable to xstrdup", __func__); XFREE (MTYPE_TMP, ws); return CMD_WARNING; } - + ws->vty = vty; ws->i = ITERS_FIRST; @@ -138,8 +138,10 @@ DEFUN (clear_foo, return CMD_SUCCESS; } +extern void test_init(void) ; + void -test_init() +test_init(void) { install_element (VIEW_NODE, &clear_foo_cmd); } diff --git a/tests/heavy-wq.c b/tests/heavy-wq.c index a2c609d4..4cd499a5 100644 --- a/tests/heavy-wq.c +++ b/tests/heavy-wq.c @@ -66,7 +66,7 @@ heavy_wq_add (struct vty *vty, const char *str, int i) zlog_err ("%s: unable to allocate hn", __func__); return; } - + hn->i = i; if (!(hn->str = XSTRDUP (MTYPE_PREFIX_LIST_STR, str))) { @@ -74,9 +74,9 @@ heavy_wq_add (struct vty *vty, const char *str, int i) XFREE (MTYPE_PREFIX_LIST, hn); return; } - + work_queue_add (heavy_wq, hn); - + return; } @@ -93,7 +93,7 @@ slow_func_del (struct work_queue *wq, void *data) assert (hn && hn->str); printf ("%s: %s\n", __func__, hn->str); XFREE (MTYPE_PREFIX_LIST_STR, hn->str); - hn->str = NULL; + hn->str = NULL; XFREE(MTYPE_PREFIX_LIST, hn); } @@ -103,18 +103,18 @@ slow_func (struct work_queue *wq, void *data) struct heavy_wq_node *hn = data; double x = 1; int j; - + assert (hn && hn->str); - + for (j = 0; j < 300; j++) x += sin(x)*j; - + if ((hn->i % ITERS_LATER) == 0) return WQ_RETRY_LATER; - + if ((hn->i % ITERS_ERR) == 0) return WQ_RETRY_NOW; - + if ((hn->i % ITERS_PRINT) == 0) printf ("%s did %d, x = %g\n", hn->str, hn->i, x); @@ -125,8 +125,8 @@ static void clear_something (struct vty *vty, const char *str) { int i; - - /* this could be like iterating through 150k of route_table + + /* this could be like iterating through 150k of route_table * or worse, iterating through a list of peers, to bgp_stop them with * each having 150k route tables to process... */ @@ -146,9 +146,9 @@ DEFUN (clear_foo, vty_out (vty, "%% string argument required%s", VTY_NEWLINE); return CMD_WARNING; } - + str = argv_concat (argv, argc, 0); - + clear_something (vty, str); XFREE (MTYPE_TMP, str); return CMD_SUCCESS; @@ -162,18 +162,20 @@ heavy_wq_init () zlog_err ("%s: could not get new work queue!", __func__); return -1; } - + heavy_wq->spec.workfunc = &slow_func; heavy_wq->spec.errorfunc = &slow_func_err; heavy_wq->spec.del_item_data = &slow_func_del; heavy_wq->spec.max_retries = 3; heavy_wq->spec.hold = 1000; - + return 0; } -void -test_init() +extern void test_init(void) ; + +extern void +test_init(void) { install_element (VIEW_NODE, &clear_foo_cmd); heavy_wq_init(); diff --git a/tests/heavy.c b/tests/heavy.c index 577a4816..901fb10f 100644 --- a/tests/heavy.c +++ b/tests/heavy.c @@ -50,27 +50,27 @@ slow_func (struct vty *vty, const char *str, const int i) { double x = 1; int j; - + for (j = 0; j < 300; j++) x += sin(x)*j; - + if ((i % ITERS_LATER) == 0) - printf ("%s: %d, temporary error, save this somehow and do it later..\n", + printf ("%s: %d, temporary error, save this somehow and do it later..\n", __func__, i); - + if ((i % ITERS_ERR) == 0) printf ("%s: hard error\n", __func__); - + if ((i % ITERS_PRINT) == 0) - printf ("%s did %d, x = %g%s", str, i, x, VTY_NEWLINE); + printf ("%s did %d, x = %g%s", str, i, x, VTY_NEWLINE); } static void clear_something (struct vty *vty, const char *str) { int i; - - /* this could be like iterating through 150k of route_table + + /* this could be like iterating through 150k of route_table * or worse, iterating through a list of peers, to bgp_stop them with * each having 150k route tables to process... */ @@ -90,9 +90,9 @@ DEFUN (clear_foo, vty_out (vty, "%% string argument required%s", VTY_NEWLINE); return CMD_WARNING; } - + str = argv_concat (argv, argc, 0); - + clear_something (vty, str); XFREE (MTYPE_TMP, str); return CMD_SUCCESS; @@ -104,8 +104,10 @@ slow_vty_init() install_element (VIEW_NODE, &clear_foo_cmd); } -void -test_init() +extern void test_init(void) ; + +extern void +test_init(void) { slow_vty_init(); } diff --git a/tests/main.c b/tests/main.c index e0fbb4d5..f735e1e1 100644 --- a/tests/main.c +++ b/tests/main.c @@ -32,7 +32,7 @@ extern void test_init(); struct thread_master *master; -struct option longopts[] = +struct option longopts[] = { { "daemon", no_argument, NULL, 'd'}, { "config_file", required_argument, NULL, 'f'}, @@ -51,12 +51,14 @@ DEFUN (daemon_exit, exit(0); } +extern int test_timer (struct thread *thread) ; + static int timer_count; -int +extern int test_timer (struct thread *thread) { int *count = THREAD_ARG(thread); - + printf ("run %d of timer\n", (*count)++); thread_add_timer (master, test_timer, count, 5); return 0; @@ -81,7 +83,7 @@ usage (char *progname, int status) if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", progname); else - { + { printf ("Usage : %s [OPTION...]\n\ Daemon which does 'slow' things.\n\n\ -d, --daemon Runs in daemon mode\n\ @@ -95,8 +97,8 @@ Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS); } exit (status); } - - + + /* main routine. */ int main (int argc, char **argv) @@ -108,7 +110,7 @@ main (int argc, char **argv) char *progname; struct thread thread; char *config_file = NULL; - + /* Set umask before anything for security */ umask (0027); @@ -118,16 +120,16 @@ main (int argc, char **argv) /* master init. */ master = thread_master_create (); - while (1) + while (1) { int opt; opt = getopt_long (argc, argv, "dhf:A:P:v", longopts, 0); - + if (opt == EOF) break; - switch (opt) + switch (opt) { case 0: break; @@ -146,7 +148,7 @@ main (int argc, char **argv) { vty_port = 0; break; - } + } vty_port = atoi (optarg); vty_port = (vty_port ? vty_port : 4000); break; @@ -182,16 +184,16 @@ main (int argc, char **argv) /* Create VTY socket */ vty_serv_sock (vty_addr, vty_port, "/tmp/.heavy.sock"); - + /* Configuration file read*/ if (!config_file) usage (progname, 1); vty_read_config (config_file, NULL); - + test_timer_init(); - - test_init(); - + + test_init(); + /* Fetch next active thread. */ while (thread_fetch (master, &thread)) thread_call (&thread); diff --git a/tests/test-checksum.c b/tests/test-checksum.c index bd156baa..5fb5d0dd 100644 --- a/tests/test-checksum.c +++ b/tests/test-checksum.c @@ -13,7 +13,7 @@ struct acc_vals { struct csum_vals { struct acc_vals a; - int x; + int x; int y; }; @@ -24,9 +24,9 @@ typedef uint16_t testoff_t; /* Fletcher Checksum -- Refer to RFC1008. */ #define MODX 4102 - + /* Accumulator phase of checksum */ -static +static struct acc_vals accumulate (u_char *buffer, testsz_t len, testoff_t off) { @@ -34,15 +34,15 @@ accumulate (u_char *buffer, testsz_t len, testoff_t off) u_int16_t *csum; int i, init_len, partial_len; struct acc_vals ret; - + csum = (u_int16_t *) (buffer + off); *(csum) = 0; - + p = buffer; ret.c0 = 0; ret.c1 = 0; init_len = len; - + while (len != 0) { partial_len = MIN(len, MODX); @@ -62,9 +62,9 @@ accumulate (u_char *buffer, testsz_t len, testoff_t off) } /* The final reduction phase. - * This one should be the original ospfd version + * This one should be the original ospfd version */ -static u_int16_t +static u_int16_t reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off) { #define x vals->x @@ -73,7 +73,7 @@ reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off) #define c1 vals->a.c1 x = ((len - off - 1) * c0 - c1) % 255; - + if (x <= 0) x += 255; y = 510 - c0 - x; @@ -81,7 +81,7 @@ reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off) y -= 255; /* take care endian issue. */ - return htons ((x << 8) + y); + return htons ((x << 8) + y); #undef x #undef y #undef c0 @@ -89,7 +89,7 @@ reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off) } /* slightly different concatenation */ -static u_int16_t +static u_int16_t reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off) { #define x vals->x @@ -105,7 +105,7 @@ reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off) y -= 255; /* take care endian issue. */ - return htons ((x << 8) | (y & 0xff)); + return htons ((x << 8) | (y & 0xff)); #undef x #undef y #undef c0 @@ -113,7 +113,7 @@ reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off) } /* original isisd version */ -static u_int16_t +static u_int16_t reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off) { #define x vals->x @@ -121,7 +121,7 @@ reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off) #define c0 vals->a.c0 #define c1 vals->a.c1 u_int32_t mul; - + mul = (len - off)*(c0); x = mul - c0 - c1; y = c1 - mul - 1; @@ -148,7 +148,7 @@ reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off) } /* Is the -1 in y wrong perhaps? */ -static u_int16_t +static u_int16_t reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off) { #define x vals->x @@ -156,7 +156,7 @@ reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off) #define c0 vals->a.c0 #define c1 vals->a.c1 u_int32_t mul; - + mul = (len - off)*(c0); x = mul - c0 - c1; y = c1 - mul; @@ -183,7 +183,7 @@ reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off) } /* Move the mods yp */ -static u_int16_t +static u_int16_t reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off) { #define x vals->x @@ -191,7 +191,7 @@ reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off) #define c0 vals->a.c0 #define c1 vals->a.c1 u_int32_t mul; - + mul = (len - off)*(c0); x = mul - c1 - c0; y = c1 - mul - 1; @@ -218,7 +218,7 @@ reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off) } /* Move the mods up + fix y */ -static u_int16_t +static u_int16_t reduce_isisd_mody (struct csum_vals *vals, testsz_t len, testoff_t off) { #define x vals->x @@ -226,7 +226,7 @@ reduce_isisd_mody (struct csum_vals *vals, testsz_t len, testoff_t off) #define c0 vals->a.c0 #define c1 vals->a.c1 u_int32_t mul; - + mul = (len - off)*(c0); x = mul - c0 - c1; y = c1 - mul; @@ -264,7 +264,7 @@ struct reductions_t { { .name = "isisd-mody", .f = reduce_isisd_mody }, { NULL, NULL }, }; - + /* The original ospfd checksum */ static u_int16_t ospfd_checksum (u_char *buffer, testsz_t len, testoff_t off) @@ -276,7 +276,7 @@ ospfd_checksum (u_char *buffer, testsz_t len, testoff_t off) csum = (u_int16_t *) (buffer + off); *(csum) = 0; - + sp = buffer; for (ep = sp + len; sp < ep; sp = q) @@ -292,27 +292,27 @@ ospfd_checksum (u_char *buffer, testsz_t len, testoff_t off) c0 %= 255; c1 %= 255; } - + ospfd_vals.a.c0 = c0; ospfd_vals.a.c1 = c1; - + //printf ("%s: len %u, off %u, c0 %d, c1 %d\n", // __func__, len, off, c0, c1); x = ((int)(len - off - 1) * (int)c0 - (int)c1) % 255; - + if (x <= 0) x += 255; y = 510 - c0 - x; if (y > 255) y -= 255; - + ospfd_vals.x = x; ospfd_vals.y = y; - + buffer[off] = x; buffer[off + 1] = y; - + /* take care endian issue. */ checksum = htons ((x << 8) | (y & 0xff)); @@ -334,15 +334,15 @@ iso_csum_create (u_char * buffer, testsz_t len, testoff_t off) int i, init_len, partial_len; checksum = 0; - + csum = (u_int16_t *) (buffer + off); *(csum) = checksum; - + p = buffer; c0 = 0; c1 = 0; init_len = len; - + while (len != 0) { partial_len = MIN(len, MODX); @@ -361,7 +361,7 @@ iso_csum_create (u_char * buffer, testsz_t len, testoff_t off) isisd_vals.a.c0 = c0; isisd_vals.a.c1 = c1; - + mul = (init_len - off) * c0; x = mul - c1 - c0; @@ -379,14 +379,14 @@ iso_csum_create (u_char * buffer, testsz_t len, testoff_t off) x = 255; if (y == 0) y = 1; - + isisd_vals.x = x; isisd_vals.y = y; - + checksum = htons((x << 8) | (y & 0xFF)); - + *(csum) = checksum; - + /* return the checksum for user usage */ return checksum; } @@ -399,7 +399,7 @@ verify (u_char * buffer, testsz_t len) u_int32_t c1; u_int16_t checksum; int i, partial_len; - + p = buffer; checksum = 0; @@ -427,6 +427,8 @@ verify (u_char * buffer, testsz_t len) return 1; } +extern int in_cksum_optimized(void *parg, int nbytes) ; + int /* return checksum in low-order 16 bits */ in_cksum_optimized(void *parg, int nbytes) { @@ -458,6 +460,7 @@ in_cksum_optimized(void *parg, int nbytes) return(answer); } +extern int in_cksum_rfc(void *parg, int count) ; int /* return checksum in low-order 16 bits */ in_cksum_rfc(void *parg, int count) @@ -495,29 +498,29 @@ main(int argc, char **argv) u_char buffer[BUFSIZE]; int exercise = 0; #define EXERCISESTEP 257 - + srandom (time (NULL)); - + while (1) { u_int16_t ospfd, isisd, lib, in_csum, in_csum_res, in_csum_rfc; int i,j; exercise += EXERCISESTEP; exercise %= MAXDATALEN; - + for (i = 0; i < exercise; i += sizeof (long int)) { long int rand = random (); - + for (j = sizeof (long int); j > 0; j--) buffer[i + (sizeof (long int) - j)] = (rand >> (j * 8)) & 0xff; } - + in_csum = in_cksum(buffer, exercise); in_csum_res = in_cksum_optimized(buffer, exercise); in_csum_rfc = in_cksum_rfc(buffer, exercise); if (in_csum_res != in_csum || in_csum != in_csum_rfc) printf ("verify: in_chksum failed in_csum:%x, in_csum_res:%x," - "in_csum_rfc %x, len:%d\n", + "in_csum_rfc %x, len:%d\n", in_csum, in_csum_res, in_csum_rfc, exercise); ospfd = ospfd_checksum (buffer, exercise + sizeof(u_int16_t), exercise); @@ -529,7 +532,7 @@ main(int argc, char **argv) lib = fletcher_checksum (buffer, exercise + sizeof(u_int16_t), exercise); if (verify (buffer, exercise + sizeof(u_int16_t))) printf ("verify: lib failed\n"); - + if (ospfd != lib) { printf ("Mismatch in values at size %u\n" "ospfd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n" @@ -540,12 +543,12 @@ main(int argc, char **argv) isisd, isisd_vals.a.c0, isisd_vals.a.c1, isisd_vals.x, isisd_vals.y, lib ); - + /* Investigate reduction phase discrepencies */ if (ospfd_vals.a.c0 == isisd_vals.a.c0 && ospfd_vals.a.c1 == isisd_vals.a.c1) { printf ("\n"); - for (i = 0; reducts[i].name != NULL; i++) { + for (i = 0; reducts[i].name != NULL; i++) { ospfd = reducts[i].f (&ospfd_vals, exercise + sizeof (u_int16_t), exercise); @@ -553,7 +556,7 @@ main(int argc, char **argv) reducts[i].name, ospfd_vals.x & 0xff, ospfd_vals.y & 0xff, ospfd); } } - + printf ("\n u_char testdata [] = {\n "); for (i = 0; i < exercise; i++) { printf ("0x%02x,%s", diff --git a/tests/test-sig.c b/tests/test-sig.c index 63aab6f0..d9eb24f0 100644 --- a/tests/test-sig.c +++ b/tests/test-sig.c @@ -2,6 +2,10 @@ #include <sigevent.h> #include "lib/log.h" +extern void sighup (void) ; +extern void sigusr1 (void) ; +extern void sigusr2 (void) ; + void sighup (void) { @@ -20,7 +24,7 @@ sigusr2 (void) printf ("processed usr2\n"); } -struct quagga_signal_t sigs[] = +struct quagga_signal_t sigs[] = { { .signal = SIGHUP, @@ -44,13 +48,13 @@ main (void) { master = thread_master_create (); signal_init (master, Q_SIGC(sigs), sigs); - + zlog_default = openzlog("testsig", ZLOG_NONE, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); - + while (thread_fetch (master, &t)) thread_call (&t); |