Annotation of embedaddon/quagga/tests/bgp_mp_attr_test.c, revision 1.1.1.2

1.1.1.2 ! misho       1: /* this testcase is currently broken
        !             2:  * -- 2012-05-01 David Lamparter <equinox@diac24.net>
        !             3:  */
        !             4: int main() { return 0; }
        !             5: 
1.1       misho       6: #include <zebra.h>
                      7: 
                      8: #include "vty.h"
                      9: #include "stream.h"
                     10: #include "privs.h"
                     11: #include "memory.h"
                     12: 
                     13: #include "bgpd/bgpd.h"
                     14: #include "bgpd/bgp_attr.h"
                     15: #include "bgpd/bgp_open.h"
                     16: #include "bgpd/bgp_debug.h"
                     17: 
                     18: #define VT100_RESET "\x1b[0m"
                     19: #define VT100_RED "\x1b[31m"
                     20: #define VT100_GREEN "\x1b[32m"
                     21: #define VT100_YELLOW "\x1b[33m"
                     22: 
                     23: 
                     24: #define CAPABILITY 0
                     25: #define DYNCAP     1
                     26: #define OPT_PARAM  2
                     27: 
                     28: /* need these to link in libbgp */
                     29: struct zebra_privs_t *bgpd_privs = NULL;
                     30: struct thread_master *master = NULL;
                     31: 
