diff options
| author | whitespace / reindent <invalid@invalid.invalid> | 2017-08-09 11:49:42 +0200 | 
|---|---|---|
| committer | whitespace / reindent <invalid@invalid.invalid> | 2017-08-09 12:03:17 +0200 | 
| commit | ac4d0be5874fafd14212d6007fff7495edc9b152 (patch) | |
| tree | 5e2f0d3189de928c849f9983406389ade3b098cb /tests | |
| parent | 76a86854181c27819e5cf71b12ae1fa5ccd9e02a (diff) | |
*: reindentreindent-3.0-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tests')
29 files changed, 6023 insertions, 5698 deletions
diff --git a/tests/bgpd/test_aspath.c b/tests/bgpd/test_aspath.c index e5ff6a1377..a8ecaa5710 100644 --- a/tests/bgpd/test_aspath.c +++ b/tests/bgpd/test_aspath.c @@ -1,4 +1,4 @@ -/*  +/*   * Copyright (C) 2005 Sun Microsystems, Inc.   *   * This file is part of Quagga. @@ -16,7 +16,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -45,1345 +45,1346 @@ struct thread_master *master = NULL;  static int failed = 0;  /* specification for a test - what the results should be */ -struct test_spec  -{ -  const char *shouldbe; /* the string the path should parse to */ -  const char *shouldbe_delete_confed; /* ditto, but once confeds are deleted */ -  const unsigned int hops; /* aspath_count_hops result */ -  const unsigned int confeds; /* aspath_count_confeds */ -  const int private_as; /* whether the private_as check should pass or fail */ +struct test_spec { +	const char *shouldbe; /* the string the path should parse to */ +	const char *shouldbe_delete_confed; /* ditto, but once confeds are +					       deleted */ +	const unsigned int hops;	    /* aspath_count_hops result */ +	const unsigned int confeds;	 /* aspath_count_confeds */ +	const int private_as; /* whether the private_as check should pass or +				 fail */  #define NOT_ALL_PRIVATE 0  #define ALL_PRIVATE 1 -  const as_t does_loop; /* an ASN which should trigger loop-check */ -  const as_t doesnt_loop; /* one which should not */ -  const as_t first; /* the first ASN, if there is one */ +	const as_t does_loop;   /* an ASN which should trigger loop-check */ +	const as_t doesnt_loop; /* one which should not */ +	const as_t first;       /* the first ASN, if there is one */  #define NULL_ASN 0  };  /* test segments to parse and validate, and use for other tests */  static struct test_segment { -  const char *name; -  const char *desc; -  const u_char asdata[1024]; -  int len; -  struct test_spec sp; -} test_segments [] =  -{ -  { /* 0 */  -    "seq1", -    "seq(8466,3,52737,4096)", -    { 0x2,0x4, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00 }, -    10, -    { "8466 3 52737 4096", -      "8466 3 52737 4096", -      4, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, -  }, -  { /* 1 */ -    "seq2", -    "seq(8722) seq(4)", -    { 0x2,0x1, 0x22,0x12, -      0x2,0x1, 0x00,0x04 }, -    8, -    { "8722 4", -      "8722 4", -      2, 0, NOT_ALL_PRIVATE, 4, 5, 8722, }, -  }, -  { /* 2 */ -    "seq3", -    "seq(8466,3,52737,4096,8722,4)", -    { 0x2,0x6, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00,  -               0x22,0x12, 0x00,0x04}, -    14, -    { "8466 3 52737 4096 8722 4", -      "8466 3 52737 4096 8722 4", -       6, 0, NOT_ALL_PRIVATE, 3, 5, 8466 }, -  }, -  { /* 3 */ -    "seqset", -    "seq(8482,51457) set(5204)", -    { 0x2,0x2, 0x21,0x22, 0xc9,0x01, -      0x1,0x1, 0x14,0x54 }, -    10, -    { "8482 51457 {5204}", -      "8482 51457 {5204}", -      3, 0, NOT_ALL_PRIVATE, 5204, 51456, 8482}, -  }, -  { /* 4 */ -    "seqset2", -    "seq(8467, 59649) set(4196,48658) set(17322,30745)", -    { 0x2,0x2, 0x21,0x13, 0xe9,0x01, -      0x1,0x2, 0x10,0x64, 0xbe,0x12, -      0x1,0x2, 0x43,0xaa, 0x78,0x19 },     -    18, -    { "8467 59649 {4196,48658} {17322,30745}", -      "8467 59649 {4196,48658} {17322,30745}", -      4, 0, NOT_ALL_PRIVATE, 48658, 1, 8467}, -  }, -  { /* 5 */ -    "multi", -    "seq(6435,59408,21665) set(2457,61697,4369), seq(1842,41590,51793)", -    { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, -      0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11, -      0x2,0x3, 0x07,0x32, 0xa2,0x76, 0xca,0x51 }, -    24, -    { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", -      "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", -      7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 }, -  }, -  { /* 6 */ -    "confed", -    "confseq(123,456,789)", -    { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15 }, -    8, -    { "(123 456 789)", -      "", -      0, 3, NOT_ALL_PRIVATE, 789, 1, NULL_ASN }, -  }, -  { /* 7 */ -    "confed2", -    "confseq(123,456,789) confseq(111,222)", -    { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15, -      0x3,0x2, 0x00,0x6f, 0x00,0xde }, -    14, -    { "(123 456 789) (111 222)", -      "", -      0, 5, NOT_ALL_PRIVATE, 111, 1, NULL_ASN }, -  }, -  { /* 8 */ -    "confset", -    "confset(456,123,789)", -    { 0x4,0x3, 0x01,0xc8, 0x00,0x7b, 0x03,0x15 }, -    8, -    { "[123,456,789]", -      "", -      0, 1, NOT_ALL_PRIVATE, 123, 1, NULL_ASN }, -  }, -  { /* 9 */ -    "confmulti", -    "confseq(123,456,789) confset(222,111) seq(8722) set(4196,48658)", -    { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15, -      0x4,0x2, 0x00,0xde, 0x00,0x6f, -      0x2,0x1, 0x22,0x12, -      0x1,0x2, 0x10,0x64, 0xbe,0x12 }, -    24, -    { "(123 456 789) [111,222] 8722 {4196,48658}", -      "8722 {4196,48658}", -      2, 4, NOT_ALL_PRIVATE, 123, 1, NULL_ASN }, -  }, -  { /* 10 */ -    "seq4", -    "seq(8466,2,52737,4096,8722,4)", -    { 0x2,0x6, 0x21,0x12, 0x00,0x02, 0xce,0x01, 0x10,0x00,  -               0x22,0x12, 0x00,0x04}, -    14, -    { "8466 2 52737 4096 8722 4", -      "8466 2 52737 4096 8722 4", -      6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 }, -  }, -  { /* 11 */ -    "tripleseq1", -    "seq(8466,2,52737) seq(4096,8722,4) seq(8722)", -    { 0x2,0x3, 0x21,0x12, 0x00,0x02, 0xce,0x01,  -      0x2,0x3, 0x10,0x00, 0x22,0x12, 0x00,0x04, -      0x2,0x1, 0x22,0x12}, -    20, -    { "8466 2 52737 4096 8722 4 8722", -      "8466 2 52737 4096 8722 4 8722", -      7, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 }, -  }, -  { /* 12 */  -    "someprivate", -    "seq(8466,64512,52737,65535)", -    { 0x2,0x4, 0x21,0x12, 0xfc,0x00, 0xce,0x01, 0xff,0xff }, -    10, -    { "8466 64512 52737 65535", -      "8466 64512 52737 65535", -      4, 0, NOT_ALL_PRIVATE, 65535, 4, 8466 }, -  }, -  { /* 13 */  -    "allprivate", -    "seq(65534,64512,64513,65535)", -    { 0x2,0x4, 0xff,0xfe, 0xfc,0x00, 0xfc,0x01, 0xff,0xff }, -    10, -    { "65534 64512 64513 65535", -      "65534 64512 64513 65535", -      4, 0, ALL_PRIVATE, 65534, 4, 65534 }, -  }, -  { /* 14 */  -    "long", -    "seq(8466,3,52737,4096,34285,<repeated 49 more times>)", -    { 0x2,0xfa, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, -                0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, }, -    502, -    { "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285", -       -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285", -      250, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, -  }, -  { /* 15 */  -    "seq1extra", -    "seq(8466,3,52737,4096,3456)", -    { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 }, -    12, -    { "8466 3 52737 4096 3456", -      "8466 3 52737 4096 3456", -      5, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, -  }, -  { /* 16 */ -    "empty", -    "<empty>", -    {}, -    0, -    { "", "", 0, 0, 0, 0, 0, 0 }, -  }, -  { /* 17 */  -    "redundantset", -    "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)", -    { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80, -      0x1,0x4, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9 }, -    22, -    { -     /* We shouldn't ever /generate/ such paths. However, we should -      * cope with them fine. -      */ -     "8466 3 52737 4096 3456 {7099,8153}", -      "8466 3 52737 4096 3456 {7099,8153}", -      6, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, -  }, -  { /* 18 */ -    "reconcile_lead_asp", -    "seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)", -    { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, -      0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0, -      0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 }, -    24, -    { "6435 59408 21665 {23456} 23456 23456 23456", -      "6435 59408 21665 {23456} 23456 23456 23456", -      7, 0, NOT_ALL_PRIVATE, 23456, 1, 6435 }, -  }, -  { /* 19 */ -    "reconcile_new_asp", -    "set(2457,61697,4369), seq(1842,41591,51793)", -    {  -      0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11, -      0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51 }, -    16, -    { "{2457,4369,61697} 1842 41591 51793", -      "{2457,4369,61697} 1842 41591 51793", -      4, 0, NOT_ALL_PRIVATE, 51793, 1, 2457 }, -  }, -  { /* 20 */ -    "reconcile_confed", -    "confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665)" -    " set(23456,23456,23456), seq(23456,23456,23456)", -    { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15, -      0x4,0x3, 0x01,0xc8, 0x00,0x7c, 0x03,0x14, -      0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, -      0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0, -      0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 }, -    40, -    { "(123 456 789) [124,456,788] 6435 59408 21665" -      " {23456} 23456 23456 23456", -      "6435 59408 21665 {23456} 23456 23456 23456", -      7, 4, NOT_ALL_PRIVATE, 23456, 1, 6435 }, -  }, -  { /* 21 */ -    "reconcile_start_trans", -    "seq(23456,23456,23456) seq(6435,59408,21665)", -    { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0, -      0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, }, -    16, -    { "23456 23456 23456 6435 59408 21665", -      "23456 23456 23456 6435 59408 21665", -      6, 0, NOT_ALL_PRIVATE, 21665, 1, 23456 }, -  }, -  { /* 22 */ -    "reconcile_start_trans4", -    "seq(1842,41591,51793) seq(6435,59408,21665)", -    { 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51, -      0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, }, -    16, -    { "1842 41591 51793 6435 59408 21665", -      "1842 41591 51793 6435 59408 21665", -      6, 0, NOT_ALL_PRIVATE, 41591, 1, 1842 }, -  }, -  { /* 23 */ -    "reconcile_start_trans_error", -    "seq(23456,23456,23456) seq(6435,59408)", -    { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0, -      0x2,0x2, 0x19,0x23, 0xe8,0x10, }, -    14, -    { "23456 23456 23456 6435 59408", -      "23456 23456 23456 6435 59408", -      5, 0, NOT_ALL_PRIVATE, 59408, 1, 23456 }, -  }, -  { /* 24 */  -    "redundantset2", -    "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)", -    { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80, -      0x1,0x5, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9, 0x1b,0xbb,}, -    24, -    { -     /* We should weed out duplicate set members. */ -     "8466 3 52737 4096 3456 {7099,8153}", -      "8466 3 52737 4096 3456 {7099,8153}", -      6, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, -  }, -  { /* 25 */  -    "zero-size overflow", -    "#ASNs = 0, data = seq(8466 3 52737 4096 3456)", -    { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 }, -    12, -    { NULL, NULL, -      0, 0, 0, 0, 0, 0 }, -  }, -  { /* 26  */  -    "zero-size overflow + valid segment", -    "seq(#AS=0:8466 3 52737),seq(4096 3456)", -    { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01,  -      0x2,0x2, 0x10,0x00, 0x0d,0x80 }, -    14 -    , -    { NULL, NULL, -      0, 0, 0, 0, 0, 0 }, -  }, -  { /* 27  */  -    "invalid segment type", -    "type=8(4096 3456)", -    { 0x8,0x2, 0x10,0x00, 0x0d,0x80 }, -    14 -    , -    { NULL, NULL, -      0, 0, 0, 0, 0, 0 }, -  },  { NULL, NULL, {0}, 0, { NULL, 0, 0 } } -}; +	const char *name; +	const char *desc; +	const u_char asdata[1024]; +	int len; +	struct test_spec sp; +} test_segments[] = { +	{ +		/* 0 */ +		"seq1", +		"seq(8466,3,52737,4096)", +		{0x2, 0x4, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00}, +		10, +		{"8466 3 52737 4096", "8466 3 52737 4096", 4, 0, +		 NOT_ALL_PRIVATE, 4096, 4, 8466}, +	}, +	{ +		/* 1 */ +		"seq2", +		"seq(8722) seq(4)", +		{0x2, 0x1, 0x22, 0x12, 0x2, 0x1, 0x00, 0x04}, +		8, +		{ +			"8722 4", "8722 4", 2, 0, NOT_ALL_PRIVATE, 4, 5, 8722, +		}, +	}, +	{ +		/* 2 */ +		"seq3", +		"seq(8466,3,52737,4096,8722,4)", +		{0x2, 0x6, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x22, +		 0x12, 0x00, 0x04}, +		14, +		{"8466 3 52737 4096 8722 4", "8466 3 52737 4096 8722 4", 6, 0, +		 NOT_ALL_PRIVATE, 3, 5, 8466}, +	}, +	{ +		/* 3 */ +		"seqset", +		"seq(8482,51457) set(5204)", +		{0x2, 0x2, 0x21, 0x22, 0xc9, 0x01, 0x1, 0x1, 0x14, 0x54}, +		10, +		{"8482 51457 {5204}", "8482 51457 {5204}", 3, 0, +		 NOT_ALL_PRIVATE, 5204, 51456, 8482}, +	}, +	{ +		/* 4 */ +		"seqset2", +		"seq(8467, 59649) set(4196,48658) set(17322,30745)", +		{0x2, 0x2, 0x21, 0x13, 0xe9, 0x01, 0x1, 0x2, 0x10, 0x64, 0xbe, +		 0x12, 0x1, 0x2, 0x43, 0xaa, 0x78, 0x19}, +		18, +		{"8467 59649 {4196,48658} {17322,30745}", +		 "8467 59649 {4196,48658} {17322,30745}", 4, 0, NOT_ALL_PRIVATE, +		 48658, 1, 8467}, +	}, +	{ +		/* 5 */ +		"multi", +		"seq(6435,59408,21665) set(2457,61697,4369), seq(1842,41590,51793)", +		{0x2, 0x3, 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1, +		 0x1, 0x3, 0x09, 0x99, 0xf1, 0x01, 0x11, 0x11, +		 0x2, 0x3, 0x07, 0x32, 0xa2, 0x76, 0xca, 0x51}, +		24, +		{"6435 59408 21665 {2457,4369,61697} 1842 41590 51793", +		 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", 7, 0, +		 NOT_ALL_PRIVATE, 51793, 1, 6435}, +	}, +	{ +		/* 6 */ +		"confed", +		"confseq(123,456,789)", +		{0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15}, +		8, +		{"(123 456 789)", "", 0, 3, NOT_ALL_PRIVATE, 789, 1, NULL_ASN}, +	}, +	{ +		/* 7 */ +		"confed2", +		"confseq(123,456,789) confseq(111,222)", +		{0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, 0x3, 0x2, 0x00, +		 0x6f, 0x00, 0xde}, +		14, +		{"(123 456 789) (111 222)", "", 0, 5, NOT_ALL_PRIVATE, 111, 1, +		 NULL_ASN}, +	}, +	{ +		/* 8 */ +		"confset", +		"confset(456,123,789)", +		{0x4, 0x3, 0x01, 0xc8, 0x00, 0x7b, 0x03, 0x15}, +		8, +		{"[123,456,789]", "", 0, 1, NOT_ALL_PRIVATE, 123, 1, NULL_ASN}, +	}, +	{ +		/* 9 */ +		"confmulti", +		"confseq(123,456,789) confset(222,111) seq(8722) set(4196,48658)", +		{0x3,  0x3,  0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, +		 0x4,  0x2,  0x00, 0xde, 0x00, 0x6f, 0x2,  0x1, +		 0x22, 0x12, 0x1,  0x2,  0x10, 0x64, 0xbe, 0x12}, +		24, +		{"(123 456 789) [111,222] 8722 {4196,48658}", +		 "8722 {4196,48658}", 2, 4, NOT_ALL_PRIVATE, 123, 1, NULL_ASN}, +	}, +	{ +		/* 10 */ +		"seq4", +		"seq(8466,2,52737,4096,8722,4)", +		{0x2, 0x6, 0x21, 0x12, 0x00, 0x02, 0xce, 0x01, 0x10, 0x00, 0x22, +		 0x12, 0x00, 0x04}, +		14, +		{"8466 2 52737 4096 8722 4", "8466 2 52737 4096 8722 4", 6, 0, +		 NOT_ALL_PRIVATE, 4096, 1, 8466}, +	}, +	{ +		/* 11 */ +		"tripleseq1", +		"seq(8466,2,52737) seq(4096,8722,4) seq(8722)", +		{0x2,  0x3,  0x21, 0x12, 0x00, 0x02, 0xce, 0x01, 0x2,  0x3, +		 0x10, 0x00, 0x22, 0x12, 0x00, 0x04, 0x2,  0x1,  0x22, 0x12}, +		20, +		{"8466 2 52737 4096 8722 4 8722", +		 "8466 2 52737 4096 8722 4 8722", 7, 0, NOT_ALL_PRIVATE, 4096, +		 1, 8466}, +	}, +	{ +		/* 12 */ +		"someprivate", +		"seq(8466,64512,52737,65535)", +		{0x2, 0x4, 0x21, 0x12, 0xfc, 0x00, 0xce, 0x01, 0xff, 0xff}, +		10, +		{"8466 64512 52737 65535", "8466 64512 52737 65535", 4, 0, +		 NOT_ALL_PRIVATE, 65535, 4, 8466}, +	}, +	{ +		/* 13 */ +		"allprivate", +		"seq(65534,64512,64513,65535)", +		{0x2, 0x4, 0xff, 0xfe, 0xfc, 0x00, 0xfc, 0x01, 0xff, 0xff}, +		10, +		{"65534 64512 64513 65535", "65534 64512 64513 65535", 4, 0, +		 ALL_PRIVATE, 65534, 4, 65534}, +	}, +	{ +		/* 14 */ +		"long", +		"seq(8466,3,52737,4096,34285,<repeated 49 more times>)", +		{ +			0x2,  0xfa, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, +			0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, +			0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, +			0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, +			0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, +			0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, +			0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, +			0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, +			0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, +			0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, +			0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, +			0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, +			0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, +			0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, +			0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, +			0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, +			0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, +			0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, +			0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, +			0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, +			0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, +			0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, +			0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, +			0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, +			0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, +			0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, +			0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, +			0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, +			0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, +			0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, +			0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, +			0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, +			0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, +			0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, +			0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, +			0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, +			0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, +			0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, +			0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, +			0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, +			0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, +			0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, +			0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, +			0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, +			0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, +			0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, +			0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, +			0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, +			0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, +			0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, +			0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, +			0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, +			0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, +			0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, +			0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, +			0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, +		}, +		502, +		{"8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285", -#define COMMON_ATTRS \ -      BGP_ATTR_FLAG_TRANS, \ -      BGP_ATTR_ORIGIN, \ -      1, \ -      BGP_ORIGIN_EGP, \ -      BGP_ATTR_FLAG_TRANS, \ -      BGP_ATTR_NEXT_HOP, \ -      4, 192, 0, 2, 0 +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285", +		 250, 0, NOT_ALL_PRIVATE, 4096, 4, 8466}, +	}, +	{ +		/* 15 */ +		"seq1extra", +		"seq(8466,3,52737,4096,3456)", +		{0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x0d, +		 0x80}, +		12, +		{"8466 3 52737 4096 3456", "8466 3 52737 4096 3456", 5, 0, +		 NOT_ALL_PRIVATE, 4096, 4, 8466}, +	}, +	{ +		/* 16 */ +		"empty", +		"<empty>", +		{}, +		0, +		{"", "", 0, 0, 0, 0, 0, 0}, +	}, +	{ +		/* 17 */ +		"redundantset", +		"seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)", +		{0x2,  0x5,  0x21, 0x12, 0x00, 0x03, 0xce, 0x01, +		 0x10, 0x00, 0x0d, 0x80, 0x1,  0x4,  0x1b, 0xbb, +		 0x1f, 0xd9, 0x1f, 0xd9, 0x1f, 0xd9}, +		22, +		{/* We shouldn't ever /generate/ such paths. However, we should +		  * cope with them fine. +		  */ +		 "8466 3 52737 4096 3456 {7099,8153}", +		 "8466 3 52737 4096 3456 {7099,8153}", 6, 0, NOT_ALL_PRIVATE, +		 4096, 4, 8466}, +	}, +	{ +		/* 18 */ +		"reconcile_lead_asp", +		"seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)", +		{0x2, 0x3, 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1, +		 0x1, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0, +		 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0}, +		24, +		{"6435 59408 21665 {23456} 23456 23456 23456", +		 "6435 59408 21665 {23456} 23456 23456 23456", 7, 0, +		 NOT_ALL_PRIVATE, 23456, 1, 6435}, +	}, +	{ +		/* 19 */ +		"reconcile_new_asp", +		"set(2457,61697,4369), seq(1842,41591,51793)", +		{0x1, 0x3, 0x09, 0x99, 0xf1, 0x01, 0x11, 0x11, 0x2, 0x3, 0x07, +		 0x32, 0xa2, 0x77, 0xca, 0x51}, +		16, +		{"{2457,4369,61697} 1842 41591 51793", +		 "{2457,4369,61697} 1842 41591 51793", 4, 0, NOT_ALL_PRIVATE, +		 51793, 1, 2457}, +	}, +	{ +		/* 20 */ +		"reconcile_confed", +		"confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665)" +		" set(23456,23456,23456), seq(23456,23456,23456)", +		{0x3,  0x3,  0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, 0x4,  0x3, +		 0x01, 0xc8, 0x00, 0x7c, 0x03, 0x14, 0x2,  0x3,  0x19, 0x23, +		 0xe8, 0x10, 0x54, 0xa1, 0x1,  0x3,  0x5b, 0xa0, 0x5b, 0xa0, +		 0x5b, 0xa0, 0x2,  0x3,  0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0}, +		40, +		{"(123 456 789) [124,456,788] 6435 59408 21665" +		 " {23456} 23456 23456 23456", +		 "6435 59408 21665 {23456} 23456 23456 23456", 7, 4, +		 NOT_ALL_PRIVATE, 23456, 1, 6435}, +	}, +	{ +		/* 21 */ +		"reconcile_start_trans", +		"seq(23456,23456,23456) seq(6435,59408,21665)", +		{ +			0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0, 0x2, 0x3, +			0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1, +		}, +		16, +		{"23456 23456 23456 6435 59408 21665", +		 "23456 23456 23456 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE, +		 21665, 1, 23456}, +	}, +	{ +		/* 22 */ +		"reconcile_start_trans4", +		"seq(1842,41591,51793) seq(6435,59408,21665)", +		{ +			0x2, 0x3, 0x07, 0x32, 0xa2, 0x77, 0xca, 0x51, 0x2, 0x3, +			0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1, +		}, +		16, +		{"1842 41591 51793 6435 59408 21665", +		 "1842 41591 51793 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE, +		 41591, 1, 1842}, +	}, +	{ +		/* 23 */ +		"reconcile_start_trans_error", +		"seq(23456,23456,23456) seq(6435,59408)", +		{ +			0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0, 0x2, 0x2, +			0x19, 0x23, 0xe8, 0x10, +		}, +		14, +		{"23456 23456 23456 6435 59408", "23456 23456 23456 6435 59408", +		 5, 0, NOT_ALL_PRIVATE, 59408, 1, 23456}, +	}, +	{ +		/* 24 */ +		"redundantset2", +		"seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)", +		{ +			0x2,  0x5,  0x21, 0x12, 0x00, 0x03, 0xce, 0x01, +			0x10, 0x00, 0x0d, 0x80, 0x1,  0x5,  0x1b, 0xbb, +			0x1f, 0xd9, 0x1f, 0xd9, 0x1f, 0xd9, 0x1b, 0xbb, +		}, +		24, +		{/* We should weed out duplicate set members. */ +		 "8466 3 52737 4096 3456 {7099,8153}", +		 "8466 3 52737 4096 3456 {7099,8153}", 6, 0, NOT_ALL_PRIVATE, +		 4096, 4, 8466}, +	}, +	{ +		/* 25 */ +		"zero-size overflow", +		"#ASNs = 0, data = seq(8466 3 52737 4096 3456)", +		{0x2, 0x0, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x0d, +		 0x80}, +		12, +		{NULL, NULL, 0, 0, 0, 0, 0, 0}, +	}, +	{ +		/* 26  */ +		"zero-size overflow + valid segment", +		"seq(#AS=0:8466 3 52737),seq(4096 3456)", +		{0x2, 0x0, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x2, 0x2, 0x10, +		 0x00, 0x0d, 0x80}, +		14, +		{NULL, NULL, 0, 0, 0, 0, 0, 0}, +	}, +	{ +		/* 27  */ +		"invalid segment type", +		"type=8(4096 3456)", +		{0x8, 0x2, 0x10, 0x00, 0x0d, 0x80}, +		14, +		{NULL, NULL, 0, 0, 0, 0, 0, 0}, +	}, +	{NULL, NULL, {0}, 0, {NULL, 0, 0}}}; + +#define COMMON_ATTRS                                                           \ +	BGP_ATTR_FLAG_TRANS, BGP_ATTR_ORIGIN, 1, BGP_ORIGIN_EGP,               \ +		BGP_ATTR_FLAG_TRANS, BGP_ATTR_NEXT_HOP, 4, 192, 0, 2, 0  #define COMMON_ATTR_SIZE 11  /* */  static struct aspath_tests { -  const char *desc; -  const struct test_segment *segment; -  const char *shouldbe;  /* String it should evaluate to */ -  const enum as4 { AS4_DATA, AS2_DATA } -          as4; 	/* whether data should be as4 or not (ie as2) */ -  const int result;	/* expected result for bgp_attr_parse */ -  const int cap;	/* capabilities to set for peer */ -  const char attrheader [1024]; -  size_t len; -  const struct test_segment *old_segment; -} aspath_tests [] = -{ -  /* 0 */ -  { -    "basic test", -    &test_segments[0], -    "8466 3 52737 4096", -    AS2_DATA, 0, -    0, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS, -      BGP_ATTR_AS_PATH, -      10, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 1 */ -  { -    "length too short", -    &test_segments[0], -    "8466 3 52737 4096", -    AS2_DATA, -1, -    0, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS, -      BGP_ATTR_AS_PATH,  -      8, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 2 */ -  { -    "length too long", -    &test_segments[0], -    "8466 3 52737 4096", -    AS2_DATA, -1, -    0, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS, -      BGP_ATTR_AS_PATH,  -      12, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 3 */ -  { -    "incorrect flag", -    &test_segments[0], -    "8466 3 52737 4096", -    AS2_DATA, -1, -    0, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, -      BGP_ATTR_AS_PATH,  -      10, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 4 */ -  { -    "as4_path, with as2 format data", -    &test_segments[0], -    "8466 3 52737 4096", -    AS2_DATA, -1, -    0, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, -      BGP_ATTR_AS4_PATH,  -      10, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 5 */ -  { -    "as4, with incorrect attr length", -    &test_segments[0], -    "8466 3 52737 4096", -    AS4_DATA, -1, -    PEER_CAP_AS4_RCV, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, -      BGP_ATTR_AS4_PATH,  -      10, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 6 */ -  { -    "basic 4-byte as-path", -    &test_segments[0], -    "8466 3 52737 4096", -    AS4_DATA, 0, -    PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS, -      BGP_ATTR_AS_PATH,  -      18, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 7 */ -  { -    "4b AS_PATH: too short", -    &test_segments[0], -    "8466 3 52737 4096", -    AS4_DATA, -1, -    PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS, -      BGP_ATTR_AS_PATH,  -      16, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 8 */ -  { -    "4b AS_PATH: too long", -    &test_segments[0], -    "8466 3 52737 4096", -    AS4_DATA, -1, -    PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS, -      BGP_ATTR_AS_PATH,  -      20, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 9 */ -  { -    "4b AS_PATH: too long2", -    &test_segments[0], -    "8466 3 52737 4096", -    AS4_DATA, -1, -    PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS, -      BGP_ATTR_AS_PATH,  -      22, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 10 */ -  { -    "4b AS_PATH: bad flags", -    &test_segments[0], -    "8466 3 52737 4096", -    AS4_DATA, -1, -    PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, -      BGP_ATTR_AS_PATH,  -      18, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 11 */ -  { -    "4b AS4_PATH w/o AS_PATH", -    &test_segments[6], -    NULL, -    AS4_DATA, -1, -    PEER_CAP_AS4_ADV, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, -      BGP_ATTR_AS4_PATH,  -      14, -    }, -    COMMON_ATTR_SIZE + 3, -  }, -  /* 12 */ -  { -    "4b AS4_PATH: confed", -    &test_segments[6], -    "8466 3 52737 4096 (123 456 789)", -    AS4_DATA, 0, -    PEER_CAP_AS4_ADV, -    { COMMON_ATTRS, -      BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, -      BGP_ATTR_AS4_PATH,  -      14, -    }, -    COMMON_ATTR_SIZE + 3, -    &test_segments[0], -  }, -  { NULL, NULL, NULL, 0, 0, 0, { 0 }, 0 }, +	const char *desc; +	const struct test_segment *segment; +	const char *shouldbe; /* String it should evaluate to */ +	const enum as4 { +		AS4_DATA, +		AS2_DATA +	} as4;		  /* whether data should be as4 or not (ie as2) */ +	const int result; /* expected result for bgp_attr_parse */ +	const int cap;    /* capabilities to set for peer */ +	const char attrheader[1024]; +	size_t len; +	const struct test_segment *old_segment; +} aspath_tests[] = { +	/* 0 */ +	{ +		"basic test", +		&test_segments[0], +		"8466 3 52737 4096", +		AS2_DATA, +		0, +		0, +		{ +			COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 10, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 1 */ +	{ +		"length too short", +		&test_segments[0], +		"8466 3 52737 4096", +		AS2_DATA, +		-1, +		0, +		{ +			COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 8, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 2 */ +	{ +		"length too long", +		&test_segments[0], +		"8466 3 52737 4096", +		AS2_DATA, +		-1, +		0, +		{ +			COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 12, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 3 */ +	{ +		"incorrect flag", +		&test_segments[0], +		"8466 3 52737 4096", +		AS2_DATA, +		-1, +		0, +		{ +			COMMON_ATTRS, +			BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, +			BGP_ATTR_AS_PATH, 10, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 4 */ +	{ +		"as4_path, with as2 format data", +		&test_segments[0], +		"8466 3 52737 4096", +		AS2_DATA, +		-1, +		0, +		{ +			COMMON_ATTRS, +			BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, +			BGP_ATTR_AS4_PATH, 10, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 5 */ +	{ +		"as4, with incorrect attr length", +		&test_segments[0], +		"8466 3 52737 4096", +		AS4_DATA, +		-1, +		PEER_CAP_AS4_RCV, +		{ +			COMMON_ATTRS, +			BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, +			BGP_ATTR_AS4_PATH, 10, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 6 */ +	{ +		"basic 4-byte as-path", +		&test_segments[0], +		"8466 3 52737 4096", +		AS4_DATA, +		0, +		PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, +		{ +			COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 18, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 7 */ +	{ +		"4b AS_PATH: too short", +		&test_segments[0], +		"8466 3 52737 4096", +		AS4_DATA, +		-1, +		PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, +		{ +			COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 16, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 8 */ +	{ +		"4b AS_PATH: too long", +		&test_segments[0], +		"8466 3 52737 4096", +		AS4_DATA, +		-1, +		PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, +		{ +			COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 20, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 9 */ +	{ +		"4b AS_PATH: too long2", +		&test_segments[0], +		"8466 3 52737 4096", +		AS4_DATA, +		-1, +		PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, +		{ +			COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 22, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 10 */ +	{ +		"4b AS_PATH: bad flags", +		&test_segments[0], +		"8466 3 52737 4096", +		AS4_DATA, +		-1, +		PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, +		{ +			COMMON_ATTRS, +			BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, +			BGP_ATTR_AS_PATH, 18, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 11 */ +	{ +		"4b AS4_PATH w/o AS_PATH", +		&test_segments[6], +		NULL, +		AS4_DATA, +		-1, +		PEER_CAP_AS4_ADV, +		{ +			COMMON_ATTRS, +			BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, +			BGP_ATTR_AS4_PATH, 14, +		}, +		COMMON_ATTR_SIZE + 3, +	}, +	/* 12 */ +	{ +		"4b AS4_PATH: confed", +		&test_segments[6], +		"8466 3 52737 4096 (123 456 789)", +		AS4_DATA, +		0, +		PEER_CAP_AS4_ADV, +		{ +			COMMON_ATTRS, +			BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, +			BGP_ATTR_AS4_PATH, 14, +		}, +		COMMON_ATTR_SIZE + 3, +		&test_segments[0], +	}, +	{NULL, NULL, NULL, 0, 0, 0, {0}, 0},  };  /* prepending tests */  static struct tests { -  const struct test_segment *test1; -  const struct test_segment *test2; -  struct test_spec sp; -} prepend_tests[] =  -{ -  /* 0 */ -  { &test_segments[0], &test_segments[1], -    { "8466 3 52737 4096 8722 4", -      "8466 3 52737 4096 8722 4", -      6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 }, -  }, -  /* 1 */ -  { &test_segments[1], &test_segments[3], -    { "8722 4 8482 51457 {5204}", -      "8722 4 8482 51457 {5204}", -      5, 0, NOT_ALL_PRIVATE, 5204, 1, 8722 } -  }, -  /* 2 */ -  { &test_segments[3], &test_segments[4], -    { "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", -      "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", -      7, 0, NOT_ALL_PRIVATE, 5204, 1, 8482 }, -  }, -  /* 3 */ -  { &test_segments[4], &test_segments[5], -    { "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665" -      " {2457,4369,61697} 1842 41590 51793", -      "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665" -      " {2457,4369,61697} 1842 41590 51793", -      11, 0, NOT_ALL_PRIVATE, 61697, 1, 8467 } -  }, -  /* 4 */ -  { &test_segments[5], &test_segments[6], -    { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", -      "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", -      7, 0, NOT_ALL_PRIVATE, 1842, 1, 6435 }, -  }, -  /* 5 */ -  { &test_segments[6], &test_segments[7], -    { "(123 456 789) (123 456 789) (111 222)", -      "", -      0, 8, NOT_ALL_PRIVATE, 111, 1, 0 } -  }, -  { &test_segments[7], &test_segments[8], -    { "(123 456 789) (111 222) [123,456,789]", -      "", -      0, 6, NOT_ALL_PRIVATE, 111, 1, 0 } -  }, -  { &test_segments[8], &test_segments[9], -    { "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}", -      "8722 {4196,48658}", -      2, 5, NOT_ALL_PRIVATE, 456, 1, NULL_ASN }, -  }, -  { &test_segments[9], &test_segments[8], -    { "(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]", -      "8722 {4196,48658}", -      2, 5, NOT_ALL_PRIVATE, 48658, 1, NULL_ASN }, -  }, -  { &test_segments[14], &test_segments[11], -    { "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 2 52737 4096 8722 4 8722", -       -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " -      "8466 2 52737 4096 8722 4 8722", -      257, 0, NOT_ALL_PRIVATE, 4096, 1000, 8466 }, -  }, -  { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } }, +	const struct test_segment *test1; +	const struct test_segment *test2; +	struct test_spec sp; +} prepend_tests[] = { +	/* 0 */ +	{ +		&test_segments[0], +		&test_segments[1], +		{"8466 3 52737 4096 8722 4", "8466 3 52737 4096 8722 4", 6, 0, +		 NOT_ALL_PRIVATE, 4096, 1, 8466}, +	}, +	/* 1 */ +	{&test_segments[1], +	 &test_segments[3], +	 {"8722 4 8482 51457 {5204}", "8722 4 8482 51457 {5204}", 5, 0, +	  NOT_ALL_PRIVATE, 5204, 1, 8722}}, +	/* 2 */ +	{ +		&test_segments[3], +		&test_segments[4], +		{"8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", +		 "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", 7, +		 0, NOT_ALL_PRIVATE, 5204, 1, 8482}, +	}, +	/* 3 */ +	{&test_segments[4], +	 &test_segments[5], +	 {"8467 59649 {4196,48658} {17322,30745} 6435 59408 21665" +	  " {2457,4369,61697} 1842 41590 51793", +	  "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665" +	  " {2457,4369,61697} 1842 41590 51793", +	  11, 0, NOT_ALL_PRIVATE, 61697, 1, 8467}}, +	/* 4 */ +	{ +		&test_segments[5], +		&test_segments[6], +		{"6435 59408 21665 {2457,4369,61697} 1842 41590 51793", +		 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", 7, 0, +		 NOT_ALL_PRIVATE, 1842, 1, 6435}, +	}, +	/* 5 */ +	{&test_segments[6], +	 &test_segments[7], +	 {"(123 456 789) (123 456 789) (111 222)", "", 0, 8, NOT_ALL_PRIVATE, +	  111, 1, 0}}, +	{&test_segments[7], +	 &test_segments[8], +	 {"(123 456 789) (111 222) [123,456,789]", "", 0, 6, NOT_ALL_PRIVATE, +	  111, 1, 0}}, +	{ +		&test_segments[8], +		&test_segments[9], +		{"[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}", +		 "8722 {4196,48658}", 2, 5, NOT_ALL_PRIVATE, 456, 1, NULL_ASN}, +	}, +	{ +		&test_segments[9], +		&test_segments[8], +		{"(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]", +		 "8722 {4196,48658}", 2, 5, NOT_ALL_PRIVATE, 48658, 1, +		 NULL_ASN}, +	}, +	{ +		&test_segments[14], +		&test_segments[11], +		{"8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 2 52737 4096 8722 4 8722", + +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " +		 "8466 2 52737 4096 8722 4 8722", +		 257, 0, NOT_ALL_PRIVATE, 4096, 1000, 8466}, +	}, +	{NULL, +	 NULL, +	 { +		 NULL, 0, 0, 0, 0, 0, 0, +	 }},  }; -struct tests reconcile_tests[] = -{ -  { &test_segments[18], &test_segments[19], -    { "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", -      "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", -      7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 }, -  }, -  { &test_segments[19], &test_segments[18], -    /* AS_PATH (19) has more hops than NEW_AS_PATH, -     * so just AS_PATH should be used (though, this practice -     * is bad imho). -     */ -    { "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456", -      "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456", -      11, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 }, -  }, -  { &test_segments[20], &test_segments[19], -    { "(123 456 789) [124,456,788] 6435 59408 21665" -      " {2457,4369,61697} 1842 41591 51793", -      "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", -      7, 4, NOT_ALL_PRIVATE, 51793, 1, 6435 }, -  }, -  { &test_segments[21], &test_segments[22], -    { "1842 41591 51793 6435 59408 21665", -      "1842 41591 51793 6435 59408 21665", -      6, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 }, -  }, -  { &test_segments[23], &test_segments[22], -    { "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665", -      "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665", -      11, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 }, -  }, -  { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } }, +struct tests reconcile_tests[] = { +	{ +		&test_segments[18], +		&test_segments[19], +		{"6435 59408 21665 {2457,4369,61697} 1842 41591 51793", +		 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", 7, 0, +		 NOT_ALL_PRIVATE, 51793, 1, 6435}, +	}, +	{ +		&test_segments[19], +		&test_segments[18], +		/* AS_PATH (19) has more hops than NEW_AS_PATH, +		 * so just AS_PATH should be used (though, this practice +		 * is bad imho). +		 */ +		{"{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456", +		 "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456", +		 11, 0, NOT_ALL_PRIVATE, 51793, 1, 6435}, +	}, +	{ +		&test_segments[20], +		&test_segments[19], +		{"(123 456 789) [124,456,788] 6435 59408 21665" +		 " {2457,4369,61697} 1842 41591 51793", +		 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", 7, 4, +		 NOT_ALL_PRIVATE, 51793, 1, 6435}, +	}, +	{ +		&test_segments[21], +		&test_segments[22], +		{"1842 41591 51793 6435 59408 21665", +		 "1842 41591 51793 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE, +		 51793, 1, 1842}, +	}, +	{ +		&test_segments[23], +		&test_segments[22], +		{"23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665", +		 "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665", +		 11, 0, NOT_ALL_PRIVATE, 51793, 1, 1842}, +	}, +	{NULL, +	 NULL, +	 { +		 NULL, 0, 0, 0, 0, 0, 0, +	 }},  }; -   -struct tests aggregate_tests[] = -{ -  { &test_segments[0], &test_segments[2], -    { "8466 3 52737 4096 {4,8722}", -      "8466 3 52737 4096 {4,8722}", -      5, 0, NOT_ALL_PRIVATE, 4, 1, 8466 }, -  }, -  { &test_segments[2], &test_segments[0], -    { "8466 3 52737 4096 {4,8722}", -      "8466 3 52737 4096 {4,8722}", -      5, 0, NOT_ALL_PRIVATE, 8722, 1, 8466 }, -  }, -  { &test_segments[2], &test_segments[10], -    { "8466 {2,3,4,4096,8722,52737}", -      "8466 {2,3,4,4096,8722,52737}", -      2, 0, NOT_ALL_PRIVATE, 8722, 5, 8466 }, -  }, -  { &test_segments[10], &test_segments[2], -    { "8466 {2,3,4,4096,8722,52737}", -      "8466 {2,3,4,4096,8722,52737}", -      2, 0, NOT_ALL_PRIVATE, 2, 20000, 8466 }, -  }, - -  { &test_segments[5], &test_segments[18], -    { "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", -      "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", -      4, 0, NOT_ALL_PRIVATE, 41590, 1, 6435 }, -  }, - -  { NULL, NULL, { NULL, 0, 0}  }, + +struct tests aggregate_tests[] = { +	{ +		&test_segments[0], +		&test_segments[2], +		{"8466 3 52737 4096 {4,8722}", "8466 3 52737 4096 {4,8722}", 5, +		 0, NOT_ALL_PRIVATE, 4, 1, 8466}, +	}, +	{ +		&test_segments[2], +		&test_segments[0], +		{"8466 3 52737 4096 {4,8722}", "8466 3 52737 4096 {4,8722}", 5, +		 0, NOT_ALL_PRIVATE, 8722, 1, 8466}, +	}, +	{ +		&test_segments[2], +		&test_segments[10], +		{"8466 {2,3,4,4096,8722,52737}", "8466 {2,3,4,4096,8722,52737}", +		 2, 0, NOT_ALL_PRIVATE, 8722, 5, 8466}, +	}, +	{ +		&test_segments[10], +		&test_segments[2], +		{"8466 {2,3,4,4096,8722,52737}", "8466 {2,3,4,4096,8722,52737}", +		 2, 0, NOT_ALL_PRIVATE, 2, 20000, 8466}, +	}, + +	{ +		&test_segments[5], +		&test_segments[18], +		{"6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", +		 "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", 4, +		 0, NOT_ALL_PRIVATE, 41590, 1, 6435}, +	}, + +	{NULL, NULL, {NULL, 0, 0}},  }; -struct compare_tests  -{ -  int test_index1; -  int test_index2; +struct compare_tests { +	int test_index1; +	int test_index2;  #define CMP_RES_YES 1  #define CMP_RES_NO 0 -  char shouldbe_cmp; -  char shouldbe_confed; -} left_compare [] = -{ -  { 0, 1, CMP_RES_NO, CMP_RES_NO }, -  { 0, 2, CMP_RES_YES, CMP_RES_NO }, -  { 0, 11, CMP_RES_YES, CMP_RES_NO }, -  { 0, 15, CMP_RES_YES, CMP_RES_NO }, -  { 0, 16, CMP_RES_NO, CMP_RES_NO }, -  { 1, 11, CMP_RES_NO, CMP_RES_NO }, -  { 6, 7, CMP_RES_NO, CMP_RES_YES }, -  { 6, 8, CMP_RES_NO, CMP_RES_NO }, -  { 7, 8, CMP_RES_NO, CMP_RES_NO }, -  { 1, 9, CMP_RES_YES, CMP_RES_NO }, -  { 0, 9, CMP_RES_NO, CMP_RES_NO }, -  { 3, 9, CMP_RES_NO, CMP_RES_NO }, -  { 0, 6, CMP_RES_NO, CMP_RES_NO }, -  { 1, 6, CMP_RES_NO, CMP_RES_NO }, -  { 0, 8, CMP_RES_NO, CMP_RES_NO }, -  { 1, 8, CMP_RES_NO, CMP_RES_NO }, -  { 11, 6, CMP_RES_NO, CMP_RES_NO }, -  { 11, 7, CMP_RES_NO, CMP_RES_NO }, -  { 11, 8, CMP_RES_NO, CMP_RES_NO }, -  { 9, 6, CMP_RES_NO, CMP_RES_YES }, -  { 9, 7, CMP_RES_NO, CMP_RES_YES }, -  { 9, 8, CMP_RES_NO, CMP_RES_NO }, +	char shouldbe_cmp; +	char shouldbe_confed; +} left_compare[] = { +	{0, 1, CMP_RES_NO, CMP_RES_NO},   {0, 2, CMP_RES_YES, CMP_RES_NO}, +	{0, 11, CMP_RES_YES, CMP_RES_NO}, {0, 15, CMP_RES_YES, CMP_RES_NO}, +	{0, 16, CMP_RES_NO, CMP_RES_NO},  {1, 11, CMP_RES_NO, CMP_RES_NO}, +	{6, 7, CMP_RES_NO, CMP_RES_YES},  {6, 8, CMP_RES_NO, CMP_RES_NO}, +	{7, 8, CMP_RES_NO, CMP_RES_NO},   {1, 9, CMP_RES_YES, CMP_RES_NO}, +	{0, 9, CMP_RES_NO, CMP_RES_NO},   {3, 9, CMP_RES_NO, CMP_RES_NO}, +	{0, 6, CMP_RES_NO, CMP_RES_NO},   {1, 6, CMP_RES_NO, CMP_RES_NO}, +	{0, 8, CMP_RES_NO, CMP_RES_NO},   {1, 8, CMP_RES_NO, CMP_RES_NO}, +	{11, 6, CMP_RES_NO, CMP_RES_NO},  {11, 7, CMP_RES_NO, CMP_RES_NO}, +	{11, 8, CMP_RES_NO, CMP_RES_NO},  {9, 6, CMP_RES_NO, CMP_RES_YES}, +	{9, 7, CMP_RES_NO, CMP_RES_YES},  {9, 8, CMP_RES_NO, CMP_RES_NO},  };  /* make an aspath from a data stream */ -static struct aspath * -make_aspath (const u_char *data, size_t len, int use32bit) +static struct aspath *make_aspath(const u_char *data, size_t len, int use32bit)  { -  struct stream *s = NULL; -  struct aspath *as; -   -  if (len) -    { -      s = stream_new (len); -      stream_put (s, data, len); -    } -  as = aspath_parse (s, len, use32bit); -   -  if (s) -    stream_free (s); -   -  return as; +	struct stream *s = NULL; +	struct aspath *as; + +	if (len) { +		s = stream_new(len); +		stream_put(s, data, len); +	} +	as = aspath_parse(s, len, use32bit); + +	if (s) +		stream_free(s); + +	return as;  } -static void -printbytes (const u_char *bytes, int len) +static void printbytes(const u_char *bytes, int len)  { -  int i = 0; -  while (i < len) -    { -      if (i % 2) -        printf ("%02hhx%s", bytes[i], " "); -      else -        printf ("0x%02hhx", bytes[i]); -      i++; -    } -  printf ("\n"); -}   +	int i = 0; +	while (i < len) { +		if (i % 2) +			printf("%02hhx%s", bytes[i], " "); +		else +			printf("0x%02hhx", bytes[i]); +		i++; +	} +	printf("\n"); +}  /* validate the given aspath */ -static int -validate (struct aspath *as, const struct test_spec *sp) +static int validate(struct aspath *as, const struct test_spec *sp)  { -  size_t bytes, bytes4; -  int fails = 0; -  const u_char *out; -  static struct stream *s; -  struct aspath *asinout, *asconfeddel, *asstr, *as4; -   -  if (as == NULL && sp->shouldbe == NULL) -    { -      printf ("Correctly failed to parse\n"); -      return fails; -    } -   -  out = aspath_snmp_pathseg (as, &bytes); -  asinout = make_aspath (out, bytes, 0); -   -  /* Excercise AS4 parsing a bit, with a dogfood test */ -  if (!s) -    s = stream_new (4096); -  bytes4 = aspath_put (s, as, 1); -  as4 = make_aspath (STREAM_DATA(s), bytes4, 1); -   -  asstr = aspath_str2aspath (sp->shouldbe); -   -  asconfeddel = aspath_delete_confed_seq (aspath_dup (asinout)); -   -  printf ("got: %s\n", aspath_print(as)); -   -  /* the parsed path should match the specified 'shouldbe' string. -   * We should pass the "eat our own dog food" test, be able to output -   * this path and then input it again. Ie the path resulting from: -   * -   *   aspath_parse(aspath_put(as))  -   * -   * should: -   * -   * - also match the specified 'shouldbe' value -   * - hash to same value as original path -   * - have same hops and confed counts as original, and as the -   *   the specified counts -   * -   * aspath_str2aspath() and shouldbe should match -   * -   * We do the same for: -   * -   *   aspath_parse(aspath_put(as,USE32BIT)) -   * -   * Confederation related tests:  -   * - aspath_delete_confed_seq(aspath) should match shouldbe_confed -   * - aspath_delete_confed_seq should be idempotent. -   */ -  if (strcmp(aspath_print (as), sp->shouldbe) -         /* hash validation */ -      || (aspath_key_make (as) != aspath_key_make (asinout)) -         /* by string */ -      || strcmp(aspath_print (asinout), sp->shouldbe) -         /* By 4-byte parsing */ -      || strcmp(aspath_print (as4), sp->shouldbe) -         /* by various path counts */ -      || (aspath_count_hops (as) != sp->hops) -      || (aspath_count_confeds (as) != sp->confeds) -      || (aspath_count_hops (asinout) != sp->hops) -      || (aspath_count_confeds (asinout) != sp->confeds)) -    { -      failed++; -      fails++; -      printf ("shouldbe:\n%s\n", sp->shouldbe); -      printf ("as4:\n%s\n", aspath_print (as4)); -      printf ("hash keys: in: %d out->in: %d\n",  -              aspath_key_make (as), aspath_key_make (asinout)); -      printf ("hops: %d, counted %d %d\n", sp->hops,  -              aspath_count_hops (as), -              aspath_count_hops (asinout) ); -      printf ("confeds: %d, counted %d %d\n", sp->confeds, -              aspath_count_confeds (as), -              aspath_count_confeds (asinout)); -      printf ("out->in:\n%s\nbytes: ", aspath_print(asinout)); -      printbytes (out, bytes); -    } -         /* basic confed related tests */ -  if ((aspath_print (asconfeddel) == NULL  -          && sp->shouldbe_delete_confed != NULL) -      || (aspath_print (asconfeddel) != NULL  -          && sp->shouldbe_delete_confed == NULL) -      || strcmp(aspath_print (asconfeddel), sp->shouldbe_delete_confed) -         /* delete_confed_seq should be idempotent */ -      || (aspath_key_make (asconfeddel)  -          != aspath_key_make (aspath_delete_confed_seq (asconfeddel)))) -    { -      failed++; -      fails++; -      printf ("as-path minus confeds is: %s\n", aspath_print (asconfeddel)); -      printf ("as-path minus confeds should be: %s\n", sp->shouldbe_delete_confed); -    } -      /* aspath_str2aspath test */ -  if ((aspath_print (asstr) == NULL && sp->shouldbe != NULL) -      || (aspath_print (asstr) != NULL && sp->shouldbe == NULL) -      || strcmp(aspath_print (asstr), sp->shouldbe)) -    { -      failed++; -      fails++; -      printf ("asstr: %s\n", aspath_print (asstr)); -    } -   -    /* loop, private and first as checks */ -  if ((sp->does_loop && aspath_loop_check (as, sp->does_loop) == 0) -      || (sp->doesnt_loop && aspath_loop_check (as, sp->doesnt_loop) != 0) -      || (aspath_private_as_check (as) != sp->private_as) -      || (aspath_firstas_check (as,sp->first) -          && sp->first == 0)) -    { -      failed++; -      fails++; -      printf ("firstas: %d,  got %d\n", sp->first, -              aspath_firstas_check (as,sp->first)); -      printf ("loop does: %d %d, doesnt: %d %d\n", -              sp->does_loop, aspath_loop_check (as, sp->does_loop), -              sp->doesnt_loop, aspath_loop_check (as, sp->doesnt_loop)); -      printf ("private check: %d %d\n", sp->private_as, -              aspath_private_as_check (as)); -    } -  aspath_unintern (&asinout); -  aspath_unintern (&as4); -   -  aspath_free (asconfeddel); -  aspath_free (asstr); -  stream_reset (s); -   -  return fails; +	size_t bytes, bytes4; +	int fails = 0; +	const u_char *out; +	static struct stream *s; +	struct aspath *asinout, *asconfeddel, *asstr, *as4; + +	if (as == NULL && sp->shouldbe == NULL) { +		printf("Correctly failed to parse\n"); +		return fails; +	} + +	out = aspath_snmp_pathseg(as, &bytes); +	asinout = make_aspath(out, bytes, 0); + +	/* Excercise AS4 parsing a bit, with a dogfood test */ +	if (!s) +		s = stream_new(4096); +	bytes4 = aspath_put(s, as, 1); +	as4 = make_aspath(STREAM_DATA(s), bytes4, 1); + +	asstr = aspath_str2aspath(sp->shouldbe); + +	asconfeddel = aspath_delete_confed_seq(aspath_dup(asinout)); + +	printf("got: %s\n", aspath_print(as)); + +	/* the parsed path should match the specified 'shouldbe' string. +	 * We should pass the "eat our own dog food" test, be able to output +	 * this path and then input it again. Ie the path resulting from: +	 * +	 *   aspath_parse(aspath_put(as)) +	 * +	 * should: +	 * +	 * - also match the specified 'shouldbe' value +	 * - hash to same value as original path +	 * - have same hops and confed counts as original, and as the +	 *   the specified counts +	 * +	 * aspath_str2aspath() and shouldbe should match +	 * +	 * We do the same for: +	 * +	 *   aspath_parse(aspath_put(as,USE32BIT)) +	 * +	 * Confederation related tests: +	 * - aspath_delete_confed_seq(aspath) should match shouldbe_confed +	 * - aspath_delete_confed_seq should be idempotent. +	 */ +	if (strcmp(aspath_print(as), sp->shouldbe) +	    /* hash validation */ +	    || (aspath_key_make(as) != aspath_key_make(asinout)) +	    /* by string */ +	    || strcmp(aspath_print(asinout), sp->shouldbe) +	    /* By 4-byte parsing */ +	    || strcmp(aspath_print(as4), sp->shouldbe) +	    /* by various path counts */ +	    || (aspath_count_hops(as) != sp->hops) +	    || (aspath_count_confeds(as) != sp->confeds) +	    || (aspath_count_hops(asinout) != sp->hops) +	    || (aspath_count_confeds(asinout) != sp->confeds)) { +		failed++; +		fails++; +		printf("shouldbe:\n%s\n", sp->shouldbe); +		printf("as4:\n%s\n", aspath_print(as4)); +		printf("hash keys: in: %d out->in: %d\n", aspath_key_make(as), +		       aspath_key_make(asinout)); +		printf("hops: %d, counted %d %d\n", sp->hops, +		       aspath_count_hops(as), aspath_count_hops(asinout)); +		printf("confeds: %d, counted %d %d\n", sp->confeds, +		       aspath_count_confeds(as), aspath_count_confeds(asinout)); +		printf("out->in:\n%s\nbytes: ", aspath_print(asinout)); +		printbytes(out, bytes); +	} +	/* basic confed related tests */ +	if ((aspath_print(asconfeddel) == NULL +	     && sp->shouldbe_delete_confed != NULL) +	    || (aspath_print(asconfeddel) != NULL +		&& sp->shouldbe_delete_confed == NULL) +	    || strcmp(aspath_print(asconfeddel), sp->shouldbe_delete_confed) +	    /* delete_confed_seq should be idempotent */ +	    || (aspath_key_make(asconfeddel) +		!= aspath_key_make(aspath_delete_confed_seq(asconfeddel)))) { +		failed++; +		fails++; +		printf("as-path minus confeds is: %s\n", +		       aspath_print(asconfeddel)); +		printf("as-path minus confeds should be: %s\n", +		       sp->shouldbe_delete_confed); +	} +	/* aspath_str2aspath test */ +	if ((aspath_print(asstr) == NULL && sp->shouldbe != NULL) +	    || (aspath_print(asstr) != NULL && sp->shouldbe == NULL) +	    || strcmp(aspath_print(asstr), sp->shouldbe)) { +		failed++; +		fails++; +		printf("asstr: %s\n", aspath_print(asstr)); +	} + +	/* loop, private and first as checks */ +	if ((sp->does_loop && aspath_loop_check(as, sp->does_loop) == 0) +	    || (sp->doesnt_loop && aspath_loop_check(as, sp->doesnt_loop) != 0) +	    || (aspath_private_as_check(as) != sp->private_as) +	    || (aspath_firstas_check(as, sp->first) && sp->first == 0)) { +		failed++; +		fails++; +		printf("firstas: %d,  got %d\n", sp->first, +		       aspath_firstas_check(as, sp->first)); +		printf("loop does: %d %d, doesnt: %d %d\n", sp->does_loop, +		       aspath_loop_check(as, sp->does_loop), sp->doesnt_loop, +		       aspath_loop_check(as, sp->doesnt_loop)); +		printf("private check: %d %d\n", sp->private_as, +		       aspath_private_as_check(as)); +	} +	aspath_unintern(&asinout); +	aspath_unintern(&as4); + +	aspath_free(asconfeddel); +	aspath_free(asstr); +	stream_reset(s); + +	return fails;  } -static void -empty_get_test () +static void empty_get_test()  { -  struct aspath *as = aspath_empty_get (); -  struct test_spec sp = { "", "", 0, 0, 0, 0, 0, 0 }; - -  printf ("empty_get_test, as: %s\n",aspath_print (as)); -  if (!validate (as, &sp)) -    printf ("%s\n", OK); -  else -    printf ("%s!\n", FAILED); -   -  printf ("\n"); -   -  aspath_free (as); +	struct aspath *as = aspath_empty_get(); +	struct test_spec sp = {"", "", 0, 0, 0, 0, 0, 0}; + +	printf("empty_get_test, as: %s\n", aspath_print(as)); +	if (!validate(as, &sp)) +		printf("%s\n", OK); +	else +		printf("%s!\n", FAILED); + +	printf("\n"); + +	aspath_free(as);  }  /* basic parsing test */ -static void -parse_test (struct test_segment *t) +static void parse_test(struct test_segment *t)  { -  struct aspath *asp; -   -  printf ("%s: %s\n", t->name, t->desc); - -  asp = make_aspath (t->asdata, t->len, 0); -   -  printf ("aspath: %s\nvalidating...:\n", aspath_print (asp)); - -  if (!validate (asp, &t->sp)) -    printf (OK "\n"); -  else -    printf (FAILED "\n"); -   -  printf ("\n"); -   -  if (asp) -    aspath_unintern (&asp); +	struct aspath *asp; + +	printf("%s: %s\n", t->name, t->desc); + +	asp = make_aspath(t->asdata, t->len, 0); + +	printf("aspath: %s\nvalidating...:\n", aspath_print(asp)); + +	if (!validate(asp, &t->sp)) +		printf(OK "\n"); +	else +		printf(FAILED "\n"); + +	printf("\n"); + +	if (asp) +		aspath_unintern(&asp);  }  /* prepend testing */ -static void -prepend_test (struct tests *t) +static void prepend_test(struct tests *t)  { -  struct aspath *asp1, *asp2, *ascratch; -   -  printf ("prepend %s: %s\n", t->test1->name, t->test1->desc); -  printf ("to %s: %s\n", t->test2->name, t->test2->desc); -   -  asp1 = make_aspath (t->test1->asdata, t->test1->len, 0); -  asp2 = make_aspath (t->test2->asdata, t->test2->len, 0); -   -  ascratch = aspath_dup (asp2); -  aspath_unintern (&asp2); -   -  asp2 = aspath_prepend (asp1, ascratch); -   -  printf ("aspath: %s\n", aspath_print (asp2)); -   -  if (!validate (asp2, &t->sp)) -    printf ("%s\n", OK); -  else -    printf ("%s!\n", FAILED); -   -  printf ("\n"); -  aspath_unintern (&asp1); -  aspath_free (asp2); +	struct aspath *asp1, *asp2, *ascratch; + +	printf("prepend %s: %s\n", t->test1->name, t->test1->desc); +	printf("to %s: %s\n", t->test2->name, t->test2->desc); + +	asp1 = make_aspath(t->test1->asdata, t->test1->len, 0); +	asp2 = make_aspath(t->test2->asdata, t->test2->len, 0); + +	ascratch = aspath_dup(asp2); +	aspath_unintern(&asp2); + +	asp2 = aspath_prepend(asp1, ascratch); + +	printf("aspath: %s\n", aspath_print(asp2)); + +	if (!validate(asp2, &t->sp)) +		printf("%s\n", OK); +	else +		printf("%s!\n", FAILED); + +	printf("\n"); +	aspath_unintern(&asp1); +	aspath_free(asp2);  }  /* empty-prepend testing */ -static void -empty_prepend_test (struct test_segment *t) +static void empty_prepend_test(struct test_segment *t)  { -  struct aspath *asp1, *asp2, *ascratch; -   -  printf ("empty prepend %s: %s\n", t->name, t->desc); -   -  asp1 = make_aspath (t->asdata, t->len, 0); -  asp2 = aspath_empty (); -   -  ascratch = aspath_dup (asp2); -  aspath_unintern (&asp2); -   -  asp2 = aspath_prepend (asp1, ascratch); -   -  printf ("aspath: %s\n", aspath_print (asp2)); -   -  if (!validate (asp2, &t->sp)) -    printf (OK "\n"); -  else -    printf (FAILED "!\n"); -   -  printf ("\n"); -  if (asp1) -    aspath_unintern (&asp1); -  aspath_free (asp2); +	struct aspath *asp1, *asp2, *ascratch; + +	printf("empty prepend %s: %s\n", t->name, t->desc); + +	asp1 = make_aspath(t->asdata, t->len, 0); +	asp2 = aspath_empty(); + +	ascratch = aspath_dup(asp2); +	aspath_unintern(&asp2); + +	asp2 = aspath_prepend(asp1, ascratch); + +	printf("aspath: %s\n", aspath_print(asp2)); + +	if (!validate(asp2, &t->sp)) +		printf(OK "\n"); +	else +		printf(FAILED "!\n"); + +	printf("\n"); +	if (asp1) +		aspath_unintern(&asp1); +	aspath_free(asp2);  }  /* as2+as4 reconciliation testing */ -static void -as4_reconcile_test (struct tests *t) +static void as4_reconcile_test(struct tests *t)  { -  struct aspath *asp1, *asp2, *ascratch; -   -  printf ("reconciling %s:\n  %s\n", t->test1->name, t->test1->desc); -  printf ("with %s:\n  %s\n", t->test2->name, t->test2->desc); -   -  asp1 = make_aspath (t->test1->asdata, t->test1->len, 0); -  asp2 = make_aspath (t->test2->asdata, t->test2->len, 0); -   -  ascratch = aspath_reconcile_as4 (asp1, asp2); -   -  if (!validate (ascratch, &t->sp)) -    printf (OK "\n"); -  else -    printf (FAILED "!\n"); -   -  printf ("\n"); -  aspath_unintern (&asp1); -  aspath_unintern (&asp2); -  aspath_free (ascratch); +	struct aspath *asp1, *asp2, *ascratch; + +	printf("reconciling %s:\n  %s\n", t->test1->name, t->test1->desc); +	printf("with %s:\n  %s\n", t->test2->name, t->test2->desc); + +	asp1 = make_aspath(t->test1->asdata, t->test1->len, 0); +	asp2 = make_aspath(t->test2->asdata, t->test2->len, 0); + +	ascratch = aspath_reconcile_as4(asp1, asp2); + +	if (!validate(ascratch, &t->sp)) +		printf(OK "\n"); +	else +		printf(FAILED "!\n"); + +	printf("\n"); +	aspath_unintern(&asp1); +	aspath_unintern(&asp2); +	aspath_free(ascratch);  }  /* aggregation testing */ -static void -aggregate_test (struct tests *t) +static void aggregate_test(struct tests *t)  { -  struct aspath *asp1, *asp2, *ascratch; -   -  printf ("aggregate %s: %s\n", t->test1->name, t->test1->desc); -  printf ("with %s: %s\n", t->test2->name, t->test2->desc); -   -  asp1 = make_aspath (t->test1->asdata, t->test1->len, 0); -  asp2 = make_aspath (t->test2->asdata, t->test2->len, 0); -   -  ascratch = aspath_aggregate (asp1, asp2); -   -  if (!validate (ascratch, &t->sp)) -    printf (OK "\n"); -  else -    printf (FAILED "!\n"); -   -  printf ("\n"); -  aspath_unintern (&asp1); -  aspath_unintern (&asp2); -  aspath_free (ascratch); -/*  aspath_unintern (ascratch);*/ +	struct aspath *asp1, *asp2, *ascratch; + +	printf("aggregate %s: %s\n", t->test1->name, t->test1->desc); +	printf("with %s: %s\n", t->test2->name, t->test2->desc); + +	asp1 = make_aspath(t->test1->asdata, t->test1->len, 0); +	asp2 = make_aspath(t->test2->asdata, t->test2->len, 0); + +	ascratch = aspath_aggregate(asp1, asp2); + +	if (!validate(ascratch, &t->sp)) +		printf(OK "\n"); +	else +		printf(FAILED "!\n"); + +	printf("\n"); +	aspath_unintern(&asp1); +	aspath_unintern(&asp2); +	aspath_free(ascratch); +	/*  aspath_unintern (ascratch);*/  }  /* cmp_left tests  */ -static void -cmp_test () +static void cmp_test()  { -  unsigned int i; -#define CMP_TESTS_MAX \ -  (sizeof(left_compare) / sizeof (struct compare_tests)) - -  for (i = 0; i < CMP_TESTS_MAX; i++) -    { -      struct test_segment *t1 = &test_segments[left_compare[i].test_index1]; -      struct test_segment *t2 = &test_segments[left_compare[i].test_index2]; -      struct aspath *asp1, *asp2; -       -      printf ("left cmp %s: %s\n", t1->name, t1->desc); -      printf ("and %s: %s\n", t2->name, t2->desc); -       -      asp1 = make_aspath (t1->asdata, t1->len, 0); -      asp2 = make_aspath (t2->asdata, t2->len, 0); -       -      if (aspath_cmp_left (asp1, asp2) != left_compare[i].shouldbe_cmp -          || aspath_cmp_left (asp2, asp1) != left_compare[i].shouldbe_cmp -          || aspath_cmp_left_confed (asp1, asp2)  -               != left_compare[i].shouldbe_confed -          || aspath_cmp_left_confed (asp2, asp1)  -               != left_compare[i].shouldbe_confed) -        { -          failed++; -          printf (FAILED "\n"); -          printf ("result should be: cmp: %d, confed: %d\n",  -                  left_compare[i].shouldbe_cmp, -                  left_compare[i].shouldbe_confed); -          printf ("got: cmp %d, cmp_confed: %d\n", -                  aspath_cmp_left (asp1, asp2), -                  aspath_cmp_left_confed (asp1, asp2)); -          printf("path1: %s\npath2: %s\n", aspath_print (asp1), -                 aspath_print (asp2)); -        } -      else -        printf (OK "\n"); -       -      printf ("\n"); -      aspath_unintern (&asp1); -      aspath_unintern (&asp2); -    } +	unsigned int i; +#define CMP_TESTS_MAX (sizeof(left_compare) / sizeof(struct compare_tests)) + +	for (i = 0; i < CMP_TESTS_MAX; i++) { +		struct test_segment *t1 = +			&test_segments[left_compare[i].test_index1]; +		struct test_segment *t2 = +			&test_segments[left_compare[i].test_index2]; +		struct aspath *asp1, *asp2; + +		printf("left cmp %s: %s\n", t1->name, t1->desc); +		printf("and %s: %s\n", t2->name, t2->desc); + +		asp1 = make_aspath(t1->asdata, t1->len, 0); +		asp2 = make_aspath(t2->asdata, t2->len, 0); + +		if (aspath_cmp_left(asp1, asp2) != left_compare[i].shouldbe_cmp +		    || aspath_cmp_left(asp2, asp1) +			       != left_compare[i].shouldbe_cmp +		    || aspath_cmp_left_confed(asp1, asp2) +			       != left_compare[i].shouldbe_confed +		    || aspath_cmp_left_confed(asp2, asp1) +			       != left_compare[i].shouldbe_confed) { +			failed++; +			printf(FAILED "\n"); +			printf("result should be: cmp: %d, confed: %d\n", +			       left_compare[i].shouldbe_cmp, +			       left_compare[i].shouldbe_confed); +			printf("got: cmp %d, cmp_confed: %d\n", +			       aspath_cmp_left(asp1, asp2), +			       aspath_cmp_left_confed(asp1, asp2)); +			printf("path1: %s\npath2: %s\n", aspath_print(asp1), +			       aspath_print(asp2)); +		} else +			printf(OK "\n"); + +		printf("\n"); +		aspath_unintern(&asp1); +		aspath_unintern(&asp2); +	}  } -static int -handle_attr_test (struct aspath_tests *t) +static int handle_attr_test(struct aspath_tests *t)  { -  struct bgp bgp = { 0 };  -  struct peer peer = { 0 }; -  struct attr attr = { 0 };   -  int ret; -  int initfail = failed; -  struct aspath *asp; -  size_t datalen; -   -  asp = make_aspath (t->segment->asdata, t->segment->len, 0); -     -  peer.ibuf = stream_new (BGP_MAX_PACKET_SIZE); -  peer.obuf = stream_fifo_new (); -  peer.bgp = &bgp; -  peer.host = (char *)"none"; -  peer.fd = -1; -  peer.cap = t->cap; -   -  stream_write (peer.ibuf, t->attrheader, t->len); -  datalen = aspath_put (peer.ibuf, asp, t->as4 == AS4_DATA); -  if (t->old_segment) -    { -      char dummyaspath[] = { BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, -                             t->old_segment->len }; -      stream_write (peer.ibuf, dummyaspath, sizeof (dummyaspath)); -      stream_write (peer.ibuf, t->old_segment->asdata, t->old_segment->len); -      datalen += sizeof (dummyaspath) + t->old_segment->len; -    } -   -  ret = bgp_attr_parse (&peer, &attr, t->len + datalen, NULL, NULL); -   -  if (ret != t->result) -    { -      printf ("bgp_attr_parse returned %d, expected %d\n", ret, t->result); -      printf ("datalen %zd\n", datalen); -      failed++; -    } -  if (ret != 0) -    goto out; -   -  if (t->shouldbe && attr.aspath == NULL) -    { -      printf ("aspath is NULL, but should be: %s\n", t->shouldbe); -      failed++; -    } -  if (t->shouldbe && attr.aspath && strcmp (attr.aspath->str, t->shouldbe)) -    { -      printf ("attr str and 'shouldbe' mismatched!\n" -              "attr str:  %s\n" -              "shouldbe:  %s\n", -              attr.aspath->str, t->shouldbe); -      failed++; -    } -  if (!t->shouldbe && attr.aspath) -    { -      printf ("aspath should be NULL, but is: %s\n", attr.aspath->str); -      failed++; -    } +	struct bgp bgp = {0}; +	struct peer peer = {0}; +	struct attr attr = {0}; +	int ret; +	int initfail = failed; +	struct aspath *asp; +	size_t datalen; + +	asp = make_aspath(t->segment->asdata, t->segment->len, 0); + +	peer.ibuf = stream_new(BGP_MAX_PACKET_SIZE); +	peer.obuf = stream_fifo_new(); +	peer.bgp = &bgp; +	peer.host = (char *)"none"; +	peer.fd = -1; +	peer.cap = t->cap; + +	stream_write(peer.ibuf, t->attrheader, t->len); +	datalen = aspath_put(peer.ibuf, asp, t->as4 == AS4_DATA); +	if (t->old_segment) { +		char dummyaspath[] = {BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, +				      t->old_segment->len}; +		stream_write(peer.ibuf, dummyaspath, sizeof(dummyaspath)); +		stream_write(peer.ibuf, t->old_segment->asdata, +			     t->old_segment->len); +		datalen += sizeof(dummyaspath) + t->old_segment->len; +	} + +	ret = bgp_attr_parse(&peer, &attr, t->len + datalen, NULL, NULL); + +	if (ret != t->result) { +		printf("bgp_attr_parse returned %d, expected %d\n", ret, +		       t->result); +		printf("datalen %zd\n", datalen); +		failed++; +	} +	if (ret != 0) +		goto out; + +	if (t->shouldbe && attr.aspath == NULL) { +		printf("aspath is NULL, but should be: %s\n", t->shouldbe); +		failed++; +	} +	if (t->shouldbe && attr.aspath +	    && strcmp(attr.aspath->str, t->shouldbe)) { +		printf("attr str and 'shouldbe' mismatched!\n" +		       "attr str:  %s\n" +		       "shouldbe:  %s\n", +		       attr.aspath->str, t->shouldbe); +		failed++; +	} +	if (!t->shouldbe && attr.aspath) { +		printf("aspath should be NULL, but is: %s\n", attr.aspath->str); +		failed++; +	}  out: -  if (attr.aspath) -    aspath_unintern (&attr.aspath); -  if (asp) -    aspath_unintern (&asp); -  return failed - initfail; +	if (attr.aspath) +		aspath_unintern(&attr.aspath); +	if (asp) +		aspath_unintern(&asp); +	return failed - initfail;  } -static void -attr_test (struct aspath_tests *t) +static void attr_test(struct aspath_tests *t)  { -    printf ("%s\n", t->desc); -    printf ("%s\n\n", handle_attr_test (t) ? FAILED : OK);   +	printf("%s\n", t->desc); +	printf("%s\n\n", handle_attr_test(t) ? FAILED : OK);  } -int -main (void) +int main(void)  { -  int i = 0; -  qobj_init (); -  bgp_master_init (thread_master_create ()); -  master = bm->master; -  bgp_option_set (BGP_OPT_NO_LISTEN); -  bgp_attr_init (); -   -  while (test_segments[i].name) -    { -      printf ("test %u\n", i); -      parse_test (&test_segments[i]); -      empty_prepend_test (&test_segments[i++]); -    } -   -  i = 0; -  while (prepend_tests[i].test1) -    { -      printf ("prepend test %u\n", i); -      prepend_test (&prepend_tests[i++]); -    } -   -  i = 0; -  while (aggregate_tests[i].test1) -    { -      printf ("aggregate test %u\n", i); -      aggregate_test (&aggregate_tests[i++]); -    } -   -  i = 0; -   -  while (reconcile_tests[i].test1) -    { -      printf ("reconcile test %u\n", i); -      as4_reconcile_test (&reconcile_tests[i++]); -    } -   -  i = 0; -   -  cmp_test(); -   -  i = 0; -   -  empty_get_test(); -   -  i = 0; -   -  while (aspath_tests[i].desc) -    { -      printf ("aspath_attr test %d\n", i); -      attr_test (&aspath_tests[i++]); -    } -   -  printf ("failures: %d\n", failed); -  printf ("aspath count: %ld\n", aspath_count()); -   -  return (failed + aspath_count()); +	int i = 0; +	qobj_init(); +	bgp_master_init(thread_master_create()); +	master = bm->master; +	bgp_option_set(BGP_OPT_NO_LISTEN); +	bgp_attr_init(); + +	while (test_segments[i].name) { +		printf("test %u\n", i); +		parse_test(&test_segments[i]); +		empty_prepend_test(&test_segments[i++]); +	} + +	i = 0; +	while (prepend_tests[i].test1) { +		printf("prepend test %u\n", i); +		prepend_test(&prepend_tests[i++]); +	} + +	i = 0; +	while (aggregate_tests[i].test1) { +		printf("aggregate test %u\n", i); +		aggregate_test(&aggregate_tests[i++]); +	} + +	i = 0; + +	while (reconcile_tests[i].test1) { +		printf("reconcile test %u\n", i); +		as4_reconcile_test(&reconcile_tests[i++]); +	} + +	i = 0; + +	cmp_test(); + +	i = 0; + +	empty_get_test(); + +	i = 0; + +	while (aspath_tests[i].desc) { +		printf("aspath_attr test %d\n", i); +		attr_test(&aspath_tests[i++]); +	} + +	printf("failures: %d\n", failed); +	printf("aspath count: %ld\n", aspath_count()); + +	return (failed + aspath_count());  } diff --git a/tests/bgpd/test_capability.c b/tests/bgpd/test_capability.c index c3de6a16e8..1c0b72cfaa 100644 --- a/tests/bgpd/test_capability.c +++ b/tests/bgpd/test_capability.c @@ -1,4 +1,4 @@ -/*  +/*   * Copyright (C) 2007 Sun Microsystems, Inc.   *   * This file is part of Quagga. @@ -16,7 +16,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -39,7 +39,6 @@  #define VT100_GREEN "\x1b[32m"  #define VT100_YELLOW "\x1b[33m" -  #define CAPABILITY 0  #define DYNCAP     1  #define OPT_PARAM  2 @@ -53,649 +52,900 @@ static int tty = 0;  /* test segments to parse and validate, and use for other tests */  static struct test_segment { -  const char *name; -  const char *desc; -  const u_char data[1024]; -  int len; +	const char *name; +	const char *desc; +	const u_char data[1024]; +	int len;  #define SHOULD_PARSE	0  #define SHOULD_ERR	-1 -  int parses; /* whether it should parse or not */ -  as_t peek_for; /* what peek_for_as4_capability should say */ -   -  /* AFI/SAFI validation */ -  int validate_afi; -  afi_t afi; -  safi_t safi; +	int parses;    /* whether it should parse or not */ +	as_t peek_for; /* what peek_for_as4_capability should say */ + +	/* AFI/SAFI validation */ +	int validate_afi; +	afi_t afi; +	safi_t safi;  #define VALID_AFI 1  #define INVALID_AFI 0 -  int afi_valid; -} test_segments [] =  -{ -  /* 0 */ -  { "caphdr",  -    "capability header, and no more", -    { CAPABILITY_CODE_REFRESH, 0x0 }, -    2, SHOULD_PARSE, -  }, -  /* 1 */ -  { "nodata", -    "header, no data but length says there is", -    { 0x1, 0xa }, -    2, SHOULD_ERR, -  }, -  /* 2 */ -  { "padded", -    "valid, with padding", -    { CAPABILITY_CODE_REFRESH, 0x2, 0x0, 0x0 }, -    4, SHOULD_PARSE, -  }, -  /* 3 */ -  { "minsize", -    "violates minsize requirement", -    { CAPABILITY_CODE_ORF, 0x2, 0x0, 0x0 }, -    4, SHOULD_ERR, -  }, -  { NULL, NULL, {0}, 0, 0}, +	int afi_valid; +} test_segments[] = { +	/* 0 */ +	{ +		"caphdr", +		"capability header, and no more", +		{CAPABILITY_CODE_REFRESH, 0x0}, +		2, +		SHOULD_PARSE, +	}, +	/* 1 */ +	{ +		"nodata", +		"header, no data but length says there is", +		{0x1, 0xa}, +		2, +		SHOULD_ERR, +	}, +	/* 2 */ +	{ +		"padded", +		"valid, with padding", +		{CAPABILITY_CODE_REFRESH, 0x2, 0x0, 0x0}, +		4, +		SHOULD_PARSE, +	}, +	/* 3 */ +	{ +		"minsize", +		"violates minsize requirement", +		{CAPABILITY_CODE_ORF, 0x2, 0x0, 0x0}, +		4, +		SHOULD_ERR, +	}, +	{NULL, NULL, {0}, 0, 0},  }; -static struct test_segment mp_segments[] = -{ -  { "MP4", -    "MP IP/Uni", -    { 0x1, 0x4, 0x0, 0x1, 0x0, 0x1 }, -    6, SHOULD_PARSE, 0, -    1, AFI_IP, SAFI_UNICAST, VALID_AFI, -  }, -  { "MPv6", -    "MP IPv6/Uni", -    { 0x1, 0x4, 0x0, 0x2, 0x0, 0x1 }, -    6, SHOULD_PARSE, 0, -    1, AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  /* 5 */ -  { "MP2", -    "MP IP/Multicast", -    { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x2 }, -    6, SHOULD_PARSE, 0, -    1, AFI_IP, SAFI_MULTICAST, VALID_AFI, -  }, -  /* 6 */ -  { "MP3", -    "MP IP6/MPLS-labeled VPN", -    { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x80 }, -    6, SHOULD_PARSE, 0, -    1, AFI_IP6, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  /* 7 */ -  { "MP5", -    "MP IP6/MPLS-VPN", -    { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x4 }, -    6, SHOULD_PARSE, 0, -    1, AFI_IP6, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  /* 8 */ -  { "MP6", -    "MP IP4/MPLS-laveled VPN", -    { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80 }, -    6, SHOULD_PARSE, 0, -    1, AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  },   -  /* 10 */ -  { "MP8", -    "MP unknown AFI/SAFI", -    { CAPABILITY_CODE_MP, 0x4, 0x0, 0xa, 0x0, 0x81 }, -    6, SHOULD_PARSE, 0, -    1, 0xa, 0x81, INVALID_AFI, /* parses, but unknown */ -  }, -  /* 11 */ -  { "MP-short", -    "MP IP4/Unicast, length too short (< minimum)", -    { CAPABILITY_CODE_MP, 0x2, 0x0, 0x1, 0x0, 0x1 }, -    6, SHOULD_ERR, -  }, -  /* 12 */ -  { "MP-overflow", -    "MP IP4/Unicast, length too long", -    { CAPABILITY_CODE_MP, 0x6, 0x0, 0x1, 0x0, 0x1 }, -    6, SHOULD_ERR, 0, -    1, AFI_IP, SAFI_UNICAST, VALID_AFI, -  }, -  { NULL, NULL, {0}, 0, 0} -}; +static struct test_segment mp_segments[] = { +	{ +		"MP4", +		"MP IP/Uni", +		{0x1, 0x4, 0x0, 0x1, 0x0, 0x1}, +		6, +		SHOULD_PARSE, +		0, +		1, +		AFI_IP, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"MPv6", +		"MP IPv6/Uni", +		{0x1, 0x4, 0x0, 0x2, 0x0, 0x1}, +		6, +		SHOULD_PARSE, +		0, +		1, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	/* 5 */ +	{ +		"MP2", +		"MP IP/Multicast", +		{CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x2}, +		6, +		SHOULD_PARSE, +		0, +		1, +		AFI_IP, +		SAFI_MULTICAST, +		VALID_AFI, +	}, +	/* 6 */ +	{ +		"MP3", +		"MP IP6/MPLS-labeled VPN", +		{CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x80}, +		6, +		SHOULD_PARSE, +		0, +		1, +		AFI_IP6, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	/* 7 */ +	{ +		"MP5", +		"MP IP6/MPLS-VPN", +		{CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x4}, +		6, +		SHOULD_PARSE, +		0, +		1, +		AFI_IP6, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	/* 8 */ +	{ +		"MP6", +		"MP IP4/MPLS-laveled VPN", +		{CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80}, +		6, +		SHOULD_PARSE, +		0, +		1, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	/* 10 */ +	{ +		"MP8", +		"MP unknown AFI/SAFI", +		{CAPABILITY_CODE_MP, 0x4, 0x0, 0xa, 0x0, 0x81}, +		6, +		SHOULD_PARSE, +		0, +		1, +		0xa, +		0x81, +		INVALID_AFI, /* parses, but unknown */ +	}, +	/* 11 */ +	{ +		"MP-short", +		"MP IP4/Unicast, length too short (< minimum)", +		{CAPABILITY_CODE_MP, 0x2, 0x0, 0x1, 0x0, 0x1}, +		6, +		SHOULD_ERR, +	}, +	/* 12 */ +	{ +		"MP-overflow", +		"MP IP4/Unicast, length too long", +		{CAPABILITY_CODE_MP, 0x6, 0x0, 0x1, 0x0, 0x1}, +		6, +		SHOULD_ERR, +		0, +		1, +		AFI_IP, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{NULL, NULL, {0}, 0, 0}};  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,  -      /* tuples */	0x40, 0x3 -    }, -    9, SHOULD_PARSE, -  }, -  /* 14 */ -  { "ORF-many", -    "ORF, multi entry/tuple", -    { /* hdr */		CAPABILITY_CODE_ORF, 0x21, -      /* 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,  -      /* tuples */	0x40, ORF_MODE_BOTH, -                        0x80, ORF_MODE_RECEIVE, -                        0x80, ORF_MODE_SEND, -      /* mpc */		0x0, 0x2, 0x0, 0x2, -      /* num */		0x3,  -      /* tuples */	0x40, ORF_MODE_RECEIVE, -                        0x80, ORF_MODE_SEND, -                        0x80, ORF_MODE_BOTH, -    }, -    35, SHOULD_PARSE, -  }, -  /* 15 */ -  { "ORFlo", -    "ORF, multi entry/tuple, hdr length too short", -    { /* hdr */		CAPABILITY_CODE_ORF, 0x15, -      /* mpc */		0x0, 0x1, 0x0, 0x1,  -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x1, 0x0, 0x1,  -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x2, -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -    }, -    35, SHOULD_ERR, /* It should error on invalid Route-Refresh.. */ -  }, -  /* 16 */ -  { "ORFlu", -    "ORF, multi entry/tuple, length too long", -    { /* hdr */		0x3, 0x22, -      /* mpc */		0x0, 0x1, 0x0, 0x1,  -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x1,  -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x2, -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -    }, -    35, SHOULD_ERR -  }, -  /* 17 */ -  { "ORFnu", -    "ORF, multi entry/tuple, entry number too long", -    { /* hdr */		0x3, 0x21, -      /* mpc */		0x0, 0x1, 0x0, 0x1,  -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x1,  -      /* num */		0x4,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x2, -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -    }, -    35, SHOULD_PARSE, /* parses, but last few tuples should be gibberish */ -  }, -  /* 18 */ -  { "ORFno", -    "ORF, multi entry/tuple, entry number too short", -    { /* hdr */		0x3, 0x21, -      /* mpc */		0x0, 0x1, 0x0, 0x1,  -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x1,  -      /* num */		0x1,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x2, -      /* num */		0x3, -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -    }, -    35, SHOULD_PARSE, /* Parses, but should get gibberish afi/safis */ -  }, -  /* 17 */ -  { "ORFpad", -    "ORF, multi entry/tuple, padded to align", -    { /* hdr */		0x3, 0x22, -      /* mpc */		0x0, 0x1, 0x0, 0x1,  -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x1,  -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -      /* mpc */		0x0, 0x2, 0x0, 0x2, -      /* num */		0x3,  -      /* tuples */	0x40, 0x3, -                        0x80, 0x1, -                        0x80, 0x2, -                        0x00, -    }, -    36, SHOULD_PARSE, -  }, -  /* 19 */ -  { "AS4", -    "AS4 capability", -    { 0x41, 0x4, 0xab, 0xcd, 0xef, 0x12 }, /* AS: 2882400018 */ -    6, SHOULD_PARSE, 2882400018, -  }, -  { "AS4", -    "AS4 capability: short", -    { 0x41, 0x4, 0xab, 0xcd, 0xef }, /* AS: 2882400018 */ -    5, SHOULD_ERR, -  }, -  { "AS4", -    "AS4 capability: long", -    { 0x41, 0x4, 0xab, 0xcd, 0xef, 0x12, 0x12 }, -    7, SHOULD_ERR, 2882400018, -  }, -  { "GR", -    "GR capability", -    { /* hdr */		CAPABILITY_CODE_RESTART, 0xe, -      /* R-bit, time */	0xf1, 0x12, -      /* afi */		0x0, 0x1, -      /* safi */	0x1, -      /* flags */	0xf, -      /* afi */		0x0, 0x2, -      /* safi */	0x1, -      /* flags */	0x0, -      /* afi */		0x0, 0x2, -      /* safi */	0x2, -      /* flags */	0x1, -    }, -    16, SHOULD_PARSE, -  }, -  { "GR-short", -    "GR capability, but header length too short", -    { /* hdr */		0x40, 0xa, -      /* R-bit, time */	0xf1, 0x12, -      /* afi */		0x0, 0x1, -      /* safi */	0x1, -      /* flags */	0xf, -      /* afi */		0x0, 0x2, -      /* safi */	0x1, -      /* flags */	0x0, -      /* afi */		0x0, 0x2, -      /* safi */	0x2, -      /* flags */	0x1, -    }, -    15 /* array is 16 though */, SHOULD_ERR, -  }, -  { "GR-long", -    "GR capability, but header length too long", -    { /* hdr */		0x40, 0xf, -      /* R-bit, time */	0xf1, 0x12, -      /* afi */		0x0, 0x1, -      /* safi */	0x1, -      /* flags */	0xf, -      /* afi */		0x0, 0x2, -      /* safi */	0x1, -      /* flags */	0x0, -      /* afi */		0x0, 0x2, -      /* safi */	0x2, -      /* flags */	0x01, -    }, -    16, SHOULD_ERR, -  }, -  { "GR-trunc", -    "GR capability, but truncated", -    { /* hdr */		0x40, 0xf, -      /* R-bit, time */	0xf1, 0x12, -      /* afi */		0x0, 0x1, -      /* safi */	0x1, -      /* flags */	0xf, -      /* afi */		0x0, 0x2, -      /* safi */	0x1, -      /* flags */	0x0, -      /* afi */		0x0, 0x2, -      /* safi */	0x2, -      /* flags */	0x1, -    }, -    15, SHOULD_ERR, -  }, -  { "GR-empty", -    "GR capability, but empty.", -    { /* hdr */		0x40, 0x0, -    }, -    2, SHOULD_ERR, -  }, -  { "MP-empty", -    "MP capability, but empty.", -    { /* hdr */		0x1, 0x0, -    }, -    2, SHOULD_ERR, -  }, -  { "ORF-empty", -    "ORF capability, but empty.", -    { /* hdr */		0x3, 0x0, -    }, -    2, SHOULD_ERR, -  }, -  { "AS4-empty", -    "AS4 capability, but empty.", -    { /* hdr */		0x41, 0x0, -    }, -    2, SHOULD_ERR, -  }, -  { "dyn-empty", -    "Dynamic capability, but empty.", -    { /* hdr */		0x42, 0x0, -    }, -    2, SHOULD_PARSE, -  }, -  { "dyn-old", -    "Dynamic capability (deprecated version)", -    { CAPABILITY_CODE_DYNAMIC, 0x0 }, -    2, SHOULD_PARSE, -  }, -  { NULL, NULL, {0}, 0, 0} -}; +	{ +		/* 13 */ +		{ +			"ORF", +			"ORF, simple, single entry, single tuple", +			{/* hdr */ CAPABILITY_CODE_ORF, 0x7, +			 /* mpc */ 0x0, 0x1, 0x0, 0x1, +			 /* num */ 0x1, +			 /* tuples */ 0x40, 0x3}, +			9, +			SHOULD_PARSE, +		}, +		/* 14 */ +		{ +			"ORF-many", +			"ORF, multi entry/tuple", +			{ +				/* hdr */ CAPABILITY_CODE_ORF, +				0x21, +				/* 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, +				/* tuples */ 0x40, +				ORF_MODE_BOTH, +				0x80, +				ORF_MODE_RECEIVE, +				0x80, +				ORF_MODE_SEND, +				/* mpc */ 0x0, +				0x2, +				0x0, +				0x2, +				/* num */ 0x3, +				/* tuples */ 0x40, +				ORF_MODE_RECEIVE, +				0x80, +				ORF_MODE_SEND, +				0x80, +				ORF_MODE_BOTH, +			}, +			35, +			SHOULD_PARSE, +		}, +		/* 15 */ +		{ +			"ORFlo", +			"ORF, multi entry/tuple, hdr length too short", +			{ +				/* hdr */ CAPABILITY_CODE_ORF, +				0x15, +				/* mpc */ 0x0, +				0x1, +				0x0, +				0x1, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				/* mpc */ 0x0, +				0x1, +				0x0, +				0x1, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				/* mpc */ 0x0, +				0x2, +				0x0, +				0x2, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +			}, +			35, +			SHOULD_ERR, /* It should error on invalid +				       Route-Refresh.. */ +		}, +		/* 16 */ +		{"ORFlu", +		 "ORF, multi entry/tuple, length too long", +		 { +			 /* hdr */ 0x3, +			 0x22, +			 /* mpc */ 0x0, +			 0x1, +			 0x0, +			 0x1, +			 /* num */ 0x3, +			 /* tuples */ 0x40, +			 0x3, +			 0x80, +			 0x1, +			 0x80, +			 0x2, +			 /* mpc */ 0x0, +			 0x2, +			 0x0, +			 0x1, +			 /* num */ 0x3, +			 /* tuples */ 0x40, +			 0x3, +			 0x80, +			 0x1, +			 0x80, +			 0x2, +			 /* mpc */ 0x0, +			 0x2, +			 0x0, +			 0x2, +			 /* num */ 0x3, +			 /* tuples */ 0x40, +			 0x3, +			 0x80, +			 0x1, +			 0x80, +			 0x2, +		 }, +		 35, +		 SHOULD_ERR}, +		/* 17 */ +		{ +			"ORFnu", +			"ORF, multi entry/tuple, entry number too long", +			{ +				/* hdr */ 0x3, +				0x21, +				/* mpc */ 0x0, +				0x1, +				0x0, +				0x1, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				/* mpc */ 0x0, +				0x2, +				0x0, +				0x1, +				/* num */ 0x4, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				/* mpc */ 0x0, +				0x2, +				0x0, +				0x2, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +			}, +			35, +			SHOULD_PARSE, /* parses, but last few tuples should be +					 gibberish */ +		}, +		/* 18 */ +		{ +			"ORFno", +			"ORF, multi entry/tuple, entry number too short", +			{ +				/* hdr */ 0x3, +				0x21, +				/* mpc */ 0x0, +				0x1, +				0x0, +				0x1, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				/* mpc */ 0x0, +				0x2, +				0x0, +				0x1, +				/* num */ 0x1, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				/* mpc */ 0x0, +				0x2, +				0x0, +				0x2, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +			}, +			35, +			SHOULD_PARSE, /* Parses, but should get gibberish +					 afi/safis */ +		}, +		/* 17 */ +		{ +			"ORFpad", +			"ORF, multi entry/tuple, padded to align", +			{ +				/* hdr */ 0x3, +				0x22, +				/* mpc */ 0x0, +				0x1, +				0x0, +				0x1, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				/* mpc */ 0x0, +				0x2, +				0x0, +				0x1, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				/* mpc */ 0x0, +				0x2, +				0x0, +				0x2, +				/* num */ 0x3, +				/* tuples */ 0x40, +				0x3, +				0x80, +				0x1, +				0x80, +				0x2, +				0x00, +			}, +			36, +			SHOULD_PARSE, +		}, +		/* 19 */ +		{ +			"AS4", +			"AS4 capability", +			{0x41, 0x4, 0xab, 0xcd, 0xef, +			 0x12}, /* AS: 2882400018 */ +			6, +			SHOULD_PARSE, +			2882400018, +		}, +		{ +			"AS4", +			"AS4 capability: short", +			{0x41, 0x4, 0xab, 0xcd, 0xef}, /* AS: 2882400018 */ +			5, +			SHOULD_ERR, +		}, +		{ +			"AS4", +			"AS4 capability: long", +			{0x41, 0x4, 0xab, 0xcd, 0xef, 0x12, 0x12}, +			7, +			SHOULD_ERR, +			2882400018, +		}, +		{ +			"GR", +			"GR capability", +			{ +				/* hdr */ CAPABILITY_CODE_RESTART, 0xe, +				/* R-bit, time */ 0xf1, 0x12, +				/* afi */ 0x0, 0x1, +				/* safi */ 0x1, +				/* flags */ 0xf, +				/* afi */ 0x0, 0x2, +				/* safi */ 0x1, +				/* flags */ 0x0, +				/* afi */ 0x0, 0x2, +				/* safi */ 0x2, +				/* flags */ 0x1, +			}, +			16, +			SHOULD_PARSE, +		}, +		{ +			"GR-short", +			"GR capability, but header length too short", +			{ +				/* hdr */ 0x40, 0xa, +				/* R-bit, time */ 0xf1, 0x12, +				/* afi */ 0x0, 0x1, +				/* safi */ 0x1, +				/* flags */ 0xf, +				/* afi */ 0x0, 0x2, +				/* safi */ 0x1, +				/* flags */ 0x0, +				/* afi */ 0x0, 0x2, +				/* safi */ 0x2, +				/* flags */ 0x1, +			}, +			15 /* array is 16 though */, +			SHOULD_ERR, +		}, +		{ +			"GR-long", +			"GR capability, but header length too long", +			{ +				/* hdr */ 0x40, 0xf, +				/* R-bit, time */ 0xf1, 0x12, +				/* afi */ 0x0, 0x1, +				/* safi */ 0x1, +				/* flags */ 0xf, +				/* afi */ 0x0, 0x2, +				/* safi */ 0x1, +				/* flags */ 0x0, +				/* afi */ 0x0, 0x2, +				/* safi */ 0x2, +				/* flags */ 0x01, +			}, +			16, +			SHOULD_ERR, +		}, +		{ +			"GR-trunc", +			"GR capability, but truncated", +			{ +				/* hdr */ 0x40, 0xf, +				/* R-bit, time */ 0xf1, 0x12, +				/* afi */ 0x0, 0x1, +				/* safi */ 0x1, +				/* flags */ 0xf, +				/* afi */ 0x0, 0x2, +				/* safi */ 0x1, +				/* flags */ 0x0, +				/* afi */ 0x0, 0x2, +				/* safi */ 0x2, +				/* flags */ 0x1, +			}, +			15, +			SHOULD_ERR, +		}, +		{ +			"GR-empty", +			"GR capability, but empty.", +			{ +				/* hdr */ 0x40, 0x0, +			}, +			2, +			SHOULD_ERR, +		}, +		{ +			"MP-empty", +			"MP capability, but empty.", +			{ +				/* hdr */ 0x1, 0x0, +			}, +			2, +			SHOULD_ERR, +		}, +		{ +			"ORF-empty", +			"ORF capability, but empty.", +			{ +				/* hdr */ 0x3, 0x0, +			}, +			2, +			SHOULD_ERR, +		}, +		{ +			"AS4-empty", +			"AS4 capability, but empty.", +			{ +				/* hdr */ 0x41, 0x0, +			}, +			2, +			SHOULD_ERR, +		}, +		{ +			"dyn-empty", +			"Dynamic capability, but empty.", +			{ +				/* hdr */ 0x42, 0x0, +			}, +			2, +			SHOULD_PARSE, +		}, +		{ +			"dyn-old", +			"Dynamic capability (deprecated version)", +			{CAPABILITY_CODE_DYNAMIC, 0x0}, +			2, +			SHOULD_PARSE, +		}, +		{NULL, NULL, {0}, 0, 0}};  /* DYNAMIC message */ -struct test_segment dynamic_cap_msgs[] =  -{ -  { "DynCap", -    "Dynamic Capability Message, IP/Multicast", -    { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2 }, -      7, SHOULD_PARSE, /* horrible alignment, just as with ORF */ -  }, -  { "DynCapLong", -    "Dynamic Capability Message, IP/Multicast, truncated", -    { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2 }, -      5, SHOULD_ERR, -  }, -  { "DynCapPadded", -    "Dynamic Capability Message, IP/Multicast, padded", -    { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2, 0x0 }, -      8, SHOULD_ERR, /* No way to tell padding from data.. */ -  }, -  { "DynCapMPCpadded", -    "Dynamic Capability Message, IP/Multicast, cap data padded", -    { 0x0, 0x1, 0x5, 0x0, 0x1, 0x0, 0x2, 0x0 }, -      8, SHOULD_PARSE, /* You can though add padding to the capability data */ -  }, -  { "DynCapMPCoverflow", -    "Dynamic Capability Message, IP/Multicast, cap data != length", -    { 0x0, 0x1, 0x3, 0x0, 0x1, 0x0, 0x2, 0x0 }, -      8, SHOULD_ERR, -  }, -  { NULL, NULL, {0}, 0, 0} -}; +struct test_segment dynamic_cap_msgs[] = { +	{ +		"DynCap", +		"Dynamic Capability Message, IP/Multicast", +		{0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2}, +		7, +		SHOULD_PARSE, /* horrible alignment, just as with ORF */ +	}, +	{ +		"DynCapLong", +		"Dynamic Capability Message, IP/Multicast, truncated", +		{0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2}, +		5, +		SHOULD_ERR, +	}, +	{ +		"DynCapPadded", +		"Dynamic Capability Message, IP/Multicast, padded", +		{0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2, 0x0}, +		8, +		SHOULD_ERR, /* No way to tell padding from data.. */ +	}, +	{ +		"DynCapMPCpadded", +		"Dynamic Capability Message, IP/Multicast, cap data padded", +		{0x0, 0x1, 0x5, 0x0, 0x1, 0x0, 0x2, 0x0}, +		8, +		SHOULD_PARSE, /* You can though add padding to the capability +				 data */ +	}, +	{ +		"DynCapMPCoverflow", +		"Dynamic Capability Message, IP/Multicast, cap data != length", +		{0x0, 0x1, 0x3, 0x0, 0x1, 0x0, 0x2, 0x0}, +		8, +		SHOULD_ERR, +	}, +	{NULL, NULL, {0}, 0, 0}};  /* Entire Optional-Parameters block */ -struct test_segment opt_params[] = -{ -  { "Cap-singlets", -    "One capability per Optional-Param", -    { 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 */   -    }, -    24, SHOULD_PARSE, -  }, -  { "Cap-series", -    "Series of capability, one Optional-Param", -    { 0x02, 0x10, -      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 */   -    }, -    18, SHOULD_PARSE, -  }, -  { "AS4more", -    "AS4 capability after other caps (singlets)", -    { 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, 0x06, 0x41, 0x04, 0x00, 0x03, 0x00, 0x06  /* AS4: 1996614 */ -    }, -    32, SHOULD_PARSE, 196614, -  }, -  { "AS4series", -    "AS4 capability, in series of capabilities", -    { 0x02, 0x16, -      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 */   -      0x41, 0x04, 0x00, 0x03, 0x00, 0x06  /* AS4: 1996614 */ -    }, -    24, SHOULD_PARSE, 196614, -  }, -  { "AS4real", -    "AS4 capability, in series of capabilities", -    { -      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, 0x06, 0x41, 0x04, 0x00, 0x03, 0x00, 0x06, /* AS4 */ -    }, -    32, SHOULD_PARSE, 196614, -  }, -  { "AS4real2", -    "AS4 capability, in series of capabilities", -    { -      0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, -      0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, -      0x02, 0x02, 0x80, 0x00, -      0x02, 0x02, 0x02, 0x00, -      0x02, 0x06, 0x41, 0x04, 0x00, 0x00, 0xfc, 0x03, -      0x02, 0x09, 0x82, 0x07, 0x00, 0x01, 0x00, 0x01, 0x01, 0x80, 0x03, -      0x02, 0x09, 0x03, 0x07, 0x00, 0x01, 0x00, 0x01, 0x01, 0x40, 0x03, -      0x02, 0x02, 0x42, 0x00, -    }, -    58, SHOULD_PARSE, 64515, -  }, - -  { NULL, NULL, {0}, 0, 0} -}; +struct test_segment opt_params[] = { +	{ +		"Cap-singlets", +		"One capability per Optional-Param", +		{ +			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 */ +		}, +		24, +		SHOULD_PARSE, +	}, +	{ +		"Cap-series", +		"Series of capability, one Optional-Param", +		{ +			0x02, 0x10, 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 */ +		}, +		18, +		SHOULD_PARSE, +	}, +	{ +		"AS4more", +		"AS4 capability after other caps (singlets)", +		{ +			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, 0x06, 0x41, 0x04, +			0x00, 0x03, 0x00, 0x06 /* AS4: 1996614 */ +		}, +		32, +		SHOULD_PARSE, +		196614, +	}, +	{ +		"AS4series", +		"AS4 capability, in series of capabilities", +		{ +			0x02, 0x16, 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 */ +			0x41, 0x04, 0x00, 0x03, 0x00, 0x06  /* AS4: 1996614 */ +		}, +		24, +		SHOULD_PARSE, +		196614, +	}, +	{ +		"AS4real", +		"AS4 capability, in series of capabilities", +		{ +			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, 0x06, 0x41, 0x04, +			0x00, 0x03, 0x00, 0x06, /* AS4 */ +		}, +		32, +		SHOULD_PARSE, +		196614, +	}, +	{ +		"AS4real2", +		"AS4 capability, in series of capabilities", +		{ +			0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, 0x02, +			0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, 0x02, 0x02, +			0x80, 0x00, 0x02, 0x02, 0x02, 0x00, 0x02, 0x06, 0x41, +			0x04, 0x00, 0x00, 0xfc, 0x03, 0x02, 0x09, 0x82, 0x07, +			0x00, 0x01, 0x00, 0x01, 0x01, 0x80, 0x03, 0x02, 0x09, +			0x03, 0x07, 0x00, 0x01, 0x00, 0x01, 0x01, 0x40, 0x03, +			0x02, 0x02, 0x42, 0x00, +		}, +		58, +		SHOULD_PARSE, +		64515, +	}, + +	{NULL, NULL, {0}, 0, 0}};  /* basic parsing test */ -static void -parse_test (struct peer *peer, struct test_segment *t, int type) +static void parse_test(struct peer *peer, struct test_segment *t, int type)  { -  int ret; -  int capability = 0; -  as_t as4 = 0; -  int oldfailed = failed; -  int len = t->len; +	int ret; +	int capability = 0; +	as_t as4 = 0; +	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: -        stream_putc (peer->ibuf, BGP_OPEN_OPT_CAP); -        stream_putc (peer->ibuf, t->len); -        break; -      case DYNCAP: -/*        for (i = 0; i < BGP_MARKER_SIZE; i++) -          stream_putc (peer->, 0xff); -        stream_putw (s, 0); -        stream_putc (s, BGP_MSG_CAPABILITY);*/ -        break; -    } -  stream_write (peer->ibuf, t->data, t->len); -   -  printf ("%s: %s\n", t->name, t->desc); - -  switch (type) -    { -      case CAPABILITY: -        len += 2; /* to cover the OPT-Param header */ -      case OPT_PARAM: -        printf ("len: %u\n", len); -        /* peek_for_as4 wants getp at capibility*/ -        as4 = peek_for_as4_capability (peer, len); -        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: -        ret = bgp_capability_receive (peer, t->len); -        break; -      default: -        printf ("unknown type %u\n", type); -        exit(1); -    } -   -  if (!ret && t->validate_afi) -    { -      afi_t afi; -      safi_t safi; -       -      /* Convert AFI, SAFI to internal values, check. */ -      if (bgp_map_afi_safi_iana2int (afi_int2iana(t->afi), t->safi, &afi, &safi)) -        { -          if (t->afi_valid == VALID_AFI) -            failed++; -        } -      printf ("MP: %u(%u)/%u(%u): recv %u, nego %u\n", -              t->afi, afi, t->safi, safi, -              peer->afc_recv[afi][safi], -              peer->afc_nego[afi][safi]); -         -      if (t->afi_valid == VALID_AFI) -        { -         -          if (!peer->afc_recv[afi][safi]) -            failed++; -          if (!peer->afc_nego[afi][safi]) -            failed++; -        } -    } -   -  if (as4 != 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  -                                         : VT100_GREEN "OK" VT100_RESET); -  else -    printf ("%s", (failed > oldfailed) ? "failed!" : "OK" ); -   -  if (failed) -    printf (" (%u)", failed); -   -  printf ("\n\n"); +	stream_reset(peer->ibuf); +	stream_put(peer->ibuf, NULL, RANDOM_FUZZ); +	stream_set_getp(peer->ibuf, RANDOM_FUZZ); + +	switch (type) { +	case CAPABILITY: +		stream_putc(peer->ibuf, BGP_OPEN_OPT_CAP); +		stream_putc(peer->ibuf, t->len); +		break; +	case DYNCAP: +		/*        for (i = 0; i < BGP_MARKER_SIZE; i++) +			  stream_putc (peer->, 0xff); +			stream_putw (s, 0); +			stream_putc (s, BGP_MSG_CAPABILITY);*/ +		break; +	} +	stream_write(peer->ibuf, t->data, t->len); + +	printf("%s: %s\n", t->name, t->desc); + +	switch (type) { +	case CAPABILITY: +		len += 2; /* to cover the OPT-Param header */ +	case OPT_PARAM: +		printf("len: %u\n", len); +		/* peek_for_as4 wants getp at capibility*/ +		as4 = peek_for_as4_capability(peer, len); +		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: +		ret = bgp_capability_receive(peer, t->len); +		break; +	default: +		printf("unknown type %u\n", type); +		exit(1); +	} + +	if (!ret && t->validate_afi) { +		afi_t afi; +		safi_t safi; + +		/* Convert AFI, SAFI to internal values, check. */ +		if (bgp_map_afi_safi_iana2int(afi_int2iana(t->afi), t->safi, +					      &afi, &safi)) { +			if (t->afi_valid == VALID_AFI) +				failed++; +		} +		printf("MP: %u(%u)/%u(%u): recv %u, nego %u\n", t->afi, afi, +		       t->safi, safi, peer->afc_recv[afi][safi], +		       peer->afc_nego[afi][safi]); + +		if (t->afi_valid == VALID_AFI) { + +			if (!peer->afc_recv[afi][safi]) +				failed++; +			if (!peer->afc_nego[afi][safi]) +				failed++; +		} +	} + +	if (as4 != 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 +					    : VT100_GREEN "OK" VT100_RESET); +	else +		printf("%s", (failed > oldfailed) ? "failed!" : "OK"); + +	if (failed) +		printf(" (%u)", failed); + +	printf("\n\n");  }  static struct bgp *bgp;  static as_t asn = 100; -int -main (void) +int main(void)  { -  struct peer *peer; -  int i, j; -   -  conf_bgp_debug_neighbor_events = -1UL; -  conf_bgp_debug_packet = -1UL; -  conf_bgp_debug_as4 = -1UL; -  term_bgp_debug_neighbor_events = -1UL; -  term_bgp_debug_packet = -1UL; -  term_bgp_debug_as4 = -1UL; -   -  qobj_init (); -  master = thread_master_create (); -  bgp_master_init (master); -  vrf_init (); -  bgp_option_set (BGP_OPT_NO_LISTEN); -   -  if (fileno (stdout) >= 0)  -    tty = isatty (fileno (stdout)); -   -  if (bgp_get (&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT)) -    return -1; -   -  peer = peer_create_accept (bgp); -  peer->host = (char *) "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); - -  /* These tests assume mp_segments tests set at least -   * one of the afc_nego's -   */ -  i = 0; -  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); - -  i = 0; -  while (opt_params[i].name) -    parse_test (peer, &opt_params[i++], OPT_PARAM); - -  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; +	struct peer *peer; +	int i, j; + +	conf_bgp_debug_neighbor_events = -1UL; +	conf_bgp_debug_packet = -1UL; +	conf_bgp_debug_as4 = -1UL; +	term_bgp_debug_neighbor_events = -1UL; +	term_bgp_debug_packet = -1UL; +	term_bgp_debug_as4 = -1UL; + +	qobj_init(); +	master = thread_master_create(); +	bgp_master_init(master); +	vrf_init(); +	bgp_option_set(BGP_OPT_NO_LISTEN); + +	if (fileno(stdout) >= 0) +		tty = isatty(fileno(stdout)); + +	if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT)) +		return -1; + +	peer = peer_create_accept(bgp); +	peer->host = (char *)"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); + +	/* These tests assume mp_segments tests set at least +	 * one of the afc_nego's +	 */ +	i = 0; +	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); + +	i = 0; +	while (opt_params[i].name) +		parse_test(peer, &opt_params[i++], OPT_PARAM); + +	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/bgpd/test_ecommunity.c b/tests/bgpd/test_ecommunity.c index 9174191cb3..1d609b4946 100644 --- a/tests/bgpd/test_ecommunity.c +++ b/tests/bgpd/test_ecommunity.c @@ -1,4 +1,4 @@ -/*  +/*   * Copyright (C) 2007 Sun Microsystems, Inc.   *   * This file is part of Quagga. @@ -16,7 +16,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -37,127 +37,114 @@ struct thread_master *master = NULL;  static int failed = 0;  /* specification for a test - what the results should be */ -struct test_spec  -{ -  const char *shouldbe; /* the string the path should parse to */ +struct test_spec { +	const char *shouldbe; /* the string the path should parse to */  };  /* test segments to parse and validate, and use for other tests */  static struct test_segment { -  const char *name; -  const char *desc; -  const u_int8_t data[1024]; -  int len; -  struct test_spec sp; -} test_segments [] =  -{ -  { /* 0 */ -    "ipaddr", -    "rt 1.2.3.4:257", -    { ECOMMUNITY_ENCODE_IP, ECOMMUNITY_ROUTE_TARGET, -      0x1,0x2,0x3,0x4,	0x1,0x1 }, -    8, -    { "rt 1.2.3.4:257" } -  }, -  { /* 1 */ -    "ipaddr-so", -    "soo 1.2.3.4:257", -    { ECOMMUNITY_ENCODE_IP, ECOMMUNITY_SITE_ORIGIN, -      0x1,0x2,0x3,0x4,	0x1,0x1}, -    8, -    { "soo 1.2.3.4:257" } -  }, -  { /* 2 */ -    "asn", -    "rt 23456:987654321", -    { ECOMMUNITY_ENCODE_AS, ECOMMUNITY_SITE_ORIGIN, -      0x5b,0xa0,	0x3a,0xde,0x68,0xb1 }, -    8, -    { "soo 23456:987654321" } -  }, -  { /* 3 */ -    "asn4", -    "rt 168450976:4321", -    { ECOMMUNITY_ENCODE_AS4, ECOMMUNITY_SITE_ORIGIN, -      0xa,0xa,0x5b,0xa0,	0x10,0xe1 }, -    8, -    { "soo 168450976:4321" } -  }, -  { NULL, NULL, {0}, 0, { NULL } } -}; +	const char *name; +	const char *desc; +	const u_int8_t data[1024]; +	int len; +	struct test_spec sp; +} test_segments[] = {{/* 0 */ +		      "ipaddr", +		      "rt 1.2.3.4:257", +		      {ECOMMUNITY_ENCODE_IP, ECOMMUNITY_ROUTE_TARGET, 0x1, 0x2, +		       0x3, 0x4, 0x1, 0x1}, +		      8, +		      {"rt 1.2.3.4:257"}}, +		     {/* 1 */ +		      "ipaddr-so", +		      "soo 1.2.3.4:257", +		      {ECOMMUNITY_ENCODE_IP, ECOMMUNITY_SITE_ORIGIN, 0x1, 0x2, +		       0x3, 0x4, 0x1, 0x1}, +		      8, +		      {"soo 1.2.3.4:257"}}, +		     {/* 2 */ +		      "asn", +		      "rt 23456:987654321", +		      {ECOMMUNITY_ENCODE_AS, ECOMMUNITY_SITE_ORIGIN, 0x5b, 0xa0, +		       0x3a, 0xde, 0x68, 0xb1}, +		      8, +		      {"soo 23456:987654321"}}, +		     {/* 3 */ +		      "asn4", +		      "rt 168450976:4321", +		      {ECOMMUNITY_ENCODE_AS4, ECOMMUNITY_SITE_ORIGIN, 0xa, 0xa, +		       0x5b, 0xa0, 0x10, 0xe1}, +		      8, +		      {"soo 168450976:4321"}}, +		     {NULL, NULL, {0}, 0, {NULL}}};  /* validate the given aspath */ -static int -validate (struct ecommunity *ecom, const struct test_spec *sp) +static int 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, 0); -  etmp = ecommunity_str2com (str1, 0, 1); -  if (etmp) -    str2 = ecommunity_ecom2str (etmp, ECOMMUNITY_FORMAT_COMMUNITY_LIST, 0); -  else -    str2 = NULL; -   -  if (strcmp (sp->shouldbe, str1)) -    { -      failed++; -      fails++; -      printf ("shouldbe: %s\n%s\n", str1, sp->shouldbe); -    } -  if (!etmp || strcmp (str1, str2)) -    { -      failed++; -      fails++; -      printf ("dogfood: in %s\n" -              "    in->out %s\n", -              str1,  -              (etmp && str2) ? str2 : "NULL"); -    } -  ecommunity_free (&etmp); -  XFREE (MTYPE_ECOMMUNITY_STR, str1); -  XFREE (MTYPE_ECOMMUNITY_STR, str2); -   -  return fails; +	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, 0); +	etmp = ecommunity_str2com(str1, 0, 1); +	if (etmp) +		str2 = ecommunity_ecom2str(etmp, +					   ECOMMUNITY_FORMAT_COMMUNITY_LIST, 0); +	else +		str2 = NULL; + +	if (strcmp(sp->shouldbe, str1)) { +		failed++; +		fails++; +		printf("shouldbe: %s\n%s\n", str1, sp->shouldbe); +	} +	if (!etmp || strcmp(str1, str2)) { +		failed++; +		fails++; +		printf("dogfood: in %s\n" +		       "    in->out %s\n", +		       str1, (etmp && str2) ? str2 : "NULL"); +	} +	ecommunity_free(&etmp); +	XFREE(MTYPE_ECOMMUNITY_STR, str1); +	XFREE(MTYPE_ECOMMUNITY_STR, str2); + +	return fails;  }  /* basic parsing test */ -static void -parse_test (struct test_segment *t) +static void parse_test(struct test_segment *t)  { -  struct ecommunity *ecom; -   -  printf ("%s: %s\n", t->name, t->desc); +	struct ecommunity *ecom; + +	printf("%s: %s\n", t->name, t->desc); + +	ecom = ecommunity_parse((u_int8_t *)t->data, t->len); -  ecom = ecommunity_parse ((u_int8_t *)t->data, t->len); +	printf("ecom: %s\nvalidating...:\n", ecommunity_str(ecom)); -  printf ("ecom: %s\nvalidating...:\n", ecommunity_str (ecom)); +	if (!validate(ecom, &t->sp)) +		printf("OK\n"); +	else +		printf("failed\n"); -  if (!validate (ecom, &t->sp)) -    printf ("OK\n"); -  else -    printf ("failed\n"); -   -  printf ("\n"); -  ecommunity_unintern (&ecom); +	printf("\n"); +	ecommunity_unintern(&ecom);  } -      -int -main (void) + +int main(void)  { -  int i = 0; -  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; -  //return (failed + aspath_count()); +	int i = 0; +	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; +	// return (failed + aspath_count());  } diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c index 6824c11fea..d5e3808a6d 100644 --- a/tests/bgpd/test_mp_attr.c +++ b/tests/bgpd/test_mp_attr.c @@ -1,4 +1,4 @@ -/*  +/*   * Copyright (C) 2008 Sun Microsystems, Inc.   *   * This file is part of Quagga. @@ -16,7 +16,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -43,7 +43,6 @@  #define VT100_GREEN "\x1b[32m"  #define VT100_YELLOW "\x1b[33m" -  #define CAPABILITY 0  #define DYNCAP     1  #define OPT_PARAM  2 @@ -57,729 +56,1080 @@ static int tty = 0;  /* test segments to parse and validate, and use for other tests */  static struct test_segment { -  const char *name; -  const char *desc; -  const u_char data[1024]; -  int len; +	const char *name; +	const char *desc; +	const u_char data[1024]; +	int len;  #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; +	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 [] =  -{ -  { "IPv6", -    "IPV6 MP Reach, global nexthop, 1 NLRI",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	16, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2, -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -    }, -    (4 + 16 + 1 + 5),  -    SHOULD_PARSE, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-2", -    "IPV6 MP Reach, global nexthop, 2 NLRIs",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	16, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2,   /* ffee:102:... */ -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -      /* SNPA (defunct, MBZ) */	0x0, -      /* 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),  -    SHOULD_PARSE, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-default", -    "IPV6 MP Reach, global nexthop, 2 NLRIs + default",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	16, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2, -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		32,  -                                0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -                                64, -                                0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ -                                0x0,  0x2,  0x0, 0x3, -                                0x0, /* ::/0 */ -    }, -    (4 + 16 + 1 + 5 + 9 + 1), -    SHOULD_PARSE, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-lnh", -    "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	32, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */ -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -      /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */ -                                0x0,  0x0,  0x0,  0x0, -                                0x2,  0x10, 0x2,  0xff, -                                0x1,  0x2,  0x3,  0x4, -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		32,  -                                0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -                                64, -                                0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ -                                0x0,  0x2,  0x0, 0x3, -                                0x0, /* ::/0 */ -    }, -    (4 + 32 + 1 + 5 + 9 + 1), -    SHOULD_PARSE, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-nhlen", -    "IPV6 MP Reach, inappropriate nexthop length",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	4, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */ -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -      /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */ -                                0x0,  0x0,  0x0,  0x0, -                                0x2,  0x10, 0x2,  0xff, -                                0x1,  0x2,  0x3,  0x4, -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		32,  -                                0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -                                64, -                                0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ -                                0x0,  0x2,  0x0, 0x3, -                                0x0, /* ::/0 */ -    }, -    (4 + 32 + 1 + 5 + 9 + 1), -    SHOULD_ERR, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-nhlen2", -    "IPV6 MP Reach, invalid nexthop length",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	5, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */ -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -      /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */ -                                0x0,  0x0,  0x0,  0x0, -                                0x2,  0x10, 0x2,  0xff, -                                0x1,  0x2,  0x3,  0x4, -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		32,  -                                0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -                                64, -                                0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ -                                0x0,  0x2,  0x0, 0x3, -                                0x0, /* ::/0 */ -    }, -    (4 + 32 + 1 + 5 + 9 + 1), -    SHOULD_ERR, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-nhlen3", -    "IPV6 MP Reach, nexthop length overflow",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	32, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */ -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -    }, -    (4 + 16), -    SHOULD_ERR, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-nhlen4", -    "IPV6 MP Reach, nexthop length short",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	16, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */ -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -      /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */ -                                0x0,  0x0,  0x0,  0x0, -                                0x2,  0x10, 0x2,  0xff, -                                0x1,  0x2,  0x3,  0x4, -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		32,  -                                0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -                                64, -                                0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ -                                0x0,  0x2,  0x0, 0x3, -                                0x0, /* ::/0 */ -    }, -    (4 + 32 + 1 + 5 + 9 + 1), -    SHOULD_ERR, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-nlri", -    "IPV6 MP Reach, NLRI bitlen overflow",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* nexthop bytes */	32, -      /* Nexthop (global) */	0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */ -                                0xaa, 0xbb, 0xcc, 0xdd, -                                0x3,  0x4,  0x5,  0x6, -                                0xa1, 0xa2, 0xa3, 0xa4, -      /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */ -                                0x0,  0x0,  0x0,  0x0, -                                0x2,  0x10, 0x2,  0xff, -                                0x1,  0x2,  0x3,  0x4, -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		120,  -                                0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -                                64, -                                0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ -                                0x0,  0x2,  0x0, 0x3, -                                0, /* ::/0 */ -    }, -    (4 + 32 + 1 + 5 + 9 + 1), -    SHOULD_ERR, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv4", -    "IPv4 MP Reach, 2 NLRIs + default",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, SAFI_UNICAST, -      /* nexthop bytes */	4, -      /* 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 */ -                                0, /* 0/0 */ -    }, -    (4 + 4 + 1 + 3 + 4 + 1), -    SHOULD_PARSE, -    AFI_IP, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv4-nhlen", -    "IPv4 MP Reach, nexthop lenth overflow",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, SAFI_UNICAST, -      /* nexthop bytes */	32, -      /* 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 */ -                                0, /* 0/0 */ -    }, -    (4 + 4 + 1 + 3 + 4 + 1), -    SHOULD_ERR, -    AFI_IP, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv4-nlrilen", -    "IPv4 MP Reach, nlri lenth overflow",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, SAFI_UNICAST, -      /* nexthop bytes */	4, -      /* Nexthop */		192, 168,   0,  1,  -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		16, 10, 1,    /* 10.1/16 */ -                                30, 10,  -                                0, /* 0/0 */ -    }, -    (4 + 4 + 1 + 3 + 2 + 1), -    SHOULD_ERR, -    AFI_IP, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv4-VPNv4", -    "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* nexthop bytes */	12, -      /* RD */			0, 0, 0, 0, /* RD defined to be 0 */ -                                0, 0, 0, 0, -      /* Nexthop */		192, 168,   0,  1,  -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		88 + 16, -                                  0, 1, 2,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_AS */ -                                    0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */ -                                  10, 1,    /* 10.1/16 */ -                                88 + 17, -                                  0xff, 0, 0,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_IP */ -                                    192, 168, 0, 1, /* IPv4 */ -                                  10, 2, 3,  /* 10.2.3/17 */ -    }, -    (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), -    SHOULD_PARSE, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  { "IPv4-VPNv4-bogus-plen", -    "IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* nexthop bytes */	12, -      /* RD */			0, 0, 1, 2, -                                0, 0xff, 3, 4, -      /* 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 */ -                                0, /* 0/0 */ -    }, -    (3 + 1 + 3*4 + 1 + 3 + 4 + 1), -    SHOULD_ERR, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  { "IPv4-VPNv4-plen1-short", -    "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* nexthop bytes */	12, -      /* RD */			0, 0, 0, 0, /* RD defined to be 0 */ -                                0, 0, 0, 0, -      /* Nexthop */		192, 168,   0,  1,  -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		88 + 1, -                                  0, 1, 2,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_AS */ -                                    0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */ -                                  10, 1,    /* 10.1/16 */ -                                88 + 17, -                                  0xff, 0, 0,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_IP */ -                                    192, 168, 0, 1, /* IPv4 */ -                                  10, 2, 3,  /* 10.2.3/17 */ -    }, -    (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), -    SHOULD_ERR, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  { "IPv4-VPNv4-plen1-long", -    "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* nexthop bytes */	12, -      /* RD */			0, 0, 0, 0, /* RD defined to be 0 */ -                                0, 0, 0, 0, -      /* Nexthop */		192, 168,   0,  1,  -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		88 + 32, -                                  0, 1, 2,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_AS */ -                                    0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */ -                                  10, 1,    /* 10.1/16 */ -                                88 + 17, -                                  0xff, 0, 0,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_IP */ -                                    192, 168, 0, 1, /* IPv4 */ -                                  10, 2, 3,  /* 10.2.3/17 */ -    }, -    (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), -    SHOULD_ERR, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  { "IPv4-VPNv4-plenn-long", -    "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* nexthop bytes */	12, -      /* RD */			0, 0, 0, 0, /* RD defined to be 0 */ -                                0, 0, 0, 0, -      /* Nexthop */		192, 168,   0,  1,  -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		88 + 16, -                                  0, 1, 2,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_AS */ -                                    0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */ -                                  10, 1,    /* 10.1/16 */ -                                88 + 17, -                                  0xff, 0, 0,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_IP */ -                                    192, 168, 0, 1, /* IPv4 */ -                                  10, 2, 3,  /* 10.2.3/17 */ -                                88 + 1, /* bogus */ -    }, -    (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1), -    SHOULD_ERR, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  { "IPv4-VPNv4-plenn-short", -    "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* nexthop bytes */	12, -      /* RD */			0, 0, 0, 0, /* RD defined to be 0 */ -                                0, 0, 0, 0, -      /* Nexthop */		192, 168,   0,  1,  -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		88 + 16, -                                  0, 1, 2,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_AS */ -                                    0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */ -                                  10, 1,    /* 10.1/16 */ -                                88 + 2, -                                  0xff, 0, 0,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_IP */ -                                    192, 168, 0, 1, /* IPv4 */ -                                  10, 2, 3,  /* 10.2.3/17 */ -    }, -    (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), -    SHOULD_ERR, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  { "IPv4-VPNv4-bogus-rd-type", -    "IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* nexthop bytes */	12, -      /* RD */			0, 0, 0, 0, /* RD defined to be 0 */ -                                0, 0, 0, 0, -      /* Nexthop */		192, 168,   0,  1,  -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		88 + 16, -                                  0, 1, 2,   /* tag */ -                                  /* rd, 8 octets */ -                                    0xff, 0, /* Bogus RD */ -                                    0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */ -                                  10, 1,    /* 10.1/16 */ -                                88 + 17, -                                  0xff, 0, 0,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_IP */ -                                    192, 168, 0, 1, /* IPv4 */ -                                  10, 2, 3,  /* 10.2.3/17 */ -    }, -    (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), -    SHOULD_PARSE, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  { "IPv4-VPNv4-0-nlri", -    "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* nexthop bytes */	12, -      /* RD */			0, 0, 0, 0, /* RD defined to be 0 */ -                                0, 0, 0, 0, -      /* Nexthop */		192, 168,   0,  1,  -      /* SNPA (defunct, MBZ) */	0x0, -      /* NLRI tuples */		88 + 16, -                                  0, 1, 2,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_AS */ -                                    0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */ -                                  10, 1,    /* 10.1/16 */ -                                88 + 17, -                                  0xff, 0, 0,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_IP */ -                                    192, 168, 0, 1, /* IPv4 */ -                                  10, 2, 3,  /* 10.2.3/17 */ -                                0 /* 0/0, bogus for vpnv4 ?? */ -    }, -    (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1), -    SHOULD_ERR, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, - -  /* From bug #385 */ -  { "IPv6-bug", -    "IPv6, global nexthop, 1 default NLRI",  -    { -      /* AFI / SAFI */		0x0, 0x2, 0x1, -      /* nexthop bytes */	0x20, -      /* 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, 0x00, -                                0x02, 0x0c, 0xdb, 0xff,  -                                0xfe, 0xfe, 0xeb, 0x00, -      /* SNPA (defunct, MBZ) */	0, -      /* NLRI tuples */		/* Should have 0 here for ::/0, but dont */ -    }, -    37, -    SHOULD_ERR, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -   -  { NULL, NULL, {0}, 0, 0} -}; +	int afi_valid; +} mp_reach_segments[] = { +	{ +		"IPv6", +		"IPV6 MP Reach, global nexthop, 1 NLRI", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 16, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 32, +			0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102::/32 */ +		}, +		(4 + 16 + 1 + 5), +		SHOULD_PARSE, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-2", +		"IPV6 MP Reach, global nexthop, 2 NLRIs", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 16, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, /* ffee:102:... */ +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* 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), +		SHOULD_PARSE, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-default", +		"IPV6 MP Reach, global nexthop, 2 NLRIs + default", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 16, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 32, +			0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102::/32 */ +			64, +			0xff, +			0xfe, +			0x0, +			0x1, /* fffe:1:2:3::/64 */ +			0x0, +			0x2, +			0x0, +			0x3, +			0x0, /* ::/0 */ +		}, +		(4 + 16 + 1 + 5 + 9 + 1), +		SHOULD_PARSE, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-lnh", +		"IPV6 MP Reach, global+local nexthops, 2 NLRIs + default", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 32, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102:... */ +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +			/* Nexthop (local) */ 0xfe, +			0x80, +			0x0, +			0x0, /* fe80::210:2ff:.. */ +			0x0, +			0x0, +			0x0, +			0x0, +			0x2, +			0x10, +			0x2, +			0xff, +			0x1, +			0x2, +			0x3, +			0x4, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 32, +			0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102::/32 */ +			64, +			0xff, +			0xfe, +			0x0, +			0x1, /* fffe:1:2:3::/64 */ +			0x0, +			0x2, +			0x0, +			0x3, +			0x0, /* ::/0 */ +		}, +		(4 + 32 + 1 + 5 + 9 + 1), +		SHOULD_PARSE, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-nhlen", +		"IPV6 MP Reach, inappropriate nexthop length", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 4, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102:... */ +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +			/* Nexthop (local) */ 0xfe, +			0x80, +			0x0, +			0x0, /* fe80::210:2ff:.. */ +			0x0, +			0x0, +			0x0, +			0x0, +			0x2, +			0x10, +			0x2, +			0xff, +			0x1, +			0x2, +			0x3, +			0x4, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 32, +			0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102::/32 */ +			64, +			0xff, +			0xfe, +			0x0, +			0x1, /* fffe:1:2:3::/64 */ +			0x0, +			0x2, +			0x0, +			0x3, +			0x0, /* ::/0 */ +		}, +		(4 + 32 + 1 + 5 + 9 + 1), +		SHOULD_ERR, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-nhlen2", +		"IPV6 MP Reach, invalid nexthop length", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 5, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102:... */ +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +			/* Nexthop (local) */ 0xfe, +			0x80, +			0x0, +			0x0, /* fe80::210:2ff:.. */ +			0x0, +			0x0, +			0x0, +			0x0, +			0x2, +			0x10, +			0x2, +			0xff, +			0x1, +			0x2, +			0x3, +			0x4, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 32, +			0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102::/32 */ +			64, +			0xff, +			0xfe, +			0x0, +			0x1, /* fffe:1:2:3::/64 */ +			0x0, +			0x2, +			0x0, +			0x3, +			0x0, /* ::/0 */ +		}, +		(4 + 32 + 1 + 5 + 9 + 1), +		SHOULD_ERR, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-nhlen3", +		"IPV6 MP Reach, nexthop length overflow", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 32, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102:... */ +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +		}, +		(4 + 16), +		SHOULD_ERR, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-nhlen4", +		"IPV6 MP Reach, nexthop length short", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 16, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102:... */ +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +			/* Nexthop (local) */ 0xfe, +			0x80, +			0x0, +			0x0, /* fe80::210:2ff:.. */ +			0x0, +			0x0, +			0x0, +			0x0, +			0x2, +			0x10, +			0x2, +			0xff, +			0x1, +			0x2, +			0x3, +			0x4, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 32, +			0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102::/32 */ +			64, +			0xff, +			0xfe, +			0x0, +			0x1, /* fffe:1:2:3::/64 */ +			0x0, +			0x2, +			0x0, +			0x3, +			0x0, /* ::/0 */ +		}, +		(4 + 32 + 1 + 5 + 9 + 1), +		SHOULD_ERR, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-nlri", +		"IPV6 MP Reach, NLRI bitlen overflow", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP6, +			SAFI_UNICAST, +			/* nexthop bytes */ 32, +			/* Nexthop (global) */ 0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102:... */ +			0xaa, +			0xbb, +			0xcc, +			0xdd, +			0x3, +			0x4, +			0x5, +			0x6, +			0xa1, +			0xa2, +			0xa3, +			0xa4, +			/* Nexthop (local) */ 0xfe, +			0x80, +			0x0, +			0x0, /* fe80::210:2ff:.. */ +			0x0, +			0x0, +			0x0, +			0x0, +			0x2, +			0x10, +			0x2, +			0xff, +			0x1, +			0x2, +			0x3, +			0x4, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 120, +			0xff, +			0xfe, +			0x1, +			0x2, /* fffe:102::/32 */ +			64, +			0xff, +			0xfe, +			0x0, +			0x1, /* fffe:1:2:3::/64 */ +			0x0, +			0x2, +			0x0, +			0x3, +			0, /* ::/0 */ +		}, +		(4 + 32 + 1 + 5 + 9 + 1), +		SHOULD_ERR, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv4", +		"IPv4 MP Reach, 2 NLRIs + default", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, +			/* nexthop bytes */ 4, +			/* 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 */ +			0,			     /* 0/0 */ +		}, +		(4 + 4 + 1 + 3 + 4 + 1), +		SHOULD_PARSE, +		AFI_IP, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv4-nhlen", +		"IPv4 MP Reach, nexthop lenth overflow", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, +			/* nexthop bytes */ 32, +			/* 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 */ +			0,			     /* 0/0 */ +		}, +		(4 + 4 + 1 + 3 + 4 + 1), +		SHOULD_ERR, +		AFI_IP, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv4-nlrilen", +		"IPv4 MP Reach, nlri lenth overflow", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, +			/* nexthop bytes */ 4, +			/* Nexthop */ 192, 168, 0, 1, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ +			30, 10, 0,		     /* 0/0 */ +		}, +		(4 + 4 + 1 + 3 + 2 + 1), +		SHOULD_ERR, +		AFI_IP, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv4-VPNv4", +		"IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, +			/* nexthop bytes */ 12, +			/* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ +			0, 0, 0, 0, +			/* Nexthop */ 192, 168, 0, 1, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 88 + 16, 0, 1, 2, /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_AS */ +			0, 2, 0, 0xff, 3, 4,		    /* AS(2):val(4) */ +			10, 1,				    /* 10.1/16 */ +			88 + 17, 0xff, 0, 0,		    /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_IP */ +			192, 168, 0, 1,			    /* IPv4 */ +			10, 2, 3,			    /* 10.2.3/17 */ +		}, +		(4 + 12 + 1 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3)), +		SHOULD_PARSE, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	{ +		"IPv4-VPNv4-bogus-plen", +		"IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len", +		{ +			/* AFI / SAFI */ 0x0, +			AFI_IP, +			IANA_SAFI_MPLS_VPN, +			/* nexthop bytes */ 12, +			/* RD */ 0, +			0, +			1, +			2, +			0, +			0xff, +			3, +			4, +			/* 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 */ +			0, /* 0/0 */ +		}, +		(3 + 1 + 3 * 4 + 1 + 3 + 4 + 1), +		SHOULD_ERR, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	{ +		"IPv4-VPNv4-plen1-short", +		"IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, +			/* nexthop bytes */ 12, +			/* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ +			0, 0, 0, 0, +			/* Nexthop */ 192, 168, 0, 1, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 88 + 1, 0, 1, 2, /* tag */ +							   /* rd, 8 octets */ +			0, 0,				   /* RD_TYPE_AS */ +			0, 2, 0, 0xff, 3, 4,		   /* AS(2):val(4) */ +			10, 1,				   /* 10.1/16 */ +			88 + 17, 0xff, 0, 0,		   /* tag */ +							   /* rd, 8 octets */ +			0, 0,				   /* RD_TYPE_IP */ +			192, 168, 0, 1,			   /* IPv4 */ +			10, 2, 3,			   /* 10.2.3/17 */ +		}, +		(4 + 12 + 1 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3)), +		SHOULD_ERR, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	{ +		"IPv4-VPNv4-plen1-long", +		"IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, +			/* nexthop bytes */ 12, +			/* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ +			0, 0, 0, 0, +			/* Nexthop */ 192, 168, 0, 1, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 88 + 32, 0, 1, 2, /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_AS */ +			0, 2, 0, 0xff, 3, 4,		    /* AS(2):val(4) */ +			10, 1,				    /* 10.1/16 */ +			88 + 17, 0xff, 0, 0,		    /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_IP */ +			192, 168, 0, 1,			    /* IPv4 */ +			10, 2, 3,			    /* 10.2.3/17 */ +		}, +		(4 + 12 + 1 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3)), +		SHOULD_ERR, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	{ +		"IPv4-VPNv4-plenn-long", +		"IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, +			/* nexthop bytes */ 12, +			/* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ +			0, 0, 0, 0, +			/* Nexthop */ 192, 168, 0, 1, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 88 + 16, 0, 1, 2, /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_AS */ +			0, 2, 0, 0xff, 3, 4,		    /* AS(2):val(4) */ +			10, 1,				    /* 10.1/16 */ +			88 + 17, 0xff, 0, 0,		    /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_IP */ +			192, 168, 0, 1,			    /* IPv4 */ +			10, 2, 3,			    /* 10.2.3/17 */ +			88 + 1,				    /* bogus */ +		}, +		(4 + 12 + 1 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3) + 1), +		SHOULD_ERR, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	{ +		"IPv4-VPNv4-plenn-short", +		"IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, +			/* nexthop bytes */ 12, +			/* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ +			0, 0, 0, 0, +			/* Nexthop */ 192, 168, 0, 1, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 88 + 16, 0, 1, 2, /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_AS */ +			0, 2, 0, 0xff, 3, 4,		    /* AS(2):val(4) */ +			10, 1,				    /* 10.1/16 */ +			88 + 2, 0xff, 0, 0,		    /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_IP */ +			192, 168, 0, 1,			    /* IPv4 */ +			10, 2, 3,			    /* 10.2.3/17 */ +		}, +		(4 + 12 + 1 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3)), +		SHOULD_ERR, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	{ +		"IPv4-VPNv4-bogus-rd-type", +		"IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, +			/* nexthop bytes */ 12, +			/* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ +			0, 0, 0, 0, +			/* Nexthop */ 192, 168, 0, 1, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 88 + 16, 0, 1, 2, /* tag */ +							    /* rd, 8 octets */ +			0xff, 0,			    /* Bogus RD */ +			0, 2, 0, 0xff, 3, 4,		    /* AS(2):val(4) */ +			10, 1,				    /* 10.1/16 */ +			88 + 17, 0xff, 0, 0,		    /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_IP */ +			192, 168, 0, 1,			    /* IPv4 */ +			10, 2, 3,			    /* 10.2.3/17 */ +		}, +		(4 + 12 + 1 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3)), +		SHOULD_PARSE, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	{ +		"IPv4-VPNv4-0-nlri", +		"IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, +			/* nexthop bytes */ 12, +			/* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ +			0, 0, 0, 0, +			/* Nexthop */ 192, 168, 0, 1, +			/* SNPA (defunct, MBZ) */ 0x0, +			/* NLRI tuples */ 88 + 16, 0, 1, 2, /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_AS */ +			0, 2, 0, 0xff, 3, 4,		    /* AS(2):val(4) */ +			10, 1,				    /* 10.1/16 */ +			88 + 17, 0xff, 0, 0,		    /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_IP */ +			192, 168, 0, 1,			    /* IPv4 */ +			10, 2, 3,			    /* 10.2.3/17 */ +			0 /* 0/0, bogus for vpnv4 ?? */ +		}, +		(4 + 12 + 1 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3) + 1), +		SHOULD_ERR, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, + +	/* From bug #385 */ +	{ +		"IPv6-bug", +		"IPv6, global nexthop, 1 default NLRI", +		{ +			/* AFI / SAFI */ 0x0, +			0x2, +			0x1, +			/* nexthop bytes */ 0x20, +			/* 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, +			0x00, +			0x02, +			0x0c, +			0xdb, +			0xff, +			0xfe, +			0xfe, +			0xeb, +			0x00, +			/* SNPA (defunct, MBZ) */ 0, +			/* NLRI tuples */ /* Should have 0 here for ::/0, but +					     dont */ +		}, +		37, +		SHOULD_ERR, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, + +	{NULL, NULL, {0}, 0, 0}};  /* MP_UNREACH_NLRI tests */ -static struct test_segment mp_unreach_segments [] = -{ -  { "IPv6-unreach", -    "IPV6 MP Unreach, 1 NLRI",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* NLRI tuples */		32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -    }, -    (3 + 5),  -    SHOULD_PARSE, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-unreach2", -    "IPV6 MP Unreach, 2 NLRIs",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* 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),  -    SHOULD_PARSE, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-unreach-default", -    "IPV6 MP Unreach, 2 NLRIs + default",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* NLRI tuples */		32,  -                                0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -                                64, -                                0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ -                                0x0,  0x2,  0x0, 0x3, -                                0x0, /* ::/0 */ -    }, -    (3 + 5 + 9 + 1), -    SHOULD_PARSE, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv6-unreach-nlri", -    "IPV6 MP Unreach, NLRI bitlen overflow",  -    { -      /* AFI / SAFI */		0x0, AFI_IP6, SAFI_UNICAST, -      /* NLRI tuples */		120,  -                                0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */ -                                64, -                                0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ -                                0x0,  0x2,  0x0, 0x3, -                                0, /* ::/0 */ -    }, -    (3 + 5 + 9 + 1), -    SHOULD_ERR, -    AFI_IP6, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv4-unreach", -    "IPv4 MP Unreach, 2 NLRIs + default",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, SAFI_UNICAST, -      /* NLRI tuples */		16, 10, 1,    /* 10.1/16 */ -                                17, 10, 2, 3, /* 10.2.3/17 */ -                                0, /* 0/0 */ -    }, -    (3 + 3 + 4 + 1), -    SHOULD_PARSE, -    AFI_IP, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv4-unreach-nlrilen", -    "IPv4 MP Unreach, nlri length overflow",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, SAFI_UNICAST, -      /* NLRI tuples */		16, 10, 1,    /* 10.1/16 */ -                                30, 10,  -                                0, /* 0/0 */ -    }, -    (3 + 3 + 2 + 1), -    SHOULD_ERR, -    AFI_IP, SAFI_UNICAST, VALID_AFI, -  }, -  { "IPv4-unreach-VPNv4", -    "IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs",  -    { -      /* AFI / SAFI */		0x0, AFI_IP, IANA_SAFI_MPLS_VPN, -      /* NLRI tuples */		88 + 16, -                                  0, 1, 2,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_AS */ -                                    0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */ -                                  10, 1,    /* 10.1/16 */ -                                88 + 17, -                                  0xff, 0, 0,   /* tag */ -                                  /* rd, 8 octets */ -                                    0, 0, /* RD_TYPE_IP */ -                                    192, 168, 0, 1, /* IPv4 */ -                                  10, 2, 3,  /* 10.2.3/17 */ -    }, -    (3 + (1+3+8+2) + (1+3+8+3)), -    SHOULD_PARSE, -    AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, -  }, -  { NULL, NULL, {0}, 0, 0} -}; +static struct test_segment mp_unreach_segments[] = { +	{ +		"IPv6-unreach", +		"IPV6 MP Unreach, 1 NLRI", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, +			/* NLRI tuples */ 32, 0xff, 0xfe, 0x1, +			0x2, /* fffe:102::/32 */ +		}, +		(3 + 5), +		SHOULD_PARSE, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-unreach2", +		"IPV6 MP Unreach, 2 NLRIs", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, +			/* 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), +		SHOULD_PARSE, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-unreach-default", +		"IPV6 MP Unreach, 2 NLRIs + default", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, +			/* NLRI tuples */ 32, 0xff, 0xfe, 0x1, +			0x2,			  /* fffe:102::/32 */ +			64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ +			0x0, 0x2, 0x0, 0x3, 0x0,  /* ::/0 */ +		}, +		(3 + 5 + 9 + 1), +		SHOULD_PARSE, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv6-unreach-nlri", +		"IPV6 MP Unreach, NLRI bitlen overflow", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST, +			/* NLRI tuples */ 120, 0xff, 0xfe, 0x1, +			0x2,			  /* fffe:102::/32 */ +			64, 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */ +			0x0, 0x2, 0x0, 0x3, 0,    /* ::/0 */ +		}, +		(3 + 5 + 9 + 1), +		SHOULD_ERR, +		AFI_IP6, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv4-unreach", +		"IPv4 MP Unreach, 2 NLRIs + default", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, +			/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ +			17, 10, 2, 3,		     /* 10.2.3/17 */ +			0,			     /* 0/0 */ +		}, +		(3 + 3 + 4 + 1), +		SHOULD_PARSE, +		AFI_IP, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv4-unreach-nlrilen", +		"IPv4 MP Unreach, nlri length overflow", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST, +			/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */ +			30, 10, 0,		     /* 0/0 */ +		}, +		(3 + 3 + 2 + 1), +		SHOULD_ERR, +		AFI_IP, +		SAFI_UNICAST, +		VALID_AFI, +	}, +	{ +		"IPv4-unreach-VPNv4", +		"IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs", +		{ +			/* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, +			/* NLRI tuples */ 88 + 16, 0, 1, 2, /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_AS */ +			0, 2, 0, 0xff, 3, 4,		    /* AS(2):val(4) */ +			10, 1,				    /* 10.1/16 */ +			88 + 17, 0xff, 0, 0,		    /* tag */ +							    /* rd, 8 octets */ +			0, 0,				    /* RD_TYPE_IP */ +			192, 168, 0, 1,			    /* IPv4 */ +			10, 2, 3,			    /* 10.2.3/17 */ +		}, +		(3 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3)), +		SHOULD_PARSE, +		AFI_IP, +		IANA_SAFI_MPLS_VPN, +		VALID_AFI, +	}, +	{NULL, NULL, {0}, 0, 0}};  /* nlri_parse indicates 0 on successful parse, and -1 otherwise.   * attr_parse indicates BGP_ATTR_PARSE_PROCEED/0 on success,   * and BGP_ATTR_PARSE_ERROR/-1 or lower negative ret on err.   */ -static void -handle_result (struct peer *peer, struct test_segment *t, -               int parse_ret, int nlri_ret) +static void handle_result(struct peer *peer, struct test_segment *t, +			  int parse_ret, int nlri_ret)  { -  int oldfailed = failed; -   -  printf ("mp attr parsed?: %s\n", parse_ret ? "no" : "yes"); -  if (!parse_ret) -    printf ("nrli parsed?:  %s\n", nlri_ret ? "no" : "yes"); -  printf ("should parse?:  %s\n", t->parses ? "no" : "yes"); -   -  if ((parse_ret != 0 || nlri_ret != 0) != (t->parses != 0)) -    failed++; -   -     -  if (tty) -    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"); +	int oldfailed = failed; + +	printf("mp attr parsed?: %s\n", parse_ret ? "no" : "yes"); +	if (!parse_ret) +		printf("nrli parsed?:  %s\n", nlri_ret ? "no" : "yes"); +	printf("should parse?:  %s\n", t->parses ? "no" : "yes"); + +	if ((parse_ret != 0 || nlri_ret != 0) != (t->parses != 0)) +		failed++; + + +	if (tty) +		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");  }  /* basic parsing test */ -static void -parse_test (struct peer *peer, struct test_segment *t, int type) +static void parse_test(struct peer *peer, struct test_segment *t, int type)  { -  int parse_ret = 0, nlri_ret = 0; -  struct attr attr = { }; -  struct bgp_nlri nlri = { }; -  struct bgp_attr_parser_args attr_args = { -    .peer = peer, -    .length = t->len, -    .total = 1, -    .attr = &attr, -    .type = type, -    .flags = BGP_ATTR_FLAG_OPTIONAL,  -    .startp = BGP_INPUT_PNT (peer), -  }; +	int parse_ret = 0, nlri_ret = 0; +	struct attr attr = {}; +	struct bgp_nlri nlri = {}; +	struct bgp_attr_parser_args attr_args = { +		.peer = peer, +		.length = t->len, +		.total = 1, +		.attr = &attr, +		.type = type, +		.flags = BGP_ATTR_FLAG_OPTIONAL, +		.startp = BGP_INPUT_PNT(peer), +	};  #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) -    parse_ret = bgp_mp_reach_parse (&attr_args, &nlri); -  else -    parse_ret = bgp_mp_unreach_parse (&attr_args, &nlri); -  if (!parse_ret) -    { -      iana_afi_t pkt_afi; -      safi_t pkt_safi; -       -      /* Convert AFI, SAFI to internal values, check. */ -      if (bgp_map_afi_safi_int2iana (nlri.afi, nlri.safi, &pkt_afi, &pkt_safi)) -        assert (0); - -      printf ("MP: %u(%u)/%u(%u): recv %u, nego %u\n", -              nlri.afi , pkt_afi, nlri.safi, pkt_safi, -              peer->afc_recv[nlri.afi][nlri.safi], -              peer->afc_nego[nlri.afi][nlri.safi]); -    } -   -  if (!parse_ret) -    { -      if (type == BGP_ATTR_MP_REACH_NLRI) -        nlri_ret = bgp_nlri_parse (peer, &attr, &nlri, 0); -      else -        nlri_ret = bgp_nlri_parse (peer, &attr, &nlri, 1); -    } -  handle_result (peer, t, parse_ret, nlri_ret); +	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) +		parse_ret = bgp_mp_reach_parse(&attr_args, &nlri); +	else +		parse_ret = bgp_mp_unreach_parse(&attr_args, &nlri); +	if (!parse_ret) { +		iana_afi_t pkt_afi; +		safi_t pkt_safi; + +		/* Convert AFI, SAFI to internal values, check. */ +		if (bgp_map_afi_safi_int2iana(nlri.afi, nlri.safi, &pkt_afi, +					      &pkt_safi)) +			assert(0); + +		printf("MP: %u(%u)/%u(%u): recv %u, nego %u\n", nlri.afi, +		       pkt_afi, nlri.safi, pkt_safi, +		       peer->afc_recv[nlri.afi][nlri.safi], +		       peer->afc_nego[nlri.afi][nlri.safi]); +	} + +	if (!parse_ret) { +		if (type == BGP_ATTR_MP_REACH_NLRI) +			nlri_ret = bgp_nlri_parse(peer, &attr, &nlri, 0); +		else +			nlri_ret = bgp_nlri_parse(peer, &attr, &nlri, 1); +	} +	handle_result(peer, t, parse_ret, nlri_ret);  }  static struct bgp *bgp;  static as_t asn = 100; -int -main (void) +int main(void)  { -  struct peer *peer; -  int i, j; -   -  conf_bgp_debug_neighbor_events = -1UL; -  conf_bgp_debug_packet = -1UL; -  conf_bgp_debug_as4 = -1UL; -  term_bgp_debug_neighbor_events = -1UL; -  term_bgp_debug_packet = -1UL; -  term_bgp_debug_as4 = -1UL; -   -  qobj_init (); -  master = thread_master_create (); -  bgp_master_init (master); -  vrf_init (); -  bgp_option_set (BGP_OPT_NO_LISTEN); -  bgp_attr_init (); -   -  if (fileno (stdout) >= 0)  -    tty = isatty (fileno (stdout)); -   -  if (bgp_get (&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT)) -    return -1; -   -  peer = peer_create_accept (bgp); -  peer->host = (char *)"foo"; -  peer->status = Established; -   -  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); - -  i = 0; -  while (mp_unreach_segments[i].name) -    parse_test (peer, &mp_unreach_segments[i++], BGP_ATTR_MP_UNREACH_NLRI); - -  printf ("failures: %d\n", failed); -  return failed; +	struct peer *peer; +	int i, j; + +	conf_bgp_debug_neighbor_events = -1UL; +	conf_bgp_debug_packet = -1UL; +	conf_bgp_debug_as4 = -1UL; +	term_bgp_debug_neighbor_events = -1UL; +	term_bgp_debug_packet = -1UL; +	term_bgp_debug_as4 = -1UL; + +	qobj_init(); +	master = thread_master_create(); +	bgp_master_init(master); +	vrf_init(); +	bgp_option_set(BGP_OPT_NO_LISTEN); +	bgp_attr_init(); + +	if (fileno(stdout) >= 0) +		tty = isatty(fileno(stdout)); + +	if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT)) +		return -1; + +	peer = peer_create_accept(bgp); +	peer->host = (char *)"foo"; +	peer->status = Established; + +	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); + +	i = 0; +	while (mp_unreach_segments[i].name) +		parse_test(peer, &mp_unreach_segments[i++], +			   BGP_ATTR_MP_UNREACH_NLRI); + +	printf("failures: %d\n", failed); +	return failed;  } diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c index a2fd66528c..e4dcc42b14 100644 --- a/tests/bgpd/test_mpath.c +++ b/tests/bgpd/test_mpath.c @@ -49,13 +49,12 @@  #define TEST_PASSED 0  #define TEST_FAILED -1 -#define EXPECT_TRUE(expr, res)                                          \ -  if (!(expr))                                                          \ -    {                                                                   \ -      printf ("Test failure in %s line %u: %s\n",                       \ -              __FUNCTION__, __LINE__, #expr);                           \ -      (res) = TEST_FAILED;                                              \ -    } +#define EXPECT_TRUE(expr, res)                                                 \ +	if (!(expr)) {                                                         \ +		printf("Test failure in %s line %u: %s\n", __FUNCTION__,       \ +		       __LINE__, #expr);                                       \ +		(res) = TEST_FAILED;                                           \ +	}  typedef struct testcase_t__ testcase_t; @@ -64,224 +63,227 @@ typedef int (*test_run_func)(testcase_t *);  typedef int (*test_cleanup_func)(testcase_t *);  struct testcase_t__ { -  const char *desc; -  void *test_data; -  void *verify_data; -  void *tmp_data; -  test_setup_func setup; -  test_run_func run; -  test_cleanup_func cleanup; +	const char *desc; +	void *test_data; +	void *verify_data; +	void *tmp_data; +	test_setup_func setup; +	test_run_func run; +	test_cleanup_func cleanup;  };  /* need these to link in libbgp */  struct thread_master *master = NULL;  struct zclient *zclient; -struct zebra_privs_t bgpd_privs = -{ -  .user = NULL, -  .group = NULL, -  .vty_group = NULL, +struct zebra_privs_t bgpd_privs = { +	.user = NULL, +	.group = NULL, +	.vty_group = NULL,  };  static int tty = 0;  /* Create fake bgp instance */ -static struct bgp * -bgp_create_fake (as_t *as, const char *name) +static struct bgp *bgp_create_fake(as_t *as, const char *name)  { -  struct bgp *bgp; -  afi_t afi; -  safi_t safi; - -  if ( (bgp = XCALLOC (MTYPE_BGP, sizeof (struct bgp))) == NULL) -    return NULL; - -  bgp_lock (bgp); -  //bgp->peer_self = peer_new (bgp); -  //bgp->peer_self->host = XSTRDUP (MTYPE_BGP_PEER_HOST, "Static announcement"); - -  bgp->peer = list_new (); -  //bgp->peer->cmp = (int (*)(void *, void *)) peer_cmp; - -  bgp->group = list_new (); -  //bgp->group->cmp = (int (*)(void *, void *)) peer_group_cmp; - -  for (afi = AFI_IP; afi < AFI_MAX; afi++) -    for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) -      { -        bgp->route[afi][safi] = bgp_table_init (afi, safi); -        bgp->aggregate[afi][safi] = bgp_table_init (afi, safi); -        bgp->rib[afi][safi] = bgp_table_init (afi, safi); -        bgp->maxpaths[afi][safi].maxpaths_ebgp = MULTIPATH_NUM; -        bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM; -      } - -  bgp_scan_init (bgp); -  bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF; -  bgp->default_holdtime = BGP_DEFAULT_HOLDTIME; -  bgp->default_keepalive = BGP_DEFAULT_KEEPALIVE; -  bgp->restart_time = BGP_DEFAULT_RESTART_TIME; -  bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME; - -  bgp->as = *as; - -  if (name) -    bgp->name = strdup (name); - -  return bgp; +	struct bgp *bgp; +	afi_t afi; +	safi_t safi; + +	if ((bgp = XCALLOC(MTYPE_BGP, sizeof(struct bgp))) == NULL) +		return NULL; + +	bgp_lock(bgp); +	// bgp->peer_self = peer_new (bgp); +	// bgp->peer_self->host = XSTRDUP (MTYPE_BGP_PEER_HOST, "Static +	// announcement"); + +	bgp->peer = list_new(); +	// bgp->peer->cmp = (int (*)(void *, void *)) peer_cmp; + +	bgp->group = list_new(); +	// bgp->group->cmp = (int (*)(void *, void *)) peer_group_cmp; + +	for (afi = AFI_IP; afi < AFI_MAX; afi++) +		for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { +			bgp->route[afi][safi] = bgp_table_init(afi, safi); +			bgp->aggregate[afi][safi] = bgp_table_init(afi, safi); +			bgp->rib[afi][safi] = bgp_table_init(afi, safi); +			bgp->maxpaths[afi][safi].maxpaths_ebgp = MULTIPATH_NUM; +			bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM; +		} + +	bgp_scan_init(bgp); +	bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF; +	bgp->default_holdtime = BGP_DEFAULT_HOLDTIME; +	bgp->default_keepalive = BGP_DEFAULT_KEEPALIVE; +	bgp->restart_time = BGP_DEFAULT_RESTART_TIME; +	bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME; + +	bgp->as = *as; + +	if (name) +		bgp->name = strdup(name); + +	return bgp;  }  /*=========================================================   * Testcase for maximum-paths configuration   */ -static int -setup_bgp_cfg_maximum_paths (testcase_t *t) +static int setup_bgp_cfg_maximum_paths(testcase_t *t)  { -  as_t asn = 1; -  t->tmp_data = bgp_create_fake (&asn, NULL); -  if (!t->tmp_data) -    return -1; -  return 0; +	as_t asn = 1; +	t->tmp_data = bgp_create_fake(&asn, NULL); +	if (!t->tmp_data) +		return -1; +	return 0;  } -static int -run_bgp_cfg_maximum_paths (testcase_t *t) +static int run_bgp_cfg_maximum_paths(testcase_t *t)  { -  afi_t afi; -  safi_t safi; -  struct bgp *bgp; -  int api_result; -  int test_result = TEST_PASSED; - -  bgp = t->tmp_data; -  for (afi = AFI_IP; afi < AFI_MAX; afi++) -    for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) -      { -        /* test bgp_maximum_paths_set */ -        api_result = bgp_maximum_paths_set (bgp, afi, safi, BGP_PEER_EBGP, 10, 0); -        EXPECT_TRUE (api_result == 0, test_result); -        api_result = bgp_maximum_paths_set (bgp, afi, safi, BGP_PEER_IBGP, 10, 0); -        EXPECT_TRUE (api_result == 0, test_result); -        EXPECT_TRUE (bgp->maxpaths[afi][safi].maxpaths_ebgp == 10, test_result); -        EXPECT_TRUE (bgp->maxpaths[afi][safi].maxpaths_ibgp == 10, test_result); - -        /* test bgp_maximum_paths_unset */ -        api_result = bgp_maximum_paths_unset (bgp, afi, safi, BGP_PEER_EBGP); -        EXPECT_TRUE (api_result == 0, test_result); -        api_result = bgp_maximum_paths_unset (bgp, afi, safi, BGP_PEER_IBGP); -        EXPECT_TRUE (api_result == 0, test_result); -        EXPECT_TRUE ((bgp->maxpaths[afi][safi].maxpaths_ebgp == -                      MULTIPATH_NUM), test_result); -        EXPECT_TRUE ((bgp->maxpaths[afi][safi].maxpaths_ibgp == -                      MULTIPATH_NUM), test_result); -      } - -  return test_result; +	afi_t afi; +	safi_t safi; +	struct bgp *bgp; +	int api_result; +	int test_result = TEST_PASSED; + +	bgp = t->tmp_data; +	for (afi = AFI_IP; afi < AFI_MAX; afi++) +		for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { +			/* test bgp_maximum_paths_set */ +			api_result = bgp_maximum_paths_set( +				bgp, afi, safi, BGP_PEER_EBGP, 10, 0); +			EXPECT_TRUE(api_result == 0, test_result); +			api_result = bgp_maximum_paths_set( +				bgp, afi, safi, BGP_PEER_IBGP, 10, 0); +			EXPECT_TRUE(api_result == 0, test_result); +			EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ebgp +					    == 10, +				    test_result); +			EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ibgp +					    == 10, +				    test_result); + +			/* test bgp_maximum_paths_unset */ +			api_result = bgp_maximum_paths_unset(bgp, afi, safi, +							     BGP_PEER_EBGP); +			EXPECT_TRUE(api_result == 0, test_result); +			api_result = bgp_maximum_paths_unset(bgp, afi, safi, +							     BGP_PEER_IBGP); +			EXPECT_TRUE(api_result == 0, test_result); +			EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ebgp +				     == MULTIPATH_NUM), +				    test_result); +			EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ibgp +				     == MULTIPATH_NUM), +				    test_result); +		} + +	return test_result;  } -static int -cleanup_bgp_cfg_maximum_paths (testcase_t *t) +static int cleanup_bgp_cfg_maximum_paths(testcase_t *t)  { -  return bgp_delete ((struct bgp *)t->tmp_data); +	return bgp_delete((struct bgp *)t->tmp_data);  }  testcase_t test_bgp_cfg_maximum_paths = { -  .desc = "Test bgp maximum-paths config", -  .setup = setup_bgp_cfg_maximum_paths, -  .run = run_bgp_cfg_maximum_paths, -  .cleanup = cleanup_bgp_cfg_maximum_paths, +	.desc = "Test bgp maximum-paths config", +	.setup = setup_bgp_cfg_maximum_paths, +	.run = run_bgp_cfg_maximum_paths, +	.cleanup = cleanup_bgp_cfg_maximum_paths,  };  /*=========================================================   * Testcase for bgp_mp_list   */  struct peer test_mp_list_peer[] = { -  { .local_as = 1, .as = 2 }, -  { .local_as = 1, .as = 2 }, -  { .local_as = 1, .as = 2 }, -  { .local_as = 1, .as = 2 }, -  { .local_as = 1, .as = 2 }, +	{.local_as = 1, .as = 2}, {.local_as = 1, .as = 2}, +	{.local_as = 1, .as = 2}, {.local_as = 1, .as = 2}, +	{.local_as = 1, .as = 2},  }; -int test_mp_list_peer_count = sizeof (test_mp_list_peer)/ sizeof (struct peer); +int test_mp_list_peer_count = sizeof(test_mp_list_peer) / sizeof(struct peer);  struct attr test_mp_list_attr[4];  struct bgp_info test_mp_list_info[] = { -  { .peer = &test_mp_list_peer[0], .attr = &test_mp_list_attr[0] }, -  { .peer = &test_mp_list_peer[1], .attr = &test_mp_list_attr[1] }, -  { .peer = &test_mp_list_peer[2], .attr = &test_mp_list_attr[1] }, -  { .peer = &test_mp_list_peer[3], .attr = &test_mp_list_attr[2] }, -  { .peer = &test_mp_list_peer[4], .attr = &test_mp_list_attr[3] }, +	{.peer = &test_mp_list_peer[0], .attr = &test_mp_list_attr[0]}, +	{.peer = &test_mp_list_peer[1], .attr = &test_mp_list_attr[1]}, +	{.peer = &test_mp_list_peer[2], .attr = &test_mp_list_attr[1]}, +	{.peer = &test_mp_list_peer[3], .attr = &test_mp_list_attr[2]}, +	{.peer = &test_mp_list_peer[4], .attr = &test_mp_list_attr[3]},  };  int test_mp_list_info_count = -  sizeof (test_mp_list_info)/sizeof (struct bgp_info); +	sizeof(test_mp_list_info) / sizeof(struct bgp_info); -static int -setup_bgp_mp_list (testcase_t *t) +static int setup_bgp_mp_list(testcase_t *t)  { -  test_mp_list_attr[0].nexthop.s_addr = 0x01010101; -  test_mp_list_attr[1].nexthop.s_addr = 0x02020202; -  test_mp_list_attr[2].nexthop.s_addr = 0x03030303; -  test_mp_list_attr[3].nexthop.s_addr = 0x04040404; - -  if ((test_mp_list_peer[0].su_remote = sockunion_str2su ("1.1.1.1")) == NULL) -    return -1; -  if ((test_mp_list_peer[1].su_remote = sockunion_str2su ("2.2.2.2")) == NULL) -    return -1; -  if ((test_mp_list_peer[2].su_remote = sockunion_str2su ("3.3.3.3")) == NULL) -    return -1; -  if ((test_mp_list_peer[3].su_remote = sockunion_str2su ("4.4.4.4")) == NULL) -    return -1; -  if ((test_mp_list_peer[4].su_remote = sockunion_str2su ("5.5.5.5")) == NULL) -    return -1; - -  return 0; +	test_mp_list_attr[0].nexthop.s_addr = 0x01010101; +	test_mp_list_attr[1].nexthop.s_addr = 0x02020202; +	test_mp_list_attr[2].nexthop.s_addr = 0x03030303; +	test_mp_list_attr[3].nexthop.s_addr = 0x04040404; + +	if ((test_mp_list_peer[0].su_remote = sockunion_str2su("1.1.1.1")) +	    == NULL) +		return -1; +	if ((test_mp_list_peer[1].su_remote = sockunion_str2su("2.2.2.2")) +	    == NULL) +		return -1; +	if ((test_mp_list_peer[2].su_remote = sockunion_str2su("3.3.3.3")) +	    == NULL) +		return -1; +	if ((test_mp_list_peer[3].su_remote = sockunion_str2su("4.4.4.4")) +	    == NULL) +		return -1; +	if ((test_mp_list_peer[4].su_remote = sockunion_str2su("5.5.5.5")) +	    == NULL) +		return -1; + +	return 0;  } -static int -run_bgp_mp_list (testcase_t *t) +static int run_bgp_mp_list(testcase_t *t)  { -  struct list mp_list; -  struct listnode *mp_node; -  struct bgp_info *info; -  int i; -  int test_result = TEST_PASSED; -  bgp_mp_list_init (&mp_list); -  EXPECT_TRUE (listcount(&mp_list) == 0, test_result); - -  bgp_mp_list_add (&mp_list, &test_mp_list_info[1]); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[4]); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[2]); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[3]); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[0]); - -  for (i = 0, mp_node = mp_list.head; i < test_mp_list_info_count; -       i++, mp_node = listnextnode(mp_node)) -    { -      info = listgetdata(mp_node); -      EXPECT_TRUE (info == &test_mp_list_info[i], test_result); -    } - -  bgp_mp_list_clear (&mp_list); -  EXPECT_TRUE (listcount(&mp_list) == 0, test_result); - -  return test_result; +	struct list mp_list; +	struct listnode *mp_node; +	struct bgp_info *info; +	int i; +	int test_result = TEST_PASSED; +	bgp_mp_list_init(&mp_list); +	EXPECT_TRUE(listcount(&mp_list) == 0, test_result); + +	bgp_mp_list_add(&mp_list, &test_mp_list_info[1]); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[4]); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[2]); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[3]); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[0]); + +	for (i = 0, mp_node = mp_list.head; i < test_mp_list_info_count; +	     i++, mp_node = listnextnode(mp_node)) { +		info = listgetdata(mp_node); +		EXPECT_TRUE(info == &test_mp_list_info[i], test_result); +	} + +	bgp_mp_list_clear(&mp_list); +	EXPECT_TRUE(listcount(&mp_list) == 0, test_result); + +	return test_result;  } -static int -cleanup_bgp_mp_list (testcase_t *t) +static int cleanup_bgp_mp_list(testcase_t *t)  { -  int i; +	int i; -  for (i = 0; i < test_mp_list_peer_count; i++) -    sockunion_free (test_mp_list_peer[i].su_remote); +	for (i = 0; i < test_mp_list_peer_count; i++) +		sockunion_free(test_mp_list_peer[i].su_remote); -  return 0; +	return 0;  }  testcase_t test_bgp_mp_list = { -  .desc = "Test bgp_mp_list", -  .setup = setup_bgp_mp_list, -  .run = run_bgp_mp_list, -  .cleanup = cleanup_bgp_mp_list, +	.desc = "Test bgp_mp_list", +	.setup = setup_bgp_mp_list, +	.run = run_bgp_mp_list, +	.cleanup = cleanup_bgp_mp_list,  };  /*========================================================= @@ -290,195 +292,185 @@ testcase_t test_bgp_mp_list = {  struct bgp_node test_rn; -static int -setup_bgp_info_mpath_update (testcase_t *t) +static int setup_bgp_info_mpath_update(testcase_t *t)  { -  int i; -  str2prefix ("42.1.1.0/24", &test_rn.p); -  setup_bgp_mp_list (t); -  for (i = 0; i < test_mp_list_info_count; i++) -    bgp_info_add (&test_rn, &test_mp_list_info[i]); -  return 0; +	int i; +	str2prefix("42.1.1.0/24", &test_rn.p); +	setup_bgp_mp_list(t); +	for (i = 0; i < test_mp_list_info_count; i++) +		bgp_info_add(&test_rn, &test_mp_list_info[i]); +	return 0;  } -static int -run_bgp_info_mpath_update (testcase_t *t) +static int run_bgp_info_mpath_update(testcase_t *t)  { -  struct bgp_info *new_best, *old_best, *mpath; -  struct list mp_list; -  struct bgp_maxpaths_cfg mp_cfg = { 3, 3 }; -  int test_result = TEST_PASSED; -  bgp_mp_list_init (&mp_list); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[4]); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[3]); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[0]); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[1]); -  new_best = &test_mp_list_info[3]; -  old_best = NULL; -  bgp_info_mpath_update (&test_rn, new_best, old_best, &mp_list, &mp_cfg); -  bgp_mp_list_clear (&mp_list); -  EXPECT_TRUE (bgp_info_mpath_count (new_best) == 2, test_result); -  mpath = bgp_info_mpath_first (new_best); -  EXPECT_TRUE (mpath == &test_mp_list_info[0], test_result); -  EXPECT_TRUE (CHECK_FLAG (mpath->flags, BGP_INFO_MULTIPATH), test_result); -  mpath = bgp_info_mpath_next (mpath); -  EXPECT_TRUE (mpath == &test_mp_list_info[1], test_result); -  EXPECT_TRUE (CHECK_FLAG (mpath->flags, BGP_INFO_MULTIPATH), test_result); - -  bgp_mp_list_add (&mp_list, &test_mp_list_info[0]); -  bgp_mp_list_add (&mp_list, &test_mp_list_info[1]); -  new_best = &test_mp_list_info[0]; -  old_best = &test_mp_list_info[3]; -  bgp_info_mpath_update (&test_rn, new_best, old_best, &mp_list, &mp_cfg); -  bgp_mp_list_clear (&mp_list); -  EXPECT_TRUE (bgp_info_mpath_count (new_best) == 1, test_result); -  mpath = bgp_info_mpath_first (new_best); -  EXPECT_TRUE (mpath == &test_mp_list_info[1], test_result); -  EXPECT_TRUE (CHECK_FLAG (mpath->flags, BGP_INFO_MULTIPATH), test_result); -  EXPECT_TRUE (!CHECK_FLAG (test_mp_list_info[0].flags, BGP_INFO_MULTIPATH), -               test_result); - -  return test_result; +	struct bgp_info *new_best, *old_best, *mpath; +	struct list mp_list; +	struct bgp_maxpaths_cfg mp_cfg = {3, 3}; +	int test_result = TEST_PASSED; +	bgp_mp_list_init(&mp_list); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[4]); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[3]); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[0]); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[1]); +	new_best = &test_mp_list_info[3]; +	old_best = NULL; +	bgp_info_mpath_update(&test_rn, new_best, old_best, &mp_list, &mp_cfg); +	bgp_mp_list_clear(&mp_list); +	EXPECT_TRUE(bgp_info_mpath_count(new_best) == 2, test_result); +	mpath = bgp_info_mpath_first(new_best); +	EXPECT_TRUE(mpath == &test_mp_list_info[0], test_result); +	EXPECT_TRUE(CHECK_FLAG(mpath->flags, BGP_INFO_MULTIPATH), test_result); +	mpath = bgp_info_mpath_next(mpath); +	EXPECT_TRUE(mpath == &test_mp_list_info[1], test_result); +	EXPECT_TRUE(CHECK_FLAG(mpath->flags, BGP_INFO_MULTIPATH), test_result); + +	bgp_mp_list_add(&mp_list, &test_mp_list_info[0]); +	bgp_mp_list_add(&mp_list, &test_mp_list_info[1]); +	new_best = &test_mp_list_info[0]; +	old_best = &test_mp_list_info[3]; +	bgp_info_mpath_update(&test_rn, new_best, old_best, &mp_list, &mp_cfg); +	bgp_mp_list_clear(&mp_list); +	EXPECT_TRUE(bgp_info_mpath_count(new_best) == 1, test_result); +	mpath = bgp_info_mpath_first(new_best); +	EXPECT_TRUE(mpath == &test_mp_list_info[1], test_result); +	EXPECT_TRUE(CHECK_FLAG(mpath->flags, BGP_INFO_MULTIPATH), test_result); +	EXPECT_TRUE(!CHECK_FLAG(test_mp_list_info[0].flags, BGP_INFO_MULTIPATH), +		    test_result); + +	return test_result;  } -static int -cleanup_bgp_info_mpath_update (testcase_t *t) +static int cleanup_bgp_info_mpath_update(testcase_t *t)  { -  int i; +	int i; -  for (i = 0; i < test_mp_list_peer_count; i++) -    sockunion_free (test_mp_list_peer[i].su_remote); +	for (i = 0; i < test_mp_list_peer_count; i++) +		sockunion_free(test_mp_list_peer[i].su_remote); -  return 0; +	return 0;  }  testcase_t test_bgp_info_mpath_update = { -  .desc = "Test bgp_info_mpath_update", -  .setup = setup_bgp_info_mpath_update, -  .run = run_bgp_info_mpath_update, -  .cleanup = cleanup_bgp_info_mpath_update, +	.desc = "Test bgp_info_mpath_update", +	.setup = setup_bgp_info_mpath_update, +	.run = run_bgp_info_mpath_update, +	.cleanup = cleanup_bgp_info_mpath_update,  };  /*=========================================================   * Set up testcase vector   */  testcase_t *all_tests[] = { -  &test_bgp_cfg_maximum_paths, -  &test_bgp_mp_list, -  &test_bgp_info_mpath_update, +	&test_bgp_cfg_maximum_paths, &test_bgp_mp_list, +	&test_bgp_info_mpath_update,  }; -int all_tests_count = (sizeof(all_tests)/sizeof(testcase_t *)); +int all_tests_count = (sizeof(all_tests) / sizeof(testcase_t *));  /*=========================================================   * Test Driver Functions   */ -static int -global_test_init (void) +static int global_test_init(void)  { -  qobj_init (); -  master = thread_master_create (); -  zclient = zclient_new(master); -  bgp_master_init (master); -  vrf_init (); -  bgp_option_set (BGP_OPT_NO_LISTEN); -   -  if (fileno (stdout) >= 0) -    tty = isatty (fileno (stdout)); -  return 0; +	qobj_init(); +	master = thread_master_create(); +	zclient = zclient_new(master); +	bgp_master_init(master); +	vrf_init(); +	bgp_option_set(BGP_OPT_NO_LISTEN); + +	if (fileno(stdout) >= 0) +		tty = isatty(fileno(stdout)); +	return 0;  } -static int -global_test_cleanup (void) +static int global_test_cleanup(void)  { -  if (zclient != NULL) -    zclient_free (zclient); -  thread_master_free (master); -  return 0; +	if (zclient != NULL) +		zclient_free(zclient); +	thread_master_free(master); +	return 0;  } -static void -display_result (testcase_t *test, int result) +static void display_result(testcase_t *test, int result)  { -  if (tty) -    printf ("%s: %s\n", test->desc, result == TEST_PASSED ? OK : FAILED); -  else -    printf ("%s: %s\n", test->desc, result == TEST_PASSED ? "OK" : "FAILED"); +	if (tty) +		printf("%s: %s\n", test->desc, +		       result == TEST_PASSED ? OK : FAILED); +	else +		printf("%s: %s\n", test->desc, +		       result == TEST_PASSED ? "OK" : "FAILED");  } -static int -setup_test (testcase_t *t) +static int setup_test(testcase_t *t)  { -  int res = 0; -  if (t->setup) -    res = t->setup (t); -  return res; +	int res = 0; +	if (t->setup) +		res = t->setup(t); +	return res;  } -static int -cleanup_test (testcase_t *t) +static int cleanup_test(testcase_t *t)  { -  int res = 0; -  if (t->cleanup) -    res = t->cleanup (t); -  return res; +	int res = 0; +	if (t->cleanup) +		res = t->cleanup(t); +	return res;  } -static void -run_tests (testcase_t *tests[], int num_tests, int *pass_count, int *fail_count) +static void run_tests(testcase_t *tests[], int num_tests, int *pass_count, +		      int *fail_count)  { -  int test_index, result; -  testcase_t *cur_test; - -  *pass_count = *fail_count = 0; - -  for (test_index = 0; test_index < num_tests; test_index++) -    { -      cur_test = tests[test_index]; -      if (!cur_test->desc) -        { -          printf ("error: test %d has no description!\n", test_index); -          continue; -        } -      if (!cur_test->run) -        { -          printf ("error: test %s has no run function!\n", cur_test->desc); -          continue; -        } -      if (setup_test (cur_test) != 0) -        { -          printf ("error: setup failed for test %s\n", cur_test->desc); -          continue; -        } -      result = cur_test->run (cur_test); -      if (result == TEST_PASSED) -        *pass_count += 1; -      else -        *fail_count += 1; -      display_result (cur_test, result); -      if (cleanup_test (cur_test) != 0) -        { -          printf ("error: cleanup failed for test %s\n", cur_test->desc); -          continue; -        } -    } +	int test_index, result; +	testcase_t *cur_test; + +	*pass_count = *fail_count = 0; + +	for (test_index = 0; test_index < num_tests; test_index++) { +		cur_test = tests[test_index]; +		if (!cur_test->desc) { +			printf("error: test %d has no description!\n", +			       test_index); +			continue; +		} +		if (!cur_test->run) { +			printf("error: test %s has no run function!\n", +			       cur_test->desc); +			continue; +		} +		if (setup_test(cur_test) != 0) { +			printf("error: setup failed for test %s\n", +			       cur_test->desc); +			continue; +		} +		result = cur_test->run(cur_test); +		if (result == TEST_PASSED) +			*pass_count += 1; +		else +			*fail_count += 1; +		display_result(cur_test, result); +		if (cleanup_test(cur_test) != 0) { +			printf("error: cleanup failed for test %s\n", +			       cur_test->desc); +			continue; +		} +	}  } -int -main (void) +int main(void)  { -  int pass_count, fail_count; -  time_t cur_time; - -  time (&cur_time); -  printf("BGP Multipath Tests Run at %s", ctime(&cur_time)); -  if (global_test_init () != 0) -    { -      printf("Global init failed. Terminating.\n"); -      exit(1); -    } -  run_tests (all_tests, all_tests_count, &pass_count, &fail_count); -  global_test_cleanup (); -  printf("Total pass/fail: %d/%d\n", pass_count, fail_count); -  return fail_count; +	int pass_count, fail_count; +	time_t cur_time; + +	time(&cur_time); +	printf("BGP Multipath Tests Run at %s", ctime(&cur_time)); +	if (global_test_init() != 0) { +		printf("Global init failed. Terminating.\n"); +		exit(1); +	} +	run_tests(all_tests, all_tests_count, &pass_count, &fail_count); +	global_test_cleanup(); +	printf("Total pass/fail: %d/%d\n", pass_count, fail_count); +	return fail_count;  } diff --git a/tests/helpers/c/main.c b/tests/helpers/c/main.c index b3e6e706ff..0b3e942b77 100644 --- a/tests/helpers/c/main.c +++ b/tests/helpers/c/main.c @@ -33,57 +33,50 @@ extern void test_init();  struct thread_master *master; -struct option longopts[] =  -{ -  { "daemon",      no_argument,       NULL, 'd'}, -  { "config_file", required_argument, NULL, 'f'}, -  { "help",        no_argument,       NULL, 'h'}, -  { "vty_addr",    required_argument, NULL, 'A'}, -  { "vty_port",    required_argument, NULL, 'P'}, -  { "version",     no_argument,       NULL, 'v'}, -  { 0 } -}; +struct option longopts[] = {{"daemon", no_argument, NULL, 'd'}, +			    {"config_file", required_argument, NULL, 'f'}, +			    {"help", no_argument, NULL, 'h'}, +			    {"vty_addr", required_argument, NULL, 'A'}, +			    {"vty_port", required_argument, NULL, 'P'}, +			    {"version", no_argument, NULL, 'v'}, +			    {0}};  DEFUN (daemon_exit,         daemon_exit_cmd,         "daemon-exit",         "Make the daemon exit\n")  { -  exit(0); +	exit(0);  }  static int timer_count; -static int -test_timer (struct thread *thread) +static 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; +	int *count = THREAD_ARG(thread); + +	printf("run %d of timer\n", (*count)++); +	thread_add_timer(master, test_timer, count, 5); +	return 0;  } -static void -test_timer_init() +static void test_timer_init()  { -  thread_add_timer (master, test_timer, &timer_count, 10); +	thread_add_timer(master, test_timer, &timer_count, 10);  } -static void -test_vty_init() +static void test_vty_init()  { -  install_element (VIEW_NODE, &daemon_exit_cmd); +	install_element(VIEW_NODE, &daemon_exit_cmd);  }  /* Help information display. */ -static void -usage (char *progname, int status) +static void usage(char *progname, int status)  { -  if (status != 0) -    fprintf (stderr, "Try `%s --help' for more information.\n", progname); -  else -    {     -      printf ("Usage : %s [OPTION...]\n\ +	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\  -f, --config_file  Set configuration file name\n\ @@ -92,110 +85,105 @@ Daemon which does 'slow' things.\n\n\  -v, --version      Print program version\n\  -h, --help         Display this help and exit\n\  \n\ -Report bugs to %s\n", progname, FRR_BUG_ADDRESS); -    } -  exit (status); +Report bugs to %s\n", +		       progname, FRR_BUG_ADDRESS); +	} +	exit(status);  }  /* main routine. */ -int -main (int argc, char **argv) +int main(int argc, char **argv)  { -  char *p; -  char *vty_addr = NULL; -  int vty_port = 4000; -  int daemon_mode = 0; -  char *progname; -  struct thread thread; -  char *config_file = NULL; -   -  /* Set umask before anything for security */ -  umask (0027); - -  /* get program name */ -  progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); - -  /* master init. */ -  master = thread_master_create (); - -  while (1)  -    { -      int opt; - -      opt = getopt_long (argc, argv, "dhf:A:P:v", longopts, 0); -     -      if (opt == EOF) -	break; - -      switch (opt)  -	{ -	case 0: -	  break; -        case 'f': -          config_file = optarg; -          break; -	case 'd': -	  daemon_mode = 1; -	  break; -	case 'A': -	  vty_addr = optarg; -	  break; -	case 'P': -          /* Deal with atoi() returning 0 on failure */ -          if (strcmp(optarg, "0") == 0) -            { -              vty_port = 0; -              break; -            }  -          vty_port = atoi (optarg); -          vty_port = (vty_port ? vty_port : 4000); -  	  break; -	case 'v': -	  print_version (progname); -	  exit (0); -	  break; -	case 'h': -	  usage (progname, 0); -	  break; -	default: -	  usage (progname, 1); -	  break; +	char *p; +	char *vty_addr = NULL; +	int vty_port = 4000; +	int daemon_mode = 0; +	char *progname; +	struct thread thread; +	char *config_file = NULL; + +	/* Set umask before anything for security */ +	umask(0027); + +	/* get program name */ +	progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]); + +	/* master init. */ +	master = thread_master_create(); + +	while (1) { +		int opt; + +		opt = getopt_long(argc, argv, "dhf:A:P:v", longopts, 0); + +		if (opt == EOF) +			break; + +		switch (opt) { +		case 0: +			break; +		case 'f': +			config_file = optarg; +			break; +		case 'd': +			daemon_mode = 1; +			break; +		case 'A': +			vty_addr = optarg; +			break; +		case 'P': +			/* Deal with atoi() returning 0 on failure */ +			if (strcmp(optarg, "0") == 0) { +				vty_port = 0; +				break; +			} +			vty_port = atoi(optarg); +			vty_port = (vty_port ? vty_port : 4000); +			break; +		case 'v': +			print_version(progname); +			exit(0); +			break; +		case 'h': +			usage(progname, 0); +			break; +		default: +			usage(progname, 1); +			break; +		}  	} -    } - -  /* Library inits. */ -  cmd_init (1); -  vty_init (master); -  memory_init (); - -  /* OSPF vty inits. */ -  test_vty_init (); - -  /* Change to the daemon program. */ -  if (daemon_mode && daemon (0, 0) < 0) -    { -      fprintf(stderr, "daemon failed: %s", strerror(errno)); -      exit (1); -    } - -  /* 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();   -   -  /* Fetch next active thread. */ -  while (thread_fetch (master, &thread)) -    thread_call (&thread); - -  /* Not reached. */ -  exit (0); -} +	/* Library inits. */ +	cmd_init(1); +	vty_init(master); +	memory_init(); + +	/* OSPF vty inits. */ +	test_vty_init(); + +	/* Change to the daemon program. */ +	if (daemon_mode && daemon(0, 0) < 0) { +		fprintf(stderr, "daemon failed: %s", strerror(errno)); +		exit(1); +	} + +	/* 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(); + +	/* Fetch next active thread. */ +	while (thread_fetch(master, &thread)) +		thread_call(&thread); + +	/* Not reached. */ +	exit(0); +} diff --git a/tests/helpers/c/prng.c b/tests/helpers/c/prng.c index bdcfb07af1..36e83173d9 100644 --- a/tests/helpers/c/prng.c +++ b/tests/helpers/c/prng.c @@ -31,102 +31,92 @@  #include "prng.h" -struct prng -{ -  unsigned long long state1; -  unsigned long long state2; +struct prng { +	unsigned long long state1; +	unsigned long long state2;  }; -static char -prng_bit(struct prng *prng) +static char prng_bit(struct prng *prng)  { -  prng->state1 *= 2416; -  prng->state1 += 374441; -  prng->state1 %= 1771875; - -  if (prng->state1 % 2) -    { -      prng->state2 *= 84589; -      prng->state2 += 45989; -      prng->state2 %= 217728; -    } - -  return prng->state2 % 2; +	prng->state1 *= 2416; +	prng->state1 += 374441; +	prng->state1 %= 1771875; + +	if (prng->state1 % 2) { +		prng->state2 *= 84589; +		prng->state2 += 45989; +		prng->state2 %= 217728; +	} + +	return prng->state2 % 2;  } -struct prng* -prng_new(unsigned long long seed) +struct prng *prng_new(unsigned long long seed)  { -  struct prng *rv = calloc(sizeof(*rv), 1); -  assert(rv); +	struct prng *rv = calloc(sizeof(*rv), 1); +	assert(rv); -  rv->state1 = rv->state2 = seed; +	rv->state1 = rv->state2 = seed; -  return rv; +	return rv;  } -unsigned int -prng_rand(struct prng *prng) +unsigned int prng_rand(struct prng *prng)  { -  unsigned int i, rv = 0; - -  for (i = 0; i < 32; i++) -    { -      rv |= prng_bit(prng); -      rv <<= 1; -    } -  return rv; +	unsigned int i, rv = 0; + +	for (i = 0; i < 32; i++) { +		rv |= prng_bit(prng); +		rv <<= 1; +	} +	return rv;  } -const char * -prng_fuzz(struct prng *prng, -          const char *string, -          const char *charset, -          unsigned int operations) +const char *prng_fuzz(struct prng *prng, const char *string, +		      const char *charset, unsigned int operations)  { -  static char buf[256]; -  unsigned int charset_len; -  unsigned int i; -  unsigned int offset; -  unsigned int op; -  unsigned int character; - -  assert(strlen(string) < sizeof(buf)); - -  strncpy(buf, string, sizeof(buf)); -  charset_len = strlen(charset); - -  for (i = 0; i < operations; i++) -    { -      offset = prng_rand(prng) % strlen(buf); -      op = prng_rand(prng) % 3; - -      switch (op) -        { -        case 0: -          /* replace */ -          character = prng_rand(prng) % charset_len; -          buf[offset] = charset[character]; -          break; -        case 1: -          /* remove */ -          memmove(buf + offset, buf + offset + 1, strlen(buf) - offset); -          break; -        case 2: -          /* insert */ -          assert(strlen(buf) + 1 < sizeof(buf)); - -          memmove(buf + offset + 1, buf + offset, strlen(buf) + 1 - offset); -          character = prng_rand(prng) % charset_len; -          buf[offset] = charset[character]; -          break; -        } -    } -  return buf; +	static char buf[256]; +	unsigned int charset_len; +	unsigned int i; +	unsigned int offset; +	unsigned int op; +	unsigned int character; + +	assert(strlen(string) < sizeof(buf)); + +	strncpy(buf, string, sizeof(buf)); +	charset_len = strlen(charset); + +	for (i = 0; i < operations; i++) { +		offset = prng_rand(prng) % strlen(buf); +		op = prng_rand(prng) % 3; + +		switch (op) { +		case 0: +			/* replace */ +			character = prng_rand(prng) % charset_len; +			buf[offset] = charset[character]; +			break; +		case 1: +			/* remove */ +			memmove(buf + offset, buf + offset + 1, +				strlen(buf) - offset); +			break; +		case 2: +			/* insert */ +			assert(strlen(buf) + 1 < sizeof(buf)); + +			memmove(buf + offset + 1, buf + offset, +				strlen(buf) + 1 - offset); +			character = prng_rand(prng) % charset_len; +			buf[offset] = charset[character]; +			break; +		} +	} +	return buf;  } -void -prng_free(struct prng *prng) +void prng_free(struct prng *prng)  { -  free(prng); +	free(prng);  } diff --git a/tests/helpers/c/prng.h b/tests/helpers/c/prng.h index cf0bacc5f8..ab4f071703 100644 --- a/tests/helpers/c/prng.h +++ b/tests/helpers/c/prng.h @@ -27,12 +27,10 @@  struct prng; -struct prng* prng_new(unsigned long long seed); -unsigned int prng_rand(struct prng*); -const char * prng_fuzz(struct prng*, -                       const char *string, -                       const char *charset, -                       unsigned int operations); +struct prng *prng_new(unsigned long long seed); +unsigned int prng_rand(struct prng *); +const char *prng_fuzz(struct prng *, const char *string, const char *charset, +		      unsigned int operations);  void prng_free(struct prng *);  #endif diff --git a/tests/helpers/c/tests.h b/tests/helpers/c/tests.h index a528e55f05..dc6c03e4b8 100644 --- a/tests/helpers/c/tests.h +++ b/tests/helpers/c/tests.h @@ -25,7 +25,7 @@  #ifndef _QUAGGA_TESTS_H  #define _QUAGGA_TESTS_H -extern void test_init (void); -extern void test_init_cmd (void); +extern void test_init(void); +extern void test_init_cmd(void);  #endif /* _QUAGGA_TESTS_H */ diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c index 56db460438..93d6382a63 100644 --- a/tests/lib/cli/common_cli.c +++ b/tests/lib/cli/common_cli.c @@ -33,65 +33,62 @@  struct thread_master *master; -int dump_args(struct vty *vty, const char *descr, -              int argc, struct cmd_token *argv[]) +int dump_args(struct vty *vty, const char *descr, int argc, +	      struct cmd_token *argv[])  { -  int i; -  vty_out (vty, "%s with %d args.%s", descr, argc, VTY_NEWLINE); -  for (i = 0; i < argc; i++) -    { -      vty_out (vty, "[%02d]: %s%s", i, argv[i]->arg, VTY_NEWLINE); -    } - -  return CMD_SUCCESS; +	int i; +	vty_out(vty, "%s with %d args.%s", descr, argc, VTY_NEWLINE); +	for (i = 0; i < argc; i++) { +		vty_out(vty, "[%02d]: %s%s", i, argv[i]->arg, VTY_NEWLINE); +	} + +	return CMD_SUCCESS;  }  static void vty_do_exit(void)  { -  printf ("\nend.\n"); -  cmd_terminate (); -  vty_terminate (); -  thread_master_free (master); -  closezlog (); - -  log_memstats_stderr ("testcli"); -  exit (0); +	printf("\nend.\n"); +	cmd_terminate(); +	vty_terminate(); +	thread_master_free(master); +	closezlog(); + +	log_memstats_stderr("testcli"); +	exit(0);  }  /* main routine. */ -int -main (int argc, char **argv) +int main(int argc, char **argv)  { -  struct thread thread; +	struct thread thread; -  /* Set umask before anything for security */ -  umask (0027); +	/* Set umask before anything for security */ +	umask(0027); -  /* master init. */ -  master = thread_master_create (); +	/* master init. */ +	master = thread_master_create(); -  openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, -           LOG_DAEMON); -  zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); -  zlog_set_level(ZLOG_DEST_STDOUT, ZLOG_DISABLED); -  zlog_set_level(ZLOG_DEST_MONITOR, LOG_DEBUG); +	openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, +		 LOG_DAEMON); +	zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); +	zlog_set_level(ZLOG_DEST_STDOUT, ZLOG_DISABLED); +	zlog_set_level(ZLOG_DEST_MONITOR, LOG_DEBUG); -  /* Library inits. */ -  cmd_init (1); -  cmd_hostname_set ("test"); +	/* Library inits. */ +	cmd_init(1); +	cmd_hostname_set("test"); -  vty_init (master); -  memory_init (); +	vty_init(master); +	memory_init(); -  test_init (argc, argv); +	test_init(argc, argv); -  vty_stdio (vty_do_exit); +	vty_stdio(vty_do_exit); -  /* Fetch next active thread. */ -  while (thread_fetch (master, &thread)) -    thread_call (&thread); +	/* Fetch next active thread. */ +	while (thread_fetch(master, &thread)) +		thread_call(&thread); -  /* Not reached. */ -  exit (0); +	/* Not reached. */ +	exit(0);  } - diff --git a/tests/lib/cli/common_cli.h b/tests/lib/cli/common_cli.h index 9e7fe99830..6ca1f1ba84 100644 --- a/tests/lib/cli/common_cli.h +++ b/tests/lib/cli/common_cli.h @@ -28,22 +28,24 @@  #include "command.h"  /* function to be implemented by test */ -extern void test_init (int argc, char **argv); +extern void test_init(int argc, char **argv);  /* functions provided by common cli   * (includes main())   */  extern struct thread_master *master; -extern int dump_args(struct vty *vty, const char *descr, -              int argc, struct cmd_token *argv[]); +extern int dump_args(struct vty *vty, const char *descr, int argc, +		     struct cmd_token *argv[]); -#define DUMMY_HELPSTR \ -       "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n" \ -       "10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n" \ -       "20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n" -#define DUMMY_DEFUN(name, cmdstr) \ -        DEFUN (name, name ## _cmd, cmdstr, DUMMY_HELPSTR) \ -        { return dump_args(vty, #name, argc, argv); } +#define DUMMY_HELPSTR                                                          \ +	"00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n"                             \ +	"10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n"                             \ +	"20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n" +#define DUMMY_DEFUN(name, cmdstr)                                              \ +	DEFUN(name, name##_cmd, cmdstr, DUMMY_HELPSTR)                         \ +	{                                                                      \ +		return dump_args(vty, #name, argc, argv);                      \ +	}  #endif /* _COMMON_CLI_H */ diff --git a/tests/lib/cli/test_cli.c b/tests/lib/cli/test_cli.c index 54b34bc799..c8762362e4 100644 --- a/tests/lib/cli/test_cli.c +++ b/tests/lib/cli/test_cli.c @@ -24,15 +24,15 @@  #include "common_cli.h" -DUMMY_DEFUN(cmd0,  "arg ipv4 A.B.C.D"); -DUMMY_DEFUN(cmd1,  "arg ipv4m A.B.C.D/M"); -DUMMY_DEFUN(cmd2,  "arg ipv6 X:X::X:X"); -DUMMY_DEFUN(cmd3,  "arg ipv6m X:X::X:X/M"); -DUMMY_DEFUN(cmd4,  "arg range (5-15)"); -DUMMY_DEFUN(cmd5,  "pat a < a|b>"); -DUMMY_DEFUN(cmd7,  "pat c <a | b|c> A.B.C.D"); -DUMMY_DEFUN(cmd8,  "pat d {  foo A.B.C.D|bar   X:X::X:X| baz }"); -DUMMY_DEFUN(cmd9,  "pat e [ WORD ]"); +DUMMY_DEFUN(cmd0, "arg ipv4 A.B.C.D"); +DUMMY_DEFUN(cmd1, "arg ipv4m A.B.C.D/M"); +DUMMY_DEFUN(cmd2, "arg ipv6 X:X::X:X"); +DUMMY_DEFUN(cmd3, "arg ipv6m X:X::X:X/M"); +DUMMY_DEFUN(cmd4, "arg range (5-15)"); +DUMMY_DEFUN(cmd5, "pat a < a|b>"); +DUMMY_DEFUN(cmd7, "pat c <a | b|c> A.B.C.D"); +DUMMY_DEFUN(cmd8, "pat d {  foo A.B.C.D|bar   X:X::X:X| baz }"); +DUMMY_DEFUN(cmd9, "pat e [ WORD ]");  DUMMY_DEFUN(cmd10, "pat f [key]");  DUMMY_DEFUN(cmd11, "alt a WORD");  DUMMY_DEFUN(cmd12, "alt a A.B.C.D"); @@ -40,27 +40,27 @@ DUMMY_DEFUN(cmd13, "alt a X:X::X:X");  void test_init(int argc, char **argv)  { -  size_t repeat = argc > 1 ? strtoul(argv[1], NULL, 0) : 223; +	size_t repeat = argc > 1 ? strtoul(argv[1], NULL, 0) : 223; -  install_element (ENABLE_NODE, &cmd0_cmd); -  install_element (ENABLE_NODE, &cmd1_cmd); -  install_element (ENABLE_NODE, &cmd2_cmd); -  install_element (ENABLE_NODE, &cmd3_cmd); -  install_element (ENABLE_NODE, &cmd4_cmd); -  install_element (ENABLE_NODE, &cmd5_cmd); -  install_element (ENABLE_NODE, &cmd7_cmd); -  install_element (ENABLE_NODE, &cmd8_cmd); -  install_element (ENABLE_NODE, &cmd9_cmd); -  install_element (ENABLE_NODE, &cmd10_cmd); -  install_element (ENABLE_NODE, &cmd11_cmd); -  install_element (ENABLE_NODE, &cmd12_cmd); -  install_element (ENABLE_NODE, &cmd13_cmd); -  for (size_t i = 0; i < repeat; i++) { -    uninstall_element (ENABLE_NODE, &cmd5_cmd); -    install_element (ENABLE_NODE, &cmd5_cmd); -  } -  for (size_t i = 0; i < repeat; i++) { -    uninstall_element (ENABLE_NODE, &cmd13_cmd); -    install_element (ENABLE_NODE, &cmd13_cmd); -  } +	install_element(ENABLE_NODE, &cmd0_cmd); +	install_element(ENABLE_NODE, &cmd1_cmd); +	install_element(ENABLE_NODE, &cmd2_cmd); +	install_element(ENABLE_NODE, &cmd3_cmd); +	install_element(ENABLE_NODE, &cmd4_cmd); +	install_element(ENABLE_NODE, &cmd5_cmd); +	install_element(ENABLE_NODE, &cmd7_cmd); +	install_element(ENABLE_NODE, &cmd8_cmd); +	install_element(ENABLE_NODE, &cmd9_cmd); +	install_element(ENABLE_NODE, &cmd10_cmd); +	install_element(ENABLE_NODE, &cmd11_cmd); +	install_element(ENABLE_NODE, &cmd12_cmd); +	install_element(ENABLE_NODE, &cmd13_cmd); +	for (size_t i = 0; i < repeat; i++) { +		uninstall_element(ENABLE_NODE, &cmd5_cmd); +		install_element(ENABLE_NODE, &cmd5_cmd); +	} +	for (size_t i = 0; i < repeat; i++) { +		uninstall_element(ENABLE_NODE, &cmd13_cmd); +		install_element(ENABLE_NODE, &cmd13_cmd); +	}  } diff --git a/tests/lib/cli/test_commands.c b/tests/lib/cli/test_commands.c index 272e3d12b7..4bbddb5741 100644 --- a/tests/lib/cli/test_commands.c +++ b/tests/lib/cli/test_commands.c @@ -49,360 +49,297 @@ struct thread_master *master; /* dummy for libfrr*/  static vector test_cmds;  static char test_buf[32768]; -static struct cmd_node bgp_node = -{ -  BGP_NODE, -  "%s(config-router)# ", +static struct cmd_node bgp_node = { +	BGP_NODE, "%s(config-router)# ",  }; -static struct cmd_node rip_node = -{ -  RIP_NODE, -  "%s(config-router)# ", +static struct cmd_node rip_node = { +	RIP_NODE, "%s(config-router)# ",  }; -static struct cmd_node isis_node = -{ -  ISIS_NODE, -  "%s(config-router)# ", +static struct cmd_node isis_node = { +	ISIS_NODE, "%s(config-router)# ",  }; -static struct cmd_node interface_node = -{ -  INTERFACE_NODE, -  "%s(config-if)# ", +static struct cmd_node interface_node = { +	INTERFACE_NODE, "%s(config-if)# ",  }; -static struct cmd_node rmap_node = -{ -  RMAP_NODE, -  "%s(config-route-map)# " -}; +static struct cmd_node rmap_node = {RMAP_NODE, "%s(config-route-map)# "}; -static struct cmd_node zebra_node = -{ -  ZEBRA_NODE, -  "%s(config-router)# " -}; +static struct cmd_node zebra_node = {ZEBRA_NODE, "%s(config-router)# "}; -static struct cmd_node bgp_vpnv4_node = -{ -  BGP_VPNV4_NODE, -  "%s(config-router-af)# " -}; +static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE, +					 "%s(config-router-af)# "}; -static struct cmd_node bgp_ipv4_node = -{ -  BGP_IPV4_NODE, -  "%s(config-router-af)# " -}; +static struct cmd_node bgp_ipv4_node = {BGP_IPV4_NODE, +					"%s(config-router-af)# "}; -static struct cmd_node bgp_ipv4m_node = -{ -  BGP_IPV4M_NODE, -  "%s(config-router-af)# " -}; +static struct cmd_node bgp_ipv4m_node = {BGP_IPV4M_NODE, +					 "%s(config-router-af)# "}; -static struct cmd_node bgp_ipv6_node = -{ -  BGP_IPV6_NODE, -  "%s(config-router-af)# " -}; +static struct cmd_node bgp_ipv6_node = {BGP_IPV6_NODE, +					"%s(config-router-af)# "}; -static struct cmd_node bgp_ipv6m_node = -{ -  BGP_IPV6M_NODE, -  "%s(config-router-af)# " -}; +static struct cmd_node bgp_ipv6m_node = {BGP_IPV6M_NODE, +					 "%s(config-router-af)# "}; -static struct cmd_node ospf_node = -{ -  OSPF_NODE, -  "%s(config-router)# " -}; +static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# "}; -static struct cmd_node ripng_node = -{ -  RIPNG_NODE, -  "%s(config-router)# " -}; +static struct cmd_node ripng_node = {RIPNG_NODE, "%s(config-router)# "}; -static struct cmd_node ospf6_node = -{ -  OSPF6_NODE, -  "%s(config-ospf6)# " -}; +static struct cmd_node ospf6_node = {OSPF6_NODE, "%s(config-ospf6)# "}; -static struct cmd_node keychain_node = -{ -  KEYCHAIN_NODE, -  "%s(config-keychain)# " -}; +static struct cmd_node keychain_node = {KEYCHAIN_NODE, "%s(config-keychain)# "}; -static struct cmd_node keychain_key_node = -{ -  KEYCHAIN_KEY_NODE, -  "%s(config-keychain-key)# " -}; +static struct cmd_node keychain_key_node = {KEYCHAIN_KEY_NODE, +					    "%s(config-keychain-key)# "}; -static int -test_callback(const struct cmd_element *cmd, struct vty *vty, int argc, struct cmd_token *argv[]) +static int test_callback(const struct cmd_element *cmd, struct vty *vty, +			 int argc, struct cmd_token *argv[])  { -  int offset; -  int rv; -  int i; - -  offset = 0; -  rv = snprintf(test_buf, sizeof(test_buf), "'%s'", cmd->string); -  if (rv < 0) -    abort(); - -  offset += rv; - -  for (i = 0; i < argc; i++) -    { -      rv = snprintf(test_buf + offset, sizeof(test_buf) - offset, "%s'%s'", -                    (i == 0) ? ": " : ", ", argv[i]->arg); -      if (rv < 0) -        abort(); -      offset += rv; -    } - -  return CMD_SUCCESS; +	int offset; +	int rv; +	int i; + +	offset = 0; +	rv = snprintf(test_buf, sizeof(test_buf), "'%s'", cmd->string); +	if (rv < 0) +		abort(); + +	offset += rv; + +	for (i = 0; i < argc; i++) { +		rv = snprintf(test_buf + offset, sizeof(test_buf) - offset, +			      "%s'%s'", (i == 0) ? ": " : ", ", argv[i]->arg); +		if (rv < 0) +			abort(); +		offset += rv; +	} + +	return CMD_SUCCESS;  } -static void -test_load(void) +static void test_load(void)  { -  char line[4096]; - -  test_cmds = vector_init(VECTOR_MIN_SIZE); - -  while (fgets(line, sizeof(line), stdin) != NULL) -    { -      if (strlen(line)) -        line[strlen(line) - 1] = '\0'; -      if (line[0] == '#') -        continue; -      vector_set(test_cmds, XSTRDUP(MTYPE_STRVEC, line)); -    } +	char line[4096]; + +	test_cmds = vector_init(VECTOR_MIN_SIZE); + +	while (fgets(line, sizeof(line), stdin) != NULL) { +		if (strlen(line)) +			line[strlen(line) - 1] = '\0'; +		if (line[0] == '#') +			continue; +		vector_set(test_cmds, XSTRDUP(MTYPE_STRVEC, line)); +	}  } -static void -test_init(void) +static void test_init(void)  { -  unsigned int node; -  unsigned int i; -  struct cmd_node *cnode; -  struct cmd_element *cmd; - -  cmd_init(1); - -  install_node (&bgp_node, NULL); -  install_node (&rip_node, NULL); -  install_node (&interface_node, NULL); -  install_node (&rmap_node, NULL); -  install_node (&zebra_node, NULL); -  install_node (&bgp_vpnv4_node, NULL); -  install_node (&bgp_ipv4_node, NULL); -  install_node (&bgp_ipv4m_node, NULL); -  install_node (&bgp_ipv6_node, NULL); -  install_node (&bgp_ipv6m_node, NULL); -  install_node (&ospf_node, NULL); -  install_node (&ripng_node, NULL); -  install_node (&ospf6_node, NULL); -  install_node (&keychain_node, NULL); -  install_node (&keychain_key_node, NULL); -  install_node (&isis_node, NULL); -  install_node (&vty_node, NULL); - -  test_init_cmd(); - -  for (node = 0; node < vector_active(cmdvec); node++) -    if ((cnode = vector_slot(cmdvec, node)) != NULL) -      for (i = 0; i < vector_active(cnode->cmd_vector); i++) -        if ((cmd = vector_slot(cnode->cmd_vector, i)) != NULL) -          { -            cmd->daemon = 0; -            cmd->func = test_callback; -          } -  test_load(); -  vty_init_vtysh(); +	unsigned int node; +	unsigned int i; +	struct cmd_node *cnode; +	struct cmd_element *cmd; + +	cmd_init(1); + +	install_node(&bgp_node, NULL); +	install_node(&rip_node, NULL); +	install_node(&interface_node, NULL); +	install_node(&rmap_node, NULL); +	install_node(&zebra_node, NULL); +	install_node(&bgp_vpnv4_node, NULL); +	install_node(&bgp_ipv4_node, NULL); +	install_node(&bgp_ipv4m_node, NULL); +	install_node(&bgp_ipv6_node, NULL); +	install_node(&bgp_ipv6m_node, NULL); +	install_node(&ospf_node, NULL); +	install_node(&ripng_node, NULL); +	install_node(&ospf6_node, NULL); +	install_node(&keychain_node, NULL); +	install_node(&keychain_key_node, NULL); +	install_node(&isis_node, NULL); +	install_node(&vty_node, NULL); + +	test_init_cmd(); + +	for (node = 0; node < vector_active(cmdvec); node++) +		if ((cnode = vector_slot(cmdvec, node)) != NULL) +			for (i = 0; i < vector_active(cnode->cmd_vector); i++) +				if ((cmd = vector_slot(cnode->cmd_vector, i)) +				    != NULL) { +					cmd->daemon = 0; +					cmd->func = test_callback; +				} +	test_load(); +	vty_init_vtysh();  } -static void -test_terminate(void) +static void test_terminate(void)  { -  unsigned int i; +	unsigned int i; -  vty_terminate(); -  for (i = 0; i < vector_active(test_cmds); i++) -    XFREE(MTYPE_STRVEC, vector_slot(test_cmds, i)); -  vector_free(test_cmds); -  cmd_terminate(); +	vty_terminate(); +	for (i = 0; i < vector_active(test_cmds); i++) +		XFREE(MTYPE_STRVEC, vector_slot(test_cmds, i)); +	vector_free(test_cmds); +	cmd_terminate();  } -static void -test_run(struct prng *prng, struct vty *vty, const char *cmd, unsigned int edit_dist, unsigned int node_index, int verbose) +static void test_run(struct prng *prng, struct vty *vty, const char *cmd, +		     unsigned int edit_dist, unsigned int node_index, +		     int verbose)  { -  const char *test_str; -  vector vline; -  int ret; -  unsigned int i; -  char **completions; -  unsigned int j; -  struct cmd_node *cnode; -  vector descriptions; -  int appended_null; -  int no_match; - -  test_str = prng_fuzz(prng, cmd, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_:. /", edit_dist); -  vline = cmd_make_strvec(test_str); - -  if (vline == NULL) -    return; - -  appended_null = 0; -  for (i = 0; i < vector_active(cmdvec); i++) -    if ((cnode = vector_slot(cmdvec, i)) != NULL) -      { -        if (node_index != (unsigned int)-1 && i != node_index) -          continue; - -        if (appended_null) -          { -            vector_unset(vline, vector_active(vline) - 1); -            appended_null = 0; -          } -        vty->node = cnode->node; -        test_buf[0] = '\0'; -        ret = cmd_execute_command(vline, vty, NULL, 0); -        no_match = (ret == CMD_ERR_NO_MATCH); -        if (verbose || !no_match) -          printf("execute relaxed '%s'@%d: rv==%d%s%s\n", -                 test_str, -                 cnode->node, -                 ret, -                 (test_buf[0] != '\0') ? ", " : "", -                 test_buf); - -        vty->node = cnode->node; -        test_buf[0] = '\0'; -        ret = cmd_execute_command_strict(vline, vty, NULL); -        if (verbose || !no_match) -          printf("execute strict '%s'@%d: rv==%d%s%s\n", -                 test_str, -                 cnode->node, -                 ret, -                 (test_buf[0] != '\0') ? ", " : "", -                 test_buf); - -        if (isspace((int) test_str[strlen(test_str) - 1])) -          { -            vector_set (vline, NULL); -            appended_null = 1; -          } - -        vty->node = cnode->node; -        completions = cmd_complete_command(vline, vty, &ret); -        if (verbose || !no_match) -          printf("complete '%s'@%d: rv==%d\n", -                 test_str, -                 cnode->node, -                 ret); -        if (completions != NULL) -          { -            for (j = 0; completions[j] != NULL; j++) -              { -                printf("  '%s'\n", completions[j]); -                XFREE(MTYPE_TMP, completions[j]); -              } -            XFREE(MTYPE_TMP, completions); -          } - -        vty->node = cnode->node; -        descriptions = cmd_describe_command(vline, vty, &ret); -        if (verbose || !no_match) -          printf("describe '%s'@%d: rv==%d\n", -                 test_str, -                 cnode->node, -                 ret); -        if (descriptions != NULL) -          { -            for (j = 0; j < vector_active(descriptions); j++) -              { -                struct cmd_token *cmd = vector_slot(descriptions, j); -                printf("  '%s' '%s'\n", cmd->text, cmd->desc); -              } -            vector_free(descriptions); -          } -      } -  cmd_free_strvec(vline); +	const char *test_str; +	vector vline; +	int ret; +	unsigned int i; +	char **completions; +	unsigned int j; +	struct cmd_node *cnode; +	vector descriptions; +	int appended_null; +	int no_match; + +	test_str = prng_fuzz( +		prng, cmd, +		"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_:. /", +		edit_dist); +	vline = cmd_make_strvec(test_str); + +	if (vline == NULL) +		return; + +	appended_null = 0; +	for (i = 0; i < vector_active(cmdvec); i++) +		if ((cnode = vector_slot(cmdvec, i)) != NULL) { +			if (node_index != (unsigned int)-1 && i != node_index) +				continue; + +			if (appended_null) { +				vector_unset(vline, vector_active(vline) - 1); +				appended_null = 0; +			} +			vty->node = cnode->node; +			test_buf[0] = '\0'; +			ret = cmd_execute_command(vline, vty, NULL, 0); +			no_match = (ret == CMD_ERR_NO_MATCH); +			if (verbose || !no_match) +				printf("execute relaxed '%s'@%d: rv==%d%s%s\n", +				       test_str, cnode->node, ret, +				       (test_buf[0] != '\0') ? ", " : "", +				       test_buf); + +			vty->node = cnode->node; +			test_buf[0] = '\0'; +			ret = cmd_execute_command_strict(vline, vty, NULL); +			if (verbose || !no_match) +				printf("execute strict '%s'@%d: rv==%d%s%s\n", +				       test_str, cnode->node, ret, +				       (test_buf[0] != '\0') ? ", " : "", +				       test_buf); + +			if (isspace((int)test_str[strlen(test_str) - 1])) { +				vector_set(vline, NULL); +				appended_null = 1; +			} + +			vty->node = cnode->node; +			completions = cmd_complete_command(vline, vty, &ret); +			if (verbose || !no_match) +				printf("complete '%s'@%d: rv==%d\n", test_str, +				       cnode->node, ret); +			if (completions != NULL) { +				for (j = 0; completions[j] != NULL; j++) { +					printf("  '%s'\n", completions[j]); +					XFREE(MTYPE_TMP, completions[j]); +				} +				XFREE(MTYPE_TMP, completions); +			} + +			vty->node = cnode->node; +			descriptions = cmd_describe_command(vline, vty, &ret); +			if (verbose || !no_match) +				printf("describe '%s'@%d: rv==%d\n", test_str, +				       cnode->node, ret); +			if (descriptions != NULL) { +				for (j = 0; j < vector_active(descriptions); +				     j++) { +					struct cmd_token *cmd = +						vector_slot(descriptions, j); +					printf("  '%s' '%s'\n", cmd->text, +					       cmd->desc); +				} +				vector_free(descriptions); +			} +		} +	cmd_free_strvec(vline);  } -int -main(int argc, char **argv) +int main(int argc, char **argv)  { -  int opt; -  struct prng *prng; -  struct vty *vty; -  unsigned int edit_distance; -  unsigned int max_edit_distance; -  unsigned int node_index; -  int verbose; -  unsigned int test_cmd; -  unsigned int iteration; -  unsigned int num_iterations; - -  max_edit_distance = 3; -  node_index = -1; -  verbose = 0; - -  while ((opt = getopt(argc, argv, "e:n:v")) != -1) -    { -      switch (opt) -        { -        case 'e': -          max_edit_distance = atoi(optarg); -          break; -        case 'n': -          node_index = atoi(optarg); -          break; -        case 'v': -          verbose++; -          break; -        default: -          fprintf(stderr, "Usage: %s [-e <edit_dist>] [-n <node_idx>] [-v]\n", argv[0]); -          exit(1); -          break; -        } -    } - -  test_init(); -  prng = prng_new(0); - -  vty = vty_new(); -  vty->type = VTY_TERM; - -  fprintf(stderr, "Progress:\n0/%u", vector_active(test_cmds)); -  for (test_cmd = 0; test_cmd < vector_active(test_cmds); test_cmd++) -    { -      for (edit_distance = 0; -           edit_distance <= max_edit_distance; -           edit_distance++) -        { -          num_iterations = 1 << edit_distance; -          num_iterations *= num_iterations * num_iterations; - -          for (iteration = 0; iteration < num_iterations; iteration++) -            test_run(prng, vty, vector_slot(test_cmds, test_cmd), edit_distance, node_index, verbose); -        } -      fprintf(stderr, "\r%u/%u", test_cmd + 1, vector_active(test_cmds)); -    } -  fprintf(stderr, "\nDone.\n"); - -  vty_close(vty); -  prng_free(prng); -  test_terminate(); -  return 0; +	int opt; +	struct prng *prng; +	struct vty *vty; +	unsigned int edit_distance; +	unsigned int max_edit_distance; +	unsigned int node_index; +	int verbose; +	unsigned int test_cmd; +	unsigned int iteration; +	unsigned int num_iterations; + +	max_edit_distance = 3; +	node_index = -1; +	verbose = 0; + +	while ((opt = getopt(argc, argv, "e:n:v")) != -1) { +		switch (opt) { +		case 'e': +			max_edit_distance = atoi(optarg); +			break; +		case 'n': +			node_index = atoi(optarg); +			break; +		case 'v': +			verbose++; +			break; +		default: +			fprintf(stderr, +				"Usage: %s [-e <edit_dist>] [-n <node_idx>] [-v]\n", +				argv[0]); +			exit(1); +			break; +		} +	} + +	test_init(); +	prng = prng_new(0); + +	vty = vty_new(); +	vty->type = VTY_TERM; + +	fprintf(stderr, "Progress:\n0/%u", vector_active(test_cmds)); +	for (test_cmd = 0; test_cmd < vector_active(test_cmds); test_cmd++) { +		for (edit_distance = 0; edit_distance <= max_edit_distance; +		     edit_distance++) { +			num_iterations = 1 << edit_distance; +			num_iterations *= num_iterations * num_iterations; + +			for (iteration = 0; iteration < num_iterations; +			     iteration++) +				test_run(prng, vty, +					 vector_slot(test_cmds, test_cmd), +					 edit_distance, node_index, verbose); +		} +		fprintf(stderr, "\r%u/%u", test_cmd + 1, +			vector_active(test_cmds)); +	} +	fprintf(stderr, "\nDone.\n"); + +	vty_close(vty); +	prng_free(prng); +	test_terminate(); +	return 0;  } diff --git a/tests/lib/test_buffer.c b/tests/lib/test_buffer.c index 67e4035806..7e124c1f56 100644 --- a/tests/lib/test_buffer.c +++ b/tests/lib/test_buffer.c @@ -1,4 +1,4 @@ -/*  +/*   * Copyright (C) 2004 Paul Jakma   *   * This file is part of Quagga. @@ -16,7 +16,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -26,35 +26,33 @@  struct thread_master *master; -int -main(int argc, char **argv) +int main(int argc, char **argv)  { -  struct buffer *b1, *b2; -  int n; -  char junk[3]; -  char c = 'a'; +	struct buffer *b1, *b2; +	int n; +	char junk[3]; +	char c = 'a'; -  memory_init(); -   -  if ((argc != 2) || (sscanf(argv[1], "%d%1s", &n, junk) != 1)) -    { -      fprintf(stderr, "Usage: %s <number of chars to simulate>\n", *argv); -      return 1; -    } +	memory_init(); -  b1 = buffer_new(0); -  b2 = buffer_new(1024); -   -  while (n-- > 0) -    { -      buffer_put(b1, &c, 1); -      buffer_put(b2, &c, 1); -      if (c++ == 'z') -        c = 'a'; -      buffer_reset(b1); -      buffer_reset(b2); -    } -  buffer_free(b1); -  buffer_free(b2); -  return 0; +	if ((argc != 2) || (sscanf(argv[1], "%d%1s", &n, junk) != 1)) { +		fprintf(stderr, "Usage: %s <number of chars to simulate>\n", +			*argv); +		return 1; +	} + +	b1 = buffer_new(0); +	b2 = buffer_new(1024); + +	while (n-- > 0) { +		buffer_put(b1, &c, 1); +		buffer_put(b2, &c, 1); +		if (c++ == 'z') +			c = 'a'; +		buffer_reset(b1); +		buffer_reset(b2); +	} +	buffer_free(b1); +	buffer_free(b2); +	return 0;  } diff --git a/tests/lib/test_checksum.c b/tests/lib/test_checksum.c index 53ab260e26..6abf5c1f9b 100644 --- a/tests/lib/test_checksum.c +++ b/tests/lib/test_checksum.c @@ -1,4 +1,4 @@ -/*  +/*   * Copyright (C) 2008 Sun Microsystems, Inc.   *   * This file is part of Quagga. @@ -16,7 +16,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -28,14 +28,14 @@  struct thread_master *master;  struct acc_vals { -  int c0; -  int c1; +	int c0; +	int c1;  };  struct csum_vals { -  struct acc_vals a; -  int x;  -  int y; +	struct acc_vals a; +	int x; +	int y;  };  static struct csum_vals ospfd_vals, isisd_vals; @@ -47,26 +47,26 @@ typedef uint16_t testoff_t;  #define MODX                 4102U  /* The final reduction phase. - * This one should be the original ospfd version  + * This one should be the original ospfd version   */ -static u_int16_t  -reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off) +static u_int16_t reduce_ospfd(struct csum_vals *vals, testsz_t len, +			      testoff_t off)  {  #define x vals->x  #define y vals->y  #define c0 vals->a.c0  #define c1 vals->a.c1 -  x = ((len - off - 1) * c0 - c1) % 255; -   -  if (x <= 0) -    x += 255; -  y = 510 - c0 - x; -  if (y > 255) -    y -= 255; +	x = ((len - off - 1) * c0 - c1) % 255; -   /* take care endian issue. */ -   return htons ((x << 8) + y);  +	if (x <= 0) +		x += 255; +	y = 510 - c0 - x; +	if (y > 255) +		y -= 255; + +	/* take care endian issue. */ +	return htons((x << 8) + y);  #undef x  #undef y  #undef c0 @@ -74,23 +74,23 @@ reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off)  }  /* slightly different concatenation */ -static u_int16_t  -reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off) +static u_int16_t reduce_ospfd1(struct csum_vals *vals, testsz_t len, +			       testoff_t off)  {  #define x vals->x  #define y vals->y  #define c0 vals->a.c0  #define c1 vals->a.c1 -  x = ((len - off - 1) * c0 - c1) % 255; -  if (x <= 0) -    x += 255; -  y = 510 - c0 - x; -  if (y > 255) -    y -= 255; +	x = ((len - off - 1) * c0 - c1) % 255; +	if (x <= 0) +		x += 255; +	y = 510 - c0 - x; +	if (y > 255) +		y -= 255; -   /* take care endian issue. */ -   return htons ((x << 8) | (y & 0xff));  +	/* take care endian issue. */ +	return htons((x << 8) | (y & 0xff));  #undef x  #undef y  #undef c0 @@ -98,33 +98,33 @@ reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off)  }  /* original isisd version */ -static u_int16_t  -reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off) +static u_int16_t reduce_isisd(struct csum_vals *vals, testsz_t len, +			      testoff_t off)  {  #define x vals->x  #define y vals->y  #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; +	u_int32_t mul; + +	mul = (len - off) * (c0); +	x = mul - c0 - c1; +	y = c1 - mul - 1; -  if (y > 0) -    y++; -  if (x < 0) -    x--; +	if (y > 0) +		y++; +	if (x < 0) +		x--; -  x %= 255; -  y %= 255; +	x %= 255; +	y %= 255; -  if (x == 0) -    x = 255; -  if (y == 0) -    y = 1; +	if (x == 0) +		x = 255; +	if (y == 0) +		y = 1; -  return htons ((x << 8) | (y & 0xff)); +	return htons((x << 8) | (y & 0xff));  #undef x  #undef y @@ -133,33 +133,33 @@ reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off)  }  /* Is the -1 in y wrong perhaps? */ -static u_int16_t  -reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off) +static u_int16_t reduce_isisd_yfix(struct csum_vals *vals, testsz_t len, +				   testoff_t off)  {  #define x vals->x  #define y vals->y  #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; +	u_int32_t mul; + +	mul = (len - off) * (c0); +	x = mul - c0 - c1; +	y = c1 - mul; -  if (y > 0) -    y++; -  if (x < 0) -    x--; +	if (y > 0) +		y++; +	if (x < 0) +		x--; -  x %= 255; -  y %= 255; +	x %= 255; +	y %= 255; -  if (x == 0) -    x = 255; -  if (y == 0) -    y = 1; +	if (x == 0) +		x = 255; +	if (y == 0) +		y = 1; -  return htons ((x << 8) | (y & 0xff)); +	return htons((x << 8) | (y & 0xff));  #undef x  #undef y @@ -168,33 +168,33 @@ reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off)  }  /* Move the mods yp */ -static u_int16_t  -reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off) +static u_int16_t reduce_isisd_mod(struct csum_vals *vals, testsz_t len, +				  testoff_t off)  {  #define x vals->x  #define y vals->y  #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; +	u_int32_t mul; -  x %= 255; -  y %= 255; +	mul = (len - off) * (c0); +	x = mul - c1 - c0; +	y = c1 - mul - 1; -  if (y > 0) -    y++; -  if (x < 0) -    x--; +	x %= 255; +	y %= 255; -  if (x == 0) -    x = 255; -  if (y == 0) -    y = 1; +	if (y > 0) +		y++; +	if (x < 0) +		x--; -  return htons ((x << 8) | (y & 0xff)); +	if (x == 0) +		x = 255; +	if (y == 0) +		y = 1; + +	return htons((x << 8) | (y & 0xff));  #undef x  #undef y @@ -203,33 +203,33 @@ reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off)  }  /* Move the mods up + fix y */ -static u_int16_t  -reduce_isisd_mody (struct csum_vals *vals, testsz_t len, testoff_t off) +static u_int16_t reduce_isisd_mody(struct csum_vals *vals, testsz_t len, +				   testoff_t off)  {  #define x vals->x  #define y vals->y  #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; +	u_int32_t mul; + +	mul = (len - off) * (c0); +	x = mul - c0 - c1; +	y = c1 - mul; -  x %= 255; -  y %= 255; +	x %= 255; +	y %= 255; -  if (y > 0) -    y++; -  if (x < 0) -    x--; +	if (y > 0) +		y++; +	if (x < 0) +		x--; -  if (x == 0) -    x = 255; -  if (y == 0) -    y = 1; +	if (x == 0) +		x = 255; +	if (y == 0) +		y = 1; -  return htons ((x << 8) | (y & 0xff)); +	return htons((x << 8) | (y & 0xff));  #undef x  #undef y @@ -238,184 +238,175 @@ reduce_isisd_mody (struct csum_vals *vals, testsz_t len, testoff_t off)  }  struct reductions_t { -  const char *name; -  u_int16_t (*f) (struct csum_vals *, testsz_t, testoff_t); +	const char *name; +	u_int16_t (*f)(struct csum_vals *, testsz_t, testoff_t);  } reducts[] = { -  { .name = "ospfd",		.f = reduce_ospfd }, -  { .name = "ospfd-1",		.f = reduce_ospfd1 }, -  { .name = "isisd", 		.f = reduce_isisd }, -  { .name = "isisd-yfix", 	.f = reduce_isisd_yfix }, -  { .name = "isisd-mod", 	.f = reduce_isisd_mod }, -  { .name = "isisd-mody", 	.f = reduce_isisd_mody }, -  { NULL, NULL }, +	{.name = "ospfd", .f = reduce_ospfd}, +	{.name = "ospfd-1", .f = reduce_ospfd1}, +	{.name = "isisd", .f = reduce_isisd}, +	{.name = "isisd-yfix", .f = reduce_isisd_yfix}, +	{.name = "isisd-mod", .f = reduce_isisd_mod}, +	{.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) +static u_int16_t ospfd_checksum(u_char *buffer, testsz_t len, testoff_t off)  { -  u_char *sp, *ep, *p, *q; -  int c0 = 0, c1 = 0; -  int x, y; -  u_int16_t checksum, *csum; - -  csum = (u_int16_t *) (buffer + off); -  *(csum) = 0; -   -  sp = buffer; - -  for (ep = sp + len; sp < ep; sp = q) -    { -      q = sp + MODX; -      if (q > ep) -        q = ep; -      for (p = sp; p < q; p++) -        { -          c0 += *p; -          c1 += c0; -        } -      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)); - -  return (checksum); +	u_char *sp, *ep, *p, *q; +	int c0 = 0, c1 = 0; +	int x, y; +	u_int16_t checksum, *csum; + +	csum = (u_int16_t *)(buffer + off); +	*(csum) = 0; + +	sp = buffer; + +	for (ep = sp + len; sp < ep; sp = q) { +		q = sp + MODX; +		if (q > ep) +			q = ep; +		for (p = sp; p < q; p++) { +			c0 += *p; +			c1 += c0; +		} +		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)); + +	return (checksum);  }  /* the original, broken isisd checksum */ -static u_int16_t -iso_csum_create (u_char * buffer, testsz_t len, testoff_t off) +static u_int16_t iso_csum_create(u_char *buffer, testsz_t len, testoff_t off)  { -  u_int8_t *p; -  int x; -  int y; -  u_int32_t mul; -  u_int32_t c0; -  u_int32_t c1; -  u_int16_t checksum, *csum; -  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); - -      for (i = 0; i < partial_len; i++) -	{ -	  c0 = c0 + *(p++); -	  c1 += c0; +	u_int8_t *p; +	int x; +	int y; +	u_int32_t mul; +	u_int32_t c0; +	u_int32_t c1; +	u_int16_t checksum, *csum; +	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); + +		for (i = 0; i < partial_len; i++) { +			c0 = c0 + *(p++); +			c1 += c0; +		} + +		c0 = c0 % 255; +		c1 = c1 % 255; + +		len -= partial_len;  	} -      c0 = c0 % 255; -      c1 = c1 % 255; - -      len -= partial_len; -    } - -  isisd_vals.a.c0 = c0; -  isisd_vals.a.c1 = c1; -   -  mul = (init_len - off) * c0; - -  x = mul - c1 - c0; -  y = c1 - mul - 1; - -  if (y > 0) -    y++; -  if (x < 0) -    x--; - -  x %= 255; -  y %= 255; - -  if (x == 0) -    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; +	isisd_vals.a.c0 = c0; +	isisd_vals.a.c1 = c1; + +	mul = (init_len - off) * c0; + +	x = mul - c1 - c0; +	y = c1 - mul - 1; + +	if (y > 0) +		y++; +	if (x < 0) +		x--; + +	x %= 255; +	y %= 255; + +	if (x == 0) +		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;  } -static int -verify (u_char * buffer, testsz_t len) +static int verify(u_char *buffer, testsz_t len)  { -  u_int8_t *p; -  u_int32_t c0; -  u_int32_t c1; -  int i, partial_len; -  -  p = buffer; - -  c0 = 0; -  c1 = 0; - -  while (len) -    { -      partial_len = MIN(len, 5803U); - -      for (i = 0; i < partial_len; i++) -        { -          c0 = c0 + *(p++); -          c1 += c0; -        } -      c0 = c0 % 255; -      c1 = c1 % 255; - -      len -= partial_len; -    } - -  if (c0 == 0 && c1 == 0) -    return 0; - -  return 1; +	u_int8_t *p; +	u_int32_t c0; +	u_int32_t c1; +	int i, partial_len; + +	p = buffer; + +	c0 = 0; +	c1 = 0; + +	while (len) { +		partial_len = MIN(len, 5803U); + +		for (i = 0; i < partial_len; i++) { +			c0 = c0 + *(p++); +			c1 += c0; +		} +		c0 = c0 % 255; +		c1 = c1 % 255; + +		len -= partial_len; +	} + +	if (c0 == 0 && c1 == 0) +		return 0; + +	return 1;  } -static int  /* return checksum in low-order 16 bits */ -in_cksum_optimized(void *parg, int nbytes) +static int /* return checksum in low-order 16 bits */ +	in_cksum_optimized(void *parg, int nbytes)  {  	u_short *ptr = parg; -	register long		sum;		/* assumes long == 32 bits */ -	register u_short	answer;		/* assumes u_short == 16 bits */ +	register long sum;       /* assumes long == 32 bits */ +	register u_short answer; /* assumes u_short == 16 bits */  	register int count;  	/*  	 * Our algorithm is simple, using a 32-bit accumulator (sum), @@ -425,126 +416,129 @@ in_cksum_optimized(void *parg, int nbytes)  	sum = 0;  	count = nbytes >> 1; /* div by 2 */ -	for(ptr--; count; --count) -	  sum += *++ptr; +	for (ptr--; count; --count) +		sum += *++ptr; -	if (nbytes & 1) /* Odd */ -	  sum += *(u_char *)(++ptr);   /* one byte only */ +	if (nbytes & 1)			   /* Odd */ +		sum += *(u_char *)(++ptr); /* one byte only */  	/*  	 * Add back carry outs from top 16 bits to low 16 bits.  	 */ -	sum  = (sum >> 16) + (sum & 0xffff);	/* add high-16 to low-16 */ -	sum += (sum >> 16);			/* add carry */ -	answer = ~sum;		/* ones-complement, then truncate to 16 bits */ -	return(answer); +	sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */ +	sum += (sum >> 16);		    /* add carry */ +	answer = ~sum; /* ones-complement, then truncate to 16 bits */ +	return (answer);  }  static int /* return checksum in low-order 16 bits */ -in_cksum_rfc(void *parg, int count) +	in_cksum_rfc(void *parg, int count)  /* from RFC 1071 */  {  	u_short *addr = parg;  	/* Compute Internet Checksum for "count" bytes  	 *         beginning at location "addr".  	 */ -	register long  sum = 0; +	register long sum = 0; -	while (count > 1)  { -	  /*  This is the inner loop */ -	  sum += *addr++; -	  count -= 2; +	while (count > 1) { +		/*  This is the inner loop */ +		sum += *addr++; +		count -= 2;  	}  	/*  Add left-over byte, if any */  	if (count > 0) { -	  sum += *(u_char *)addr; +		sum += *(u_char *)addr;  	}  	/*  Fold 32-bit sum to 16 bits */ -	while (sum>>16) -           sum = (sum & 0xffff) + (sum >> 16); +	while (sum >> 16) +		sum = (sum & 0xffff) + (sum >> 16);  	return ~sum;  } -int -main(int argc, char **argv) +int main(int argc, char **argv)  {  /* 60017 65629 702179 */  #define MAXDATALEN 60017  #define BUFSIZE MAXDATALEN + sizeof(u_int16_t) -  u_char buffer[BUFSIZE]; -  int exercise = 0; +	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, in_csum_res, in_csum_rfc, exercise); - -    ospfd = ospfd_checksum (buffer, exercise + sizeof(u_int16_t), exercise); -    if (verify (buffer, exercise + sizeof(u_int16_t))) -      printf ("verify: ospfd failed\n"); -    isisd = iso_csum_create (buffer, exercise + sizeof(u_int16_t), exercise); -    if (verify (buffer, exercise + sizeof(u_int16_t))) -      printf ("verify: isisd failed\n"); -    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" -              "isisd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n" -              "lib: 0x%04x\n", -              exercise, -              ospfd, ospfd_vals.a.c0, ospfd_vals.a.c1, ospfd_vals.x, ospfd_vals.y, -              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++) {	 -          ospfd = reducts[i].f (&ospfd_vals, -                                exercise + sizeof (u_int16_t), -                                exercise); -          printf ("%20s: x: %02x, y %02x, checksum 0x%04x\n", -                  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", -                buffer[i], -                (i + 1) % 8 ? " " : "\n  "); -      } -      printf ("\n}\n"); -      exit (1); -    } -  } +	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, in_csum_res, in_csum_rfc, exercise); + +		ospfd = ospfd_checksum(buffer, exercise + sizeof(u_int16_t), +				       exercise); +		if (verify(buffer, exercise + sizeof(u_int16_t))) +			printf("verify: ospfd failed\n"); +		isisd = iso_csum_create(buffer, exercise + sizeof(u_int16_t), +					exercise); +		if (verify(buffer, exercise + sizeof(u_int16_t))) +			printf("verify: isisd failed\n"); +		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" +			       "isisd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n" +			       "lib: 0x%04x\n", +			       exercise, ospfd, ospfd_vals.a.c0, +			       ospfd_vals.a.c1, ospfd_vals.x, ospfd_vals.y, +			       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++) { +					ospfd = reducts[i].f( +						&ospfd_vals, +						exercise + sizeof(u_int16_t), +						exercise); +					printf("%20s: x: %02x, y %02x, checksum 0x%04x\n", +					       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", buffer[i], +				       (i + 1) % 8 ? " " : "\n  "); +			} +			printf("\n}\n"); +			exit(1); +		} +	}  } diff --git a/tests/lib/test_heavy.c b/tests/lib/test_heavy.c index 6ba8d9aa6d..07cf602afe 100644 --- a/tests/lib/test_heavy.c +++ b/tests/lib/test_heavy.c @@ -38,46 +38,42 @@  #include "tests.h" -enum -{ -  ITERS_FIRST = 0, -  ITERS_ERR = 100, -  ITERS_LATER = 400, -  ITERS_PRINT = 10, -  ITERS_MAX = 1000, +enum { ITERS_FIRST = 0, +       ITERS_ERR = 100, +       ITERS_LATER = 400, +       ITERS_PRINT = 10, +       ITERS_MAX = 1000,  }; -static void -slow_func (struct vty *vty, const char *str, const int i) +static void 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%s", str, i, x, VTY_NEWLINE);   +	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%s", str, i, x, VTY_NEWLINE);  } -static void -clear_something (struct vty *vty, const char *str) +static void clear_something(struct vty *vty, const char *str)  { -  int i; -   -  /* 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... -   */ -  for (i = ITERS_FIRST; i < ITERS_MAX; i++) -    slow_func (vty, str, i); +	int i; + +	/* 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... +	 */ +	for (i = ITERS_FIRST; i < ITERS_MAX; i++) +		slow_func(vty, str, i);  }  DEFUN (clear_foo, @@ -86,28 +82,25 @@ DEFUN (clear_foo,         "clear command\n"         "arbitrary string\n")  { -  char *str; -  if (!argc) -    { -      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; +	char *str; +	if (!argc) { +		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;  } -static void -slow_vty_init() +static void slow_vty_init()  { -  install_element (VIEW_NODE, &clear_foo_cmd); +	install_element(VIEW_NODE, &clear_foo_cmd);  } -void -test_init() +void test_init()  { -  slow_vty_init(); +	slow_vty_init();  } diff --git a/tests/lib/test_heavy_thread.c b/tests/lib/test_heavy_thread.c index c43fa76c0e..e7af8dccc5 100644 --- a/tests/lib/test_heavy_thread.c +++ b/tests/lib/test_heavy_thread.c @@ -41,65 +41,59 @@  extern struct thread_master *master; -enum -{ -  ITERS_FIRST = 0, -  ITERS_ERR = 100, -  ITERS_LATER = 400, -  ITERS_PRINT = 10, -  ITERS_MAX = 1000, +enum { ITERS_FIRST = 0, +       ITERS_ERR = 100, +       ITERS_LATER = 400, +       ITERS_PRINT = 10, +       ITERS_MAX = 1000,  };  struct work_state { -  struct vty *vty; -  char *str; -  int i; +	struct vty *vty; +	char *str; +	int i;  }; -static void -slow_func (struct vty *vty, const char *str, const int i) +static void 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); +	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);  } -static int -clear_something (struct thread *thread) +static int clear_something(struct thread *thread)  { -  struct work_state *ws = THREAD_ARG(thread); -   -  /* 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... -   */ -  while (ws->i < ITERS_MAX) -    { -      slow_func(ws->vty, ws->str, ws->i); -      ws->i++; -      if (thread_should_yield(thread)) -        { -	  thread_add_background(master, clear_something, ws, 0); -	  return 0; -        } -    } -   -  /* All done! */ -  XFREE (MTYPE_TMP, ws->str); -  XFREE (MTYPE_TMP, ws); -  return 0; +	struct work_state *ws = THREAD_ARG(thread); + +	/* 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... +	 */ +	while (ws->i < ITERS_MAX) { +		slow_func(ws->vty, ws->str, ws->i); +		ws->i++; +		if (thread_should_yield(thread)) { +			thread_add_background(master, clear_something, ws, 0); +			return 0; +		} +	} + +	/* All done! */ +	XFREE(MTYPE_TMP, ws->str); +	XFREE(MTYPE_TMP, ws); +	return 0;  }  DEFUN (clear_foo, @@ -108,40 +102,36 @@ DEFUN (clear_foo,         "clear command\n"         "arbitrary string\n")  { -  char *str; -  struct work_state *ws; - -  if (!argc) -    { -      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; - -  thread_add_background(master, clear_something, ws, 0); - -  return CMD_SUCCESS; +	char *str; +	struct work_state *ws; + +	if (!argc) { +		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; + +	thread_add_background(master, clear_something, ws, 0); + +	return CMD_SUCCESS;  } -void -test_init() +void test_init()  { -  install_element (VIEW_NODE, &clear_foo_cmd); +	install_element(VIEW_NODE, &clear_foo_cmd);  } diff --git a/tests/lib/test_heavy_wq.c b/tests/lib/test_heavy_wq.c index 97371face1..7ccd1131c6 100644 --- a/tests/lib/test_heavy_wq.c +++ b/tests/lib/test_heavy_wq.c @@ -45,97 +45,88 @@ DEFINE_MTYPE_STATIC(TEST_HEAVYWQ, WQ_NODE_STR, "heavy_wq_node->str")  extern struct thread_master *master;  static struct work_queue *heavy_wq; -struct heavy_wq_node -{ -  char *str; -  int i; +struct heavy_wq_node { +	char *str; +	int i;  }; -enum -{ -  ITERS_FIRST = 0, -  ITERS_ERR = 100, -  ITERS_LATER = 400, -  ITERS_PRINT = 10, -  ITERS_MAX = 1000, +enum { ITERS_FIRST = 0, +       ITERS_ERR = 100, +       ITERS_LATER = 400, +       ITERS_PRINT = 10, +       ITERS_MAX = 1000,  }; -static void -heavy_wq_add (struct vty *vty, const char *str, int i) +static void heavy_wq_add(struct vty *vty, const char *str, int i)  { -  struct heavy_wq_node *hn; - -  if ((hn = XCALLOC (MTYPE_WQ_NODE, sizeof(struct heavy_wq_node))) == NULL) -    { -      zlog_err ("%s: unable to allocate hn", __func__); -      return; -    } -   -  hn->i = i; -  if (!(hn->str = XSTRDUP (MTYPE_WQ_NODE_STR, str))) -    { -      zlog_err ("%s: unable to xstrdup", __func__); -      XFREE (MTYPE_WQ_NODE, hn); -      return; -    } -   -  work_queue_add (heavy_wq, hn); -   -  return; +	struct heavy_wq_node *hn; + +	if ((hn = XCALLOC(MTYPE_WQ_NODE, sizeof(struct heavy_wq_node))) +	    == NULL) { +		zlog_err("%s: unable to allocate hn", __func__); +		return; +	} + +	hn->i = i; +	if (!(hn->str = XSTRDUP(MTYPE_WQ_NODE_STR, str))) { +		zlog_err("%s: unable to xstrdup", __func__); +		XFREE(MTYPE_WQ_NODE, hn); +		return; +	} + +	work_queue_add(heavy_wq, hn); + +	return;  } -static void -slow_func_err (struct work_queue *wq, struct work_queue_item *item) +static void slow_func_err(struct work_queue *wq, struct work_queue_item *item)  { -  printf ("%s: running error function\n", __func__); +	printf("%s: running error function\n", __func__);  } -static void -slow_func_del (struct work_queue *wq, void *data) +static void slow_func_del(struct work_queue *wq, void *data)  { -  struct heavy_wq_node *hn = data; -  assert (hn && hn->str); -  printf ("%s: %s\n", __func__, hn->str); -  XFREE (MTYPE_WQ_NODE_STR, hn->str); -  hn->str = NULL;   -  XFREE(MTYPE_WQ_NODE, hn); +	struct heavy_wq_node *hn = data; +	assert(hn && hn->str); +	printf("%s: %s\n", __func__, hn->str); +	XFREE(MTYPE_WQ_NODE_STR, hn->str); +	hn->str = NULL; +	XFREE(MTYPE_WQ_NODE, hn);  } -static wq_item_status -slow_func (struct work_queue *wq, void *data) +static wq_item_status 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); - -  return WQ_SUCCESS; +	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); + +	return WQ_SUCCESS;  } -static void -clear_something (struct vty *vty, const char *str) +static void clear_something(struct vty *vty, const char *str)  { -  int i; -   -  /* 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... -   */ -  for (i = ITERS_FIRST; i < ITERS_MAX; i++) -    heavy_wq_add (vty, str, i); +	int i; + +	/* 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... +	 */ +	for (i = ITERS_FIRST; i < ITERS_MAX; i++) +		heavy_wq_add(vty, str, i);  }  DEFUN (clear_foo, @@ -144,41 +135,37 @@ DEFUN (clear_foo,         "clear command\n"         "arbitrary string\n")  { -  char *str; -  if (!argc) -    { -      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; +	char *str; +	if (!argc) { +		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;  } -static int -heavy_wq_init () +static int heavy_wq_init()  { -  if (! (heavy_wq = work_queue_new (master, "heavy_work_queue"))) -    { -      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; +	if (!(heavy_wq = work_queue_new(master, "heavy_work_queue"))) { +		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() +void test_init()  { -  install_element (VIEW_NODE, &clear_foo_cmd); -  heavy_wq_init(); +	install_element(VIEW_NODE, &clear_foo_cmd); +	heavy_wq_init();  } diff --git a/tests/lib/test_memory.c b/tests/lib/test_memory.c index 6849b9dceb..d1240ab59e 100644 --- a/tests/lib/test_memory.c +++ b/tests/lib/test_memory.c @@ -1,4 +1,4 @@ -/*  +/*   * This file is part of Quagga.   *   * Quagga is free software; you can redistribute it and/or modify it @@ -14,7 +14,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -45,81 +45,77 @@ struct thread_master *master;  #define TIMES 10 -int -main(int argc, char **argv) +int main(int argc, char **argv)  { -  void *a[10]; -  int i; +	void *a[10]; +	int i; -  printf ("malloc x, malloc x, free, malloc x, free free\n\n"); -  /* simple case, test cache */ -  for (i = 0; i < TIMES; i++) -    { -      a[0] = XMALLOC (MTYPE_TEST, 1024); -      memset (a[0], 1, 1024); -      a[1] = XMALLOC (MTYPE_TEST, 1024); -      memset (a[1], 1, 1024); -      XFREE(MTYPE_TEST, a[0]); /* should go to cache */ -      a[0] = XMALLOC (MTYPE_TEST, 1024); /* should be satisfied from cache */ -      XFREE(MTYPE_TEST, a[0]); -      XFREE(MTYPE_TEST, a[1]); -    } -   -  printf ("malloc x, malloc y, free x, malloc y, free free\n\n"); -  /* cache should go invalid, valid, invalid, etc.. */ -  for (i = 0; i < TIMES; i++) -    { -      a[0] = XMALLOC (MTYPE_TEST, 512); -      memset (a[0], 1, 512); -      a[1] = XMALLOC (MTYPE_TEST, 1024); /* invalidate cache */ -      memset (a[1], 1, 1024); -      XFREE(MTYPE_TEST, a[0]); -      a[0] = XMALLOC (MTYPE_TEST, 1024); -      XFREE(MTYPE_TEST, a[0]); -      XFREE(MTYPE_TEST, a[1]); -      /* cache should become valid again on next request */ -    } +	printf("malloc x, malloc x, free, malloc x, free free\n\n"); +	/* simple case, test cache */ +	for (i = 0; i < TIMES; i++) { +		a[0] = XMALLOC(MTYPE_TEST, 1024); +		memset(a[0], 1, 1024); +		a[1] = XMALLOC(MTYPE_TEST, 1024); +		memset(a[1], 1, 1024); +		XFREE(MTYPE_TEST, a[0]); /* should go to cache */ +		a[0] = XMALLOC(MTYPE_TEST, +			       1024); /* should be satisfied from cache */ +		XFREE(MTYPE_TEST, a[0]); +		XFREE(MTYPE_TEST, a[1]); +	} -  printf ("calloc\n\n"); -  /* test calloc */ -  for (i = 0; i < TIMES; i++) -    { -      a[0] = XCALLOC (MTYPE_TEST, 1024); -      memset (a[0], 1, 1024); -      a[1] = XCALLOC (MTYPE_TEST, 512); /* invalidate cache */ -      memset (a[1], 1, 512); -      XFREE(MTYPE_TEST, a[1]); -      XFREE(MTYPE_TEST, a[0]); -      /* alloc == 0, cache can become valid again on next request */ -    } -   -  printf ("calloc and realloc\n\n"); -  /* check calloc + realloc */ -  for (i = 0; i < TIMES; i++) -    { -      printf ("calloc a0 1024\n"); -      a[0] = XCALLOC (MTYPE_TEST, 1024); -      memset (a[0], 1, 1024/2); -       -      printf ("calloc 1 1024\n"); -      a[1] = XCALLOC (MTYPE_TEST, 1024); -      memset (a[1], 1, 1024/2); -       -      printf ("realloc 0 1024\n"); -      a[3] = XREALLOC (MTYPE_TEST, a[0], 2048); /* invalidate cache */ -      if (a[3] != NULL) -        a[0] = a[3]; -      memset (a[0], 1, 1024); -       -      printf ("calloc 2 512\n"); -      a[2] = XCALLOC (MTYPE_TEST, 512); -      memset (a[2], 1, 512); -       -      printf ("free 1 0 2\n"); -      XFREE(MTYPE_TEST, a[1]); -      XFREE(MTYPE_TEST, a[0]); -      XFREE(MTYPE_TEST, a[2]); -      /* alloc == 0, cache valid next request */ -    } -  return 0; +	printf("malloc x, malloc y, free x, malloc y, free free\n\n"); +	/* cache should go invalid, valid, invalid, etc.. */ +	for (i = 0; i < TIMES; i++) { +		a[0] = XMALLOC(MTYPE_TEST, 512); +		memset(a[0], 1, 512); +		a[1] = XMALLOC(MTYPE_TEST, 1024); /* invalidate cache */ +		memset(a[1], 1, 1024); +		XFREE(MTYPE_TEST, a[0]); +		a[0] = XMALLOC(MTYPE_TEST, 1024); +		XFREE(MTYPE_TEST, a[0]); +		XFREE(MTYPE_TEST, a[1]); +		/* cache should become valid again on next request */ +	} + +	printf("calloc\n\n"); +	/* test calloc */ +	for (i = 0; i < TIMES; i++) { +		a[0] = XCALLOC(MTYPE_TEST, 1024); +		memset(a[0], 1, 1024); +		a[1] = XCALLOC(MTYPE_TEST, 512); /* invalidate cache */ +		memset(a[1], 1, 512); +		XFREE(MTYPE_TEST, a[1]); +		XFREE(MTYPE_TEST, a[0]); +		/* alloc == 0, cache can become valid again on next request */ +	} + +	printf("calloc and realloc\n\n"); +	/* check calloc + realloc */ +	for (i = 0; i < TIMES; i++) { +		printf("calloc a0 1024\n"); +		a[0] = XCALLOC(MTYPE_TEST, 1024); +		memset(a[0], 1, 1024 / 2); + +		printf("calloc 1 1024\n"); +		a[1] = XCALLOC(MTYPE_TEST, 1024); +		memset(a[1], 1, 1024 / 2); + +		printf("realloc 0 1024\n"); +		a[3] = XREALLOC(MTYPE_TEST, a[0], 2048); /* invalidate cache */ +		if (a[3] != NULL) +			a[0] = a[3]; +		memset(a[0], 1, 1024); + +		printf("calloc 2 512\n"); +		a[2] = XCALLOC(MTYPE_TEST, 512); +		memset(a[2], 1, 512); + +		printf("free 1 0 2\n"); +		XFREE(MTYPE_TEST, a[1]); +		XFREE(MTYPE_TEST, a[0]); +		XFREE(MTYPE_TEST, a[2]); +		/* alloc == 0, cache valid next request */ +	} +	return 0;  } diff --git a/tests/lib/test_nexthop_iter.c b/tests/lib/test_nexthop_iter.c index 250379329b..8d3e3c509d 100644 --- a/tests/lib/test_nexthop_iter.c +++ b/tests/lib/test_nexthop_iter.c @@ -30,139 +30,119 @@  struct thread_master *master;  static int verbose; -static void -str_append(char **buf, const char *repr) +static void str_append(char **buf, const char *repr)  { -  if (*buf) -    { -      *buf = realloc(*buf, strlen(*buf) + strlen(repr) + 1); -      assert(*buf); -      strncpy((*buf) + strlen(*buf), repr, strlen(repr) + 1); -    } -  else -    { -      *buf = strdup(repr); -      assert(*buf); -    } +	if (*buf) { +		*buf = realloc(*buf, strlen(*buf) + strlen(repr) + 1); +		assert(*buf); +		strncpy((*buf) + strlen(*buf), repr, strlen(repr) + 1); +	} else { +		*buf = strdup(repr); +		assert(*buf); +	}  } -static void -str_appendf(char **buf, const char *format, ...) +static void str_appendf(char **buf, const char *format, ...)  { -  va_list ap; -  int rv; -  char *pbuf; +	va_list ap; +	int rv; +	char *pbuf; -  va_start(ap, format); -  rv = vasprintf(&pbuf, format, ap); -  va_end(ap); -  assert(rv >= 0); +	va_start(ap, format); +	rv = vasprintf(&pbuf, format, ap); +	va_end(ap); +	assert(rv >= 0); -  str_append(buf, pbuf); -  free(pbuf); +	str_append(buf, pbuf); +	free(pbuf);  }  /* This structure contains a nexthop chain   * and its expected representation */ -struct nexthop_chain -{ -  /* Head of the chain */ -  struct nexthop *head; -  /* Last nexthop in top chain */ -  struct nexthop *current_top; -  /* Last nexthop in current recursive chain */ -  struct nexthop *current_recursive; -  /* Expected string representation. */ -  char *repr; +struct nexthop_chain { +	/* Head of the chain */ +	struct nexthop *head; +	/* Last nexthop in top chain */ +	struct nexthop *current_top; +	/* Last nexthop in current recursive chain */ +	struct nexthop *current_recursive; +	/* Expected string representation. */ +	char *repr;  }; -static struct nexthop_chain* -nexthop_chain_new(void) +static struct nexthop_chain *nexthop_chain_new(void)  { -  struct nexthop_chain *rv; +	struct nexthop_chain *rv; -  rv = calloc(sizeof(*rv), 1); -  assert(rv); -  return rv; +	rv = calloc(sizeof(*rv), 1); +	assert(rv); +	return rv;  } -static void -nexthop_chain_add_top(struct nexthop_chain *nc) +static void nexthop_chain_add_top(struct nexthop_chain *nc)  { -  struct nexthop *nh; - -  nh = calloc(sizeof(*nh), 1); -  assert(nh); - -  if (nc->head) -    { -      nc->current_top->next = nh; -      nh->prev = nc->current_top; -      nc->current_top = nh; -    } -  else -    { -      nc->head = nc->current_top = nh; -    } -  nc->current_recursive = NULL; -  str_appendf(&nc->repr, "%p\n", nh); +	struct nexthop *nh; + +	nh = calloc(sizeof(*nh), 1); +	assert(nh); + +	if (nc->head) { +		nc->current_top->next = nh; +		nh->prev = nc->current_top; +		nc->current_top = nh; +	} else { +		nc->head = nc->current_top = nh; +	} +	nc->current_recursive = NULL; +	str_appendf(&nc->repr, "%p\n", nh);  } -static void -nexthop_chain_add_recursive(struct nexthop_chain *nc) +static void nexthop_chain_add_recursive(struct nexthop_chain *nc)  { -  struct nexthop *nh; - -  nh = calloc(sizeof(*nh), 1); -  assert(nh); - -  assert(nc->current_top); -  if (nc->current_recursive) -    { -      nc->current_recursive->next = nh; -      nh->prev = nc->current_recursive; -      nc->current_recursive = nh; -    } -  else -    { -      SET_FLAG(nc->current_top->flags, NEXTHOP_FLAG_RECURSIVE); -      nc->current_top->resolved = nh; -      nc->current_recursive = nh; -    } -  str_appendf(&nc->repr, "  %p\n", nh); +	struct nexthop *nh; + +	nh = calloc(sizeof(*nh), 1); +	assert(nh); + +	assert(nc->current_top); +	if (nc->current_recursive) { +		nc->current_recursive->next = nh; +		nh->prev = nc->current_recursive; +		nc->current_recursive = nh; +	} else { +		SET_FLAG(nc->current_top->flags, NEXTHOP_FLAG_RECURSIVE); +		nc->current_top->resolved = nh; +		nc->current_recursive = nh; +	} +	str_appendf(&nc->repr, "  %p\n", nh);  } -static void -nexthop_chain_clear(struct nexthop_chain *nc) +static void nexthop_chain_clear(struct nexthop_chain *nc)  { -  struct nexthop *tcur, *tnext; - -  for (tcur = nc->head; tcur; tcur = tnext) -    { -      tnext = tcur->next; -      if (CHECK_FLAG(tcur->flags, NEXTHOP_FLAG_RECURSIVE)) -        { -          struct nexthop *rcur, *rnext; -          for (rcur = tcur->resolved; rcur; rcur = rnext) -            { -              rnext = rcur->next; -              free(rcur); -            } -        } -      free(tcur); -    } -  nc->head = nc->current_top = nc->current_recursive = NULL; -  free(nc->repr); -  nc->repr = NULL; +	struct nexthop *tcur, *tnext; + +	for (tcur = nc->head; tcur; tcur = tnext) { +		tnext = tcur->next; +		if (CHECK_FLAG(tcur->flags, NEXTHOP_FLAG_RECURSIVE)) { +			struct nexthop *rcur, *rnext; +			for (rcur = tcur->resolved; rcur; rcur = rnext) { +				rnext = rcur->next; +				free(rcur); +			} +		} +		free(tcur); +	} +	nc->head = nc->current_top = nc->current_recursive = NULL; +	free(nc->repr); +	nc->repr = NULL;  } -static void -nexthop_chain_free(struct nexthop_chain *nc) +static void nexthop_chain_free(struct nexthop_chain *nc)  { -  if (!nc) -    return; -  nexthop_chain_clear(nc); -  free(nc); +	if (!nc) +		return; +	nexthop_chain_clear(nc); +	free(nc);  }  /* This function builds a string representation of @@ -171,25 +151,24 @@ nexthop_chain_free(struct nexthop_chain *nc)   * correctly over the nexthop chain by comparing the   * generated representation with the expected representation.   */ -static void -nexthop_chain_verify_iter(struct nexthop_chain *nc) +static void nexthop_chain_verify_iter(struct nexthop_chain *nc)  { -  struct nexthop *nh, *tnh; -  int recursing; -  char *repr = NULL; - -  for (ALL_NEXTHOPS_RO(nc->head, nh, tnh, recursing)) -    { -      if (recursing) -        str_appendf(&repr, "  %p\n", nh); -      else -        str_appendf(&repr, "%p\n", nh); -    } - -  if (repr && verbose) -    printf("===\n%s", repr); -  assert((!repr && !nc->repr) || (repr && nc->repr && !strcmp(repr, nc->repr))); -  free(repr); +	struct nexthop *nh, *tnh; +	int recursing; +	char *repr = NULL; + +	for (ALL_NEXTHOPS_RO(nc->head, nh, tnh, recursing)) { +		if (recursing) +			str_appendf(&repr, "  %p\n", nh); +		else +			str_appendf(&repr, "%p\n", nh); +	} + +	if (repr && verbose) +		printf("===\n%s", repr); +	assert((!repr && !nc->repr) +	       || (repr && nc->repr && !strcmp(repr, nc->repr))); +	free(repr);  }  /* This test run builds a simple nexthop chain @@ -197,95 +176,91 @@ nexthop_chain_verify_iter(struct nexthop_chain *nc)   * the iterator works correctly in each stage along   * the way.   */ -static void -test_run_first(void) +static void test_run_first(void)  { -  struct nexthop_chain *nc; +	struct nexthop_chain *nc; -  nc = nexthop_chain_new(); -  nexthop_chain_verify_iter(nc); +	nc = nexthop_chain_new(); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_top(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_top(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_top(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_top(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_recursive(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_recursive(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_recursive(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_recursive(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_top(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_top(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_top(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_top(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_top(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_top(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_recursive(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_recursive(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_recursive(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_recursive(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_add_recursive(nc); -  nexthop_chain_verify_iter(nc); +	nexthop_chain_add_recursive(nc); +	nexthop_chain_verify_iter(nc); -  nexthop_chain_free(nc); +	nexthop_chain_free(nc);  }  /* This test run builds numerous random   * nexthop chain configurations and verifies   * that the iterator correctly progresses   * through each. */ -static void -test_run_prng(void) +static void test_run_prng(void)  { -  struct nexthop_chain *nc; -  struct prng *prng; -  int i; - -  nc = nexthop_chain_new(); -  prng = prng_new(0); - -  for (i = 0; i < 1000000; i++) -    { -      switch (prng_rand(prng) % 10) -        { -        case 0: -          nexthop_chain_clear(nc); -          break; -        case 1: -        case 2: -        case 3: -        case 4: -        case 5: -          nexthop_chain_add_top(nc); -          break; -        case 6: -        case 7: -        case 8: -        case 9: -          if (nc->current_top) -            nexthop_chain_add_recursive(nc); -          break; -        } -      nexthop_chain_verify_iter(nc); -    } -  nexthop_chain_free(nc); -  prng_free(prng); +	struct nexthop_chain *nc; +	struct prng *prng; +	int i; + +	nc = nexthop_chain_new(); +	prng = prng_new(0); + +	for (i = 0; i < 1000000; i++) { +		switch (prng_rand(prng) % 10) { +		case 0: +			nexthop_chain_clear(nc); +			break; +		case 1: +		case 2: +		case 3: +		case 4: +		case 5: +			nexthop_chain_add_top(nc); +			break; +		case 6: +		case 7: +		case 8: +		case 9: +			if (nc->current_top) +				nexthop_chain_add_recursive(nc); +			break; +		} +		nexthop_chain_verify_iter(nc); +	} +	nexthop_chain_free(nc); +	prng_free(prng);  }  int main(int argc, char **argv)  { -  if (argc >= 2 && !strcmp("-v", argv[1])) -    verbose = 1; -  test_run_first(); -  printf("Simple test passed.\n"); -  test_run_prng(); -  printf("PRNG test passed.\n"); +	if (argc >= 2 && !strcmp("-v", argv[1])) +		verbose = 1; +	test_run_first(); +	printf("Simple test passed.\n"); +	test_run_prng(); +	printf("PRNG test passed.\n");  } diff --git a/tests/lib/test_privs.c b/tests/lib/test_privs.c index c6ccc28e7a..57b5593ebf 100644 --- a/tests/lib/test_privs.c +++ b/tests/lib/test_privs.c @@ -27,127 +27,115 @@  #include "memory.h"  #include "memory_vty.h" -zebra_capabilities_t _caps_p [] =  -{ -  ZCAP_NET_RAW, -  ZCAP_BIND, -  ZCAP_NET_ADMIN, -  ZCAP_DAC_OVERRIDE, +zebra_capabilities_t _caps_p[] = { +	ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN, ZCAP_DAC_OVERRIDE,  }; -struct zebra_privs_t test_privs = -{ +struct zebra_privs_t test_privs = {  #if defined(FRR_USER) && defined(FRR_GROUP) -  .user = FRR_USER, -  .group = FRR_GROUP, +	.user = FRR_USER, +	.group = FRR_GROUP,  #endif  #if defined(VTY_GROUP) -  .vty_group = VTY_GROUP, +	.vty_group = VTY_GROUP,  #endif -  .caps_p = _caps_p, -  .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]), -  .cap_num_i = 0 -}; +	.caps_p = _caps_p, +	.cap_num_p = sizeof(_caps_p) / sizeof(_caps_p[0]), +	.cap_num_i = 0}; -struct option longopts[] =  -{ -  { "help",        no_argument,       NULL, 'h'}, -  { "user",        required_argument, NULL, 'u'}, -  { "group",       required_argument, NULL, 'g'}, -  { 0 } -}; +struct option longopts[] = {{"help", no_argument, NULL, 'h'}, +			    {"user", required_argument, NULL, 'u'}, +			    {"group", required_argument, NULL, 'g'}, +			    {0}};  /* Help information display. */ -static void -usage (char *progname, int status) +static void usage(char *progname, int status)  { -  if (status != 0) -    fprintf (stderr, "Try `%s --help' for more information.\n", progname); -  else -    {     -      printf ("Usage : %s [OPTION...]\n\ +	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\  -u, --user         User to run as\n\  -g, --group        Group to run as\n\  -h, --help         Display this help and exit\n\  \n\ -Report bugs to %s\n", progname, FRR_BUG_ADDRESS); -    } -  exit (status); +Report bugs to %s\n", +		       progname, FRR_BUG_ADDRESS); +	} +	exit(status);  }  struct thread_master *master;  /* main routine. */ -int -main (int argc, char **argv) +int main(int argc, char **argv)  { -  char *p; -  char *progname; -  struct zprivs_ids_t ids; -   -  /* Set umask before anything for security */ -  umask (0027); - -  /* get program name */ -  progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); - -  while (1)  -    { -      int opt; - -      opt = getopt_long (argc, argv, "hu:g:", longopts, 0); -     -      if (opt == EOF) -	break; - -      switch (opt)  -	{ -	case 0: -	  break; -        case 'u': -          test_privs.user = optarg; -          break; -        case 'g': -          test_privs.group = optarg; -          break; -	case 'h': -	  usage (progname, 0); -	  break; -	default: -	  usage (progname, 1); -	  break; +	char *p; +	char *progname; +	struct zprivs_ids_t ids; + +	/* Set umask before anything for security */ +	umask(0027); + +	/* get program name */ +	progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]); + +	while (1) { +		int opt; + +		opt = getopt_long(argc, argv, "hu:g:", longopts, 0); + +		if (opt == EOF) +			break; + +		switch (opt) { +		case 0: +			break; +		case 'u': +			test_privs.user = optarg; +			break; +		case 'g': +			test_privs.group = optarg; +			break; +		case 'h': +			usage(progname, 0); +			break; +		default: +			usage(progname, 1); +			break; +		}  	} -    } - -  /* Library inits. */ -  memory_init (); -  zprivs_init (&test_privs); - -#define PRIV_STATE() \ -  ((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered") -   -  printf ("%s\n", PRIV_STATE()); -  test_privs.change(ZPRIVS_RAISE); -   -  printf ("%s\n", PRIV_STATE()); -  test_privs.change(ZPRIVS_LOWER); -   -  printf ("%s\n", PRIV_STATE()); -  zprivs_get_ids (&ids);   -   -  /* terminate privileges */ -  zprivs_terminate(&test_privs); -   -  /* but these should continue to work... */ -  printf ("%s\n", PRIV_STATE()); -  test_privs.change(ZPRIVS_RAISE); -   -  printf ("%s\n", PRIV_STATE()); -  test_privs.change(ZPRIVS_LOWER); -   -  printf ("%s\n", PRIV_STATE()); -  zprivs_get_ids (&ids);   -   -  printf ("terminating\n"); -  return 0; + +	/* Library inits. */ +	memory_init(); +	zprivs_init(&test_privs); + +#define PRIV_STATE()                                                           \ +	((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered") + +	printf("%s\n", PRIV_STATE()); +	test_privs.change(ZPRIVS_RAISE); + +	printf("%s\n", PRIV_STATE()); +	test_privs.change(ZPRIVS_LOWER); + +	printf("%s\n", PRIV_STATE()); +	zprivs_get_ids(&ids); + +	/* terminate privileges */ +	zprivs_terminate(&test_privs); + +	/* but these should continue to work... */ +	printf("%s\n", PRIV_STATE()); +	test_privs.change(ZPRIVS_RAISE); + +	printf("%s\n", PRIV_STATE()); +	test_privs.change(ZPRIVS_LOWER); + +	printf("%s\n", PRIV_STATE()); +	zprivs_get_ids(&ids); + +	printf("terminating\n"); +	return 0;  } diff --git a/tests/lib/test_segv.c b/tests/lib/test_segv.c index dfc9d5f482..76e0361c79 100644 --- a/tests/lib/test_segv.c +++ b/tests/lib/test_segv.c @@ -29,32 +29,29 @@  #include "lib/log.h"  #include "lib/memory.h" -struct quagga_signal_t sigs[] =  -{ -}; +struct quagga_signal_t sigs[] = {};  struct thread_master *master; -static int -threadfunc (struct thread *thread) +static int threadfunc(struct thread *thread)  { -  int *null = NULL; -  *null += 1; -  return 0; +	int *null = NULL; +	*null += 1; +	return 0;  } -int -main (void) +int main(void)  { -  master = thread_master_create (); -  signal_init (master, array_size(sigs), sigs); +	master = thread_master_create(); +	signal_init(master, array_size(sigs), sigs); -  openzlog("testsegv", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); -  zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); -  zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG); -  zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED); +	openzlog("testsegv", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, +		 LOG_DAEMON); +	zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); +	zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG); +	zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED); -  thread_execute (master, threadfunc, 0, 0); +	thread_execute(master, threadfunc, 0, 0); -  exit (0); +	exit(0);  } diff --git a/tests/lib/test_sig.c b/tests/lib/test_sig.c index 10bce2303e..f8749c1409 100644 --- a/tests/lib/test_sig.c +++ b/tests/lib/test_sig.c @@ -1,4 +1,4 @@ -/*  +/*   * This file is part of Quagga.   *   * Quagga is free software; you can redistribute it and/or modify it @@ -14,7 +14,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -22,56 +22,50 @@  #include "lib/log.h"  #include "lib/memory.h" -static void -sighup (void) +static void sighup(void)  { -  printf ("processed hup\n"); +	printf("processed hup\n");  } -static void -sigusr1 (void) +static void sigusr1(void)  { -  printf ("processed usr1\n"); +	printf("processed usr1\n");  } -static void -sigusr2 (void) +static void sigusr2(void)  { -  printf ("processed usr2\n"); +	printf("processed usr2\n");  } -struct quagga_signal_t sigs[] =  -{ -  { -    .signal = SIGHUP, -    .handler = &sighup, -  }, -  { -    .signal = SIGUSR1, -    .handler = &sigusr1, -  }, -  { -    .signal = SIGUSR2, -    .handler = &sigusr2, -  } -}; +struct quagga_signal_t sigs[] = {{ +					 .signal = SIGHUP, +					 .handler = &sighup, +				 }, +				 { +					 .signal = SIGUSR1, +					 .handler = &sigusr1, +				 }, +				 { +					 .signal = SIGUSR2, +					 .handler = &sigusr2, +				 }};  struct thread_master *master;  struct thread t; -int -main (void) +int main(void)  { -  master = thread_master_create (); -  signal_init (master, array_size(sigs), sigs); +	master = thread_master_create(); +	signal_init(master, array_size(sigs), sigs); -  openzlog("testsig", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); -  zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); -  zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG); -  zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED); +	openzlog("testsig", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, +		 LOG_DAEMON); +	zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); +	zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG); +	zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED); -  while (thread_fetch (master, &t)) -    thread_call (&t); +	while (thread_fetch(master, &t)) +		thread_call(&t); -  exit (0); +	exit(0);  } diff --git a/tests/lib/test_srcdest_table.c b/tests/lib/test_srcdest_table.c index cfc2deb8d6..6c9c0c7250 100644 --- a/tests/lib/test_srcdest_table.c +++ b/tests/lib/test_srcdest_table.c @@ -48,410 +48,391 @@ struct thread_master *master;  /* This structure is copied from lib/srcdest_table.c to which it is   * private as far as other parts of Quagga are concerned.   */ -struct srcdest_rnode -{ -  /* must be first in structure for casting to/from route_node */ -  ROUTE_NODE_FIELDS; +struct srcdest_rnode { +	/* must be first in structure for casting to/from route_node */ +	ROUTE_NODE_FIELDS; -  struct route_table *src_table; +	struct route_table *src_table;  }; -struct test_state -{ -  struct route_table *table; -  struct hash *log; +struct test_state { +	struct route_table *table; +	struct hash *log;  }; -static char * -format_srcdest(const struct prefix_ipv6 *dst_p, -               const struct prefix_ipv6 *src_p) +static char *format_srcdest(const struct prefix_ipv6 *dst_p, +			    const struct prefix_ipv6 *src_p)  { -  char dst_str[BUFSIZ]; -  char src_str[BUFSIZ]; -  char *rv; -  int ec; - -  prefix2str((const struct prefix*)dst_p, dst_str, sizeof(dst_str)); -  if (src_p && src_p->prefixlen) -    prefix2str((const struct prefix*)src_p, src_str, sizeof(src_str)); -  else -    src_str[0] = '\0'; - -  ec = asprintf(&rv, "%s%s%s", dst_str, -                (src_str[0] != '\0') ? " from " : "", -                src_str); - -  assert(ec > 0); -  return rv; +	char dst_str[BUFSIZ]; +	char src_str[BUFSIZ]; +	char *rv; +	int ec; + +	prefix2str((const struct prefix *)dst_p, dst_str, sizeof(dst_str)); +	if (src_p && src_p->prefixlen) +		prefix2str((const struct prefix *)src_p, src_str, +			   sizeof(src_str)); +	else +		src_str[0] = '\0'; + +	ec = asprintf(&rv, "%s%s%s", dst_str, +		      (src_str[0] != '\0') ? " from " : "", src_str); + +	assert(ec > 0); +	return rv;  }  static unsigned int log_key(void *data)  { -  struct prefix *hash_entry = data; -  struct prefix_ipv6 *dst_p = (struct prefix_ipv6*) &hash_entry[0]; -  struct prefix_ipv6 *src_p = (struct prefix_ipv6*) &hash_entry[1]; -  unsigned int hash = 0; -  unsigned int i; - -  hash = (hash * 33) ^ (unsigned int)dst_p->prefixlen; -  for (i = 0; i < 4; i++) -    hash = (hash * 33) ^ (unsigned int)dst_p->prefix.s6_addr32[i]; - -  hash = (hash * 33) ^ (unsigned int)src_p->prefixlen; -  if (src_p->prefixlen) -    for (i = 0; i < 4; i++) -      hash = (hash * 33) ^ (unsigned int)src_p->prefix.s6_addr32[i]; - -  return hash; +	struct prefix *hash_entry = data; +	struct prefix_ipv6 *dst_p = (struct prefix_ipv6 *)&hash_entry[0]; +	struct prefix_ipv6 *src_p = (struct prefix_ipv6 *)&hash_entry[1]; +	unsigned int hash = 0; +	unsigned int i; + +	hash = (hash * 33) ^ (unsigned int)dst_p->prefixlen; +	for (i = 0; i < 4; i++) +		hash = (hash * 33) ^ (unsigned int)dst_p->prefix.s6_addr32[i]; + +	hash = (hash * 33) ^ (unsigned int)src_p->prefixlen; +	if (src_p->prefixlen) +		for (i = 0; i < 4; i++) +			hash = (hash * 33) +			       ^ (unsigned int)src_p->prefix.s6_addr32[i]; + +	return hash;  } -static int -log_cmp(const void *a, const void *b) +static int log_cmp(const void *a, const void *b)  { -  if (a == NULL && b != NULL) -    return 0; -  if (b == NULL && a != NULL) -    return 0; +	if (a == NULL && b != NULL) +		return 0; +	if (b == NULL && a != NULL) +		return 0; -  return !memcmp(a, b, 2 * sizeof(struct prefix)); +	return !memcmp(a, b, 2 * sizeof(struct prefix));  } -static void -log_free(void *data) +static void log_free(void *data)  { -  XFREE(MTYPE_TMP, data); +	XFREE(MTYPE_TMP, data);  } -static void * -log_alloc(void *data) +static void *log_alloc(void *data)  { -  void *rv = XMALLOC(MTYPE_TMP, 2 * sizeof(struct prefix)); -  memcpy(rv, data, 2 * sizeof(struct prefix)); -  return rv; +	void *rv = XMALLOC(MTYPE_TMP, 2 * sizeof(struct prefix)); +	memcpy(rv, data, 2 * sizeof(struct prefix)); +	return rv;  } -static struct test_state * -test_state_new(void) +static struct test_state *test_state_new(void)  { -  struct test_state *rv; +	struct test_state *rv; -  rv = XCALLOC(MTYPE_TMP, sizeof(*rv)); -  assert(rv); +	rv = XCALLOC(MTYPE_TMP, sizeof(*rv)); +	assert(rv); -  rv->table = srcdest_table_init(); -  assert(rv->table); +	rv->table = srcdest_table_init(); +	assert(rv->table); -  rv->log = hash_create(log_key, log_cmp); -  return rv; +	rv->log = hash_create(log_key, log_cmp); +	return rv;  } -static void -test_state_free(struct test_state *test) +static void test_state_free(struct test_state *test)  { -  route_table_finish(test->table); -  hash_clean(test->log, log_free); -  hash_free(test->log); -  XFREE(MTYPE_TMP, test); +	route_table_finish(test->table); +	hash_clean(test->log, log_free); +	hash_free(test->log); +	XFREE(MTYPE_TMP, test);  } -static void -test_state_add_route(struct test_state *test, -                     struct prefix_ipv6 *dst_p, -                     struct prefix_ipv6 *src_p) +static void test_state_add_route(struct test_state *test, +				 struct prefix_ipv6 *dst_p, +				 struct prefix_ipv6 *src_p)  { -  struct route_node *rn = srcdest_rnode_get( -      test->table, (struct prefix*)dst_p, src_p -  ); -  struct prefix hash_entry[2]; - -  memset(hash_entry, 0, sizeof(hash_entry)); -  memcpy(&hash_entry[0], dst_p, sizeof(*dst_p)); -  memcpy(&hash_entry[1], src_p, sizeof(*src_p)); - -  if (rn->info) { -    route_unlock_node(rn); -    assert(hash_lookup(test->log, hash_entry) != NULL); -    return; -  } else { -    assert(hash_lookup(test->log, hash_entry) == NULL); -  } - -  rn->info = (void*) 0xdeadbeef; -  hash_get(test->log, hash_entry, log_alloc); +	struct route_node *rn = +		srcdest_rnode_get(test->table, (struct prefix *)dst_p, src_p); +	struct prefix hash_entry[2]; + +	memset(hash_entry, 0, sizeof(hash_entry)); +	memcpy(&hash_entry[0], dst_p, sizeof(*dst_p)); +	memcpy(&hash_entry[1], src_p, sizeof(*src_p)); + +	if (rn->info) { +		route_unlock_node(rn); +		assert(hash_lookup(test->log, hash_entry) != NULL); +		return; +	} else { +		assert(hash_lookup(test->log, hash_entry) == NULL); +	} + +	rn->info = (void *)0xdeadbeef; +	hash_get(test->log, hash_entry, log_alloc);  }; -static void -test_state_del_route(struct test_state *test, -		     struct prefix_ipv6 *dst_p, -		     struct prefix_ipv6 *src_p) +static void test_state_del_route(struct test_state *test, +				 struct prefix_ipv6 *dst_p, +				 struct prefix_ipv6 *src_p)  { -  struct route_node *rn = srcdest_rnode_lookup( -      test->table, (struct prefix*)dst_p, src_p -  ); -  struct prefix hash_entry[2]; - -  memset(hash_entry, 0, sizeof(hash_entry)); -  memcpy(&hash_entry[0], dst_p, sizeof(*dst_p)); -  memcpy(&hash_entry[1], src_p, sizeof(*src_p)); - -  if (!rn) { -    assert(!hash_lookup(test->log, hash_entry)); -    return; -  } - -  assert(rn->info == (void*)0xdeadbeef); -  rn->info = NULL; -  route_unlock_node(rn); -  route_unlock_node(rn); - -  struct prefix *hash_entry_intern = hash_release(test->log, hash_entry); -  assert(hash_entry_intern != NULL); -  XFREE(MTYPE_TMP, hash_entry_intern); +	struct route_node *rn = srcdest_rnode_lookup( +		test->table, (struct prefix *)dst_p, src_p); +	struct prefix hash_entry[2]; + +	memset(hash_entry, 0, sizeof(hash_entry)); +	memcpy(&hash_entry[0], dst_p, sizeof(*dst_p)); +	memcpy(&hash_entry[1], src_p, sizeof(*src_p)); + +	if (!rn) { +		assert(!hash_lookup(test->log, hash_entry)); +		return; +	} + +	assert(rn->info == (void *)0xdeadbeef); +	rn->info = NULL; +	route_unlock_node(rn); +	route_unlock_node(rn); + +	struct prefix *hash_entry_intern = hash_release(test->log, hash_entry); +	assert(hash_entry_intern != NULL); +	XFREE(MTYPE_TMP, hash_entry_intern);  } -static void -verify_log(struct hash_backet* backet, void *arg) +static void verify_log(struct hash_backet *backet, void *arg)  { -  struct test_state *test = arg; -  struct prefix *hash_entry = backet->data; -  struct prefix *dst_p = &hash_entry[0]; -  struct prefix_ipv6 *src_p = (struct prefix_ipv6*)&hash_entry[1]; -  struct route_node *rn = srcdest_rnode_lookup(test->table, dst_p, src_p); +	struct test_state *test = arg; +	struct prefix *hash_entry = backet->data; +	struct prefix *dst_p = &hash_entry[0]; +	struct prefix_ipv6 *src_p = (struct prefix_ipv6 *)&hash_entry[1]; +	struct route_node *rn = srcdest_rnode_lookup(test->table, dst_p, src_p); -  assert(rn); -  assert(rn->info == (void*)0xdeadbeef); +	assert(rn); +	assert(rn->info == (void *)0xdeadbeef); -  route_unlock_node(rn); +	route_unlock_node(rn);  } -static void -dump_log(struct hash_backet* backet, void *arg) +static void dump_log(struct hash_backet *backet, void *arg)  { -  struct prefix *hash_entry = backet->data; -  struct prefix_ipv6 *dst_p = (struct prefix_ipv6*)&hash_entry[0]; -  struct prefix_ipv6 *src_p = (struct prefix_ipv6*)&hash_entry[1]; -  char *route_id = format_srcdest(dst_p, src_p); +	struct prefix *hash_entry = backet->data; +	struct prefix_ipv6 *dst_p = (struct prefix_ipv6 *)&hash_entry[0]; +	struct prefix_ipv6 *src_p = (struct prefix_ipv6 *)&hash_entry[1]; +	char *route_id = format_srcdest(dst_p, src_p); -  fprintf(stderr, "  %s\n", route_id); -  free(route_id); +	fprintf(stderr, "  %s\n", route_id); +	free(route_id);  } -static void -test_dump(struct test_state *test) +static void test_dump(struct test_state *test)  { -  fprintf(stderr, "Contents of hash table:\n"); -  hash_iterate(test->log, dump_log, test); -  fprintf(stderr, "\n"); +	fprintf(stderr, "Contents of hash table:\n"); +	hash_iterate(test->log, dump_log, test); +	fprintf(stderr, "\n");  } -static void -test_failed(struct test_state *test, const char *message, -            struct prefix_ipv6 *dst_p, struct prefix_ipv6 *src_p) +static void test_failed(struct test_state *test, const char *message, +			struct prefix_ipv6 *dst_p, struct prefix_ipv6 *src_p)  { -  char *route_id = format_srcdest(dst_p, src_p); +	char *route_id = format_srcdest(dst_p, src_p); -  fprintf(stderr, "Test failed. Error: %s\n", message); -  fprintf(stderr, "Route in question: %s\n", route_id); -  free(route_id); +	fprintf(stderr, "Test failed. Error: %s\n", message); +	fprintf(stderr, "Route in question: %s\n", route_id); +	free(route_id); -  test_dump(test); -  assert(3 == 4); +	test_dump(test); +	assert(3 == 4);  } -static void -test_state_verify(struct test_state *test) +static void test_state_verify(struct test_state *test)  { -  struct route_node *rn; -  struct prefix hash_entry[2]; - -  memset(hash_entry, 0, sizeof(hash_entry)); - -  /* Verify that there are no elements in the table which have never -   * been added */ -  for (rn = route_top(test->table); rn; rn = srcdest_route_next(rn)) -    { -      struct prefix_ipv6 *dst_p, *src_p; - -      /* While we are iterating, we hold a lock on the current route_node, -       * so all the lock counts we check for take that into account; in idle -       * state all the numbers will be exactly one less. -       * -       * Also this makes quite some assumptions based on the current -       * implementation details of route_table and srcdest_table - another -       * valid implementation might trigger assertions here. -       */ - -      if (rnode_is_dstnode(rn)) -        { -          struct srcdest_rnode *srn = (struct srcdest_rnode *)rn; -          unsigned int expected_lock = 1; /* We are in the loop */ - -          if (rn->info != NULL) /* The route node is not internal */ -            expected_lock++; -          if (srn->src_table != NULL) /* There's a source table associated with rn */ -            expected_lock++; - -          if (rn->lock != expected_lock) -            test_failed(test, "Dest rnode lock count doesn't match expected count!", -                        (struct prefix_ipv6*)&rn->p, NULL); -        } -      else -        { -          unsigned int expected_lock = 1; /* We are in the loop */ - -          if (rn->info != NULL) /* The route node is not internal */ -            expected_lock++; - -          if (rn->lock != expected_lock) -            { -              struct prefix_ipv6 *dst_p, *src_p; -              srcdest_rnode_prefixes(rn, (struct prefix**)&dst_p, -                                         (struct prefix**)&src_p); - -              test_failed(test, "Src rnode lock count doesn't match expected count!", -                          dst_p, src_p); -            } -        } - -      if (!rn->info) -        continue; - -      assert(rn->info == (void*)0xdeadbeef); - -      srcdest_rnode_prefixes(rn, (struct prefix**)&dst_p, (struct prefix**)&src_p); -      memcpy(&hash_entry[0], dst_p, sizeof(*dst_p)); -      if (src_p) -        memcpy(&hash_entry[1], src_p, sizeof(*src_p)); -      else -        memset(&hash_entry[1], 0, sizeof(hash_entry[1])); - -      if (hash_lookup(test->log, hash_entry) == NULL) -        test_failed(test, "Route is missing in hash", dst_p, src_p); -    } - -  /* Verify that all added elements are still in the table */ -  hash_iterate(test->log, verify_log, test); +	struct route_node *rn; +	struct prefix hash_entry[2]; + +	memset(hash_entry, 0, sizeof(hash_entry)); + +	/* Verify that there are no elements in the table which have never +	 * been added */ +	for (rn = route_top(test->table); rn; rn = srcdest_route_next(rn)) { +		struct prefix_ipv6 *dst_p, *src_p; + +		/* While we are iterating, we hold a lock on the current +		 * route_node, +		 * so all the lock counts we check for take that into account; +		 * in idle +		 * state all the numbers will be exactly one less. +		 * +		 * Also this makes quite some assumptions based on the current +		 * implementation details of route_table and srcdest_table - +		 * another +		 * valid implementation might trigger assertions here. +		 */ + +		if (rnode_is_dstnode(rn)) { +			struct srcdest_rnode *srn = (struct srcdest_rnode *)rn; +			unsigned int expected_lock = 1; /* We are in the loop */ + +			if (rn->info +			    != NULL) /* The route node is not internal */ +				expected_lock++; +			if (srn->src_table != NULL) /* There's a source table +						       associated with rn */ +				expected_lock++; + +			if (rn->lock != expected_lock) +				test_failed( +					test, +					"Dest rnode lock count doesn't match expected count!", +					(struct prefix_ipv6 *)&rn->p, NULL); +		} else { +			unsigned int expected_lock = 1; /* We are in the loop */ + +			if (rn->info +			    != NULL) /* The route node is not internal */ +				expected_lock++; + +			if (rn->lock != expected_lock) { +				struct prefix_ipv6 *dst_p, *src_p; +				srcdest_rnode_prefixes( +					rn, (struct prefix **)&dst_p, +					(struct prefix **)&src_p); + +				test_failed( +					test, +					"Src rnode lock count doesn't match expected count!", +					dst_p, src_p); +			} +		} + +		if (!rn->info) +			continue; + +		assert(rn->info == (void *)0xdeadbeef); + +		srcdest_rnode_prefixes(rn, (struct prefix **)&dst_p, +				       (struct prefix **)&src_p); +		memcpy(&hash_entry[0], dst_p, sizeof(*dst_p)); +		if (src_p) +			memcpy(&hash_entry[1], src_p, sizeof(*src_p)); +		else +			memset(&hash_entry[1], 0, sizeof(hash_entry[1])); + +		if (hash_lookup(test->log, hash_entry) == NULL) +			test_failed(test, "Route is missing in hash", dst_p, +				    src_p); +	} + +	/* Verify that all added elements are still in the table */ +	hash_iterate(test->log, verify_log, test);  } -static void -get_rand_prefix(struct prng *prng, struct prefix_ipv6 *p) +static void get_rand_prefix(struct prng *prng, struct prefix_ipv6 *p)  { -  int i; +	int i; -  memset(p, 0, sizeof(*p)); +	memset(p, 0, sizeof(*p)); -  for (i = 0; i < 4; i++) -    p->prefix.s6_addr32[i] = prng_rand(prng); -  p->prefixlen = prng_rand(prng) % 129; -  p->family = AF_INET6; +	for (i = 0; i < 4; i++) +		p->prefix.s6_addr32[i] = prng_rand(prng); +	p->prefixlen = prng_rand(prng) % 129; +	p->family = AF_INET6; -  apply_mask((struct prefix*)p); +	apply_mask((struct prefix *)p);  } -static void -get_rand_prefix_pair(struct prng *prng, struct prefix_ipv6 *dst_p, -                     struct prefix_ipv6 *src_p) +static void get_rand_prefix_pair(struct prng *prng, struct prefix_ipv6 *dst_p, +				 struct prefix_ipv6 *src_p)  { -  get_rand_prefix(prng, dst_p); -  if ((prng_rand(prng) % 4) == 0) -    { -      get_rand_prefix(prng, src_p); -      if (src_p->prefixlen) -        return; -    } - -  memset(src_p, 0, sizeof(*src_p)); +	get_rand_prefix(prng, dst_p); +	if ((prng_rand(prng) % 4) == 0) { +		get_rand_prefix(prng, src_p); +		if (src_p->prefixlen) +			return; +	} + +	memset(src_p, 0, sizeof(*src_p));  } -static void -test_state_add_rand_route(struct test_state *test, -                          struct prng *prng) +static void test_state_add_rand_route(struct test_state *test, +				      struct prng *prng)  { -  struct prefix_ipv6 dst_p, src_p; +	struct prefix_ipv6 dst_p, src_p; -  get_rand_prefix_pair(prng, &dst_p, &src_p); -  test_state_add_route(test, &dst_p, &src_p); +	get_rand_prefix_pair(prng, &dst_p, &src_p); +	test_state_add_route(test, &dst_p, &src_p);  } -static void -test_state_del_rand_route(struct test_state *test, -                          struct prng *prng) +static void test_state_del_rand_route(struct test_state *test, +				      struct prng *prng)  { -  struct prefix_ipv6 dst_p, src_p; +	struct prefix_ipv6 dst_p, src_p; -  get_rand_prefix_pair(prng, &dst_p, &src_p); -  test_state_del_route(test, &dst_p, &src_p); +	get_rand_prefix_pair(prng, &dst_p, &src_p); +	test_state_del_route(test, &dst_p, &src_p);  } -static void -test_state_del_one_route(struct test_state *test, -		         struct prng *prng) +static void test_state_del_one_route(struct test_state *test, struct prng *prng)  { -  unsigned int which_route = prng_rand(prng) % test->log->count; -  struct route_node *rn; -  struct prefix *dst_p, *src_p; -  struct prefix_ipv6 dst6_p, src6_p; - -  for (rn = route_top(test->table); rn; rn = srcdest_route_next(rn)) -    { -      if (!rn->info) -        continue; -      if (!which_route) { -        route_unlock_node(rn); -        break; -      } -      which_route--; -    } - -  assert(rn); -  srcdest_rnode_prefixes(rn, &dst_p, &src_p); -  memcpy(&dst6_p, dst_p, sizeof(dst6_p)); -  if (src_p) -    memcpy(&src6_p, src_p, sizeof(src6_p)); -  else -    memset(&src6_p, 0, sizeof(src6_p)); - -  test_state_del_route(test, &dst6_p, &src6_p); +	unsigned int which_route = prng_rand(prng) % test->log->count; +	struct route_node *rn; +	struct prefix *dst_p, *src_p; +	struct prefix_ipv6 dst6_p, src6_p; + +	for (rn = route_top(test->table); rn; rn = srcdest_route_next(rn)) { +		if (!rn->info) +			continue; +		if (!which_route) { +			route_unlock_node(rn); +			break; +		} +		which_route--; +	} + +	assert(rn); +	srcdest_rnode_prefixes(rn, &dst_p, &src_p); +	memcpy(&dst6_p, dst_p, sizeof(dst6_p)); +	if (src_p) +		memcpy(&src6_p, src_p, sizeof(src6_p)); +	else +		memset(&src6_p, 0, sizeof(src6_p)); + +	test_state_del_route(test, &dst6_p, &src6_p);  } -static void -run_prng_test(void) +static void run_prng_test(void)  { -  struct test_state *test = test_state_new(); -  struct prng *prng = prng_new(0); -  size_t i; - -  for (i = 0; i < 1000; i++) -    { -      switch (prng_rand(prng) % 10) -        { -        case 0: -        case 1: -        case 2: -        case 3: -        case 4: -          test_state_add_rand_route(test, prng); -          break; -        case 5: -        case 6: -        case 7: -          test_state_del_one_route(test, prng); -          break; -        case 8: -        case 9: -          test_state_del_rand_route(test, prng); -          break; -        } -      test_state_verify(test); -    } - -  prng_free(prng); -  test_state_free(test); +	struct test_state *test = test_state_new(); +	struct prng *prng = prng_new(0); +	size_t i; + +	for (i = 0; i < 1000; i++) { +		switch (prng_rand(prng) % 10) { +		case 0: +		case 1: +		case 2: +		case 3: +		case 4: +			test_state_add_rand_route(test, prng); +			break; +		case 5: +		case 6: +		case 7: +			test_state_del_one_route(test, prng); +			break; +		case 8: +		case 9: +			test_state_del_rand_route(test, prng); +			break; +		} +		test_state_verify(test); +	} + +	prng_free(prng); +	test_state_free(test);  }  int main(int argc, char *argv[])  { -  run_prng_test(); -  printf("PRNG Test successful.\n"); -  return 0; +	run_prng_test(); +	printf("PRNG Test successful.\n"); +	return 0;  } diff --git a/tests/lib/test_stream.c b/tests/lib/test_stream.c index 3ac45eb203..ad7615696c 100644 --- a/tests/lib/test_stream.c +++ b/tests/lib/test_stream.c @@ -1,5 +1,5 @@  /* Simple stream test. - *  + *   * Copyright (C) 2006 Sun Microsystems, Inc.   *   * This file is part of Quagga. @@ -17,7 +17,7 @@   * You should have received a copy of the GNU General Public License   * along with Quagga; see the file COPYING.  If not, write to the Free   * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA.   + * 02111-1307, USA.   */  #include <zebra.h> @@ -27,50 +27,45 @@  static unsigned long long ham = 0xdeadbeefdeadbeef;  struct thread_master *master; -static void -print_stream (struct stream *s) +static void print_stream(struct stream *s)  { -  size_t getp = stream_get_getp (s); -   -  printf ("endp: %zu, readable: %zu, writeable: %zu\n", -          stream_get_endp (s), -          STREAM_READABLE (s), -          STREAM_WRITEABLE (s)); -   -  while (STREAM_READABLE (s)) -    { -      printf ("0x%x ", *stream_pnt (s)); -      stream_forward_getp (s, 1); -    } -   -  printf ("\n"); -   -  /* put getp back to where it was */ -  stream_set_getp (s, getp); +	size_t getp = stream_get_getp(s); + +	printf("endp: %zu, readable: %zu, writeable: %zu\n", stream_get_endp(s), +	       STREAM_READABLE(s), STREAM_WRITEABLE(s)); + +	while (STREAM_READABLE(s)) { +		printf("0x%x ", *stream_pnt(s)); +		stream_forward_getp(s, 1); +	} + +	printf("\n"); + +	/* put getp back to where it was */ +	stream_set_getp(s, getp);  } -int -main (void) +int main(void)  { -  struct stream *s; -   -  s = stream_new (1024); -   -  stream_putc (s, ham); -  stream_putw (s, ham); -  stream_putl (s, ham); -  stream_putq (s, ham); -   -  print_stream (s); -   -  stream_resize (s, stream_get_endp (s)); -   -  print_stream (s); -   -  printf ("c: 0x%hhx\n", stream_getc (s)); -  printf ("w: 0x%hx\n", stream_getw (s)); -  printf ("l: 0x%x\n", stream_getl (s)); -  printf ("q: 0x%" PRIx64 "\n", stream_getq (s)); -   -  return 0; +	struct stream *s; + +	s = stream_new(1024); + +	stream_putc(s, ham); +	stream_putw(s, ham); +	stream_putl(s, ham); +	stream_putq(s, ham); + +	print_stream(s); + +	stream_resize(s, stream_get_endp(s)); + +	print_stream(s); + +	printf("c: 0x%hhx\n", stream_getc(s)); +	printf("w: 0x%hx\n", stream_getw(s)); +	printf("l: 0x%x\n", stream_getl(s)); +	printf("q: 0x%" PRIx64 "\n", stream_getq(s)); + +	return 0;  } diff --git a/tests/lib/test_table.c b/tests/lib/test_table.c index 4042e1aaa2..b049542eb8 100644 --- a/tests/lib/test_table.c +++ b/tests/lib/test_table.c @@ -30,14 +30,13 @@   *   * Information that is kept for each node in the radix tree.   */ -typedef struct test_node_t_ -{ +typedef struct test_node_t_ { -  /* -   * Human readable representation of the string. Allocated using -   * malloc()/dup(). -   */ -  char *prefix_str; +	/* +	 * Human readable representation of the string. Allocated using +	 * malloc()/dup(). +	 */ +	char *prefix_str;  } test_node_t;  struct thread_master *master; @@ -47,32 +46,29 @@ struct thread_master *master;   *   * Add the given prefix (passed in as a string) to the given table.   */ -static void -add_node (struct route_table *table, const char *prefix_str) +static void add_node(struct route_table *table, const char *prefix_str)  { -  struct prefix_ipv4 p; -  test_node_t *node; -  struct route_node *rn; - -  assert (prefix_str); - -  if (str2prefix_ipv4 (prefix_str, &p) <= 0) -    { -      assert (0); -    } - -  rn = route_node_get (table, (struct prefix *) &p); -  if (rn->info) -    { -      assert (0); -      return; -    } - -  node = malloc (sizeof (test_node_t)); -  assert (node); -  node->prefix_str = strdup (prefix_str); -  assert (node->prefix_str); -  rn->info = node; +	struct prefix_ipv4 p; +	test_node_t *node; +	struct route_node *rn; + +	assert(prefix_str); + +	if (str2prefix_ipv4(prefix_str, &p) <= 0) { +		assert(0); +	} + +	rn = route_node_get(table, (struct prefix *)&p); +	if (rn->info) { +		assert(0); +		return; +	} + +	node = malloc(sizeof(test_node_t)); +	assert(node); +	node->prefix_str = strdup(prefix_str); +	assert(node->prefix_str); +	rn->info = node;  }  /* @@ -83,22 +79,20 @@ add_node (struct route_table *table, const char *prefix_str)   * The arguments must be prefixes in string format, with a NULL as the   * last argument.   */ -static void -add_nodes (struct route_table *table, ...) +static void add_nodes(struct route_table *table, ...)  { -  va_list arglist; -  char *prefix; +	va_list arglist; +	char *prefix; -  va_start (arglist, table); +	va_start(arglist, table); -  prefix = va_arg (arglist, char *); -  while (prefix) -    { -      add_node (table, prefix); -      prefix = va_arg (arglist, char *); -    } +	prefix = va_arg(arglist, char *); +	while (prefix) { +		add_node(table, prefix); +		prefix = va_arg(arglist, char *); +	} -  va_end (arglist); +	va_end(arglist);  }  /* @@ -108,35 +102,31 @@ add_nodes (struct route_table *table, ...)   *   * @see print_table   */ -static void -print_subtree (struct route_node *rn, const char *legend, int indent_level) +static void print_subtree(struct route_node *rn, const char *legend, +			  int indent_level)  { -  char buf[PREFIX2STR_BUFFER]; -  int i; - -  /* -   * Print this node first. -   */ -  for (i = 0; i < indent_level; i++) -    { -      printf ("  "); -    } - -  prefix2str (&rn->p, buf, sizeof (buf)); -  printf ("%s: %s", legend, buf); -  if (!rn->info) -    { -      printf (" (internal)"); -    } -  printf ("\n"); -  if (rn->l_left) -    { -      print_subtree (rn->l_left, "Left", indent_level + 1); -    } -  if (rn->l_right) -    { -      print_subtree (rn->l_right, "Right", indent_level + 1); -    } +	char buf[PREFIX2STR_BUFFER]; +	int i; + +	/* +	 * Print this node first. +	 */ +	for (i = 0; i < indent_level; i++) { +		printf("  "); +	} + +	prefix2str(&rn->p, buf, sizeof(buf)); +	printf("%s: %s", legend, buf); +	if (!rn->info) { +		printf(" (internal)"); +	} +	printf("\n"); +	if (rn->l_left) { +		print_subtree(rn->l_left, "Left", indent_level + 1); +	} +	if (rn->l_right) { +		print_subtree(rn->l_right, "Right", indent_level + 1); +	}  }  /* @@ -144,20 +134,18 @@ print_subtree (struct route_node *rn, const char *legend, int indent_level)   *   * Function that prints out the internal structure of a route table.   */ -static void -print_table (struct route_table *table) +static void print_table(struct route_table *table)  { -  struct route_node *rn; +	struct route_node *rn; -  rn = table->top; +	rn = table->top; -  if (!rn) -    { -      printf ("<Empty Table>\n"); -      return; -    } +	if (!rn) { +		printf("<Empty Table>\n"); +		return; +	} -  print_subtree (rn, "Top", 0); +	print_subtree(rn, "Top", 0);  }  /* @@ -165,31 +153,28 @@ print_table (struct route_table *table)   *   * Remove all nodes from the given table.   */ -static void -clear_table (struct route_table *table) +static void clear_table(struct route_table *table)  { -  route_table_iter_t iter; -  struct route_node *rn; -  test_node_t *node; - -  route_table_iter_init (&iter, table); - -  while ((rn = route_table_iter_next (&iter))) -    { -      node = rn->info; -      if (!node) -	{ -	  continue; +	route_table_iter_t iter; +	struct route_node *rn; +	test_node_t *node; + +	route_table_iter_init(&iter, table); + +	while ((rn = route_table_iter_next(&iter))) { +		node = rn->info; +		if (!node) { +			continue; +		} +		rn->info = NULL; +		route_unlock_node(rn); +		free(node->prefix_str); +		free(node);  	} -      rn->info = NULL; -      route_unlock_node (rn); -      free (node->prefix_str); -      free (node); -    } -  route_table_iter_cleanup (&iter); +	route_table_iter_cleanup(&iter); -  assert (table->top == NULL); +	assert(table->top == NULL);  }  /* @@ -199,29 +184,26 @@ clear_table (struct route_table *table)   * target_pfx is the expected one. Note that target_pfx may not be   * present in the tree.   */ -static void -verify_next_by_iterating (struct route_table *table, -			  struct prefix *target_pfx, struct prefix *next_pfx) +static void verify_next_by_iterating(struct route_table *table, +				     struct prefix *target_pfx, +				     struct prefix *next_pfx)  { -  route_table_iter_t iter; -  struct route_node *rn; - -  route_table_iter_init (&iter, table); -  while ((rn = route_table_iter_next (&iter))) -    { -      if (route_table_prefix_iter_cmp (&rn->p, target_pfx) > 0) -	{ -	  assert (!prefix_cmp (&rn->p, next_pfx)); -	  break; +	route_table_iter_t iter; +	struct route_node *rn; + +	route_table_iter_init(&iter, table); +	while ((rn = route_table_iter_next(&iter))) { +		if (route_table_prefix_iter_cmp(&rn->p, target_pfx) > 0) { +			assert(!prefix_cmp(&rn->p, next_pfx)); +			break; +		}  	} -    } -  if (!rn) -    { -      assert (!next_pfx); -    } +	if (!rn) { +		assert(!next_pfx); +	} -  route_table_iter_cleanup (&iter); +	route_table_iter_cleanup(&iter);  }  /* @@ -230,200 +212,190 @@ verify_next_by_iterating (struct route_table *table,   * Verifies that route_table_get_next() returns the expected result   * (result) for the prefix string 'target'.   */ -static void -verify_next (struct route_table *table, const char *target, const char *next) +static void verify_next(struct route_table *table, const char *target, +			const char *next)  { -  struct prefix_ipv4 target_pfx, next_pfx; -  struct route_node *rn; -  char result_buf[PREFIX2STR_BUFFER]; - -  if (str2prefix_ipv4 (target, &target_pfx) <= 0) -    { -      assert (0); -    } - -  rn = route_table_get_next (table, (struct prefix *) &target_pfx); -  if (rn) -    { -      prefix2str (&rn->p, result_buf, sizeof (result_buf)); -    } -  else -    { -      snprintf (result_buf, sizeof (result_buf), "(Null)"); -    } - -  printf ("\n"); -  print_table (table); -  printf ("Verifying successor of %s. Expected: %s, Result: %s\n", target, -	  next ? next : "(Null)", result_buf); - -  if (!rn) -    { -      assert (!next); -      verify_next_by_iterating (table, (struct prefix *) &target_pfx, NULL); -      return; -    } - -  assert (next); - -  if (str2prefix_ipv4 (next, &next_pfx) <= 0) -    { -      assert (0); -    } - -  if (prefix_cmp (&rn->p, (struct prefix *) &next_pfx)) -    { -      assert (0); -    } -  route_unlock_node (rn); - -  verify_next_by_iterating (table, (struct prefix *) &target_pfx, -			    (struct prefix *) &next_pfx); +	struct prefix_ipv4 target_pfx, next_pfx; +	struct route_node *rn; +	char result_buf[PREFIX2STR_BUFFER]; + +	if (str2prefix_ipv4(target, &target_pfx) <= 0) { +		assert(0); +	} + +	rn = route_table_get_next(table, (struct prefix *)&target_pfx); +	if (rn) { +		prefix2str(&rn->p, result_buf, sizeof(result_buf)); +	} else { +		snprintf(result_buf, sizeof(result_buf), "(Null)"); +	} + +	printf("\n"); +	print_table(table); +	printf("Verifying successor of %s. Expected: %s, Result: %s\n", target, +	       next ? next : "(Null)", result_buf); + +	if (!rn) { +		assert(!next); +		verify_next_by_iterating(table, (struct prefix *)&target_pfx, +					 NULL); +		return; +	} + +	assert(next); + +	if (str2prefix_ipv4(next, &next_pfx) <= 0) { +		assert(0); +	} + +	if (prefix_cmp(&rn->p, (struct prefix *)&next_pfx)) { +		assert(0); +	} +	route_unlock_node(rn); + +	verify_next_by_iterating(table, (struct prefix *)&target_pfx, +				 (struct prefix *)&next_pfx);  }  /*   * test_get_next   */ -static void -test_get_next (void) +static void test_get_next(void)  { -  struct route_table *table; - -  printf ("\n\nTesting route_table_get_next()\n"); -  table = route_table_init (); - -  /* -   * Target exists in tree, but has no successor. -   */ -  add_nodes (table, "1.0.1.0/24", NULL); -  verify_next (table, "1.0.1.0/24", NULL); -  clear_table (table); - -  /* -   * Target exists in tree, and there is a node in its left subtree. -   */ -  add_nodes (table, "1.0.1.0/24", "1.0.1.0/25", NULL); -  verify_next (table, "1.0.1.0/24", "1.0.1.0/25"); -  clear_table (table); - -  /* -   * Target exists in tree, and there is a node in its right subtree. -   */ -  add_nodes (table, "1.0.1.0/24", "1.0.1.128/25", NULL); -  verify_next (table, "1.0.1.0/24", "1.0.1.128/25"); -  clear_table (table); - -  /* -   * Target exists in the tree, next node is outside subtree. -   */ -  add_nodes (table, "1.0.1.0/24", "1.1.0.0/16", NULL); -  verify_next (table, "1.0.1.0/24", "1.1.0.0/16"); -  clear_table (table); - -  /* -   * The target node does not exist in the tree for all the test cases -   * below this point. -   */ - -  /* -   * There is no successor in the tree. -   */ -  add_nodes (table, "1.0.0.0/16", NULL); -  verify_next (table, "1.0.1.0/24", NULL); -  clear_table (table); - -  /* -   * There exists a node that would be in the target's left subtree. -   */ -  add_nodes (table, "1.0.0.0/16", "1.0.1.0/25", NULL); -  verify_next (table, "1.0.1.0/24", "1.0.1.0/25"); -  clear_table (table); - -  /* -   * There exists a node would be in the target's right subtree. -   */ -  add_nodes (table, "1.0.0.0/16", "1.0.1.128/25", NULL); -  verify_next (table, "1.0.1.0/24", "1.0.1.128/25"); -  clear_table (table); - -  /* -   * A search for the target reaches a node where there are no child -   * nodes in the direction of the target (left), but the node has a -   * right child. -   */ -  add_nodes (table, "1.0.0.0/16", "1.0.128.0/17", NULL); -  verify_next (table, "1.0.0.0/17", "1.0.128.0/17"); -  clear_table (table); - -  /* -   * A search for the target reaches a node with no children. We have -   * to go upwards in the tree to find a successor. -   */ -  add_nodes (table, "1.0.0.0/16", "1.0.0.0/24", "1.0.1.0/24", -	     "1.0.128.0/17", NULL); -  verify_next (table, "1.0.1.0/25", "1.0.128.0/17"); -  clear_table (table); - -  /* -   * A search for the target reaches a node where neither the node nor -   * the target prefix contain each other. -   * -   * In first case below the node succeeds the target. -   * -   * In the second case, the node comes before the target, so we have -   * to go up the tree looking for a successor. -   */ -  add_nodes (table, "1.0.0.0/16", "1.0.1.0/24", NULL); -  verify_next (table, "1.0.0.0/24", "1.0.1.0/24"); -  clear_table (table); - -  add_nodes (table, "1.0.0.0/16", "1.0.0.0/24", "1.0.1.0/25", -	     "1.0.128.0/17", NULL); -  verify_next (table, "1.0.1.128/25", "1.0.128.0/17"); -  clear_table (table); - -  route_table_finish (table); +	struct route_table *table; + +	printf("\n\nTesting route_table_get_next()\n"); +	table = route_table_init(); + +	/* +	 * Target exists in tree, but has no successor. +	 */ +	add_nodes(table, "1.0.1.0/24", NULL); +	verify_next(table, "1.0.1.0/24", NULL); +	clear_table(table); + +	/* +	 * Target exists in tree, and there is a node in its left subtree. +	 */ +	add_nodes(table, "1.0.1.0/24", "1.0.1.0/25", NULL); +	verify_next(table, "1.0.1.0/24", "1.0.1.0/25"); +	clear_table(table); + +	/* +	 * Target exists in tree, and there is a node in its right subtree. +	 */ +	add_nodes(table, "1.0.1.0/24", "1.0.1.128/25", NULL); +	verify_next(table, "1.0.1.0/24", "1.0.1.128/25"); +	clear_table(table); + +	/* +	 * Target exists in the tree, next node is outside subtree. +	 */ +	add_nodes(table, "1.0.1.0/24", "1.1.0.0/16", NULL); +	verify_next(table, "1.0.1.0/24", "1.1.0.0/16"); +	clear_table(table); + +	/* +	 * The target node does not exist in the tree for all the test cases +	 * below this point. +	 */ + +	/* +	 * There is no successor in the tree. +	 */ +	add_nodes(table, "1.0.0.0/16", NULL); +	verify_next(table, "1.0.1.0/24", NULL); +	clear_table(table); + +	/* +	 * There exists a node that would be in the target's left subtree. +	 */ +	add_nodes(table, "1.0.0.0/16", "1.0.1.0/25", NULL); +	verify_next(table, "1.0.1.0/24", "1.0.1.0/25"); +	clear_table(table); + +	/* +	 * There exists a node would be in the target's right subtree. +	 */ +	add_nodes(table, "1.0.0.0/16", "1.0.1.128/25", NULL); +	verify_next(table, "1.0.1.0/24", "1.0.1.128/25"); +	clear_table(table); + +	/* +	 * A search for the target reaches a node where there are no child +	 * nodes in the direction of the target (left), but the node has a +	 * right child. +	 */ +	add_nodes(table, "1.0.0.0/16", "1.0.128.0/17", NULL); +	verify_next(table, "1.0.0.0/17", "1.0.128.0/17"); +	clear_table(table); + +	/* +	 * A search for the target reaches a node with no children. We have +	 * to go upwards in the tree to find a successor. +	 */ +	add_nodes(table, "1.0.0.0/16", "1.0.0.0/24", "1.0.1.0/24", +		  "1.0.128.0/17", NULL); +	verify_next(table, "1.0.1.0/25", "1.0.128.0/17"); +	clear_table(table); + +	/* +	 * A search for the target reaches a node where neither the node nor +	 * the target prefix contain each other. +	 * +	 * In first case below the node succeeds the target. +	 * +	 * In the second case, the node comes before the target, so we have +	 * to go up the tree looking for a successor. +	 */ +	add_nodes(table, "1.0.0.0/16", "1.0.1.0/24", NULL); +	verify_next(table, "1.0.0.0/24", "1.0.1.0/24"); +	clear_table(table); + +	add_nodes(table, "1.0.0.0/16", "1.0.0.0/24", "1.0.1.0/25", +		  "1.0.128.0/17", NULL); +	verify_next(table, "1.0.1.128/25", "1.0.128.0/17"); +	clear_table(table); + +	route_table_finish(table);  }  /*   * verify_prefix_iter_cmp   */ -static void -verify_prefix_iter_cmp (const char *p1, const char *p2, int exp_result) +static void verify_prefix_iter_cmp(const char *p1, const char *p2, +				   int exp_result)  { -  struct prefix_ipv4 p1_pfx, p2_pfx; -  int result; +	struct prefix_ipv4 p1_pfx, p2_pfx; +	int result; -  if (str2prefix_ipv4 (p1, &p1_pfx) <= 0) -    { -      assert (0); -    } +	if (str2prefix_ipv4(p1, &p1_pfx) <= 0) { +		assert(0); +	} -  if (str2prefix_ipv4 (p2, &p2_pfx) <= 0) -    { -      assert (0); -    } +	if (str2prefix_ipv4(p2, &p2_pfx) <= 0) { +		assert(0); +	} -  result = route_table_prefix_iter_cmp ((struct prefix *) &p1_pfx, -					(struct prefix *) &p2_pfx); +	result = route_table_prefix_iter_cmp((struct prefix *)&p1_pfx, +					     (struct prefix *)&p2_pfx); -  printf ("Verifying cmp(%s, %s) returns %d\n", p1, p2, exp_result); +	printf("Verifying cmp(%s, %s) returns %d\n", p1, p2, exp_result); -  assert (exp_result == result); +	assert(exp_result == result); -  /* -   * Also check the reverse comparision. -   */ -  result = route_table_prefix_iter_cmp ((struct prefix *) &p2_pfx, -					(struct prefix *) &p1_pfx); +	/* +	 * Also check the reverse comparision. +	 */ +	result = route_table_prefix_iter_cmp((struct prefix *)&p2_pfx, +					     (struct prefix *)&p1_pfx); -  if (exp_result) -    { -      exp_result = -exp_result; -    } +	if (exp_result) { +		exp_result = -exp_result; +	} -  printf ("Verifying cmp(%s, %s) returns %d\n", p1, p2, exp_result); -  assert (result == exp_result); +	printf("Verifying cmp(%s, %s) returns %d\n", p1, p2, exp_result); +	assert(result == exp_result);  }  /* @@ -431,16 +403,15 @@ verify_prefix_iter_cmp (const char *p1, const char *p2, int exp_result)   *   * Tests comparision of prefixes according to order of iteration.   */ -static void -test_prefix_iter_cmp () +static void test_prefix_iter_cmp()  { -  printf ("\n\nTesting route_table_prefix_iter_cmp()\n"); +	printf("\n\nTesting route_table_prefix_iter_cmp()\n"); -  verify_prefix_iter_cmp ("1.0.0.0/8", "1.0.0.0/8", 0); +	verify_prefix_iter_cmp("1.0.0.0/8", "1.0.0.0/8", 0); -  verify_prefix_iter_cmp ("1.0.0.0/8", "1.0.0.0/16", -1); +	verify_prefix_iter_cmp("1.0.0.0/8", "1.0.0.0/16", -1); -  verify_prefix_iter_cmp ("1.0.0.0/16", "1.128.0.0/16", -1); +	verify_prefix_iter_cmp("1.0.0.0/16", "1.128.0.0/16", -1);  }  /* @@ -450,105 +421,92 @@ test_prefix_iter_cmp ()   * iterator that pauses at each node. Verifies that the two methods   * yield the same results.   */ -static void -verify_iter_with_pause (struct route_table *table) +static void verify_iter_with_pause(struct route_table *table)  { -  unsigned long num_nodes; -  struct route_node *rn, *iter_rn; -  route_table_iter_t iter_space; -  route_table_iter_t *iter = &iter_space; - -  route_table_iter_init (iter, table); -  num_nodes = 0; - -  for (rn = route_top (table); rn; rn = route_next (rn)) -    { -      num_nodes++; -      route_table_iter_pause (iter); - -      assert (iter->current == NULL); -      if (route_table_iter_started (iter)) -	{ -	  assert (iter->state == RT_ITER_STATE_PAUSED); -	} -      else -	{ -	  assert (rn == table->top); -	  assert (iter->state == RT_ITER_STATE_INIT); +	unsigned long num_nodes; +	struct route_node *rn, *iter_rn; +	route_table_iter_t iter_space; +	route_table_iter_t *iter = &iter_space; + +	route_table_iter_init(iter, table); +	num_nodes = 0; + +	for (rn = route_top(table); rn; rn = route_next(rn)) { +		num_nodes++; +		route_table_iter_pause(iter); + +		assert(iter->current == NULL); +		if (route_table_iter_started(iter)) { +			assert(iter->state == RT_ITER_STATE_PAUSED); +		} else { +			assert(rn == table->top); +			assert(iter->state == RT_ITER_STATE_INIT); +		} + +		iter_rn = route_table_iter_next(iter); + +		/* +		 * Make sure both iterations return the same node. +		 */ +		assert(rn == iter_rn);  	} -      iter_rn = route_table_iter_next (iter); - -      /* -       * Make sure both iterations return the same node. -       */ -      assert (rn == iter_rn); -    } +	assert(num_nodes == route_table_count(table)); -  assert (num_nodes == route_table_count (table)); +	route_table_iter_pause(iter); +	iter_rn = route_table_iter_next(iter); -  route_table_iter_pause (iter); -  iter_rn = route_table_iter_next (iter); +	assert(iter_rn == NULL); +	assert(iter->state == RT_ITER_STATE_DONE); -  assert (iter_rn == NULL); -  assert (iter->state == RT_ITER_STATE_DONE); +	assert(route_table_iter_next(iter) == NULL); +	assert(iter->state == RT_ITER_STATE_DONE); -  assert (route_table_iter_next (iter) == NULL); -  assert (iter->state == RT_ITER_STATE_DONE); +	route_table_iter_cleanup(iter); -  route_table_iter_cleanup (iter); - -  print_table (table); -  printf ("Verified pausing iteration on tree with %lu nodes\n", num_nodes); +	print_table(table); +	printf("Verified pausing iteration on tree with %lu nodes\n", +	       num_nodes);  }  /*   * test_iter_pause   */ -static void -test_iter_pause (void) +static void test_iter_pause(void)  { -  struct route_table *table; -  int i, num_prefixes; -  const char *prefixes[] = { -    "1.0.1.0/24", -    "1.0.1.0/25", -    "1.0.1.128/25", -    "1.0.2.0/24", -    "2.0.0.0/8" -  }; - -  num_prefixes = sizeof (prefixes) / sizeof (prefixes[0]); - -  printf ("\n\nTesting that route_table_iter_pause() works as expected\n"); -  table = route_table_init (); -  for (i = 0; i < num_prefixes; i++) -    { -      add_nodes (table, prefixes[i], NULL); -    } - -  verify_iter_with_pause (table); - -  clear_table (table); -  route_table_finish (table); +	struct route_table *table; +	int i, num_prefixes; +	const char *prefixes[] = {"1.0.1.0/24", "1.0.1.0/25", "1.0.1.128/25", +				  "1.0.2.0/24", "2.0.0.0/8"}; + +	num_prefixes = sizeof(prefixes) / sizeof(prefixes[0]); + +	printf("\n\nTesting that route_table_iter_pause() works as expected\n"); +	table = route_table_init(); +	for (i = 0; i < num_prefixes; i++) { +		add_nodes(table, prefixes[i], NULL); +	} + +	verify_iter_with_pause(table); + +	clear_table(table); +	route_table_finish(table);  }  /*   * run_tests   */ -static void -run_tests (void) +static void run_tests(void)  { -  test_prefix_iter_cmp (); -  test_get_next (); -  test_iter_pause (); +	test_prefix_iter_cmp(); +	test_get_next(); +	test_iter_pause();  }  /*   * main   */ -int -main (void) +int main(void)  { -  run_tests (); +	run_tests();  } diff --git a/tests/lib/test_timer_correctness.c b/tests/lib/test_timer_correctness.c index e523929be1..31d936d8a4 100644 --- a/tests/lib/test_timer_correctness.c +++ b/tests/lib/test_timer_correctness.c @@ -56,142 +56,136 @@ static int timers_pending;  static void terminate_test(void)  { -  int exit_code; - -  if (strcmp(log_buf, expected_buf)) -    { -      fprintf(stderr, "Expected output and received output differ.\n"); -      fprintf(stderr, "---Expected output: ---\n%s", expected_buf); -      fprintf(stderr, "---Actual output: ---\n%s", log_buf); -      exit_code = 1; -    } -  else -    { -      printf("Expected output and actual output match.\n"); -      exit_code = 0; -    } - -  thread_master_free(master); -  XFREE(MTYPE_TMP, log_buf); -  XFREE(MTYPE_TMP, expected_buf); -  prng_free(prng); -  XFREE(MTYPE_TMP, timers); - -  exit(exit_code); +	int exit_code; + +	if (strcmp(log_buf, expected_buf)) { +		fprintf(stderr, +			"Expected output and received output differ.\n"); +		fprintf(stderr, "---Expected output: ---\n%s", expected_buf); +		fprintf(stderr, "---Actual output: ---\n%s", log_buf); +		exit_code = 1; +	} else { +		printf("Expected output and actual output match.\n"); +		exit_code = 0; +	} + +	thread_master_free(master); +	XFREE(MTYPE_TMP, log_buf); +	XFREE(MTYPE_TMP, expected_buf); +	prng_free(prng); +	XFREE(MTYPE_TMP, timers); + +	exit(exit_code);  }  static int timer_func(struct thread *thread)  { -  int rv; +	int rv; -  rv = snprintf(log_buf + log_buf_pos, log_buf_len - log_buf_pos, -                "%s\n", (char*)thread->arg); -  assert(rv >= 0); -  log_buf_pos += rv; -  assert(log_buf_pos < log_buf_len); -  XFREE(MTYPE_TMP, thread->arg); +	rv = snprintf(log_buf + log_buf_pos, log_buf_len - log_buf_pos, "%s\n", +		      (char *)thread->arg); +	assert(rv >= 0); +	log_buf_pos += rv; +	assert(log_buf_pos < log_buf_len); +	XFREE(MTYPE_TMP, thread->arg); -  timers_pending--; -  if (!timers_pending) -    terminate_test(); +	timers_pending--; +	if (!timers_pending) +		terminate_test(); -  return 0; +	return 0;  } -static int cmp_timeval(const void* a, const void *b) +static int cmp_timeval(const void *a, const void *b)  { -  const struct timeval *ta = *(struct timeval * const *)a; -  const struct timeval *tb = *(struct timeval * const *)b; - -  if (timercmp(ta, tb, <)) -    return -1; -  if (timercmp(ta, tb, >)) -    return 1; -  return 0; +	const struct timeval *ta = *(struct timeval * const *)a; +	const struct timeval *tb = *(struct timeval * const *)b; + +	if (timercmp(ta, tb, <)) +		return -1; +	if (timercmp(ta, tb, >)) +		return 1; +	return 0;  }  int main(int argc, char **argv)  { -  int i, j; -  struct thread t; -  struct timeval **alarms; - -  master = thread_master_create(); - -  log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; -  log_buf_pos = 0; -  log_buf = XMALLOC(MTYPE_TMP, log_buf_len); - -  expected_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; -  expected_buf_pos = 0; -  expected_buf = XMALLOC(MTYPE_TMP, expected_buf_len); - -  prng = prng_new(0); - -  timers = XMALLOC(MTYPE_TMP, SCHEDULE_TIMERS * sizeof(*timers)); - -  for (i = 0; i < SCHEDULE_TIMERS; i++) -    { -      long interval_msec; -      int ret; -      char *arg; - -      /* Schedule timers to expire in 0..5 seconds */ -      interval_msec = prng_rand(prng) % 5000; -      arg = XMALLOC(MTYPE_TMP, TIMESTR_LEN + 1); -      timers[i] = thread_add_timer_msec(master, timer_func, arg, interval_msec); -      ret = snprintf(arg, TIMESTR_LEN + 1, "%lld.%06lld", -                     (long long)timers[i]->u.sands.tv_sec, -                     (long long)timers[i]->u.sands.tv_usec); -      assert(ret > 0); -      assert((size_t)ret < TIMESTR_LEN + 1); -      timers_pending++; -    } - -  for (i = 0; i < REMOVE_TIMERS; i++) -    { -      int index; - -      index = prng_rand(prng) % SCHEDULE_TIMERS; -      if (!timers[index]) -        continue; - -      XFREE(MTYPE_TMP, timers[index]->arg); -      thread_cancel(timers[index]); -      timers[index] = NULL; -      timers_pending--; -    } - -  /* We create an array of pointers to the alarm times and sort -   * that array. That sorted array is used to generate a string -   * representing the expected "output" of the timers when they -   * are run. */ -  j = 0; -  alarms = XMALLOC(MTYPE_TMP, timers_pending * sizeof(*alarms)); -  for (i = 0; i < SCHEDULE_TIMERS; i++) -    { -      if (!timers[i]) -        continue; -      alarms[j++] = &timers[i]->u.sands; -    } -  qsort(alarms, j, sizeof(*alarms), cmp_timeval); -  for (i = 0; i < j; i++) -    { -      int ret; - -      ret = snprintf(expected_buf + expected_buf_pos, -                     expected_buf_len - expected_buf_pos, -                     "%lld.%06lld\n", -                     (long long)alarms[i]->tv_sec, -                     (long long)alarms[i]->tv_usec); -      assert(ret > 0); -      expected_buf_pos += ret; -      assert(expected_buf_pos < expected_buf_len); -    } -  XFREE(MTYPE_TMP, alarms); - -  while (thread_fetch(master, &t)) -    thread_call(&t); - -  return 0; +	int i, j; +	struct thread t; +	struct timeval **alarms; + +	master = thread_master_create(); + +	log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; +	log_buf_pos = 0; +	log_buf = XMALLOC(MTYPE_TMP, log_buf_len); + +	expected_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; +	expected_buf_pos = 0; +	expected_buf = XMALLOC(MTYPE_TMP, expected_buf_len); + +	prng = prng_new(0); + +	timers = XMALLOC(MTYPE_TMP, SCHEDULE_TIMERS * sizeof(*timers)); + +	for (i = 0; i < SCHEDULE_TIMERS; i++) { +		long interval_msec; +		int ret; +		char *arg; + +		/* Schedule timers to expire in 0..5 seconds */ +		interval_msec = prng_rand(prng) % 5000; +		arg = XMALLOC(MTYPE_TMP, TIMESTR_LEN + 1); +		timers[i] = thread_add_timer_msec(master, timer_func, arg, +						  interval_msec); +		ret = snprintf(arg, TIMESTR_LEN + 1, "%lld.%06lld", +			       (long long)timers[i]->u.sands.tv_sec, +			       (long long)timers[i]->u.sands.tv_usec); +		assert(ret > 0); +		assert((size_t)ret < TIMESTR_LEN + 1); +		timers_pending++; +	} + +	for (i = 0; i < REMOVE_TIMERS; i++) { +		int index; + +		index = prng_rand(prng) % SCHEDULE_TIMERS; +		if (!timers[index]) +			continue; + +		XFREE(MTYPE_TMP, timers[index]->arg); +		thread_cancel(timers[index]); +		timers[index] = NULL; +		timers_pending--; +	} + +	/* We create an array of pointers to the alarm times and sort +	 * that array. That sorted array is used to generate a string +	 * representing the expected "output" of the timers when they +	 * are run. */ +	j = 0; +	alarms = XMALLOC(MTYPE_TMP, timers_pending * sizeof(*alarms)); +	for (i = 0; i < SCHEDULE_TIMERS; i++) { +		if (!timers[i]) +			continue; +		alarms[j++] = &timers[i]->u.sands; +	} +	qsort(alarms, j, sizeof(*alarms), cmp_timeval); +	for (i = 0; i < j; i++) { +		int ret; + +		ret = snprintf(expected_buf + expected_buf_pos, +			       expected_buf_len - expected_buf_pos, +			       "%lld.%06lld\n", (long long)alarms[i]->tv_sec, +			       (long long)alarms[i]->tv_usec); +		assert(ret > 0); +		expected_buf_pos += ret; +		assert(expected_buf_pos < expected_buf_len); +	} +	XFREE(MTYPE_TMP, alarms); + +	while (thread_fetch(master, &t)) +		thread_call(&t); + +	return 0;  } diff --git a/tests/lib/test_timer_performance.c b/tests/lib/test_timer_performance.c index a7d09beecc..f3878532c4 100644 --- a/tests/lib/test_timer_performance.c +++ b/tests/lib/test_timer_performance.c @@ -39,67 +39,65 @@ struct thread_master *master;  static int dummy_func(struct thread *thread)  { -  return 0; +	return 0;  }  int main(int argc, char **argv)  { -  struct prng *prng; -  int i; -  struct thread **timers; -  struct timeval tv_start, tv_lap, tv_stop; -  unsigned long t_schedule, t_remove; - -  master = thread_master_create(); -  prng = prng_new(0); -  timers = calloc(SCHEDULE_TIMERS, sizeof(*timers)); - -  /* create thread structures so they won't be allocated during the -   * time measurement */ -  for (i = 0; i < SCHEDULE_TIMERS; i++) -    timers[i] = thread_add_timer_msec(master, dummy_func, NULL, 0); -  for (i = 0; i < SCHEDULE_TIMERS; i++) -    thread_cancel(timers[i]); - -  monotime(&tv_start); - -  for (i = 0; i < SCHEDULE_TIMERS; i++) -    { -      long interval_msec; - -      interval_msec = prng_rand(prng) % (100 * SCHEDULE_TIMERS); -      timers[i] = thread_add_timer_msec(master, dummy_func, -                                        NULL, interval_msec); -    } - -  monotime(&tv_lap); - -  for (i = 0; i < REMOVE_TIMERS; i++) -    { -      int index; - -      index = prng_rand(prng) % SCHEDULE_TIMERS; -      if (timers[index]) -        thread_cancel(timers[index]); -      timers[index] = NULL; -    } - -  monotime(&tv_stop); - -  t_schedule = 1000 * (tv_lap.tv_sec - tv_start.tv_sec); -  t_schedule += (tv_lap.tv_usec - tv_start.tv_usec) / 1000; - -  t_remove = 1000 * (tv_stop.tv_sec - tv_lap.tv_sec); -  t_remove += (tv_stop.tv_usec - tv_lap.tv_usec) / 1000; - -  printf("Scheduling %d random timers took %ld.%03ld seconds.\n", -         SCHEDULE_TIMERS, t_schedule/1000, t_schedule%1000); -  printf("Removing %d random timers took %ld.%03ld seconds.\n", -         REMOVE_TIMERS, t_remove/1000, t_remove%1000); -  fflush(stdout); - -  free(timers); -  thread_master_free(master); -  prng_free(prng); -  return 0; +	struct prng *prng; +	int i; +	struct thread **timers; +	struct timeval tv_start, tv_lap, tv_stop; +	unsigned long t_schedule, t_remove; + +	master = thread_master_create(); +	prng = prng_new(0); +	timers = calloc(SCHEDULE_TIMERS, sizeof(*timers)); + +	/* create thread structures so they won't be allocated during the +	 * time measurement */ +	for (i = 0; i < SCHEDULE_TIMERS; i++) +		timers[i] = thread_add_timer_msec(master, dummy_func, NULL, 0); +	for (i = 0; i < SCHEDULE_TIMERS; i++) +		thread_cancel(timers[i]); + +	monotime(&tv_start); + +	for (i = 0; i < SCHEDULE_TIMERS; i++) { +		long interval_msec; + +		interval_msec = prng_rand(prng) % (100 * SCHEDULE_TIMERS); +		timers[i] = thread_add_timer_msec(master, dummy_func, NULL, +						  interval_msec); +	} + +	monotime(&tv_lap); + +	for (i = 0; i < REMOVE_TIMERS; i++) { +		int index; + +		index = prng_rand(prng) % SCHEDULE_TIMERS; +		if (timers[index]) +			thread_cancel(timers[index]); +		timers[index] = NULL; +	} + +	monotime(&tv_stop); + +	t_schedule = 1000 * (tv_lap.tv_sec - tv_start.tv_sec); +	t_schedule += (tv_lap.tv_usec - tv_start.tv_usec) / 1000; + +	t_remove = 1000 * (tv_stop.tv_sec - tv_lap.tv_sec); +	t_remove += (tv_stop.tv_usec - tv_lap.tv_usec) / 1000; + +	printf("Scheduling %d random timers took %ld.%03ld seconds.\n", +	       SCHEDULE_TIMERS, t_schedule / 1000, t_schedule % 1000); +	printf("Removing %d random timers took %ld.%03ld seconds.\n", +	       REMOVE_TIMERS, t_remove / 1000, t_remove % 1000); +	fflush(stdout); + +	free(timers); +	thread_master_free(master); +	prng_free(prng); +	return 0;  } diff --git a/tests/test_lblmgr.c b/tests/test_lblmgr.c index 4a4aaa0014..fefc933318 100644 --- a/tests/test_lblmgr.c +++ b/tests/test_lblmgr.c @@ -34,117 +34,112 @@ u_short instance = 1;  const char *sequence = "GGRGGGRRG"; -static int zebra_send_get_label_chunk (void); -static int zebra_send_release_label_chunk (uint32_t start, uint32_t end); +static int zebra_send_get_label_chunk(void); +static int zebra_send_release_label_chunk(uint32_t start, uint32_t end); -static void -process_next_call (uint32_t start, uint32_t end) +static void process_next_call(uint32_t start, uint32_t end)  { -		sleep (3); -		if (!*sequence) -				exit (0); -		if (*sequence == 'G') -				zebra_send_get_label_chunk (); -		else if (*sequence == 'R') -				zebra_send_release_label_chunk (start, end); +	sleep(3); +	if (!*sequence) +		exit(0); +	if (*sequence == 'G') +		zebra_send_get_label_chunk(); +	else if (*sequence == 'R') +		zebra_send_release_label_chunk(start, end);  }  /* Connect to Label Manager */ -static int -zebra_send_label_manager_connect () +static int zebra_send_label_manager_connect()  { -		int ret; +	int ret; -		printf("Connect to Label Manager\n"); +	printf("Connect to Label Manager\n"); -		ret = lm_label_manager_connect (zclient); -		printf ("Label Manager connection result: %u \n", ret); -		if (ret != 0 ) { -				fprintf (stderr, "Error %d connecting to Label Manager %s\n", ret, -						 strerror(errno)); -				exit (1); -		} +	ret = lm_label_manager_connect(zclient); +	printf("Label Manager connection result: %u \n", ret); +	if (ret != 0) { +		fprintf(stderr, "Error %d connecting to Label Manager %s\n", +			ret, strerror(errno)); +		exit(1); +	} -		process_next_call (0, 0); +	process_next_call(0, 0);  }  /* Get Label Chunk */ -static int -zebra_send_get_label_chunk () +static int zebra_send_get_label_chunk()  { -		uint32_t start; -		uint32_t end; -		int ret; +	uint32_t start; +	uint32_t end; +	int ret; -		printf("Ask for label chunk \n"); +	printf("Ask for label chunk \n"); -		ret = lm_get_label_chunk (zclient, KEEP, CHUNK_SIZE, &start, &end); -		if (ret != 0 ) { -				fprintf (stderr, "Error %d requesting label chunk %s\n", ret, strerror(errno)); -				exit (1); -		} +	ret = lm_get_label_chunk(zclient, KEEP, CHUNK_SIZE, &start, &end); +	if (ret != 0) { +		fprintf(stderr, "Error %d requesting label chunk %s\n", ret, +			strerror(errno)); +		exit(1); +	} -		sequence++; +	sequence++; -		printf ("Label Chunk assign: %u - %u \n", -				start, end); +	printf("Label Chunk assign: %u - %u \n", start, end); -		process_next_call (start, end); +	process_next_call(start, end);  }  /* Release Label Chunk */ -static int -zebra_send_release_label_chunk (uint32_t start, uint32_t end) +static int zebra_send_release_label_chunk(uint32_t start, uint32_t end)  { -		struct stream *s; -		int ret; +	struct stream *s; +	int ret; -		printf("Release label chunk: %u - %u\n", start, end); +	printf("Release label chunk: %u - %u\n", start, end); -		ret = lm_release_label_chunk (zclient, start, end); -		if (ret != 0 ) { -				fprintf (stderr, "Error releasing label chunk\n"); -				exit (1); -		} +	ret = lm_release_label_chunk(zclient, start, end); +	if (ret != 0) { +		fprintf(stderr, "Error releasing label chunk\n"); +		exit(1); +	} -		sequence++; +	sequence++; -		process_next_call (start-CHUNK_SIZE, end-CHUNK_SIZE); +	process_next_call(start - CHUNK_SIZE, end - CHUNK_SIZE);  } -void init_zclient (struct thread_master *master, char *lm_zserv_path) +void init_zclient(struct thread_master *master, char *lm_zserv_path)  { -		if (lm_zserv_path) -				zclient_serv_path_set(lm_zserv_path); - -		zclient = zclient_new(master); -		/* zclient_init(zclient, ZEBRA_LABEL_MANAGER, 0); */ -		zclient->sock = -1; -		zclient->redist_default = ZEBRA_ROUTE_LDP; -		zclient->instance = instance; -		if (zclient_socket_connect (zclient) < 0) { -				printf ("Error connecting synchronous zclient!\n"); -				exit (1); -		} - +	if (lm_zserv_path) +		zclient_serv_path_set(lm_zserv_path); + +	zclient = zclient_new(master); +	/* zclient_init(zclient, ZEBRA_LABEL_MANAGER, 0); */ +	zclient->sock = -1; +	zclient->redist_default = ZEBRA_ROUTE_LDP; +	zclient->instance = instance; +	if (zclient_socket_connect(zclient) < 0) { +		printf("Error connecting synchronous zclient!\n"); +		exit(1); +	}  } -int main (int argc, char *argv[]) +int main(int argc, char *argv[])  { -		struct thread_master *master; -		struct thread		 thread; -		int ret; +	struct thread_master *master; +	struct thread thread; +	int ret; -		printf ("Sequence to be tested: %s\n", sequence); +	printf("Sequence to be tested: %s\n", sequence); -		master = thread_master_create(); -		init_zclient (master, ZSERV_PATH); +	master = thread_master_create(); +	init_zclient(master, ZSERV_PATH); -		zebra_send_label_manager_connect (); +	zebra_send_label_manager_connect(); -		return 0; +	return 0;  }  | 
