Annotation of embedaddon/quagga/tests/bgp_capability_test.c, revision 1.1.1.3

1.1       misho       1: #include <zebra.h>
                      2: 
                      3: #include "vty.h"
                      4: #include "stream.h"
                      5: #include "privs.h"
                      6: #include "memory.h"
                      7: 
                      8: #include "bgpd/bgpd.h"
                      9: #include "bgpd/bgp_open.h"
                     10: #include "bgpd/bgp_debug.h"
1.1.1.3 ! misho      11: #include "bgpd/bgp_packet.h"
1.1       misho      12: 
                     13: #define VT100_RESET "\x1b[0m"
                     14: #define VT100_RED "\x1b[31m"
                     15: #define VT100_GREEN "\x1b[32m"
                     16: #define VT100_YELLOW "\x1b[33m"
                     17: 
                     18: 
                     19: #define CAPABILITY 0
                     20: #define DYNCAP     1
                     21: #define OPT_PARAM  2
                     22: 
                     23: /* need these to link in libbgp */
                     24: struct zebra_privs_t *bgpd_privs = NULL;
                     25: struct thread_master *master = NULL;
                     26: 
                     27: static int failed = 0;
                     28: static int tty = 0;
                     29: 
                     30: /* test segments to parse and validate, and use for other tests */
                     31: static struct test_segment {
                     32:   const char *name;
                     33:   const char *desc;
                     34:   const u_char data[1024];
                     35:   int len;
                     36: #define SHOULD_PARSE   0
                     37: #define SHOULD_ERR     -1
                     38:   int parses; /* whether it should parse or not */
1.1.1.3 ! misho      39:   as_t peek_for; /* what peek_for_as4_capability should say */
1.1       misho      40:   
                     41:   /* AFI/SAFI validation */
                     42:   int validate_afi;
                     43:   afi_t afi;
                     44:   safi_t safi;
                     45: #define VALID_AFI 1
                     46: #define INVALID_AFI 0
                     47:   int afi_valid;
                     48: } test_segments [] = 
                     49: {
                     50:   /* 0 */
                     51:   { "caphdr", 
                     52:     "capability header, and no more",
                     53:     { CAPABILITY_CODE_REFRESH, 0x0 },
                     54:     2, SHOULD_PARSE,
                     55:   },
                     56:   /* 1 */
                     57:   { "nodata",
                     58:     "header, no data but length says there is",
                     59:     { 0x1, 0xa },
                     60:     2, SHOULD_ERR,
                     61:   },
                     62:   /* 2 */
                     63:   { "padded",
                     64:     "valid, with padding",
                     65:     { CAPABILITY_CODE_REFRESH, 0x2, 0x0, 0x0 },
                     66:     4, SHOULD_PARSE,
                     67:   },
                     68:   /* 3 */
                     69:   { "minsize",
                     70:     "violates minsize requirement",
                     71:     { CAPABILITY_CODE_ORF, 0x2, 0x0, 0x0 },
                     72:     4, SHOULD_ERR,
                     73:   },
                     74:   { NULL, NULL, {0}, 0, 0},
                     75: };
                     76: 
                     77: static struct test_segment mp_segments[] =
                     78: {
                     79:   { "MP4",
                     80:     "MP IP/Uni",
                     81:     { 0x1, 0x4, 0x0, 0x1, 0x0, 0x1 },
                     82:     6, SHOULD_PARSE, 0,
                     83:     1, AFI_IP, SAFI_UNICAST, VALID_AFI,
                     84:   },
                     85:   { "MPv6",
                     86:     "MP IPv6/Uni",
                     87:     { 0x1, 0x4, 0x0, 0x2, 0x0, 0x1 },
                     88:     6, SHOULD_PARSE, 0,
                     89:     1, AFI_IP6, SAFI_UNICAST, VALID_AFI,
                     90:   },
                     91:   /* 5 */
                     92:   { "MP2",
                     93:     "MP IP/Multicast",
                     94:     { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x2 },
                     95:     6, SHOULD_PARSE, 0,
                     96:     1, AFI_IP, SAFI_MULTICAST, VALID_AFI,
                     97:   },
                     98:   /* 6 */
                     99:   { "MP3",
1.1.1.2   misho     100:     "MP IP6/MPLS-labeled VPN",
1.1       misho     101:     { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x80 },
1.1.1.2   misho     102:     6, SHOULD_PARSE, 0,
                    103:     1, AFI_IP6, SAFI_MPLS_LABELED_VPN, VALID_AFI,
1.1       misho     104:   },
                    105:   /* 7 */
                    106:   { "MP5",
                    107:     "MP IP6/MPLS-VPN",
                    108:     { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x4 },
                    109:     6, SHOULD_PARSE, 0,
                    110:     1, AFI_IP6, SAFI_MPLS_VPN, VALID_AFI,
                    111:   },
                    112:   /* 8 */
                    113:   { "MP6",
1.1.1.2   misho     114:     "MP IP4/MPLS-laveled VPN",
1.1       misho     115:     { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80 },
                    116:     6, SHOULD_PARSE, 0,
1.1.1.2   misho     117:     1, AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
1.1       misho     118:   },  
                    119:   /* 10 */
                    120:   { "MP8",
1.1.1.2   misho     121:     "MP unknown AFI/SAFI",
1.1       misho     122:     { CAPABILITY_CODE_MP, 0x4, 0x0, 0xa, 0x0, 0x81 },
                    123:     6, SHOULD_PARSE, 0,
                    124:     1, 0xa, 0x81, INVALID_AFI, /* parses, but unknown */
                    125:   },
                    126:   /* 11 */
                    127:   { "MP-short",
                    128:     "MP IP4/Unicast, length too short (< minimum)",
                    129:     { CAPABILITY_CODE_MP, 0x2, 0x0, 0x1, 0x0, 0x1 },
                    130:     6, SHOULD_ERR,
                    131:   },
                    132:   /* 12 */
                    133:   { "MP-overflow",
                    134:     "MP IP4/Unicast, length too long",
                    135:     { CAPABILITY_CODE_MP, 0x6, 0x0, 0x1, 0x0, 0x1 },
                    136:     6, SHOULD_ERR, 0,
                    137:     1, AFI_IP, SAFI_UNICAST, VALID_AFI,
                    138:   },
                    139:   { NULL, NULL, {0}, 0, 0}
                    140: };
                    141: 
                    142: static struct test_segment misc_segments[] =
                    143: {
                    144:   /* 13 */
                    145:   { "ORF",
                    146:     "ORF, simple, single entry, single tuple",
                    147:     { /* hdr */                CAPABILITY_CODE_ORF, 0x7, 
                    148:       /* mpc */                0x0, 0x1, 0x0, 0x1, 
                    149:       /* num */                0x1, 
                    150:       /* tuples */     0x40, 0x3
                    151:     },
                    152:     9, SHOULD_PARSE,
                    153:   },
                    154:   /* 14 */
                    155:   { "ORF-many",
                    156:     "ORF, multi entry/tuple",
                    157:     { /* hdr */                CAPABILITY_CODE_ORF, 0x21,
                    158:       /* mpc */                0x0, 0x1, 0x0, 0x1, 
                    159:       /* num */                0x3, 
                    160:       /* tuples */     0x40, ORF_MODE_BOTH,
                    161:                         0x80, ORF_MODE_RECEIVE,
                    162:                         0x80, ORF_MODE_SEND,
                    163:       /* mpc */                0x0, 0x2, 0x0, 0x1, 
                    164:       /* num */                0x3, 
                    165:       /* tuples */     0x40, ORF_MODE_BOTH,
                    166:                         0x80, ORF_MODE_RECEIVE,
                    167:                         0x80, ORF_MODE_SEND,
                    168:       /* mpc */                0x0, 0x2, 0x0, 0x2,
                    169:       /* num */                0x3, 
                    170:       /* tuples */     0x40, ORF_MODE_RECEIVE,
                    171:                         0x80, ORF_MODE_SEND,
                    172:                         0x80, ORF_MODE_BOTH,
                    173:     },
                    174:     35, SHOULD_PARSE,
                    175:   },
                    176:   /* 15 */
                    177:   { "ORFlo",
                    178:     "ORF, multi entry/tuple, hdr length too short",
                    179:     { /* hdr */                CAPABILITY_CODE_ORF, 0x15,
                    180:       /* mpc */                0x0, 0x1, 0x0, 0x1, 
                    181:       /* num */                0x3, 
                    182:       /* tuples */     0x40, 0x3,
                    183:                         0x80, 0x1,
                    184:                         0x80, 0x2,
                    185:       /* mpc */                0x0, 0x1, 0x0, 0x1, 
                    186:       /* num */                0x3, 
                    187:       /* tuples */     0x40, 0x3,
                    188:                         0x80, 0x1,
                    189:                         0x80, 0x2,
                    190:       /* mpc */                0x0, 0x2, 0x0, 0x2,
                    191:       /* num */                0x3, 
                    192:       /* tuples */     0x40, 0x3,
                    193:                         0x80, 0x1,
                    194:                         0x80, 0x2,
                    195:     },
                    196:     35, SHOULD_ERR, /* It should error on invalid Route-Refresh.. */
                    197:   },
                    198:   /* 16 */
                    199:   { "ORFlu",
                    200:     "ORF, multi entry/tuple, length too long",
                    201:     { /* hdr */                0x3, 0x22,
                    202:       /* mpc */                0x0, 0x1, 0x0, 0x1, 
                    203:       /* num */                0x3, 
                    204:       /* tuples */     0x40, 0x3,
                    205:                         0x80, 0x1,
                    206:                         0x80, 0x2,
                    207:       /* mpc */                0x0, 0x2, 0x0, 0x1, 
                    208:       /* num */                0x3, 
                    209:       /* tuples */     0x40, 0x3,
                    210:                         0x80, 0x1,
                    211:                         0x80, 0x2,
                    212:       /* mpc */                0x0, 0x2, 0x0, 0x2,
                    213:       /* num */                0x3, 
                    214:       /* tuples */     0x40, 0x3,
                    215:                         0x80, 0x1,
                    216:                         0x80, 0x2,
                    217:     },
                    218:     35, SHOULD_ERR
                    219:   },
                    220:   /* 17 */
                    221:   { "ORFnu",
                    222:     "ORF, multi entry/tuple, entry number too long",
                    223:     { /* hdr */                0x3, 0x21,
                    224:       /* mpc */                0x0, 0x1, 0x0, 0x1, 
                    225:       /* num */                0x3, 
                    226:       /* tuples */     0x40, 0x3,
                    227:                         0x80, 0x1,
                    228:                         0x80, 0x2,
                    229:       /* mpc */                0x0, 0x2, 0x0, 0x1, 
                    230:       /* num */                0x4, 
                    231:       /* tuples */     0x40, 0x3,
                    232:                         0x80, 0x1,
                    233:                         0x80, 0x2,
                    234:       /* mpc */                0x0, 0x2, 0x0, 0x2,
                    235:       /* num */                0x3, 
                    236:       /* tuples */     0x40, 0x3,
                    237:                         0x80, 0x1,
                    238:                         0x80, 0x2,
                    239:     },
                    240:     35, SHOULD_PARSE, /* parses, but last few tuples should be gibberish */
                    241:   },
                    242:   /* 18 */
                    243:   { "ORFno",
                    244:     "ORF, multi entry/tuple, entry number too short",
                    245:     { /* hdr */                0x3, 0x21,
                    246:       /* mpc */                0x0, 0x1, 0x0, 0x1, 
                    247:       /* num */                0x3, 
                    248:       /* tuples */     0x40, 0x3,
                    249:                         0x80, 0x1,
                    250:                         0x80, 0x2,
                    251:       /* mpc */                0x0, 0x2, 0x0, 0x1, 
                    252:       /* num */                0x1, 
                    253:       /* tuples */     0x40, 0x3,
                    254:                         0x80, 0x1,
                    255:                         0x80, 0x2,
                    256:       /* mpc */                0x0, 0x2, 0x0, 0x2,
                    257:       /* num */                0x3,
                    258:       /* tuples */     0x40, 0x3,
                    259:                         0x80, 0x1,
                    260:                         0x80, 0x2,
                    261:     },
                    262:     35, SHOULD_PARSE, /* Parses, but should get gibberish afi/safis */
                    263:   },
                    264:   /* 17 */
                    265:   { "ORFpad",
                    266:     "ORF, multi entry/tuple, padded to align",
                    267:     { /* hdr */                0x3, 0x22,
                    268:       /* mpc */                0x0, 0x1, 0x0, 0x1, 
                    269:       /* num */                0x3, 
                    270:       /* tuples */     0x40, 0x3,
                    271:                         0x80, 0x1,
                    272:                         0x80, 0x2,
                    273:       /* mpc */                0x0, 0x2, 0x0, 0x1, 
                    274:       /* num */                0x3, 
                    275:       /* tuples */     0x40, 0x3,
                    276:                         0x80, 0x1,
                    277:                         0x80, 0x2,
                    278:       /* mpc */                0x0, 0x2, 0x0, 0x2,
                    279:       /* num */                0x3, 
                    280:       /* tuples */     0x40, 0x3,
                    281:                         0x80, 0x1,
                    282:                         0x80, 0x2,
                    283:                         0x00,
                    284:     },
                    285:     36, SHOULD_PARSE,
                    286:   },
                    287:   /* 19 */
                    288:   { "AS4",
                    289:     "AS4 capability",
                    290:     { 0x41, 0x4, 0xab, 0xcd, 0xef, 0x12 }, /* AS: 2882400018 */
                    291:     6, SHOULD_PARSE, 2882400018,
                    292:   },
                    293:   /* 20 */
                    294:   { "GR",
                    295:     "GR capability",
                    296:     { /* hdr */                CAPABILITY_CODE_RESTART, 0xe,
                    297:       /* R-bit, time */        0xf1, 0x12,
                    298:       /* afi */                0x0, 0x1,
                    299:       /* safi */       0x1,
                    300:       /* flags */      0xf,
                    301:       /* afi */                0x0, 0x2,
                    302:       /* safi */       0x1,
                    303:       /* flags */      0x0,
                    304:       /* afi */                0x0, 0x2,
                    305:       /* safi */       0x2,
                    306:       /* flags */      0x1,
                    307:     },
                    308:     16, SHOULD_PARSE,
                    309:   },
                    310:   /* 21 */
                    311:   { "GR-short",
                    312:     "GR capability, but header length too short",
                    313:     { /* hdr */                0x40, 0xa,
                    314:       /* R-bit, time */        0xf1, 0x12,
                    315:       /* afi */                0x0, 0x1,
                    316:       /* safi */       0x1,
                    317:       /* flags */      0xf,
                    318:       /* afi */                0x0, 0x2,
                    319:       /* safi */       0x1,
                    320:       /* flags */      0x0,
                    321:       /* afi */                0x0, 0x2,
                    322:       /* safi */       0x2,
                    323:       /* flags */      0x1,
                    324:     },
                    325:     16, SHOULD_PARSE,
                    326:   },
                    327:   /* 22 */
                    328:   { "GR-long",
                    329:     "GR capability, but header length too long",
                    330:     { /* hdr */                0x40, 0xf,
                    331:       /* R-bit, time */        0xf1, 0x12,
                    332:       /* afi */                0x0, 0x1,
                    333:       /* safi */       0x1,
                    334:       /* flags */      0xf,
                    335:       /* afi */                0x0, 0x2,
                    336:       /* safi */       0x1,
                    337:       /* flags */      0x0,
                    338:       /* afi */                0x0, 0x2,
                    339:       /* safi */       0x2,
                    340:     },
                    341:     16, SHOULD_ERR,
                    342:   },
                    343:   { "GR-trunc",
                    344:     "GR capability, but truncated",
                    345:     { /* hdr */                0x40, 0xf,
                    346:       /* R-bit, time */        0xf1, 0x12,
                    347:       /* afi */                0x0, 0x1,
                    348:       /* safi */       0x1,
                    349:       /* flags */      0xf,
                    350:       /* afi */                0x0, 0x2,
                    351:       /* safi */       0x1,
                    352:       /* flags */      0x0,
                    353:       /* afi */                0x0, 0x2,
                    354:       /* safi */       0x2,
                    355:       /* flags */      0x1,
                    356:     },
                    357:     15, SHOULD_ERR,
                    358:   },
                    359:   { "GR-empty",
                    360:     "GR capability, but empty.",
                    361:     { /* hdr */                0x40, 0x0,
                    362:     },
                    363:     2, SHOULD_ERR,
                    364:   },
                    365:   { "MP-empty",
                    366:     "MP capability, but empty.",
                    367:     { /* hdr */                0x1, 0x0,
                    368:     },
                    369:     2, SHOULD_ERR,
                    370:   },
                    371:   { "ORF-empty",
                    372:     "ORF capability, but empty.",
                    373:     { /* hdr */                0x3, 0x0,
                    374:     },
                    375:     2, SHOULD_ERR,
                    376:   },
                    377:   { "AS4-empty",
                    378:     "AS4 capability, but empty.",
                    379:     { /* hdr */                0x41, 0x0,
                    380:     },
                    381:     2, SHOULD_ERR,
                    382:   },
                    383:   { "dyn-empty",
                    384:     "Dynamic capability, but empty.",
                    385:     { /* hdr */                0x42, 0x0,
                    386:     },
                    387:     2, SHOULD_PARSE,
                    388:   },
                    389:   { "dyn-old",
                    390:     "Dynamic capability (deprecated version)",
                    391:     { CAPABILITY_CODE_DYNAMIC, 0x0 },
                    392:     2, SHOULD_PARSE,
                    393:   },
                    394:   { NULL, NULL, {0}, 0, 0}
                    395: };
                    396: 
                    397: /* DYNAMIC message */
                    398: struct test_segment dynamic_cap_msgs[] = 
                    399: {
                    400:   { "DynCap",
                    401:     "Dynamic Capability Message, IP/Multicast",
                    402:     { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2 },
                    403:       7, SHOULD_PARSE, /* horrible alignment, just as with ORF */
                    404:   },
                    405:   { "DynCapLong",
                    406:     "Dynamic Capability Message, IP/Multicast, truncated",
                    407:     { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2 },
                    408:       5, SHOULD_ERR,
                    409:   },
                    410:   { "DynCapPadded",
                    411:     "Dynamic Capability Message, IP/Multicast, padded",
                    412:     { 0x0, 0x1, 0x4, 0x0, 0x1, 0x0, 0x2, 0x0 },
                    413:       8, SHOULD_ERR, /* No way to tell padding from data.. */
                    414:   },
                    415:   { "DynCapMPCpadded",
                    416:     "Dynamic Capability Message, IP/Multicast, cap data padded",
                    417:     { 0x0, 0x1, 0x5, 0x0, 0x1, 0x0, 0x2, 0x0 },
                    418:       8, SHOULD_PARSE, /* You can though add padding to the capability data */
                    419:   },
                    420:   { "DynCapMPCoverflow",
                    421:     "Dynamic Capability Message, IP/Multicast, cap data != length",
                    422:     { 0x0, 0x1, 0x3, 0x0, 0x1, 0x0, 0x2, 0x0 },
                    423:       8, SHOULD_ERR,
                    424:   },
                    425:   { NULL, NULL, {0}, 0, 0}
                    426: };
                    427: 
                    428: /* Entire Optional-Parameters block */
                    429: struct test_segment opt_params[] =
                    430: {
                    431:   { "Cap-singlets",
                    432:     "One capability per Optional-Param",
                    433:     { 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
                    434:       0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
                    435:       0x02, 0x02, 0x80, 0x00, /* RR (old) */
                    436:       0x02, 0x02, 0x02, 0x00, /* RR */  
                    437:     },
                    438:     24, SHOULD_PARSE,
                    439:   },
                    440:   { "Cap-series",
                    441:     "Series of capability, one Optional-Param",
                    442:     { 0x02, 0x10,
                    443:       0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
                    444:       0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
                    445:       0x80, 0x00, /* RR (old) */
                    446:       0x02, 0x00, /* RR */  
                    447:     },
                    448:     18, SHOULD_PARSE,
                    449:   },
                    450:   { "AS4more",
                    451:     "AS4 capability after other caps (singlets)",
                    452:     { 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
                    453:       0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
                    454:       0x02, 0x02, 0x80, 0x00, /* RR (old) */
                    455:       0x02, 0x02, 0x02, 0x00, /* RR */
                    456:       0x02, 0x06, 0x41, 0x04, 0x00, 0x03, 0x00, 0x06  /* AS4: 1996614 */
                    457:     },
                    458:     32, SHOULD_PARSE, 196614,
                    459:   },
                    460:   { "AS4series",
                    461:     "AS4 capability, in series of capabilities",
                    462:     { 0x02, 0x16,
                    463:       0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
                    464:       0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
                    465:       0x80, 0x00, /* RR (old) */
                    466:       0x02, 0x00, /* RR */  
                    467:       0x41, 0x04, 0x00, 0x03, 0x00, 0x06  /* AS4: 1996614 */
                    468:     },
                    469:     24, SHOULD_PARSE, 196614,
                    470:   },
                    471:   { "AS4real",
                    472:     "AS4 capability, in series of capabilities",
                    473:     {
                    474:       0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/uni */
                    475:       0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/uni */
                    476:       0x02, 0x02, 0x80, 0x00, /* RR old */
                    477:       0x02, 0x02, 0x02, 0x00, /* RR */
                    478:       0x02, 0x06, 0x41, 0x04, 0x00, 0x03, 0x00, 0x06, /* AS4 */
                    479:     },
                    480:     32, SHOULD_PARSE, 196614,
                    481:   },
                    482:   { "AS4real2",
                    483:     "AS4 capability, in series of capabilities",
                    484:     {
                    485:       0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01,
                    486:       0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01,
                    487:       0x02, 0x02, 0x80, 0x00,
                    488:       0x02, 0x02, 0x02, 0x00,
                    489:       0x02, 0x06, 0x41, 0x04, 0x00, 0x00, 0xfc, 0x03,
                    490:       0x02, 0x09, 0x82, 0x07, 0x00, 0x01, 0x00, 0x01, 0x01, 0x80, 0x03,
                    491:       0x02, 0x09, 0x03, 0x07, 0x00, 0x01, 0x00, 0x01, 0x01, 0x40, 0x03,
                    492:       0x02, 0x02, 0x42, 0x00,
                    493:     },
                    494:     58, SHOULD_PARSE, 64515,
                    495:   },
                    496: 
                    497:   { NULL, NULL, {0}, 0, 0}
                    498: };
                    499: 
                    500: /* basic parsing test */
                    501: static void
                    502: parse_test (struct peer *peer, struct test_segment *t, int type)
                    503: {
                    504:   int ret;
                    505:   int capability = 0;
                    506:   as_t as4 = 0;
                    507:   int oldfailed = failed;
                    508:   int len = t->len;
                    509: #define RANDOM_FUZZ 35
                    510:   
                    511:   stream_reset (peer->ibuf);
                    512:   stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
                    513:   stream_set_getp (peer->ibuf, RANDOM_FUZZ);
                    514:   
                    515:   switch (type)
                    516:     {
                    517:       case CAPABILITY:
                    518:         stream_putc (peer->ibuf, BGP_OPEN_OPT_CAP);
                    519:         stream_putc (peer->ibuf, t->len);
                    520:         break;
                    521:       case DYNCAP:
                    522: /*        for (i = 0; i < BGP_MARKER_SIZE; i++)
                    523:           stream_putc (peer->, 0xff);
                    524:         stream_putw (s, 0);
                    525:         stream_putc (s, BGP_MSG_CAPABILITY);*/
                    526:         break;
                    527:     }
                    528:   stream_write (peer->ibuf, t->data, t->len);
                    529:   
                    530:   printf ("%s: %s\n", t->name, t->desc);
                    531: 
                    532:   switch (type)
                    533:     {
                    534:       case CAPABILITY:
                    535:         len += 2; /* to cover the OPT-Param header */
                    536:       case OPT_PARAM:
                    537:         printf ("len: %u\n", len);
                    538:         /* peek_for_as4 wants getp at capibility*/
                    539:         as4 = peek_for_as4_capability (peer, len);
                    540:         printf ("peek_for_as4: as4 is %u\n", as4);
                    541:         /* and it should leave getp as it found it */
                    542:         assert (stream_get_getp (peer->ibuf) == RANDOM_FUZZ);
                    543:         
                    544:         ret = bgp_open_option_parse (peer, len, &capability);
                    545:         break;
                    546:       case DYNCAP:
                    547:         ret = bgp_capability_receive (peer, t->len);
                    548:         break;
                    549:       default:
                    550:         printf ("unknown type %u\n", type);
                    551:         exit(1);
                    552:     }
                    553:   
                    554:   if (!ret && t->validate_afi)
                    555:     {
                    556:       safi_t safi = t->safi;
                    557:       
                    558:       if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid)
                    559:         failed++;
                    560:       
                    561:       printf ("MP: %u/%u (%u): recv %u, nego %u\n",
                    562:               t->afi, t->safi, safi,
                    563:               peer->afc_recv[t->afi][safi],
                    564:               peer->afc_nego[t->afi][safi]);
                    565:         
                    566:       if (t->afi_valid == VALID_AFI)
                    567:         {
                    568:         
                    569:           if (!peer->afc_recv[t->afi][safi])
                    570:             failed++;
                    571:           if (!peer->afc_nego[t->afi][safi])
                    572:             failed++;
                    573:         }
                    574:     }
                    575:   
                    576:   if (as4 != t->peek_for)
                    577:     {
                    578:       printf ("as4 %u != %u\n", as4, t->peek_for);
                    579:       failed++;
                    580:     }
                    581:   
                    582:   printf ("parsed?: %s\n", ret ? "no" : "yes");
                    583:   
                    584:   if (ret != t->parses)
                    585:     failed++;
                    586:   
                    587:   if (tty)
                    588:     printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET 
                    589:                                          : VT100_GREEN "OK" VT100_RESET);
                    590:   else
                    591:     printf ("%s", (failed > oldfailed) ? "failed!" : "OK" );
                    592:   
                    593:   if (failed)
                    594:     printf (" (%u)", failed);
                    595:   
                    596:   printf ("\n\n");
                    597: }
                    598: 
                    599: static struct bgp *bgp;
                    600: static as_t asn = 100;
                    601: 
                    602: int
                    603: main (void)
                    604: {
                    605:   struct peer *peer;
                    606:   int i, j;
                    607:   
                    608:   conf_bgp_debug_fsm = -1UL;
                    609:   conf_bgp_debug_events = -1UL;
                    610:   conf_bgp_debug_packet = -1UL;
                    611:   conf_bgp_debug_normal = -1UL;
                    612:   conf_bgp_debug_as4 = -1UL;
                    613:   term_bgp_debug_fsm = -1UL;
                    614:   term_bgp_debug_events = -1UL;
                    615:   term_bgp_debug_packet = -1UL;
                    616:   term_bgp_debug_normal = -1UL;
                    617:   term_bgp_debug_as4 = -1UL;
                    618:   
                    619:   master = thread_master_create ();
                    620:   bgp_master_init ();
1.1.1.3 ! misho     621:   bgp_option_set (BGP_OPT_NO_LISTEN);
1.1       misho     622:   
                    623:   if (fileno (stdout) >= 0) 
                    624:     tty = isatty (fileno (stdout));
                    625:   
                    626:   if (bgp_get (&bgp, &asn, NULL))
                    627:     return -1;
                    628:   
                    629:   peer = peer_create_accept (bgp);
1.1.1.3 ! misho     630:   peer->host = (char *) "foo";
1.1       misho     631:   
                    632:   for (i = AFI_IP; i < AFI_MAX; i++)
                    633:     for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
                    634:       {
                    635:         peer->afc[i][j] = 1;
                    636:         peer->afc_adv[i][j] = 1;
                    637:       }
                    638:   
                    639:   i = 0;
                    640:   while (mp_segments[i].name)
                    641:     parse_test (peer, &mp_segments[i++], CAPABILITY);
                    642: 
                    643:   /* These tests assume mp_segments tests set at least
                    644:    * one of the afc_nego's
                    645:    */
                    646:   i = 0;
                    647:   while (test_segments[i].name)   
                    648:     parse_test (peer, &test_segments[i++], CAPABILITY);
                    649:   
                    650:   i = 0;
                    651:   while (misc_segments[i].name)
                    652:     parse_test (peer, &misc_segments[i++], CAPABILITY);
                    653: 
                    654:   i = 0;
                    655:   while (opt_params[i].name)
                    656:     parse_test (peer, &opt_params[i++], OPT_PARAM);
                    657: 
                    658:   SET_FLAG (peer->cap, PEER_CAP_DYNAMIC_ADV);
                    659:   peer->status = Established;
                    660:   
                    661:   i = 0;
                    662:   while (dynamic_cap_msgs[i].name)
                    663:     parse_test (peer, &dynamic_cap_msgs[i++], DYNCAP);
                    664:   
                    665:   printf ("failures: %d\n", failed);
                    666:   return failed;
                    667: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>