1.1.1.2 ! misho      32: #if 0
1.1       misho      33: static int failed = 0;
                     34: static int tty = 0;
                     35: 
                     36: /* test segments to parse and validate, and use for other tests */
                     37: static struct test_segment {
                     38:   const char *name;
                     39:   const char *desc;
                     40:   const u_char data[1024];
                     41:   int len;
                     42: #define SHOULD_PARSE   0
                     43: #define SHOULD_ERR     -1
                     44:   int parses; /* whether it should parse or not */
                     45:   
                     46:   /* AFI/SAFI validation */
                     47:   afi_t afi;
                     48:   safi_t safi;
                     49: #define VALID_AFI 1
                     50: #define INVALID_AFI 0
                     51:   int afi_valid;
                     52: } mp_reach_segments [] = 
                     53: {
                     54:   { "IPv6",
                     55:     "IPV6 MP Reach, global nexthop, 1 NLRI", 
                     56:     {
                     57:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                     58:       /* nexthop bytes */      16,
                     59:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,
                     60:                                 0xaa, 0xbb, 0xcc, 0xdd,
                     61:                                 0x3,  0x4,  0x5,  0x6,
                     62:                                 0xa1, 0xa2, 0xa3, 0xa4,
                     63:       /* SNPA (defunct, MBZ) */        0x0,
                     64:       /* NLRI tuples */                32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                     65:     },
                     66:     (4 + 16 + 1 + 5), 
                     67:     SHOULD_PARSE,
                     68:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                     69:   },
                     70:   { "IPv6-2",
                     71:     "IPV6 MP Reach, global nexthop, 2 NLRIs", 
                     72:     {
                     73:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                     74:       /* nexthop bytes */      16,
                     75:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,   /* ffee:102:... */
                     76:                                 0xaa, 0xbb, 0xcc, 0xdd,
                     77:                                 0x3,  0x4,  0x5,  0x6,
                     78:                                 0xa1, 0xa2, 0xa3, 0xa4,
                     79:       /* SNPA (defunct, MBZ) */        0x0,
                     80:       /* NLRI tuples */                32, 
                     81:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                     82:                                 64,
                     83:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                     84:                                 0x0,  0x2,  0x0, 0x3,
                     85:     },
                     86:     (4 + 16 + 1 + 5 + 9), 
                     87:     SHOULD_PARSE,
                     88:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                     89:   },
                     90:   { "IPv6-default",
                     91:     "IPV6 MP Reach, global nexthop, 2 NLRIs + default", 
                     92:     {
                     93:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                     94:       /* nexthop bytes */      16,
                     95:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,
                     96:                                 0xaa, 0xbb, 0xcc, 0xdd,
                     97:                                 0x3,  0x4,  0x5,  0x6,
                     98:                                 0xa1, 0xa2, 0xa3, 0xa4,
                     99:       /* SNPA (defunct, MBZ) */        0x0,
                    100:       /* NLRI tuples */                32, 
                    101:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    102:                                 64,
                    103:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    104:                                 0x0,  0x2,  0x0, 0x3,
                    105:                                 0x0, /* ::/0 */
                    106:     },
                    107:     (4 + 16 + 1 + 5 + 9 + 1),
                    108:     SHOULD_PARSE,
                    109:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    110:   },
                    111:   { "IPv6-lnh",
                    112:     "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default", 
                    113:     {
                    114:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    115:       /* nexthop bytes */      32,
                    116:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */
                    117:                                 0xaa, 0xbb, 0xcc, 0xdd,
                    118:                                 0x3,  0x4,  0x5,  0x6,
                    119:                                 0xa1, 0xa2, 0xa3, 0xa4,
                    120:       /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */
                    121:                                 0x0,  0x0,  0x0,  0x0,
                    122:                                 0x2,  0x10, 0x2,  0xff,
                    123:                                 0x1,  0x2,  0x3,  0x4,
                    124:       /* SNPA (defunct, MBZ) */        0x0,
                    125:       /* NLRI tuples */                32, 
                    126:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    127:                                 64,
                    128:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    129:                                 0x0,  0x2,  0x0, 0x3,
                    130:                                 0x0, /* ::/0 */
                    131:     },
                    132:     (4 + 32 + 1 + 5 + 9 + 1),
                    133:     SHOULD_PARSE,
                    134:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    135:   },
                    136:   { "IPv6-nhlen",
                    137:     "IPV6 MP Reach, inappropriate nexthop length", 
                    138:     {
                    139:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    140:       /* nexthop bytes */      4,
                    141:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */
                    142:                                 0xaa, 0xbb, 0xcc, 0xdd,
                    143:                                 0x3,  0x4,  0x5,  0x6,
                    144:                                 0xa1, 0xa2, 0xa3, 0xa4,
                    145:       /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */
                    146:                                 0x0,  0x0,  0x0,  0x0,
                    147:                                 0x2,  0x10, 0x2,  0xff,
                    148:                                 0x1,  0x2,  0x3,  0x4,
                    149:       /* SNPA (defunct, MBZ) */        0x0,
                    150:       /* NLRI tuples */                32, 
                    151:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    152:                                 64,
                    153:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    154:                                 0x0,  0x2,  0x0, 0x3,
                    155:                                 0x0, /* ::/0 */
                    156:     },
                    157:     (4 + 32 + 1 + 5 + 9 + 1),
                    158:     SHOULD_ERR,
                    159:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    160:   },
                    161:   { "IPv6-nhlen2",
                    162:     "IPV6 MP Reach, invalid nexthop length", 
                    163:     {
                    164:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    165:       /* nexthop bytes */      5,
                    166:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */
                    167:                                 0xaa, 0xbb, 0xcc, 0xdd,
                    168:                                 0x3,  0x4,  0x5,  0x6,
                    169:                                 0xa1, 0xa2, 0xa3, 0xa4,
                    170:       /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */
                    171:                                 0x0,  0x0,  0x0,  0x0,
                    172:                                 0x2,  0x10, 0x2,  0xff,
                    173:                                 0x1,  0x2,  0x3,  0x4,
                    174:       /* SNPA (defunct, MBZ) */        0x0,
                    175:       /* NLRI tuples */                32, 
                    176:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    177:                                 64,
                    178:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    179:                                 0x0,  0x2,  0x0, 0x3,
                    180:                                 0x0, /* ::/0 */
                    181:     },
                    182:     (4 + 32 + 1 + 5 + 9 + 1),
                    183:     SHOULD_ERR,
                    184:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    185:   },
                    186:   { "IPv6-nhlen3",
                    187:     "IPV6 MP Reach, nexthop length overflow", 
                    188:     {
                    189:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    190:       /* nexthop bytes */      32,
                    191:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */
                    192:                                 0xaa, 0xbb, 0xcc, 0xdd,
                    193:                                 0x3,  0x4,  0x5,  0x6,
                    194:                                 0xa1, 0xa2, 0xa3, 0xa4,
                    195:     },
                    196:     (4 + 16),
                    197:     SHOULD_ERR,
                    198:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    199:   },
                    200:   { "IPv6-nhlen4",
                    201:     "IPV6 MP Reach, nexthop length short", 
                    202:     {
                    203:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    204:       /* nexthop bytes */      16,
                    205:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */
                    206:                                 0xaa, 0xbb, 0xcc, 0xdd,
                    207:                                 0x3,  0x4,  0x5,  0x6,
                    208:                                 0xa1, 0xa2, 0xa3, 0xa4,
                    209:       /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */
                    210:                                 0x0,  0x0,  0x0,  0x0,
                    211:                                 0x2,  0x10, 0x2,  0xff,
                    212:                                 0x1,  0x2,  0x3,  0x4,
                    213:       /* SNPA (defunct, MBZ) */        0x0,
                    214:       /* NLRI tuples */                32, 
                    215:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    216:                                 64,
                    217:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    218:                                 0x0,  0x2,  0x0, 0x3,
                    219:                                 0x0, /* ::/0 */
                    220:     },
                    221:     (4 + 32 + 1 + 5 + 9 + 1),
                    222:     SHOULD_ERR,
                    223:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    224:   },
                    225:   { "IPv6-nlri",
                    226:     "IPV6 MP Reach, NLRI bitlen overflow", 
                    227:     {
                    228:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    229:       /* nexthop bytes */      32,
                    230:       /* Nexthop (global) */   0xff, 0xfe, 0x1,  0x2,  /* fffe:102:... */
                    231:                                 0xaa, 0xbb, 0xcc, 0xdd,
                    232:                                 0x3,  0x4,  0x5,  0x6,
                    233:                                 0xa1, 0xa2, 0xa3, 0xa4,
                    234:       /* Nexthop (local) */     0xfe, 0x80, 0x0,  0x0,  /* fe80::210:2ff:.. */
                    235:                                 0x0,  0x0,  0x0,  0x0,
                    236:                                 0x2,  0x10, 0x2,  0xff,
                    237:                                 0x1,  0x2,  0x3,  0x4,
                    238:       /* SNPA (defunct, MBZ) */        0x0,
                    239:       /* NLRI tuples */                120, 
                    240:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    241:                                 64,
                    242:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    243:                                 0x0,  0x2,  0x0, 0x3,
                    244:                                 0, /* ::/0 */
                    245:     },
                    246:     (4 + 32 + 1 + 5 + 9 + 1),
                    247:     SHOULD_ERR,
                    248:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    249:   },
                    250:   { "IPv4",
                    251:     "IPv4 MP Reach, 2 NLRIs + default", 
                    252:     {
                    253:       /* AFI / SAFI */         0x0, AFI_IP, SAFI_UNICAST,
                    254:       /* nexthop bytes */      4,
                    255:       /* Nexthop */            192, 168,   0,  1, 
                    256:       /* SNPA (defunct, MBZ) */        0x0,
                    257:       /* NLRI tuples */                16, 10, 1,    /* 10.1/16 */
                    258:                                 17, 10, 2, 3, /* 10.2.3/17 */
                    259:                                 0, /* 0/0 */
                    260:     },
                    261:     (4 + 4 + 1 + 3 + 4 + 1),
                    262:     SHOULD_PARSE,
                    263:     AFI_IP, SAFI_UNICAST, VALID_AFI,
                    264:   },
                    265:   { "IPv4-nhlen",
                    266:     "IPv4 MP Reach, nexthop lenth overflow", 
                    267:     {
                    268:       /* AFI / SAFI */         0x0, AFI_IP, SAFI_UNICAST,
                    269:       /* nexthop bytes */      32,
                    270:       /* Nexthop */            192, 168,   0,  1, 
                    271:       /* SNPA (defunct, MBZ) */        0x0,
                    272:       /* NLRI tuples */                16, 10, 1,    /* 10.1/16 */
                    273:                                 17, 10, 2, 3, /* 10.2.3/17 */
                    274:                                 0, /* 0/0 */
                    275:     },
                    276:     (4 + 4 + 1 + 3 + 4 + 1),
                    277:     SHOULD_ERR,
                    278:     AFI_IP, SAFI_UNICAST, VALID_AFI,
                    279:   },
                    280:   { "IPv4-nlrilen",
                    281:     "IPv4 MP Reach, nlri lenth overflow", 
                    282:     {
                    283:       /* AFI / SAFI */         0x0, AFI_IP, SAFI_UNICAST,
                    284:       /* nexthop bytes */      4,
                    285:       /* Nexthop */            192, 168,   0,  1, 
                    286:       /* SNPA (defunct, MBZ) */        0x0,
                    287:       /* NLRI tuples */                16, 10, 1,    /* 10.1/16 */
                    288:                                 30, 10, 
                    289:                                 0, /* 0/0 */
                    290:     },
                    291:     (4 + 4 + 1 + 3 + 2 + 1),
                    292:     SHOULD_ERR,
                    293:     AFI_IP, SAFI_UNICAST, VALID_AFI,
                    294:   },
1.1.1.2 ! misho     295:   { "IPv4-MLVPN",
        !           296:     "IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, 3 NLRIs", 
1.1       misho     297:     {
1.1.1.2 ! misho     298:       /* AFI / SAFI */         0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
1.1       misho     299:       /* nexthop bytes */      12,
                    300:       /* RD */                 0, 0, 1, 2,
                    301:                                 0, 0xff, 3, 4,
                    302:       /* Nexthop */            192, 168,   0,  1, 
                    303:       /* SNPA (defunct, MBZ) */        0x0,
                    304:       /* NLRI tuples */                16, 10, 1,    /* 10.1/16 */
                    305:                                 17, 10, 2, 3,  /* 10.2.3/17 */
                    306:                                 0, /* 0/0 */
                    307:     },
                    308:     (4 + 12 + 1 + 3 + 4 + 1),
                    309:     SHOULD_PARSE,
                    310:     AFI_IP, SAFI_UNICAST, VALID_AFI,
                    311:   },
                    312:   /* From bug #385 */
                    313:   { "IPv6-bug",
                    314:     "IPv6, global nexthop, 1 default NLRI", 
                    315:     {
                    316:       /* AFI / SAFI */         0x0, 0x2, 0x1,
                    317:       /* nexthop bytes */      0x20,
                    318:       /* Nexthop (global) */   0x20, 0x01, 0x04, 0x70, 
                    319:                                 0x00, 0x01, 0x00, 0x06,
                    320:                                 0x00, 0x00, 0x00, 0x00,
                    321:                                 0x00, 0x00, 0x00, 0x01, 
                    322:       /* Nexthop (local) */     0xfe, 0x80, 0x00, 0x00, 
                    323:                                 0x00, 0x00, 0x00, 0x00,
                    324:                                 0x02, 0x0c, 0xdb, 0xff, 
                    325:                                 0xfe, 0xfe, 0xeb, 0x00,
                    326:       /* SNPA (defunct, MBZ) */        0,
                    327:       /* NLRI tuples */                /* Should have 0 here for ::/0, but dont */
                    328:     },
                    329:     37,
                    330:     SHOULD_ERR,
                    331:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    332:   },
                    333:   
                    334:   { NULL, NULL, {0}, 0, 0}
                    335: };
                    336: 
                    337: /* MP_UNREACH_NLRI tests */
                    338: static struct test_segment mp_unreach_segments [] =
                    339: {
                    340:   { "IPv6-unreach",
                    341:     "IPV6 MP Unreach, 1 NLRI", 
                    342:     {
                    343:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    344:       /* NLRI tuples */                32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    345:     },
                    346:     (3 + 5), 
                    347:     SHOULD_PARSE,
                    348:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    349:   },
                    350:   { "IPv6-unreach2",
                    351:     "IPV6 MP Unreach, 2 NLRIs", 
                    352:     {
                    353:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    354:       /* NLRI tuples */                32, 
                    355:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    356:                                 64,
                    357:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    358:                                 0x0,  0x2,  0x0, 0x3,
                    359:     },
                    360:     (3 + 5 + 9), 
                    361:     SHOULD_PARSE,
                    362:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    363:   },
                    364:   { "IPv6-unreach-default",
                    365:     "IPV6 MP Unreach, 2 NLRIs + default", 
                    366:     {
                    367:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    368:       /* NLRI tuples */                32, 
                    369:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    370:                                 64,
                    371:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    372:                                 0x0,  0x2,  0x0, 0x3,
                    373:                                 0x0, /* ::/0 */
                    374:     },
                    375:     (3 + 5 + 9 + 1),
                    376:     SHOULD_PARSE,
                    377:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    378:   },
                    379:   { "IPv6-unreach-nlri",
                    380:     "IPV6 MP Unreach, NLRI bitlen overflow", 
                    381:     {
                    382:       /* AFI / SAFI */         0x0, AFI_IP6, SAFI_UNICAST,
                    383:       /* NLRI tuples */                120, 
                    384:                                 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
                    385:                                 64,
                    386:                                 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
                    387:                                 0x0,  0x2,  0x0, 0x3,
                    388:                                 0, /* ::/0 */
                    389:     },
                    390:     (3 + 5 + 9 + 1),
                    391:     SHOULD_ERR,
                    392:     AFI_IP6, SAFI_UNICAST, VALID_AFI,
                    393:   },
                    394:   { "IPv4-unreach",
                    395:     "IPv4 MP Unreach, 2 NLRIs + default", 
                    396:     {
                    397:       /* AFI / SAFI */         0x0, AFI_IP, SAFI_UNICAST,
                    398:       /* NLRI tuples */                16, 10, 1,    /* 10.1/16 */
                    399:                                 17, 10, 2, 3, /* 10.2.3/17 */
                    400:                                 0, /* 0/0 */
                    401:     },
                    402:     (3 + 3 + 4 + 1),
                    403:     SHOULD_PARSE,
                    404:     AFI_IP, SAFI_UNICAST, VALID_AFI,
                    405:   },
                    406:   { "IPv4-unreach-nlrilen",
                    407:     "IPv4 MP Unreach, nlri length overflow", 
                    408:     {
                    409:       /* AFI / SAFI */         0x0, AFI_IP, SAFI_UNICAST,
                    410:       /* NLRI tuples */                16, 10, 1,    /* 10.1/16 */
                    411:                                 30, 10, 
                    412:                                 0, /* 0/0 */
                    413:     },
                    414:     (3 + 3 + 2 + 1),
                    415:     SHOULD_ERR,
                    416:     AFI_IP, SAFI_UNICAST, VALID_AFI,
                    417:   },
1.1.1.2 ! misho     418:   { "IPv4-unreach-MLVPN",
        !           419:     "IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs", 
1.1       misho     420:     {
1.1.1.2 ! misho     421:       /* AFI / SAFI */         0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
1.1       misho     422:       /* nexthop bytes */      12,
                    423:       /* RD */                 0, 0, 1, 2,
                    424:                                 0, 0xff, 3, 4,
                    425:       /* Nexthop */            192, 168,   0,  1, 
                    426:       /* SNPA (defunct, MBZ) */        0x0,
                    427:       /* NLRI tuples */                16, 10, 1,    /* 10.1/16 */
                    428:                                 17, 10, 2, 3,  /* 10.2.3/17 */
                    429:                                 0, /* 0/0 */
                    430:     },
                    431:     (3 + 3 + 4 + 1),
                    432:     SHOULD_PARSE,
                    433:     AFI_IP, SAFI_UNICAST, VALID_AFI,
                    434:   },
                    435:   { NULL, NULL, {0}, 0, 0}
                    436: };
                    437: 
                    438: 
                    439: /* basic parsing test */
                    440: static void
                    441: parse_test (struct peer *peer, struct test_segment *t, int type)
                    442: {
                    443:   int ret;
                    444:   int oldfailed = failed;
                    445:   struct attr attr;
                    446:   struct bgp_nlri nlri;
                    447: #define RANDOM_FUZZ 35
                    448:   
                    449:   stream_reset (peer->ibuf);
                    450:   stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
                    451:   stream_set_getp (peer->ibuf, RANDOM_FUZZ);
                    452:   
                    453:   stream_write (peer->ibuf, t->data, t->len);
                    454:   
                    455:   printf ("%s: %s\n", t->name, t->desc);
                    456: 
                    457:   if (type == BGP_ATTR_MP_REACH_NLRI)
1.1.1.2 ! misho     458:     ret = bgp_mp_reach_parse (peer, t->len, &attr, BGP_ATTR_FLAG_OPTIONAL, BGP_INPUT_PNT (peer), &nlri);
1.1       misho     459:   else
1.1.1.2 ! misho     460:     ret = bgp_mp_unreach_parse (peer, t->len, BGP_ATTR_FLAG_OPTIONAL, BGP_INPUT_PNT (peer), &nlri);
1.1       misho     461: 
                    462:   if (!ret)
                    463:     {
                    464:       safi_t safi = t->safi;
                    465:       
                    466:       if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid)
                    467:         failed++;
                    468:       
                    469:       printf ("MP: %u/%u (%u): recv %u, nego %u\n",
                    470:               t->afi, t->safi, safi,
                    471:               peer->afc_recv[t->afi][safi],
                    472:               peer->afc_nego[t->afi][safi]);
                    473:     }
                    474:   
                    475:   printf ("parsed?: %s\n", ret ? "no" : "yes");
                    476:   
                    477:   if (ret != t->parses)
                    478:     failed++;
                    479:   
                    480:   if (tty)
                    481:     printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET 
                    482:                                          : VT100_GREEN "OK" VT100_RESET);
                    483:   else
                    484:     printf ("%s", (failed > oldfailed) ? "failed!" : "OK" );
                    485:   
                    486:   if (failed)
                    487:     printf (" (%u)", failed);
                    488:   
                    489:   printf ("\n\n");
                    490: }
                    491: 
                    492: static struct bgp *bgp;
                    493: static as_t asn = 100;
                    494: 
                    495: int
                    496: main (void)
                    497: {
                    498:   struct peer *peer;
                    499:   int i, j;
                    500:   
                    501:   conf_bgp_debug_fsm = -1UL;
                    502:   conf_bgp_debug_events = -1UL;
                    503:   conf_bgp_debug_packet = -1UL;
                    504:   conf_bgp_debug_normal = -1UL;
                    505:   conf_bgp_debug_as4 = -1UL;
                    506:   term_bgp_debug_fsm = -1UL;
                    507:   term_bgp_debug_events = -1UL;
                    508:   term_bgp_debug_packet = -1UL;
                    509:   term_bgp_debug_normal = -1UL;
                    510:   term_bgp_debug_as4 = -1UL;
                    511:   
                    512:   master = thread_master_create ();
                    513:   bgp_master_init ();
                    514:   
                    515:   if (fileno (stdout) >= 0) 
                    516:     tty = isatty (fileno (stdout));
                    517:   
                    518:   if (bgp_get (&bgp, &asn, NULL))
                    519:     return -1;
                    520:   
                    521:   peer = peer_create_accept (bgp);
                    522:   peer->host = "foo";
                    523:   
                    524:   for (i = AFI_IP; i < AFI_MAX; i++)
                    525:     for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
                    526:       {
                    527:         peer->afc[i][j] = 1;
                    528:         peer->afc_adv[i][j] = 1;
                    529:       }
                    530:   
                    531:   i = 0;
                    532:   while (mp_reach_segments[i].name)
                    533:     parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI);
                    534: 
                    535:   i = 0;
                    536:   while (mp_unreach_segments[i].name)
                    537:     parse_test (peer, &mp_unreach_segments[i++], BGP_ATTR_MP_UNREACH_NLRI);
                    538: 
                    539:   printf ("failures: %d\n", failed);
                    540:   return failed;
                    541: }
1.1.1.2 ! misho     542: #endif /* #if 0 */

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