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