]> git.proxmox.com Git - mirror_frr.git/blame - tests/bgp_mp_attr_test.c
bgpd: Regularise bgp_update_receive, add missing notifies and checks
[mirror_frr.git] / tests / bgp_mp_attr_test.c
CommitLineData
46f4a4d2
PJ
1/*
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
1eab26bb
PJ
22#include <zebra.h>
23
1bf9f027 24#include "qobj.h"
1eab26bb
PJ
25#include "vty.h"
26#include "stream.h"
27#include "privs.h"
28#include "memory.h"
3f9c7369 29#include "queue.h"
039f3a34 30#include "filter.h"
1eab26bb
PJ
31
32#include "bgpd/bgpd.h"
33#include "bgpd/bgp_attr.h"
34#include "bgpd/bgp_open.h"
35#include "bgpd/bgp_debug.h"
48a5452b 36#include "bgpd/bgp_route.h"
96e52474 37#include "bgpd/bgp_packet.h"
48a5452b
PJ
38#include "bgpd/bgp_mplsvpn.h"
39#include "bgpd/bgp_nexthop.h"
1eab26bb
PJ
40
41#define VT100_RESET "\x1b[0m"
42#define VT100_RED "\x1b[31m"
43#define VT100_GREEN "\x1b[32m"
44#define VT100_YELLOW "\x1b[33m"
45
46
47#define CAPABILITY 0
48#define DYNCAP 1
49#define OPT_PARAM 2
50
51/* need these to link in libbgp */
52struct zebra_privs_t *bgpd_privs = NULL;
53struct thread_master *master = NULL;
54
55static int failed = 0;
56static int tty = 0;
57
58/* test segments to parse and validate, and use for other tests */
59static struct test_segment {
60 const char *name;
61 const char *desc;
62 const u_char data[1024];
63 int len;
64#define SHOULD_PARSE 0
65#define SHOULD_ERR -1
66 int parses; /* whether it should parse or not */
67
68 /* AFI/SAFI validation */
69 afi_t afi;
70 safi_t safi;
71#define VALID_AFI 1
72#define INVALID_AFI 0
73 int afi_valid;
74} mp_reach_segments [] =
75{
76 { "IPv6",
77 "IPV6 MP Reach, global nexthop, 1 NLRI",
78 {
79 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
80 /* nexthop bytes */ 16,
81 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2,
82 0xaa, 0xbb, 0xcc, 0xdd,
83 0x3, 0x4, 0x5, 0x6,
84 0xa1, 0xa2, 0xa3, 0xa4,
85 /* SNPA (defunct, MBZ) */ 0x0,
86 /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
87 },
88 (4 + 16 + 1 + 5),
89 SHOULD_PARSE,
90 AFI_IP6, SAFI_UNICAST, VALID_AFI,
91 },
92 { "IPv6-2",
93 "IPV6 MP Reach, global nexthop, 2 NLRIs",
94 {
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,
99 0x3, 0x4, 0x5, 0x6,
100 0xa1, 0xa2, 0xa3, 0xa4,
101 /* SNPA (defunct, MBZ) */ 0x0,
102 /* NLRI tuples */ 32,
103 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
104 64,
105 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
106 0x0, 0x2, 0x0, 0x3,
107 },
108 (4 + 16 + 1 + 5 + 9),
109 SHOULD_PARSE,
110 AFI_IP6, SAFI_UNICAST, VALID_AFI,
111 },
112 { "IPv6-default",
113 "IPV6 MP Reach, global nexthop, 2 NLRIs + default",
114 {
115 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
116 /* nexthop bytes */ 16,
117 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2,
118 0xaa, 0xbb, 0xcc, 0xdd,
119 0x3, 0x4, 0x5, 0x6,
120 0xa1, 0xa2, 0xa3, 0xa4,
121 /* SNPA (defunct, MBZ) */ 0x0,
122 /* NLRI tuples */ 32,
123 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
124 64,
125 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
126 0x0, 0x2, 0x0, 0x3,
127 0x0, /* ::/0 */
128 },
129 (4 + 16 + 1 + 5 + 9 + 1),
130 SHOULD_PARSE,
131 AFI_IP6, SAFI_UNICAST, VALID_AFI,
132 },
133 { "IPv6-lnh",
134 "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default",
135 {
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,
140 0x3, 0x4, 0x5, 0x6,
141 0xa1, 0xa2, 0xa3, 0xa4,
142 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
143 0x0, 0x0, 0x0, 0x0,
144 0x2, 0x10, 0x2, 0xff,
145 0x1, 0x2, 0x3, 0x4,
146 /* SNPA (defunct, MBZ) */ 0x0,
147 /* NLRI tuples */ 32,
148 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
149 64,
150 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
151 0x0, 0x2, 0x0, 0x3,
152 0x0, /* ::/0 */
153 },
154 (4 + 32 + 1 + 5 + 9 + 1),
155 SHOULD_PARSE,
156 AFI_IP6, SAFI_UNICAST, VALID_AFI,
157 },
158 { "IPv6-nhlen",
159 "IPV6 MP Reach, inappropriate nexthop length",
160 {
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,
165 0x3, 0x4, 0x5, 0x6,
166 0xa1, 0xa2, 0xa3, 0xa4,
167 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
168 0x0, 0x0, 0x0, 0x0,
169 0x2, 0x10, 0x2, 0xff,
170 0x1, 0x2, 0x3, 0x4,
171 /* SNPA (defunct, MBZ) */ 0x0,
172 /* NLRI tuples */ 32,
173 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
174 64,
175 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
176 0x0, 0x2, 0x0, 0x3,
177 0x0, /* ::/0 */
178 },
179 (4 + 32 + 1 + 5 + 9 + 1),
180 SHOULD_ERR,
181 AFI_IP6, SAFI_UNICAST, VALID_AFI,
182 },
183 { "IPv6-nhlen2",
184 "IPV6 MP Reach, invalid nexthop length",
185 {
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,
190 0x3, 0x4, 0x5, 0x6,
191 0xa1, 0xa2, 0xa3, 0xa4,
192 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
193 0x0, 0x0, 0x0, 0x0,
194 0x2, 0x10, 0x2, 0xff,
195 0x1, 0x2, 0x3, 0x4,
196 /* SNPA (defunct, MBZ) */ 0x0,
197 /* NLRI tuples */ 32,
198 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
199 64,
200 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
201 0x0, 0x2, 0x0, 0x3,
202 0x0, /* ::/0 */
203 },
204 (4 + 32 + 1 + 5 + 9 + 1),
205 SHOULD_ERR,
206 AFI_IP6, SAFI_UNICAST, VALID_AFI,
207 },
208 { "IPv6-nhlen3",
209 "IPV6 MP Reach, nexthop length overflow",
210 {
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,
215 0x3, 0x4, 0x5, 0x6,
216 0xa1, 0xa2, 0xa3, 0xa4,
217 },
218 (4 + 16),
219 SHOULD_ERR,
220 AFI_IP6, SAFI_UNICAST, VALID_AFI,
221 },
222 { "IPv6-nhlen4",
223 "IPV6 MP Reach, nexthop length short",
224 {
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,
229 0x3, 0x4, 0x5, 0x6,
230 0xa1, 0xa2, 0xa3, 0xa4,
231 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
232 0x0, 0x0, 0x0, 0x0,
233 0x2, 0x10, 0x2, 0xff,
234 0x1, 0x2, 0x3, 0x4,
235 /* SNPA (defunct, MBZ) */ 0x0,
236 /* NLRI tuples */ 32,
237 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
238 64,
239 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
240 0x0, 0x2, 0x0, 0x3,
241 0x0, /* ::/0 */
242 },
243 (4 + 32 + 1 + 5 + 9 + 1),
244 SHOULD_ERR,
245 AFI_IP6, SAFI_UNICAST, VALID_AFI,
246 },
247 { "IPv6-nlri",
248 "IPV6 MP Reach, NLRI bitlen overflow",
249 {
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,
254 0x3, 0x4, 0x5, 0x6,
255 0xa1, 0xa2, 0xa3, 0xa4,
256 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
257 0x0, 0x0, 0x0, 0x0,
258 0x2, 0x10, 0x2, 0xff,
259 0x1, 0x2, 0x3, 0x4,
260 /* SNPA (defunct, MBZ) */ 0x0,
261 /* NLRI tuples */ 120,
262 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
263 64,
264 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
265 0x0, 0x2, 0x0, 0x3,
266 0, /* ::/0 */
267 },
268 (4 + 32 + 1 + 5 + 9 + 1),
269 SHOULD_ERR,
270 AFI_IP6, SAFI_UNICAST, VALID_AFI,
271 },
272 { "IPv4",
273 "IPv4 MP Reach, 2 NLRIs + default",
274 {
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 */
281 0, /* 0/0 */
282 },
283 (4 + 4 + 1 + 3 + 4 + 1),
284 SHOULD_PARSE,
285 AFI_IP, SAFI_UNICAST, VALID_AFI,
286 },
287 { "IPv4-nhlen",
288 "IPv4 MP Reach, nexthop lenth overflow",
289 {
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 */
296 0, /* 0/0 */
297 },
298 (4 + 4 + 1 + 3 + 4 + 1),
299 SHOULD_ERR,
300 AFI_IP, SAFI_UNICAST, VALID_AFI,
301 },
302 { "IPv4-nlrilen",
303 "IPv4 MP Reach, nlri lenth overflow",
304 {
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 */
310 30, 10,
311 0, /* 0/0 */
312 },
313 (4 + 4 + 1 + 3 + 2 + 1),
314 SHOULD_ERR,
315 AFI_IP, SAFI_UNICAST, VALID_AFI,
316 },
48a5452b
PJ
317 { "IPv4-VPNv4",
318 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs",
319 {
320 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
321 /* nexthop bytes */ 12,
322 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
323 0, 0, 0, 0,
324 /* Nexthop */ 192, 168, 0, 1,
325 /* SNPA (defunct, MBZ) */ 0x0,
326 /* NLRI tuples */ 88 + 16,
327 0, 1, 2, /* tag */
328 /* rd, 8 octets */
329 0, 0, /* RD_TYPE_AS */
330 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
331 10, 1, /* 10.1/16 */
332 88 + 17,
333 0xff, 0, 0, /* tag */
334 /* rd, 8 octets */
335 0, 0, /* RD_TYPE_IP */
336 192, 168, 0, 1, /* IPv4 */
337 10, 2, 3, /* 10.2.3/17 */
338 },
339 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
340 SHOULD_PARSE,
341 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
342 },
343 { "IPv4-VPNv4-bogus-plen",
344 "IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len",
1eab26bb 345 {
42e6d745 346 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
1eab26bb
PJ
347 /* nexthop bytes */ 12,
348 /* RD */ 0, 0, 1, 2,
349 0, 0xff, 3, 4,
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 */
354 0, /* 0/0 */
355 },
48a5452b
PJ
356 (3 + 1 + 3*4 + 1 + 3 + 4 + 1),
357 SHOULD_ERR,
358 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
359 },
360 { "IPv4-VPNv4-plen1-short",
361 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short",
362 {
363 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
364 /* nexthop bytes */ 12,
365 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
366 0, 0, 0, 0,
367 /* Nexthop */ 192, 168, 0, 1,
368 /* SNPA (defunct, MBZ) */ 0x0,
369 /* NLRI tuples */ 88 + 1,
370 0, 1, 2, /* tag */
371 /* rd, 8 octets */
372 0, 0, /* RD_TYPE_AS */
373 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
374 10, 1, /* 10.1/16 */
375 88 + 17,
376 0xff, 0, 0, /* tag */
377 /* rd, 8 octets */
378 0, 0, /* RD_TYPE_IP */
379 192, 168, 0, 1, /* IPv4 */
380 10, 2, 3, /* 10.2.3/17 */
381 },
382 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
383 SHOULD_ERR,
384 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
385 },
386 { "IPv4-VPNv4-plen1-long",
387 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long",
388 {
389 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
390 /* nexthop bytes */ 12,
391 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
392 0, 0, 0, 0,
393 /* Nexthop */ 192, 168, 0, 1,
394 /* SNPA (defunct, MBZ) */ 0x0,
395 /* NLRI tuples */ 88 + 32,
396 0, 1, 2, /* tag */
397 /* rd, 8 octets */
398 0, 0, /* RD_TYPE_AS */
399 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
400 10, 1, /* 10.1/16 */
401 88 + 17,
402 0xff, 0, 0, /* tag */
403 /* rd, 8 octets */
404 0, 0, /* RD_TYPE_IP */
405 192, 168, 0, 1, /* IPv4 */
406 10, 2, 3, /* 10.2.3/17 */
407 },
408 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
409 SHOULD_ERR,
410 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
411 },
412 { "IPv4-VPNv4-plenn-long",
413 "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long",
414 {
415 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
416 /* nexthop bytes */ 12,
417 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
418 0, 0, 0, 0,
419 /* Nexthop */ 192, 168, 0, 1,
420 /* SNPA (defunct, MBZ) */ 0x0,
421 /* NLRI tuples */ 88 + 16,
422 0, 1, 2, /* tag */
423 /* rd, 8 octets */
424 0, 0, /* RD_TYPE_AS */
425 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
426 10, 1, /* 10.1/16 */
427 88 + 17,
428 0xff, 0, 0, /* tag */
429 /* rd, 8 octets */
430 0, 0, /* RD_TYPE_IP */
431 192, 168, 0, 1, /* IPv4 */
432 10, 2, 3, /* 10.2.3/17 */
433 88 + 1, /* bogus */
434 },
435 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1),
436 SHOULD_ERR,
437 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
438 },
439 { "IPv4-VPNv4-plenn-short",
440 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short",
441 {
442 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
443 /* nexthop bytes */ 12,
444 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
445 0, 0, 0, 0,
446 /* Nexthop */ 192, 168, 0, 1,
447 /* SNPA (defunct, MBZ) */ 0x0,
448 /* NLRI tuples */ 88 + 16,
449 0, 1, 2, /* tag */
450 /* rd, 8 octets */
451 0, 0, /* RD_TYPE_AS */
452 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
453 10, 1, /* 10.1/16 */
454 88 + 2,
455 0xff, 0, 0, /* tag */
456 /* rd, 8 octets */
457 0, 0, /* RD_TYPE_IP */
458 192, 168, 0, 1, /* IPv4 */
459 10, 2, 3, /* 10.2.3/17 */
460 },
461 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
462 SHOULD_ERR,
463 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
464 },
465 { "IPv4-VPNv4-bogus-rd-type",
466 "IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)",
467 {
468 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
469 /* nexthop bytes */ 12,
470 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
471 0, 0, 0, 0,
472 /* Nexthop */ 192, 168, 0, 1,
473 /* SNPA (defunct, MBZ) */ 0x0,
474 /* NLRI tuples */ 88 + 16,
475 0, 1, 2, /* tag */
476 /* rd, 8 octets */
477 0xff, 0, /* Bogus RD */
478 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
479 10, 1, /* 10.1/16 */
480 88 + 17,
481 0xff, 0, 0, /* tag */
482 /* rd, 8 octets */
483 0, 0, /* RD_TYPE_IP */
484 192, 168, 0, 1, /* IPv4 */
485 10, 2, 3, /* 10.2.3/17 */
486 },
487 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
1eab26bb 488 SHOULD_PARSE,
48a5452b 489 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
1eab26bb 490 },
48a5452b
PJ
491 { "IPv4-VPNv4-0-nlri",
492 "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus",
493 {
494 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
495 /* nexthop bytes */ 12,
496 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
497 0, 0, 0, 0,
498 /* Nexthop */ 192, 168, 0, 1,
499 /* SNPA (defunct, MBZ) */ 0x0,
500 /* NLRI tuples */ 88 + 16,
501 0, 1, 2, /* tag */
502 /* rd, 8 octets */
503 0, 0, /* RD_TYPE_AS */
504 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
505 10, 1, /* 10.1/16 */
506 88 + 17,
507 0xff, 0, 0, /* tag */
508 /* rd, 8 octets */
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 ?? */
513 },
514 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1),
515 SHOULD_ERR,
516 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
517 },
518
1eab26bb
PJ
519 /* From bug #385 */
520 { "IPv6-bug",
521 "IPv6, global nexthop, 1 default NLRI",
522 {
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 */
535 },
536 37,
537 SHOULD_ERR,
538 AFI_IP6, SAFI_UNICAST, VALID_AFI,
539 },
540
541 { NULL, NULL, {0}, 0, 0}
542};
543
544/* MP_UNREACH_NLRI tests */
545static struct test_segment mp_unreach_segments [] =
546{
547 { "IPv6-unreach",
548 "IPV6 MP Unreach, 1 NLRI",
549 {
550 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
551 /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
552 },
553 (3 + 5),
554 SHOULD_PARSE,
555 AFI_IP6, SAFI_UNICAST, VALID_AFI,
556 },
557 { "IPv6-unreach2",
558 "IPV6 MP Unreach, 2 NLRIs",
559 {
560 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
561 /* NLRI tuples */ 32,
562 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
563 64,
564 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
565 0x0, 0x2, 0x0, 0x3,
566 },
567 (3 + 5 + 9),
568 SHOULD_PARSE,
569 AFI_IP6, SAFI_UNICAST, VALID_AFI,
570 },
571 { "IPv6-unreach-default",
572 "IPV6 MP Unreach, 2 NLRIs + default",
573 {
574 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
575 /* NLRI tuples */ 32,
576 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
577 64,
578 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
579 0x0, 0x2, 0x0, 0x3,
580 0x0, /* ::/0 */
581 },
582 (3 + 5 + 9 + 1),
583 SHOULD_PARSE,
584 AFI_IP6, SAFI_UNICAST, VALID_AFI,
585 },
586 { "IPv6-unreach-nlri",
587 "IPV6 MP Unreach, NLRI bitlen overflow",
588 {
589 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
590 /* NLRI tuples */ 120,
591 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
592 64,
593 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
594 0x0, 0x2, 0x0, 0x3,
595 0, /* ::/0 */
596 },
597 (3 + 5 + 9 + 1),
598 SHOULD_ERR,
599 AFI_IP6, SAFI_UNICAST, VALID_AFI,
600 },
601 { "IPv4-unreach",
602 "IPv4 MP Unreach, 2 NLRIs + default",
603 {
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 */
607 0, /* 0/0 */
608 },
609 (3 + 3 + 4 + 1),
610 SHOULD_PARSE,
611 AFI_IP, SAFI_UNICAST, VALID_AFI,
612 },
613 { "IPv4-unreach-nlrilen",
614 "IPv4 MP Unreach, nlri length overflow",
615 {
616 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
617 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
618 30, 10,
619 0, /* 0/0 */
620 },
621 (3 + 3 + 2 + 1),
622 SHOULD_ERR,
623 AFI_IP, SAFI_UNICAST, VALID_AFI,
624 },
48a5452b 625 { "IPv4-unreach-VPNv4",
42e6d745 626 "IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs",
1eab26bb 627 {
42e6d745 628 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
48a5452b
PJ
629 /* NLRI tuples */ 88 + 16,
630 0, 1, 2, /* tag */
631 /* rd, 8 octets */
632 0, 0, /* RD_TYPE_AS */
633 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
634 10, 1, /* 10.1/16 */
635 88 + 17,
636 0xff, 0, 0, /* tag */
637 /* rd, 8 octets */
638 0, 0, /* RD_TYPE_IP */
639 192, 168, 0, 1, /* IPv4 */
640 10, 2, 3, /* 10.2.3/17 */
1eab26bb 641 },
48a5452b 642 (3 + (1+3+8+2) + (1+3+8+3)),
1eab26bb 643 SHOULD_PARSE,
48a5452b 644 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
1eab26bb
PJ
645 },
646 { NULL, NULL, {0}, 0, 0}
647};
648
48a5452b
PJ
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.
652 */
653static void
654handle_result (struct peer *peer, struct test_segment *t,
655 int parse_ret, int nlri_ret)
656{
657 int oldfailed = failed;
658
659 if (!parse_ret)
660 {
661 safi_t safi = t->safi;
662
663 if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid)
664 failed++;
665
666 printf ("MP: %u/%u (%u): recv %u, nego %u\n",
667 t->afi, t->safi, safi,
668 peer->afc_recv[t->afi][safi],
669 peer->afc_nego[t->afi][safi]);
670 }
671
672 printf ("mp attr parsed?: %s\n", parse_ret ? "no" : "yes");
673 if (!parse_ret)
674 printf ("nrli parsed?: %s\n", nlri_ret ? "no" : "yes");
675 printf ("should parse?: %s\n", t->parses ? "no" : "yes");
676
677 if ((parse_ret != 0 || nlri_ret != 0) != (t->parses != 0))
678 failed++;
679
680
681 if (tty)
682 printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET
683 : VT100_GREEN "OK" VT100_RESET);
684 else
685 printf ("%s", (failed > oldfailed) ? "failed!" : "OK" );
686
687 if (failed)
688 printf (" (%u)", failed);
689
690 printf ("\n\n");
691}
1eab26bb
PJ
692
693/* basic parsing test */
694static void
695parse_test (struct peer *peer, struct test_segment *t, int type)
696{
48a5452b 697 int parse_ret = 0, nlri_ret = 0;
aeef13b0
DL
698 struct attr attr = { };
699 struct bgp_nlri nlri = { };
1dba254e
PJ
700 struct bgp_attr_parser_args attr_args = {
701 .peer = peer,
702 .length = t->len,
703 .total = 1,
704 .attr = &attr,
48a5452b 705 .type = type,
1dba254e
PJ
706 .flags = BGP_ATTR_FLAG_OPTIONAL,
707 .startp = BGP_INPUT_PNT (peer),
708 };
1eab26bb
PJ
709#define RANDOM_FUZZ 35
710
711 stream_reset (peer->ibuf);
712 stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
713 stream_set_getp (peer->ibuf, RANDOM_FUZZ);
714
715 stream_write (peer->ibuf, t->data, t->len);
716
717 printf ("%s: %s\n", t->name, t->desc);
1dba254e 718
1eab26bb 719 if (type == BGP_ATTR_MP_REACH_NLRI)
48a5452b 720 parse_ret = bgp_mp_reach_parse (&attr_args, &nlri);
1eab26bb 721 else
48a5452b
PJ
722 parse_ret = bgp_mp_unreach_parse (&attr_args, &nlri);
723
724 if (parse_ret == 0 && t->afi_valid == VALID_AFI)
725 assert (nlri.afi == t->afi && nlri.safi == t->safi);
726
727 if (!parse_ret)
1eab26bb 728 {
48a5452b 729 if (type == BGP_ATTR_MP_REACH_NLRI)
96e52474 730 nlri_ret = bgp_nlri_parse (peer, &attr, &nlri);
48a5452b 731 else
96e52474 732 nlri_ret = bgp_nlri_parse (peer, NULL, &nlri);
1eab26bb
PJ
733 }
734
48a5452b 735 handle_result (peer, t, parse_ret, nlri_ret);
1eab26bb
PJ
736}
737
738static struct bgp *bgp;
739static as_t asn = 100;
740
741int
742main (void)
743{
744 struct peer *peer;
745 int i, j;
746
16286195 747 conf_bgp_debug_neighbor_events = -1UL;
1eab26bb 748 conf_bgp_debug_packet = -1UL;
1eab26bb 749 conf_bgp_debug_as4 = -1UL;
16286195 750 term_bgp_debug_neighbor_events = -1UL;
1eab26bb 751 term_bgp_debug_packet = -1UL;
1eab26bb
PJ
752 term_bgp_debug_as4 = -1UL;
753
1bf9f027 754 qobj_init ();
1eab26bb
PJ
755 master = thread_master_create ();
756 bgp_master_init ();
ebf00458 757 vrf_init ();
c9e4f862 758 bgp_option_set (BGP_OPT_NO_LISTEN);
48a5452b 759 bgp_attr_init ();
1eab26bb
PJ
760
761 if (fileno (stdout) >= 0)
762 tty = isatty (fileno (stdout));
763
ebf00458 764 if (bgp_get (&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT))
1eab26bb
PJ
765 return -1;
766
767 peer = peer_create_accept (bgp);
9fc3f9b3 768 peer->host = (char *)"foo";
48a5452b 769 peer->status = Established;
1eab26bb
PJ
770
771 for (i = AFI_IP; i < AFI_MAX; i++)
772 for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
773 {
774 peer->afc[i][j] = 1;
775 peer->afc_adv[i][j] = 1;
776 }
777
778 i = 0;
779 while (mp_reach_segments[i].name)
780 parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI);
781
782 i = 0;
783 while (mp_unreach_segments[i].name)
784 parse_test (peer, &mp_unreach_segments[i++], BGP_ATTR_MP_UNREACH_NLRI);
785
786 printf ("failures: %d\n", failed);
787 return failed;
788}