]> The Tcpdump Group git mirrors - tcpdump/blob - print-bgp.c
Patch sent to Debian by Roderick Schertler <[email protected]> to print
[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 #ifndef lint
35 static const char rcsid[] =
36 "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.17 2000-09-29 04:58:34 guy Exp $";
37 #endif
38
39 #include <sys/param.h>
40 #include <sys/time.h>
41 #include <sys/types.h>
42 #include <sys/socket.h>
43
44 #include <netinet/in.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 snprintf(buf, sizeof(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 snprintf(buf, sizeof(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 snprintf(buf, buflen, "%s/%d", getname((u_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 snprintf(buf, buflen, "%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 += 4) {
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 & 0xffff);
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 i = 0;
429 while (i < tlen) {
430 switch (af) {
431 case AFNUM_INET:
432 printf(" %s", getname(p + 1 + i));
433 i += sizeof(struct in_addr);
434 break;
435 #ifdef INET6
436 case AFNUM_INET6:
437 printf(" %s", getname6(p + 1 + i));
438 i += sizeof(struct in6_addr);
439 break;
440 #endif
441 default:
442 printf(" (unknown af)");
443 i = tlen; /*exit loop*/
444 break;
445 }
446 }
447 printf(",");
448 }
449 p += 1 + tlen;
450
451 snpa = p[0];
452 p++;
453 if (snpa) {
454 printf(" %u snpa", snpa);
455 for (/*nothing*/; snpa > 0; snpa--) {
456 printf("(%d bytes)", p[0]);
457 p += p[0] + 1;
458 }
459 printf(",");
460 }
461
462 printf(" NLRI");
463 while (len - (p - dat) > 0) {
464 switch (af) {
465 case AFNUM_INET:
466 advance = decode_prefix4(p, buf, sizeof(buf));
467 printf(" %s", buf);
468 break;
469 #ifdef INET6
470 case AFNUM_INET6:
471 advance = decode_prefix6(p, buf, sizeof(buf));
472 printf(" %s", buf);
473 break;
474 #endif
475 default:
476 printf(" (unknown af)");
477 advance = 0;
478 p = dat + len;
479 break;
480 }
481
482 p += advance;
483 }
484
485 break;
486
487 case BGPTYPE_MP_UNREACH_NLRI:
488 af = ntohs(*(u_int16_t *)p);
489 safi = p[2];
490 if (safi >= 128)
491 printf(" %s vendor specific,", af_name(af));
492 else {
493 printf(" %s %s,", af_name(af),
494 bgp_attr_nlri_safi(safi));
495 }
496 p += 3;
497
498 printf(" Withdraw");
499 while (len - (p - dat) > 0) {
500 switch (af) {
501 case AFNUM_INET:
502 advance = decode_prefix4(p, buf, sizeof(buf));
503 printf(" %s", buf);
504 break;
505 #ifdef INET6
506 case AFNUM_INET6:
507 advance = decode_prefix6(p, buf, sizeof(buf));
508 printf(" %s", buf);
509 break;
510 #endif
511 default:
512 printf(" (unknown af)");
513 advance = 0;
514 p = dat + len;
515 break;
516 }
517
518 p += advance;
519 }
520 break;
521 default:
522 break;
523 }
524 }
525
526 static void
527 bgp_open_print(const u_char *dat, int length)
528 {
529 struct bgp_open bgpo;
530 struct bgp_opt bgpopt;
531 int hlen;
532 const u_char *opt;
533 int i;
534
535 memcpy(&bgpo, dat, sizeof(bgpo));
536 hlen = ntohs(bgpo.bgpo_len);
537
538 printf(": Version %d,", bgpo.bgpo_version);
539 printf(" AS #%u,", ntohs(bgpo.bgpo_myas));
540 printf(" Holdtime %u,", ntohs(bgpo.bgpo_holdtime));
541 printf(" ID %s,", getname((u_char *)&bgpo.bgpo_id));
542 printf(" Option length %u", bgpo.bgpo_optlen);
543
544 /* ugly! */
545 opt = &((struct bgp_open *)dat)->bgpo_optlen;
546 opt++;
547
548 for (i = 0; i < bgpo.bgpo_optlen; i++) {
549 memcpy(&bgpopt, &opt[i], sizeof(bgpopt));
550 if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
551 printf(" [|opt %d %d]", bgpopt.bgpopt_len, bgpopt.bgpopt_type);
552 break;
553 }
554
555 printf(" (option %s, len=%d)", bgp_opttype(bgpopt.bgpopt_type),
556 bgpopt.bgpopt_len);
557 i += sizeof(bgpopt) + bgpopt.bgpopt_len;
558 }
559 }
560
561 static void
562 bgp_update_print(const u_char *dat, int length)
563 {
564 struct bgp bgp;
565 struct bgp_attr bgpa;
566 int hlen;
567 const u_char *p;
568 int len;
569 int i;
570 int newline;
571
572 memcpy(&bgp, dat, sizeof(bgp));
573 hlen = ntohs(bgp.bgp_len);
574 p = dat + BGP_SIZE; /*XXX*/
575 printf(":");
576
577 /* Unfeasible routes */
578 len = ntohs(*(u_int16_t *)p);
579 if (len) {
580 printf(" (Withdrawn routes: %d bytes)", len);
581 }
582 p += 2 + len;
583
584 len = ntohs(*(u_int16_t *)p);
585 if (len) {
586 /* do something more useful!*/
587 i = 2;
588 printf(" (Path attributes:"); /* ) */
589 newline = 0;
590 while (i < 2 + len) {
591 int alen, aoff;
592
593 memcpy(&bgpa, &p[i], sizeof(bgpa));
594 alen = bgp_attr_len(&bgpa);
595 aoff = bgp_attr_off(&bgpa);
596
597 if (vflag && newline)
598 printf("\n\t\t");
599 else
600 printf(" ");
601 printf("("); /* ) */
602 printf("%s", bgp_attr_type(bgpa.bgpa_type));
603 if (bgpa.bgpa_flags) {
604 printf("[%s%s%s%s]",
605 bgpa.bgpa_flags & 0x80 ? "O" : "",
606 bgpa.bgpa_flags & 0x40 ? "T" : "",
607 bgpa.bgpa_flags & 0x20 ? "P" : "",
608 bgpa.bgpa_flags & 0x00 ? "E" : "");
609 }
610
611 bgp_attr_print(&bgpa, &p[i + aoff], alen);
612 newline = 1;
613
614 /* ( */
615 printf(")");
616
617 i += aoff + alen;
618 }
619
620 /* ( */
621 printf(")");
622 }
623 p += 2 + len;
624
625 if (len && dat + length > p)
626 printf("\n\t\t");
627 if (dat + length > p) {
628 printf("(NLRI:"); /* ) */
629 while (dat + length > p) {
630 char buf[256];
631 i = decode_prefix4(p, buf, sizeof(buf));
632 printf(" %s", buf);
633 if (i < 0)
634 break;
635 p += i;
636 }
637
638 /* ( */
639 printf(")");
640 }
641 }
642
643 static void
644 bgp_notification_print(const u_char *dat, int length)
645 {
646 struct bgp_notification bgpn;
647 int hlen;
648
649 memcpy(&bgpn, dat, sizeof(bgpn));
650 hlen = ntohs(bgpn.bgpn_len);
651
652 printf(": error %s,", bgp_notify_major(bgpn.bgpn_major));
653 printf(" subcode %s",
654 bgp_notify_minor(bgpn.bgpn_major, bgpn.bgpn_minor));
655 }
656
657 static void
658 bgp_header_print(const u_char *dat, int length)
659 {
660 struct bgp bgp;
661
662 memcpy(&bgp, dat, sizeof(bgp));
663 printf("(%s", bgp_type(bgp.bgp_type)); /* ) */
664
665 switch (bgp.bgp_type) {
666 case BGP_OPEN:
667 bgp_open_print(dat, length);
668 break;
669 case BGP_UPDATE:
670 bgp_update_print(dat, length);
671 break;
672 case BGP_NOTIFICATION:
673 bgp_notification_print(dat, length);
674 break;
675 }
676
677 /* ( */
678 printf(")");
679 }
680
681 void
682 bgp_print(const u_char *dat, int length)
683 {
684 const u_char *p;
685 const u_char *ep;
686 const u_char *start;
687 const u_char marker[] = {
688 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
689 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
690 };
691 struct bgp bgp;
692 u_int16_t hlen;
693 int newline;
694
695 ep = dat + length;
696 if (snapend < dat + length)
697 ep = snapend;
698
699 printf(": BGP");
700
701 p = dat;
702 newline = 0;
703 start = p;
704 while (p < snapend) {
705 if (!TTEST2(p[0], 1))
706 break;
707 if (p[0] != 0xff) {
708 p++;
709 continue;
710 }
711
712 if (!TTEST2(p[0], sizeof(marker)))
713 break;
714 if (memcmp(p, marker, sizeof(marker)) != 0) {
715 p++;
716 continue;
717 }
718
719 /* found BGP header */
720 TCHECK2(p[0], BGP_SIZE); /*XXX*/
721 memcpy(&bgp, p, sizeof(bgp));
722
723 if (start != p)
724 printf(" [|BGP]");
725
726 hlen = ntohs(bgp.bgp_len);
727 if (vflag && newline)
728 printf("\n\t");
729 else
730 printf(" ");
731 if (TTEST2(p[0], hlen)) {
732 bgp_header_print(p, hlen);
733 newline = 1;
734 p += hlen;
735 start = p;
736 } else {
737 printf("[|BGP %s]", bgp_type(bgp.bgp_type));
738 break;
739 }
740 }
741
742 return;
743
744 trunc:
745 printf(" [|BGP]");
746 }