]> The Tcpdump Group git mirrors - tcpdump/blob - print-bgp.c
* print-rt6.c: make IPv6 routing header printing work with new 2292bis
[tcpdump] / print-bgp.c
1 /*
2 * Copyright (C) 1999 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include <sys/param.h>
35 #include <sys/time.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
42 #include <netinet/ip_var.h>
43 #include <netinet/udp.h>
44 #include <netinet/udp_var.h>
45
46 #include <errno.h>
47 #include <stdio.h>
48 #include <string.h>
49
50 #include "interface.h"
51 #include "addrtoname.h"
52
53 struct bgp {
54 u_int8_t bgp_marker[16];
55 u_int16_t bgp_len;
56 u_int8_t bgp_type;
57 };
58 #define BGP_SIZE 19 /* unaligned */
59
60 #define BGP_OPEN 1
61 #define BGP_UPDATE 2
62 #define BGP_NOTIFICATION 3
63 #define BGP_KEEPALIVE 4
64
65 struct bgp_open {
66 u_int8_t bgpo_marker[16];
67 u_int16_t bgpo_len;
68 u_int8_t bgpo_type;
69 u_int8_t bgpo_version;
70 u_int16_t bgpo_myas;
71 u_int16_t bgpo_holdtime;
72 u_int32_t bgpo_id;
73 u_int8_t bgpo_optlen;
74 /* options should follow */
75 };
76
77 struct bgp_opt {
78 u_int8_t bgpopt_type;
79 u_int8_t bgpopt_len;
80 /* variable length */
81 };
82
83 struct bgp_notification {
84 u_int8_t bgpn_marker[16];
85 u_int16_t bgpn_len;
86 u_int8_t bgpn_type;
87 u_int8_t bgpn_major;
88 u_int8_t bgpn_minor;
89 /* data should follow */
90 };
91
92 struct bgp_attr {
93 u_int8_t bgpa_flags;
94 u_int8_t bgpa_type;
95 union {
96 u_int8_t len;
97 u_int16_t elen;
98 } bgpa_len;
99 #define bgp_attr_len(p) \
100 (((p)->bgpa_flags & 0x10) ? \
101 ntohs((p)->bgpa_len.elen) : (p)->bgpa_len.len)
102 #define bgp_attr_off(p) \
103 (((p)->bgpa_flags & 0x10) ? 4 : 3)
104 };
105
106 #define BGPTYPE_ORIGIN 1
107 #define BGPTYPE_AS_PATH 2
108 #define BGPTYPE_NEXT_HOP 3
109 #define BGPTYPE_MULTI_EXIT_DISC 4
110 #define BGPTYPE_LOCAL_PREF 5
111 #define BGPTYPE_ATOMIC_AGGREGATE 6
112 #define BGPTYPE_AGGREGATOR 7
113 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
114 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
115 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
116 #define BGPTYPE_DPA 11 /* work in progress */
117 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
118 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
119 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
120 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
121
122
123 static const char *bgptype[] = {
124 NULL, "OPEN", "UPDATE", "NOTIFICATION", "KEEPALIVE",
125 };
126 #define bgp_type(x) num_or_str(bgptype, sizeof(bgptype)/sizeof(bgptype[0]), (x))
127
128 static const char *bgpopt_type[] = {
129 NULL, "Authentication Information",
130 };
131 #define bgp_opttype(x) \
132 num_or_str(bgpopt_type, sizeof(bgpopt_type)/sizeof(bgpopt_type[0]), (x))
133
134 static const char *bgpnotify_major[] = {
135 NULL, "Message Header Error",
136 "OPEN Message Error", "UPDATE Message Error",
137 "Hold Timer Expired", "Finite State Machine Error",
138 "Cease",
139 };
140 #define bgp_notify_major(x) \
141 num_or_str(bgpnotify_major, \
142 sizeof(bgpnotify_major)/sizeof(bgpnotify_major[0]), (x))
143
144 static const char *bgpnotify_minor_1[] = {
145 NULL, "Connection Not Synchronized",
146 "Bad Message Length", "Bad Message Type",
147 };
148
149 static const char *bgpnotify_minor_2[] = {
150 NULL, "Unsupported Version Number",
151 "Bad Peer AS", "Bad BGP Identifier",
152 "Unsupported Optional Parameter", "Authentication Failure",
153 "Unacceptable Hold Time",
154 };
155
156 static const char *bgpnotify_minor_3[] = {
157 NULL, "Malformed Attribute List",
158 "Unrecognized Well-known Attribute", "Missing Well-known Attribute",
159 "Attribute Flags Error", "Attribute Length Error",
160 "Invalid ORIGIN Attribute", "AS Routing Loop",
161 "Invalid NEXT_HOP Attribute", "Optional Attribute Error",
162 "Invalid Network Field", "Malformed AS_PATH",
163 };
164
165 static const char **bgpnotify_minor[] = {
166 NULL, bgpnotify_minor_1, bgpnotify_minor_2, bgpnotify_minor_3,
167 };
168 static const int bgpnotify_minor_siz[] = {
169 0, sizeof(bgpnotify_minor_1)/sizeof(bgpnotify_minor_1[0]),
170 sizeof(bgpnotify_minor_2)/sizeof(bgpnotify_minor_2[0]),
171 sizeof(bgpnotify_minor_3)/sizeof(bgpnotify_minor_3[0]),
172 };
173
174 static const char *bgpattr_origin[] = {
175 "IGP", "EGP", "INCOMPLETE",
176 };
177 #define bgp_attr_origin(x) \
178 num_or_str(bgpattr_origin, \
179 sizeof(bgpattr_origin)/sizeof(bgpattr_origin[0]), (x))
180
181 static const char *bgpattr_type[] = {
182 NULL, "ORIGIN", "AS_PATH", "NEXT_HOP",
183 "MULTI_EXIT_DISC", "LOCAL_PREF", "ATOMIC_AGGREGATE", "AGGREGATOR",
184 "COMMUNITIES", "ORIGINATOR_ID", "CLUSTER_LIST", "DPA",
185 "ADVERTISERS", "RCID_PATH", "MP_REACH_NLRI", "MP_UNREACH_NLRI",
186 };
187 #define bgp_attr_type(x) \
188 num_or_str(bgpattr_type, \
189 sizeof(bgpattr_type)/sizeof(bgpattr_type[0]), (x))
190
191 /* Subsequent address family identifier, RFC2283 section 7 */
192 static const char *bgpattr_nlri_safi[] = {
193 "Reserved", "Unicast", "Multicast", "Unicast+Multicast",
194 };
195 #define bgp_attr_nlri_safi(x) \
196 num_or_str(bgpattr_nlri_safi, \
197 sizeof(bgpattr_nlri_safi)/sizeof(bgpattr_nlri_safi[0]), (x))
198
199 /* well-known community */
200 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
201 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
202 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
203
204 /* RFC1700 address family numbers */
205 #define AFNUM_INET 1
206 #define AFNUM_INET6 2
207 #define AFNUM_NSAP 3
208 #define AFNUM_HDLC 4
209 #define AFNUM_BBN1822 5
210 #define AFNUM_802 6
211 #define AFNUM_E163 7
212 #define AFNUM_E164 8
213 #define AFNUM_F69 9
214 #define AFNUM_X121 10
215 #define AFNUM_IPX 11
216 #define AFNUM_ATALK 12
217 #define AFNUM_DECNET 13
218 #define AFNUM_BANYAN 14
219 #define AFNUM_E164NSAP 15
220
221 static const char *afnumber[] = {
222 "Reserved", "IPv4", "IPv6", "NSAP", "HDLC",
223 "BBN 1822", "802", "E.163", "E.164", "F.69",
224 "X.121", "IPX", "Appletalk", "Decnet IV", "Banyan Vines",
225 "E.164 with NSAP subaddress",
226 };
227 #define af_name(x) \
228 (((x) == 65535) ? afnumber[0] : \
229 num_or_str(afnumber, \
230 sizeof(afnumber)/sizeof(afnumber[0]), (x)))
231
232
233 static const char *
234 num_or_str(const char **table, size_t siz, int value)
235 {
236 static char buf[20];
237 if (value < 0 || siz <= value || table[value] == NULL) {
238 sprintf(buf, "#%d", value);
239 return buf;
240 } else
241 return table[value];
242 }
243
244 static const char *
245 bgp_notify_minor(int major, int minor)
246 {
247 static const char **table;
248 int siz;
249 static char buf[20];
250 const char *p;
251
252 if (0 <= major
253 && major < sizeof(bgpnotify_minor)/sizeof(bgpnotify_minor[0])
254 && bgpnotify_minor[major]) {
255 table = bgpnotify_minor[major];
256 siz = bgpnotify_minor_siz[major];
257 if (0 <= minor && minor < siz && table[minor])
258 p = table[minor];
259 else
260 p = NULL;
261 } else
262 p = NULL;
263 if (p == NULL) {
264 sprintf(buf, "#%d", minor);
265 return buf;
266 } else
267 return p;
268 }
269
270 static int
271 decode_prefix4(const u_char *pd, char *buf, int buflen)
272 {
273 struct in_addr addr;
274 int plen;
275
276 plen = pd[0];
277 if (plen < 0 || 32 < plen)
278 return -1;
279
280 memset(&addr, 0, sizeof(addr));
281 memcpy(&addr, &pd[1], (plen + 7) / 8);
282 if (plen % 8) {
283 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
284 ((0xff00 >> (plen % 8)) & 0xff);
285 }
286 sprintf(buf, "%s/%d", getname((char *)&addr), plen);
287 return 1 + (plen + 7) / 8;
288 }
289
290 #ifdef INET6
291 static int
292 decode_prefix6(const u_char *pd, char *buf, int buflen)
293 {
294 struct in6_addr addr;
295 int plen;
296
297 plen = pd[0];
298 if (plen < 0 || 128 < plen)
299 return -1;
300
301 memset(&addr, 0, sizeof(addr));
302 memcpy(&addr, &pd[1], (plen + 7) / 8);
303 if (plen % 8) {
304 addr.s6_addr[(plen + 7) / 8 - 1] &=
305 ((0xff00 >> (plen % 8)) & 0xff);
306 }
307 sprintf(buf, "%s/%d", getname6((char *)&addr), plen);
308 return 1 + (plen + 7) / 8;
309 }
310 #endif
311
312 static void
313 bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len)
314 {
315 int i;
316 u_int16_t af;
317 u_int8_t safi, snpa;
318 int advance;
319 int tlen;
320 const u_char *p;
321 char buf[256];
322
323 p = dat;
324
325 switch (attr->bgpa_type) {
326 case BGPTYPE_ORIGIN:
327 if (len != 1)
328 printf(" invalid len");
329 else
330 printf(" %s", bgp_attr_origin(p[0]));
331 break;
332 case BGPTYPE_AS_PATH:
333 if (len % 2) {
334 printf(" invalid len");
335 break;
336 }
337 while (p < dat + len) {
338 /*
339 * under RFC1965, p[0] means:
340 * 1: AS_SET 2: AS_SEQUENCE
341 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
342 */
343 printf(" ");
344 if (p[0] == 3 || p[0] == 4)
345 printf("confed");
346 printf("%s", (p[0] & 1) ? "{" : "");
347 for (i = 0; i < p[1]; i += 2) {
348 printf("%s%u", i == 0 ? "" : " ",
349 ntohs(*(u_int16_t *)&p[2 + i]));
350 }
351 printf("%s", (p[0] & 1) ? "}" : "");
352 p += 2 + p[1] * 2;
353 }
354 break;
355 case BGPTYPE_NEXT_HOP:
356 if (len != 4)
357 printf(" invalid len");
358 else
359 printf(" %s", getname(p));
360 break;
361 case BGPTYPE_MULTI_EXIT_DISC:
362 case BGPTYPE_LOCAL_PREF:
363 if (len != 4)
364 printf(" invalid len");
365 else
366 printf(" %u", (u_int32_t)ntohl(*(u_int32_t *)p));
367 break;
368 case BGPTYPE_ATOMIC_AGGREGATE:
369 if (len != 0)
370 printf(" invalid len");
371 break;
372 case BGPTYPE_AGGREGATOR:
373 if (len != 6) {
374 printf(" invalid len");
375 break;
376 }
377 printf(" AS #%u, origin %s", ntohs(*(u_int16_t *)p),
378 getname(p + 2));
379 break;
380 case BGPTYPE_COMMUNITIES:
381 if (len % 4) {
382 printf(" invalid len");
383 break;
384 }
385 for (i = 0; i < len; i++) {
386 u_int32_t comm;
387 comm = (u_int32_t)ntohl(*(u_int32_t *)&p[i]);
388 switch (comm) {
389 case BGP_COMMUNITY_NO_EXPORT:
390 printf(" NO_EXPORT");
391 break;
392 case BGP_COMMUNITY_NO_ADVERT:
393 printf(" NO_ADVERTISE");
394 break;
395 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
396 printf(" NO_EXPORT_SUBCONFED");
397 break;
398 default:
399 printf(" (AS #%d value 0x%04x)",
400 (comm >> 16) & 0xffff, comm & 0xfffff);
401 break;
402 }
403 }
404 break;
405 case BGPTYPE_MP_REACH_NLRI:
406 af = ntohs(*(u_int16_t *)p);
407 safi = p[2];
408 if (safi >= 128)
409 printf(" %s vendor specific,", af_name(af));
410 else {
411 printf(" %s %s,", af_name(af),
412 bgp_attr_nlri_safi(safi));
413 }
414 p += 3;
415
416 if (af == AFNUM_INET)
417 ;
418 #ifdef INET6
419 else if (af == AFNUM_INET6)
420 ;
421 #endif
422 else
423 break;
424
425 tlen = p[0];
426 if (tlen) {
427 printf(" nexthop");
428 if (af == AFNUM_INET)
429 advance = 4;
430 #ifdef INET6
431 else if (af == AFNUM_INET6)
432 advance = 16;
433 #endif
434
435 for (i = 0; i < tlen; i += advance) {
436 if (af == AFNUM_INET)
437 printf(" %s", getname(p + 1 + i));
438 #ifdef INET6
439 else if (af == AFNUM_INET6)
440 printf(" %s", getname6(p + 1 + i));
441 #endif
442 }
443 printf(",");
444 }
445 p += 1 + tlen;
446
447 snpa = p[0];
448 p++;
449 if (snpa) {
450 printf(" %u snpa", snpa);
451 for (/*nothing*/; snpa > 0; snpa--) {
452 printf("(%d bytes)", p[0]);
453 p += p[0] + 1;
454 }
455 printf(",");
456 }
457
458 printf(" NLRI");
459 while (len - (p - dat) > 0) {
460 if (af == AFNUM_INET)
461 advance = decode_prefix4(p, buf, sizeof(buf));
462 #ifdef INET6
463 else if (af == AFNUM_INET6)
464 advance = decode_prefix6(p, buf, sizeof(buf));
465 #endif
466 printf(" %s", buf);
467
468 p += advance;
469 }
470
471 break;
472
473 case BGPTYPE_MP_UNREACH_NLRI:
474 af = ntohs(*(u_int16_t *)p);
475 safi = p[2];
476 if (safi >= 128)
477 printf(" %s vendor specific,", af_name(af));
478 else {
479 printf(" %s %s,", af_name(af),
480 bgp_attr_nlri_safi(safi));
481 }
482 p += 3;
483
484 printf(" Withdraw");
485 while (len - (p - dat) > 0) {
486 if (af == AFNUM_INET)
487 advance = decode_prefix4(p, buf, sizeof(buf));
488 #ifdef INET6
489 else if (af == AFNUM_INET6)
490 advance = decode_prefix6(p, buf, sizeof(buf));
491 #endif
492 printf(" %s", buf);
493
494 p += advance;
495 }
496 break;
497 default:
498 break;
499 }
500 }
501
502 static void
503 bgp_open_print(const u_char *dat, int length)
504 {
505 struct bgp_open bgpo;
506 struct bgp_opt bgpopt;
507 int hlen;
508 const u_char *opt;
509 int i;
510
511 memcpy(&bgpo, dat, sizeof(bgpo));
512 hlen = ntohs(bgpo.bgpo_len);
513
514 printf(": Version %d,", bgpo.bgpo_version);
515 printf(" AS #%u,", ntohs(bgpo.bgpo_myas));
516 printf(" Holdtime %u,", ntohs(bgpo.bgpo_holdtime));
517 printf(" ID %s,", getname((char *)&bgpo.bgpo_id));
518 printf(" Option length %u", bgpo.bgpo_optlen);
519
520 /* ugly! */
521 opt = &((struct bgp_open *)dat)->bgpo_optlen;
522 opt++;
523
524 for (i = 0; i < bgpo.bgpo_optlen; i++) {
525 memcpy(&bgpopt, &opt[i], sizeof(bgpopt));
526 if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
527 printf(" [|opt %d %d]", bgpopt.bgpopt_len, bgpopt.bgpopt_type);
528 break;
529 }
530
531 printf(" (option %s, len=%d)", bgp_opttype(bgpopt.bgpopt_type),
532 bgpopt.bgpopt_len);
533 i += sizeof(bgpopt) + bgpopt.bgpopt_len;
534 }
535 }
536
537 static void
538 bgp_update_print(const u_char *dat, int length)
539 {
540 struct bgp bgp;
541 struct bgp_attr bgpa;
542 int hlen;
543 const u_char *p;
544 int len;
545 int i;
546 int newline;
547
548 memcpy(&bgp, dat, sizeof(bgp));
549 hlen = ntohs(bgp.bgp_len);
550 p = dat + BGP_SIZE; /*XXX*/
551 printf(":");
552
553 /* Unfeasible routes */
554 len = ntohs(*(u_int16_t *)p);
555 if (len) {
556 printf(" (Withdrawn routes: %d bytes)", len);
557 }
558 p += 2 + len;
559
560 len = ntohs(*(u_int16_t *)p);
561 if (len) {
562 /* do something more useful!*/
563 i = 2;
564 printf(" (Path attributes:"); /* ) */
565 newline = 0;
566 while (i < 2 + len) {
567 int alen, aoff;
568
569 memcpy(&bgpa, &p[i], sizeof(bgpa));
570 alen = bgp_attr_len(&bgpa);
571 aoff = bgp_attr_off(&bgpa);
572
573 if (vflag && newline)
574 printf("\n\t\t");
575 else
576 printf(" ");
577 printf("("); /* ) */
578 printf("%s", bgp_attr_type(bgpa.bgpa_type));
579 if (bgpa.bgpa_flags) {
580 printf("[%s%s%s%s]",
581 bgpa.bgpa_flags & 0x80 ? "O" : "",
582 bgpa.bgpa_flags & 0x40 ? "T" : "",
583 bgpa.bgpa_flags & 0x20 ? "P" : "",
584 bgpa.bgpa_flags & 0x00 ? "E" : "");
585 }
586
587 bgp_attr_print(&bgpa, &p[i + aoff], alen);
588 newline = 1;
589
590 /* ( */
591 printf(")");
592
593 i += aoff + alen;
594 }
595
596 /* ( */
597 printf(")");
598 }
599 p += 2 + len;
600
601 if (len && dat + length > p)
602 printf("\n\t\t");
603 if (dat + length > p) {
604 printf("(NLRI:"); /* ) */
605 while (dat + length > p) {
606 char buf[256];
607 i = decode_prefix4(p, buf, sizeof(buf));
608 printf(" %s", buf);
609 if (i < 0)
610 break;
611 p += i;
612 }
613
614 /* ( */
615 printf(")");
616 }
617 }
618
619 static void
620 bgp_notification_print(const u_char *dat, int length)
621 {
622 struct bgp_notification bgpn;
623 int hlen;
624
625 memcpy(&bgpn, dat, sizeof(bgpn));
626 hlen = ntohs(bgpn.bgpn_len);
627
628 printf(": error %s,", bgp_notify_major(bgpn.bgpn_major));
629 printf(" subcode %s",
630 bgp_notify_minor(bgpn.bgpn_major, bgpn.bgpn_minor));
631 }
632
633 static void
634 bgp_header_print(const u_char *dat, int length)
635 {
636 struct bgp bgp;
637
638 memcpy(&bgp, dat, sizeof(bgp));
639 printf("(%s", bgp_type(bgp.bgp_type)); /* ) */
640
641 switch (bgp.bgp_type) {
642 case BGP_OPEN:
643 bgp_open_print(dat, length);
644 break;
645 case BGP_UPDATE:
646 bgp_update_print(dat, length);
647 break;
648 case BGP_NOTIFICATION:
649 bgp_notification_print(dat, length);
650 break;
651 }
652
653 /* ( */
654 printf(")");
655 }
656
657 void
658 bgp_print(const u_char *dat, int length)
659 {
660 const u_char *p;
661 const u_char *ep;
662 const u_char *start;
663 const u_char marker[] = {
664 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
665 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
666 };
667 struct bgp bgp;
668 u_int16_t hlen;
669 int newline;
670
671 ep = dat + length;
672 if (snapend < dat + length)
673 ep = snapend;
674
675 printf(": BGP");
676
677 p = dat;
678 newline = 0;
679 start = p;
680 while (p < snapend) {
681 if (!TTEST2(p[0], 1))
682 break;
683 if (p[0] != 0xff) {
684 p++;
685 continue;
686 }
687
688 if (!TTEST2(p[0], sizeof(marker)))
689 break;
690 if (memcmp(p, marker, sizeof(marker)) != 0) {
691 p++;
692 continue;
693 }
694
695 /* found BGP header */
696 TCHECK2(p[0], BGP_SIZE); /*XXX*/
697 memcpy(&bgp, p, sizeof(bgp));
698
699 if (start != p)
700 printf(" [|BGP]");
701
702 hlen = ntohs(bgp.bgp_len);
703 if (vflag && newline)
704 printf("\n\t");
705 else
706 printf(" ");
707 if (TTEST2(p[0], hlen)) {
708 bgp_header_print(p, hlen);
709 newline = 1;
710 p += hlen;
711 start = p;
712 } else {
713 printf("[|BGP %s]", bgp_type(bgp.bgp_type));
714 break;
715 }
716 }
717
718 return;
719
720 trunc:
721 printf(" [|BGP]");
722 }