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