2 * Copyright (C) 2008 Sun Microsystems, Inc.
4 * This file is part of Quagga.
6 * Quagga is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * Quagga is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Quagga; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
32 #include "bgpd/bgpd.h"
33 #include "bgpd/bgp_attr.h"
34 #include "bgpd/bgp_open.h"
35 #include "bgpd/bgp_debug.h"
36 #include "bgpd/bgp_route.h"
37 #include "bgpd/bgp_packet.h"
38 #include "bgpd/bgp_mplsvpn.h"
39 #include "bgpd/bgp_nexthop.h"
41 #define VT100_RESET "\x1b[0m"
42 #define VT100_RED "\x1b[31m"
43 #define VT100_GREEN "\x1b[32m"
44 #define VT100_YELLOW "\x1b[33m"
51 /* need these to link in libbgp */
52 struct zebra_privs_t
*bgpd_privs
= NULL
;
53 struct thread_master
*master
= NULL
;
55 static int failed
= 0;
58 /* test segments to parse and validate, and use for other tests */
59 static struct test_segment
{
62 const u_char data
[1024];
64 #define SHOULD_PARSE 0
66 int parses
; /* whether it should parse or not */
68 /* AFI/SAFI validation */
74 } mp_reach_segments
[] =
77 "IPV6 MP Reach, global nexthop, 1 NLRI",
79 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
80 /* nexthop bytes */ 16,
81 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2,
82 0xaa, 0xbb, 0xcc, 0xdd,
84 0xa1, 0xa2, 0xa3, 0xa4,
85 /* SNPA (defunct, MBZ) */ 0x0,
86 /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
90 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
93 "IPV6 MP Reach, global nexthop, 2 NLRIs",
95 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
96 /* nexthop bytes */ 16,
97 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* ffee:102:... */
98 0xaa, 0xbb, 0xcc, 0xdd,
100 0xa1, 0xa2, 0xa3, 0xa4,
101 /* SNPA (defunct, MBZ) */ 0x0,
102 /* NLRI tuples */ 32,
103 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
105 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
108 (4 + 16 + 1 + 5 + 9),
110 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
113 "IPV6 MP Reach, global nexthop, 2 NLRIs + default",
115 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
116 /* nexthop bytes */ 16,
117 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2,
118 0xaa, 0xbb, 0xcc, 0xdd,
120 0xa1, 0xa2, 0xa3, 0xa4,
121 /* SNPA (defunct, MBZ) */ 0x0,
122 /* NLRI tuples */ 32,
123 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
125 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
129 (4 + 16 + 1 + 5 + 9 + 1),
131 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
134 "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default",
136 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
137 /* nexthop bytes */ 32,
138 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
139 0xaa, 0xbb, 0xcc, 0xdd,
141 0xa1, 0xa2, 0xa3, 0xa4,
142 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
144 0x2, 0x10, 0x2, 0xff,
146 /* SNPA (defunct, MBZ) */ 0x0,
147 /* NLRI tuples */ 32,
148 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
150 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
154 (4 + 32 + 1 + 5 + 9 + 1),
156 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
159 "IPV6 MP Reach, inappropriate nexthop length",
161 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
162 /* nexthop bytes */ 4,
163 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
164 0xaa, 0xbb, 0xcc, 0xdd,
166 0xa1, 0xa2, 0xa3, 0xa4,
167 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
169 0x2, 0x10, 0x2, 0xff,
171 /* SNPA (defunct, MBZ) */ 0x0,
172 /* NLRI tuples */ 32,
173 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
175 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
179 (4 + 32 + 1 + 5 + 9 + 1),
181 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
184 "IPV6 MP Reach, invalid nexthop length",
186 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
187 /* nexthop bytes */ 5,
188 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
189 0xaa, 0xbb, 0xcc, 0xdd,
191 0xa1, 0xa2, 0xa3, 0xa4,
192 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
194 0x2, 0x10, 0x2, 0xff,
196 /* SNPA (defunct, MBZ) */ 0x0,
197 /* NLRI tuples */ 32,
198 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
200 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
204 (4 + 32 + 1 + 5 + 9 + 1),
206 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
209 "IPV6 MP Reach, nexthop length overflow",
211 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
212 /* nexthop bytes */ 32,
213 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
214 0xaa, 0xbb, 0xcc, 0xdd,
216 0xa1, 0xa2, 0xa3, 0xa4,
220 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
223 "IPV6 MP Reach, nexthop length short",
225 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
226 /* nexthop bytes */ 16,
227 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
228 0xaa, 0xbb, 0xcc, 0xdd,
230 0xa1, 0xa2, 0xa3, 0xa4,
231 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
233 0x2, 0x10, 0x2, 0xff,
235 /* SNPA (defunct, MBZ) */ 0x0,
236 /* NLRI tuples */ 32,
237 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
239 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
243 (4 + 32 + 1 + 5 + 9 + 1),
245 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
248 "IPV6 MP Reach, NLRI bitlen overflow",
250 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
251 /* nexthop bytes */ 32,
252 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
253 0xaa, 0xbb, 0xcc, 0xdd,
255 0xa1, 0xa2, 0xa3, 0xa4,
256 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
258 0x2, 0x10, 0x2, 0xff,
260 /* SNPA (defunct, MBZ) */ 0x0,
261 /* NLRI tuples */ 120,
262 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
264 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
268 (4 + 32 + 1 + 5 + 9 + 1),
270 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
273 "IPv4 MP Reach, 2 NLRIs + default",
275 /* AFI / SAFI */ 0x0, AFI_IP
, SAFI_UNICAST
,
276 /* nexthop bytes */ 4,
277 /* Nexthop */ 192, 168, 0, 1,
278 /* SNPA (defunct, MBZ) */ 0x0,
279 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
280 17, 10, 2, 3, /* 10.2.3/17 */
283 (4 + 4 + 1 + 3 + 4 + 1),
285 AFI_IP
, SAFI_UNICAST
, VALID_AFI
,
288 "IPv4 MP Reach, nexthop lenth overflow",
290 /* AFI / SAFI */ 0x0, AFI_IP
, SAFI_UNICAST
,
291 /* nexthop bytes */ 32,
292 /* Nexthop */ 192, 168, 0, 1,
293 /* SNPA (defunct, MBZ) */ 0x0,
294 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
295 17, 10, 2, 3, /* 10.2.3/17 */
298 (4 + 4 + 1 + 3 + 4 + 1),
300 AFI_IP
, SAFI_UNICAST
, VALID_AFI
,
303 "IPv4 MP Reach, nlri lenth overflow",
305 /* AFI / SAFI */ 0x0, AFI_IP
, SAFI_UNICAST
,
306 /* nexthop bytes */ 4,
307 /* Nexthop */ 192, 168, 0, 1,
308 /* SNPA (defunct, MBZ) */ 0x0,
309 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
313 (4 + 4 + 1 + 3 + 2 + 1),
315 AFI_IP
, SAFI_UNICAST
, VALID_AFI
,
318 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs",
320 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
321 /* nexthop bytes */ 12,
322 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
324 /* Nexthop */ 192, 168, 0, 1,
325 /* SNPA (defunct, MBZ) */ 0x0,
326 /* NLRI tuples */ 88 + 16,
329 0, 0, /* RD_TYPE_AS */
330 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
333 0xff, 0, 0, /* tag */
335 0, 0, /* RD_TYPE_IP */
336 192, 168, 0, 1, /* IPv4 */
337 10, 2, 3, /* 10.2.3/17 */
339 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
341 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
343 { "IPv4-VPNv4-bogus-plen",
344 "IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len",
346 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
347 /* nexthop bytes */ 12,
350 /* Nexthop */ 192, 168, 0, 1,
351 /* SNPA (defunct, MBZ) */ 0x0,
352 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
353 17, 10, 2, 3, /* 10.2.3/17 */
356 (3 + 1 + 3*4 + 1 + 3 + 4 + 1),
358 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
360 { "IPv4-VPNv4-plen1-short",
361 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short",
363 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
364 /* nexthop bytes */ 12,
365 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
367 /* Nexthop */ 192, 168, 0, 1,
368 /* SNPA (defunct, MBZ) */ 0x0,
369 /* NLRI tuples */ 88 + 1,
372 0, 0, /* RD_TYPE_AS */
373 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
376 0xff, 0, 0, /* tag */
378 0, 0, /* RD_TYPE_IP */
379 192, 168, 0, 1, /* IPv4 */
380 10, 2, 3, /* 10.2.3/17 */
382 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
384 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
386 { "IPv4-VPNv4-plen1-long",
387 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long",
389 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
390 /* nexthop bytes */ 12,
391 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
393 /* Nexthop */ 192, 168, 0, 1,
394 /* SNPA (defunct, MBZ) */ 0x0,
395 /* NLRI tuples */ 88 + 32,
398 0, 0, /* RD_TYPE_AS */
399 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
402 0xff, 0, 0, /* tag */
404 0, 0, /* RD_TYPE_IP */
405 192, 168, 0, 1, /* IPv4 */
406 10, 2, 3, /* 10.2.3/17 */
408 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
410 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
412 { "IPv4-VPNv4-plenn-long",
413 "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long",
415 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
416 /* nexthop bytes */ 12,
417 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
419 /* Nexthop */ 192, 168, 0, 1,
420 /* SNPA (defunct, MBZ) */ 0x0,
421 /* NLRI tuples */ 88 + 16,
424 0, 0, /* RD_TYPE_AS */
425 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
428 0xff, 0, 0, /* tag */
430 0, 0, /* RD_TYPE_IP */
431 192, 168, 0, 1, /* IPv4 */
432 10, 2, 3, /* 10.2.3/17 */
435 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1),
437 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
439 { "IPv4-VPNv4-plenn-short",
440 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short",
442 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
443 /* nexthop bytes */ 12,
444 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
446 /* Nexthop */ 192, 168, 0, 1,
447 /* SNPA (defunct, MBZ) */ 0x0,
448 /* NLRI tuples */ 88 + 16,
451 0, 0, /* RD_TYPE_AS */
452 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
455 0xff, 0, 0, /* tag */
457 0, 0, /* RD_TYPE_IP */
458 192, 168, 0, 1, /* IPv4 */
459 10, 2, 3, /* 10.2.3/17 */
461 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
463 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
465 { "IPv4-VPNv4-bogus-rd-type",
466 "IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)",
468 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
469 /* nexthop bytes */ 12,
470 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
472 /* Nexthop */ 192, 168, 0, 1,
473 /* SNPA (defunct, MBZ) */ 0x0,
474 /* NLRI tuples */ 88 + 16,
477 0xff, 0, /* Bogus RD */
478 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
481 0xff, 0, 0, /* tag */
483 0, 0, /* RD_TYPE_IP */
484 192, 168, 0, 1, /* IPv4 */
485 10, 2, 3, /* 10.2.3/17 */
487 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
489 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
491 { "IPv4-VPNv4-0-nlri",
492 "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus",
494 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
495 /* nexthop bytes */ 12,
496 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
498 /* Nexthop */ 192, 168, 0, 1,
499 /* SNPA (defunct, MBZ) */ 0x0,
500 /* NLRI tuples */ 88 + 16,
503 0, 0, /* RD_TYPE_AS */
504 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
507 0xff, 0, 0, /* tag */
509 0, 0, /* RD_TYPE_IP */
510 192, 168, 0, 1, /* IPv4 */
511 10, 2, 3, /* 10.2.3/17 */
512 0 /* 0/0, bogus for vpnv4 ?? */
514 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1),
516 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
521 "IPv6, global nexthop, 1 default NLRI",
523 /* AFI / SAFI */ 0x0, 0x2, 0x1,
524 /* nexthop bytes */ 0x20,
525 /* Nexthop (global) */ 0x20, 0x01, 0x04, 0x70,
526 0x00, 0x01, 0x00, 0x06,
527 0x00, 0x00, 0x00, 0x00,
528 0x00, 0x00, 0x00, 0x01,
529 /* Nexthop (local) */ 0xfe, 0x80, 0x00, 0x00,
530 0x00, 0x00, 0x00, 0x00,
531 0x02, 0x0c, 0xdb, 0xff,
532 0xfe, 0xfe, 0xeb, 0x00,
533 /* SNPA (defunct, MBZ) */ 0,
534 /* NLRI tuples */ /* Should have 0 here for ::/0, but dont */
538 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
541 { NULL
, NULL
, {0}, 0, 0}
544 /* MP_UNREACH_NLRI tests */
545 static struct test_segment mp_unreach_segments
[] =
548 "IPV6 MP Unreach, 1 NLRI",
550 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
551 /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
555 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
558 "IPV6 MP Unreach, 2 NLRIs",
560 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
561 /* NLRI tuples */ 32,
562 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
564 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
569 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
571 { "IPv6-unreach-default",
572 "IPV6 MP Unreach, 2 NLRIs + default",
574 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
575 /* NLRI tuples */ 32,
576 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
578 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
584 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
586 { "IPv6-unreach-nlri",
587 "IPV6 MP Unreach, NLRI bitlen overflow",
589 /* AFI / SAFI */ 0x0, AFI_IP6
, SAFI_UNICAST
,
590 /* NLRI tuples */ 120,
591 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
593 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
599 AFI_IP6
, SAFI_UNICAST
, VALID_AFI
,
602 "IPv4 MP Unreach, 2 NLRIs + default",
604 /* AFI / SAFI */ 0x0, AFI_IP
, SAFI_UNICAST
,
605 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
606 17, 10, 2, 3, /* 10.2.3/17 */
611 AFI_IP
, SAFI_UNICAST
, VALID_AFI
,
613 { "IPv4-unreach-nlrilen",
614 "IPv4 MP Unreach, nlri length overflow",
616 /* AFI / SAFI */ 0x0, AFI_IP
, SAFI_UNICAST
,
617 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
623 AFI_IP
, SAFI_UNICAST
, VALID_AFI
,
625 { "IPv4-unreach-VPNv4",
626 "IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs",
628 /* AFI / SAFI */ 0x0, AFI_IP
, IANA_SAFI_MPLS_VPN
,
629 /* NLRI tuples */ 88 + 16,
632 0, 0, /* RD_TYPE_AS */
633 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
636 0xff, 0, 0, /* tag */
638 0, 0, /* RD_TYPE_IP */
639 192, 168, 0, 1, /* IPv4 */
640 10, 2, 3, /* 10.2.3/17 */
642 (3 + (1+3+8+2) + (1+3+8+3)),
644 AFI_IP
, IANA_SAFI_MPLS_VPN
, VALID_AFI
,
646 { NULL
, NULL
, {0}, 0, 0}
649 /* nlri_parse indicates 0 on successful parse, and -1 otherwise.
650 * attr_parse indicates BGP_ATTR_PARSE_PROCEED/0 on success,
651 * and BGP_ATTR_PARSE_ERROR/-1 or lower negative ret on err.
654 handle_result (struct peer
*peer
, struct test_segment
*t
,
655 int parse_ret
, int nlri_ret
)
657 int oldfailed
= failed
;
659 printf ("mp attr parsed?: %s\n", parse_ret
? "no" : "yes");
661 printf ("nrli parsed?: %s\n", nlri_ret
? "no" : "yes");
662 printf ("should parse?: %s\n", t
->parses
? "no" : "yes");
664 if ((parse_ret
!= 0 || nlri_ret
!= 0) != (t
->parses
!= 0))
669 printf ("%s", (failed
> oldfailed
) ? VT100_RED
"failed!" VT100_RESET
670 : VT100_GREEN
"OK" VT100_RESET
);
672 printf ("%s", (failed
> oldfailed
) ? "failed!" : "OK" );
675 printf (" (%u)", failed
);
680 /* basic parsing test */
682 parse_test (struct peer
*peer
, struct test_segment
*t
, int type
)
684 int parse_ret
= 0, nlri_ret
= 0;
685 struct attr attr
= { };
686 struct bgp_nlri nlri
= { };
687 struct bgp_attr_parser_args attr_args
= {
693 .flags
= BGP_ATTR_FLAG_OPTIONAL
,
694 .startp
= BGP_INPUT_PNT (peer
),
696 #define RANDOM_FUZZ 35
698 stream_reset (peer
->ibuf
);
699 stream_put (peer
->ibuf
, NULL
, RANDOM_FUZZ
);
700 stream_set_getp (peer
->ibuf
, RANDOM_FUZZ
);
702 stream_write (peer
->ibuf
, t
->data
, t
->len
);
704 printf ("%s: %s\n", t
->name
, t
->desc
);
706 if (type
== BGP_ATTR_MP_REACH_NLRI
)
707 parse_ret
= bgp_mp_reach_parse (&attr_args
, &nlri
);
709 parse_ret
= bgp_mp_unreach_parse (&attr_args
, &nlri
);
715 /* Convert AFI, SAFI to internal values, check. */
716 if (bgp_map_afi_safi_int2iana (nlri
.afi
, nlri
.safi
, &pkt_afi
, &pkt_safi
))
719 printf ("MP: %u(%u)/%u(%u): recv %u, nego %u\n",
720 nlri
.afi
, pkt_afi
, nlri
.safi
, pkt_safi
,
721 peer
->afc_recv
[nlri
.afi
][nlri
.safi
],
722 peer
->afc_nego
[nlri
.afi
][nlri
.safi
]);
727 if (type
== BGP_ATTR_MP_REACH_NLRI
)
728 nlri_ret
= bgp_nlri_parse (peer
, &attr
, &nlri
);
730 nlri_ret
= bgp_nlri_parse (peer
, NULL
, &nlri
);
732 zlog_err("xxxxxxxxxxxxxxxx nlri ret %u", nlri_ret
);
733 handle_result (peer
, t
, parse_ret
, nlri_ret
);
736 static struct bgp
*bgp
;
737 static as_t asn
= 100;
745 conf_bgp_debug_neighbor_events
= -1UL;
746 conf_bgp_debug_packet
= -1UL;
747 conf_bgp_debug_as4
= -1UL;
748 term_bgp_debug_neighbor_events
= -1UL;
749 term_bgp_debug_packet
= -1UL;
750 term_bgp_debug_as4
= -1UL;
753 master
= thread_master_create ();
756 bgp_option_set (BGP_OPT_NO_LISTEN
);
759 if (fileno (stdout
) >= 0)
760 tty
= isatty (fileno (stdout
));
762 if (bgp_get (&bgp
, &asn
, NULL
, BGP_INSTANCE_TYPE_DEFAULT
))
765 peer
= peer_create_accept (bgp
);
766 peer
->host
= (char *)"foo";
767 peer
->status
= Established
;
769 for (i
= AFI_IP
; i
< AFI_MAX
; i
++)
770 for (j
= SAFI_UNICAST
; j
< SAFI_MAX
; j
++)
773 peer
->afc_adv
[i
][j
] = 1;
777 while (mp_reach_segments
[i
].name
)
778 parse_test (peer
, &mp_reach_segments
[i
++], BGP_ATTR_MP_REACH_NLRI
);
781 while (mp_unreach_segments
[i
].name
)
782 parse_test (peer
, &mp_unreach_segments
[i
++], BGP_ATTR_MP_UNREACH_NLRI
);
784 printf ("failures: %d\n", failed
);