]> The Tcpdump Group git mirrors - tcpdump/blob - print-bgp.c
Get rid of some unnecessary includes (<time.h>, <netdb.h>, and <ctype.h>
[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.46 2002-08-06 04:42:04 guy Exp $";
37 #endif
38
39 #include <tcpdump-stdinc.h>
40
41 #include <stdio.h>
42 #include <string.h>
43
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "extract.h"
47
48 struct bgp {
49 u_int8_t bgp_marker[16];
50 u_int16_t bgp_len;
51 u_int8_t bgp_type;
52 };
53 #define BGP_SIZE 19 /* unaligned */
54
55 #define BGP_OPEN 1
56 #define BGP_UPDATE 2
57 #define BGP_NOTIFICATION 3
58 #define BGP_KEEPALIVE 4
59 #define BGP_ROUTE_REFRESH 5
60
61 static struct tok bgp_msg_values[] = {
62 { BGP_OPEN, "Open"},
63 { BGP_UPDATE, "Update"},
64 { BGP_NOTIFICATION, "Notification"},
65 { BGP_KEEPALIVE, "Keepalive"},
66 { BGP_ROUTE_REFRESH, "Route Refresh"},
67 { 0, NULL}
68 };
69
70 struct bgp_open {
71 u_int8_t bgpo_marker[16];
72 u_int16_t bgpo_len;
73 u_int8_t bgpo_type;
74 u_int8_t bgpo_version;
75 u_int16_t bgpo_myas;
76 u_int16_t bgpo_holdtime;
77 u_int32_t bgpo_id;
78 u_int8_t bgpo_optlen;
79 /* options should follow */
80 };
81 #define BGP_OPEN_SIZE 29 /* unaligned */
82
83 struct bgp_opt {
84 u_int8_t bgpopt_type;
85 u_int8_t bgpopt_len;
86 /* variable length */
87 };
88 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
89
90 struct bgp_notification {
91 u_int8_t bgpn_marker[16];
92 u_int16_t bgpn_len;
93 u_int8_t bgpn_type;
94 u_int8_t bgpn_major;
95 u_int8_t bgpn_minor;
96 /* data should follow */
97 };
98 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
99
100 struct bgp_route_refresh {
101 u_int8_t bgp_marker[16];
102 u_int16_t len;
103 u_int8_t type;
104 u_int8_t afi[2]; /* the compiler messes this structure up */
105 u_int8_t res; /* when doing misaligned sequences of int8 and int16 */
106 u_int8_t safi; /* afi should be int16 - so we have to access it using */
107 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
108 #define BGP_ROUTE_REFRESH_SIZE 23
109
110 struct bgp_attr {
111 u_int8_t bgpa_flags;
112 u_int8_t bgpa_type;
113 union {
114 u_int8_t len;
115 u_int16_t elen;
116 } bgpa_len;
117 #define bgp_attr_len(p) \
118 (((p)->bgpa_flags & 0x10) ? \
119 ntohs((p)->bgpa_len.elen) : (p)->bgpa_len.len)
120 #define bgp_attr_off(p) \
121 (((p)->bgpa_flags & 0x10) ? 4 : 3)
122 };
123
124 #define BGPTYPE_ORIGIN 1
125 #define BGPTYPE_AS_PATH 2
126 #define BGPTYPE_NEXT_HOP 3
127 #define BGPTYPE_MULTI_EXIT_DISC 4
128 #define BGPTYPE_LOCAL_PREF 5
129 #define BGPTYPE_ATOMIC_AGGREGATE 6
130 #define BGPTYPE_AGGREGATOR 7
131 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
132 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
133 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
134 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
135 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
136 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
137 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
138 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
139 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
140
141 static struct tok bgp_attr_values[] = {
142 { BGPTYPE_ORIGIN, "Origin"},
143 { BGPTYPE_AS_PATH, "AS Path"},
144 { BGPTYPE_NEXT_HOP, "Next Hop"},
145 { BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"},
146 { BGPTYPE_LOCAL_PREF, "Local Preference"},
147 { BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"},
148 { BGPTYPE_AGGREGATOR, "Aggregator"},
149 { BGPTYPE_COMMUNITIES, "Community"},
150 { BGPTYPE_ORIGINATOR_ID, "Originator ID"},
151 { BGPTYPE_CLUSTER_LIST, "Cluster List"},
152 { BGPTYPE_DPA, "DPA"},
153 { BGPTYPE_ADVERTISERS, "Advertisers"},
154 { BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"},
155 { BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"},
156 { BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"},
157 { BGPTYPE_EXTD_COMMUNITIES, "Extended Community"},
158 { 255, "Reserved for development"},
159 { 0, NULL}
160 };
161
162 #define BGP_OPT_AUTH 1
163 #define BGP_OPT_CAP 2
164
165
166 static struct tok bgp_opt_values[] = {
167 { BGP_OPT_AUTH, "Authentication Information"},
168 { BGP_OPT_CAP, "Capabilities Advertisement"},
169 { 0, NULL}
170 };
171
172 #define BGP_CAPCODE_MP 1
173 #define BGP_CAPCODE_RR 2
174 #define BGP_CAPCODE_RR_CISCO 128
175
176 static struct tok bgp_capcode_values[] = {
177 { BGP_CAPCODE_MP, "Multiprotocol Extensions"},
178 { BGP_CAPCODE_RR, "Route Refresh"},
179 { BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"},
180 { 0, NULL}
181 };
182
183 #define BGP_NOTIFY_MAJOR_MSG 1
184 #define BGP_NOTIFY_MAJOR_OPEN 2
185 #define BGP_NOTIFY_MAJOR_UPDATE 3
186 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
187 #define BGP_NOTIFY_MAJOR_FSM 5
188 #define BGP_NOTIFY_MAJOR_CEASE 6
189
190 static struct tok bgp_notify_major_values[] = {
191 { BGP_NOTIFY_MAJOR_MSG, "Message Header Error"},
192 { BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"},
193 { BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"},
194 { BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"},
195 { BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"},
196 { BGP_NOTIFY_MAJOR_CEASE, "Cease"},
197 { 0, NULL}
198 };
199
200 static struct tok bgp_notify_minor_msg_values[] = {
201 { 1, "Connection Not Synchronized"},
202 { 2, "Bad Message Length"},
203 { 3, "Bad Message Type"},
204 { 0, NULL}
205 };
206
207 static struct tok bgp_notify_minor_open_values[] = {
208 { 1, "Unsupported Version Number"},
209 { 2, "Bad Peer AS"},
210 { 3, "Bad BGP Identifier"},
211 { 4, "Unsupported Optional Parameter"},
212 { 5, "Authentication Failure"},
213 { 6, "Unacceptable Hold Time"},
214 { 0, NULL}
215 };
216
217 static struct tok bgp_notify_minor_update_values[] = {
218 { 1, "Malformed Attribute List"},
219 { 2, "Unrecognized Well-known Attribute"},
220 { 3, "Missing Well-known Attribute"},
221 { 4, "Attribute Flags Error"},
222 { 5, "Attribute Length Error"},
223 { 6, "Invalid ORIGIN Attribute"},
224 { 7, "AS Routing Loop"},
225 { 8, "Invalid NEXT_HOP Attribute"},
226 { 9, "Optional Attribute Error"},
227 { 10, "Invalid Network Field"},
228 { 11, "Malformed AS_PATH"},
229 { 0, NULL}
230 };
231
232 static struct tok bgp_origin_values[] = {
233 { 0, "IGP"},
234 { 1, "EGP"},
235 { 2, "Incomplete"},
236 { 0, NULL}
237 };
238
239 /* Subsequent address family identifier, RFC2283 section 7 */
240 #define SAFNUM_RES 0
241 #define SAFNUM_UNICAST 1
242 #define SAFNUM_MULTICAST 2
243 #define SAFNUM_UNIMULTICAST 3
244 /* labeled BGP RFC3107 */
245 #define SAFNUM_LABUNICAST 4
246 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
247 #define SAFNUM_VPNUNICAST 128
248 #define SAFNUM_VPNMULTICAST 129
249 #define SAFNUM_VPNUNIMULTICAST 130
250
251 #define BGP_VPN_RD_LEN 8
252
253 static struct tok bgp_safi_values[] = {
254 { SAFNUM_RES, "Reserved"},
255 { SAFNUM_UNICAST, "Unicast"},
256 { SAFNUM_MULTICAST, "Multicast"},
257 { SAFNUM_UNIMULTICAST, "Unicast+Multicast"},
258 { SAFNUM_LABUNICAST, "labeled Unicast"},
259 { SAFNUM_VPNUNICAST, "labeled VPN Unicast"},
260 { SAFNUM_VPNMULTICAST, "labeled VPN Multicast"},
261 { SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"},
262 { 0, NULL }
263 };
264
265 /* well-known community */
266 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
267 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
268 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
269
270 /* RFC1700 address family numbers */
271 #define AFNUM_INET 1
272 #define AFNUM_INET6 2
273 #define AFNUM_NSAP 3
274 #define AFNUM_HDLC 4
275 #define AFNUM_BBN1822 5
276 #define AFNUM_802 6
277 #define AFNUM_E163 7
278 #define AFNUM_E164 8
279 #define AFNUM_F69 9
280 #define AFNUM_X121 10
281 #define AFNUM_IPX 11
282 #define AFNUM_ATALK 12
283 #define AFNUM_DECNET 13
284 #define AFNUM_BANYAN 14
285 #define AFNUM_E164NSAP 15
286 /* draft-kompella-ppvpn-l2vpn */
287 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
288
289 static struct tok bgp_afi_values[] = {
290 { 0, "Reserved"},
291 { AFNUM_INET, "IPv4"},
292 { AFNUM_INET6, "IPv6"},
293 { AFNUM_NSAP, "NSAP"},
294 { AFNUM_HDLC, "HDLC"},
295 { AFNUM_BBN1822, "BBN 1822"},
296 { AFNUM_802, "802"},
297 { AFNUM_E163, "E.163"},
298 { AFNUM_E164, "E.164"},
299 { AFNUM_F69, "F.69"},
300 { AFNUM_X121, "X.121"},
301 { AFNUM_IPX, "Novell IPX"},
302 { AFNUM_ATALK, "Appletalk"},
303 { AFNUM_DECNET, "Decnet IV"},
304 { AFNUM_BANYAN, "Banyan Vines"},
305 { AFNUM_E164NSAP, "E.164 with NSAP subaddress"},
306 { AFNUM_L2VPN, "Layer-2 VPN"},
307 { 0, NULL},
308 };
309
310 static struct tok bgp_extd_comm_subtype_values[] = {
311 { 2, "target"},
312 { 3, "origin"},
313 { 4, "link-BW"},
314 { 10, "layer2-info"},
315 { 0, NULL},
316 };
317
318 static struct tok bgp_l2vpn_encaps_values[] = {
319 { 0, "Reserved"},
320 { 1, "Frame Relay"},
321 { 2, "ATM AAL5 VCC transport"},
322 { 3, "ATM transparent cell transport"},
323 { 4, "Ethernet VLAN"},
324 { 5, "Ethernet"},
325 { 6, "Cisco-HDLC"},
326 { 7, "PPP"},
327 { 8, "CEM"},
328 { 9, "ATM VCC cell transport"},
329 { 10, "ATM VPC cell transport"},
330 { 11, "MPLS"},
331 { 12, "VPLS"},
332 { 64, "IP-interworking"},
333 { 0, NULL},
334 };
335
336 static int
337 decode_prefix4(const u_char *pptr, char *buf, u_int buflen)
338 {
339 struct in_addr addr;
340 u_int plen;
341
342 plen = pptr[0];
343 if (plen < 0 || 32 < plen)
344 return -1;
345
346 memset(&addr, 0, sizeof(addr));
347 memcpy(&addr, &pptr[1], (plen + 7) / 8);
348 if (plen % 8) {
349 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
350 ((0xff00 >> (plen % 8)) & 0xff);
351 }
352 snprintf(buf, buflen, "%s/%d", getname((u_char *)&addr), plen);
353 return 1 + (plen + 7) / 8;
354 }
355
356 static int
357 decode_labeled_prefix4(const u_char *pptr, char *buf, u_int buflen)
358 {
359 struct in_addr addr;
360 u_int plen;
361
362 plen = pptr[0]; /* get prefix length */
363
364 /* this is one of the weirdnesses of rfc3107
365 the label length (actually the label + COS bits)
366 is added to the prefix length;
367 we also do only read out just one label -
368 there is no real application for advertisement of
369 stacked labels in a a single BGP message
370 */
371
372 plen-=24; /* adjust prefixlen - labellength */
373
374 if (plen < 0 || 32 < plen)
375 return -1;
376
377 memset(&addr, 0, sizeof(addr));
378 memcpy(&addr, &pptr[4], (plen + 7) / 8);
379 if (plen % 8) {
380 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
381 ((0xff00 >> (plen % 8)) & 0xff);
382 }
383 /* the label may get offsetted by 4 bits so lets shift it right */
384 snprintf(buf, buflen, "%s/%d, label:%u %s",
385 getname((u_char *)&addr),
386 plen,
387 EXTRACT_24BITS(pptr+1)>>4,
388 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
389
390 return 4 + (plen + 7) / 8;
391 }
392
393
394 static char *
395 bgp_vpn_rd_print (const u_char *pptr) {
396
397 /* allocate space for the following string
398 * xxx.xxx.xxx.xxx:xxxxx
399 * 21 bytes plus one termination byte */
400 static char rd[22];
401 char *pos = rd;
402
403 /* ok lets load the RD format */
404 switch (EXTRACT_16BITS(pptr)) {
405 /* AS:IP-address fmt*/
406 case 0:
407 pos+=sprintf(pos, "%u:%u.%u.%u.%u",
408 EXTRACT_16BITS(pptr+2),
409 *(pptr+4),
410 *(pptr+5),
411 *(pptr+6),
412 *(pptr+7));
413 break;
414 /* IP-address:AS fmt*/
415 case 1:
416 pos+=sprintf(pos, "%u.%u.%u.%u:%u",
417 *(pptr+2),
418 *(pptr+3),
419 *(pptr+4),
420 *(pptr+5),
421 EXTRACT_16BITS(pptr+6));
422 break;
423 default:
424 pos+=sprintf(pos, "unknown RD format");
425 break;
426 }
427 *(pos) = '\0';
428 return (rd);
429 }
430
431 static int
432 decode_labeled_vpn_prefix4(const u_char *pptr, char *buf, u_int buflen)
433 {
434 struct in_addr addr;
435 u_int plen;
436
437 plen = pptr[0]; /* get prefix length */
438
439 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
440
441 if (plen < 0 || 32 < plen)
442 return -1;
443
444 memset(&addr, 0, sizeof(addr));
445 memcpy(&addr, &pptr[12], (plen + 7) / 8);
446 if (plen % 8) {
447 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
448 ((0xff00 >> (plen % 8)) & 0xff);
449 }
450 /* the label may get offsetted by 4 bits so lets shift it right */
451 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
452 bgp_vpn_rd_print(pptr+4),
453 getname((u_char *)&addr),
454 plen,
455 EXTRACT_24BITS(pptr+1)>>4,
456 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
457
458 return 12 + (plen + 7) / 8;
459 }
460
461 static int
462 decode_labeled_vpn_l2(const u_char *pptr, char *buf, u_int buflen)
463 {
464 int plen,tlen,strlen,tlv_type,tlv_len,ttlv_len;
465 plen=EXTRACT_16BITS(pptr);
466 tlen=plen;
467 pptr+=2;
468 strlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
469 bgp_vpn_rd_print(pptr),
470 EXTRACT_16BITS(pptr+8),
471 EXTRACT_16BITS(pptr+10),
472 EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
473 pptr+=15;
474 tlen-=15;
475
476 /* ok now the variable part - lets read out TLVs*/
477 while (tlen>0) {
478 tlv_type=*pptr++;
479 tlv_len=EXTRACT_16BITS(pptr);
480 ttlv_len=tlv_len;
481 pptr+=2;
482
483 switch(tlv_type) {
484 case 1:
485 strlen+=snprintf(buf+strlen,buflen-strlen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
486 tlv_type,
487 tlv_len);
488 ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
489 while (ttlv_len>0) {
490 strlen+=snprintf(buf+strlen,buflen-strlen, "%02x",*pptr++);
491 ttlv_len--;
492 }
493 break;
494 default:
495 snprintf(buf+strlen,buflen-strlen, "\n\t\tunknown TLV #%u, length: %u",
496 tlv_type,
497 tlv_len);
498 break;
499 }
500 tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it tright */
501 }
502 return plen+2;
503 }
504
505 #ifdef INET6
506 static int
507 decode_prefix6(const u_char *pd, char *buf, u_int buflen)
508 {
509 struct in6_addr addr;
510 u_int plen;
511
512 plen = pd[0];
513 if (plen < 0 || 128 < plen)
514 return -1;
515
516 memset(&addr, 0, sizeof(addr));
517 memcpy(&addr, &pd[1], (plen + 7) / 8);
518 if (plen % 8) {
519 addr.s6_addr[(plen + 7) / 8 - 1] &=
520 ((0xff00 >> (plen % 8)) & 0xff);
521 }
522 snprintf(buf, buflen, "%s/%d", getname6((u_char *)&addr), plen);
523 return 1 + (plen + 7) / 8;
524 }
525 #endif
526
527 static void
528 bgp_attr_print(const struct bgp_attr *attr, const u_char *pptr, int len)
529 {
530 int i;
531 u_int16_t af;
532 u_int8_t safi, snpa;
533 int advance;
534 int tlen;
535 const u_char *tptr;
536 char buf[MAXHOSTNAMELEN + 100];
537
538 tptr = pptr;
539 tlen=len;
540
541 switch (attr->bgpa_type) {
542 case BGPTYPE_ORIGIN:
543 if (len != 1)
544 printf("invalid len");
545 else
546 printf("%s", tok2str(bgp_origin_values, "Unknown Origin Typecode", tptr[0]));
547 break;
548 case BGPTYPE_AS_PATH:
549 if (len % 2) {
550 printf("invalid len");
551 break;
552 }
553 if (!len) {
554 printf("empty");
555 break;
556 }
557 while (tptr < pptr + len) {
558 /*
559 * under RFC1965, p[0] means:
560 * 1: AS_SET 2: AS_SEQUENCE
561 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
562 */
563 if (tptr[0] == 3 || tptr[0] == 4)
564 printf("confed");
565 printf("%s", (tptr[0] & 1) ? "{" : "");
566 for (i = 0; i < tptr[1] * 2; i += 2) {
567 printf("%s%u", i == 0 ? "" : " ",
568 EXTRACT_16BITS(&tptr[2 + i]));
569 }
570 printf("%s", (tptr[0] & 1) ? "}" : "");
571 tptr += 2 + tptr[1] * 2;
572 }
573 break;
574 case BGPTYPE_NEXT_HOP:
575 if (len != 4)
576 printf("invalid len");
577 else
578 printf("%s", getname(tptr));
579 break;
580 case BGPTYPE_MULTI_EXIT_DISC:
581 case BGPTYPE_LOCAL_PREF:
582 if (len != 4)
583 printf("invalid len");
584 else
585 printf("%u", EXTRACT_32BITS(tptr));
586 break;
587 case BGPTYPE_ATOMIC_AGGREGATE:
588 if (len != 0)
589 printf("invalid len");
590 break;
591 case BGPTYPE_AGGREGATOR:
592 if (len != 6) {
593 printf("invalid len");
594 break;
595 }
596 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr),
597 getname(tptr + 2));
598 break;
599 case BGPTYPE_COMMUNITIES:
600 if (len % 4) {
601 printf("invalid len");
602 break;
603 }
604 while (tlen>0) {
605 u_int32_t comm;
606 comm = EXTRACT_32BITS(tptr);
607 switch (comm) {
608 case BGP_COMMUNITY_NO_EXPORT:
609 printf(" NO_EXPORT");
610 break;
611 case BGP_COMMUNITY_NO_ADVERT:
612 printf(" NO_ADVERTISE");
613 break;
614 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
615 printf(" NO_EXPORT_SUBCONFED");
616 break;
617 default:
618 printf("%u:%u%s",
619 (comm >> 16) & 0xffff,
620 comm & 0xffff,
621 (tlen>4) ? ", " : "");
622 break;
623 }
624 tlen -=4;
625 tptr +=4;
626 }
627 break;
628 case BGPTYPE_ORIGINATOR_ID:
629 if (len != 4) {
630 printf("invalid len");
631 break;
632 }
633 printf("%s",getname(tptr));
634 break;
635 case BGPTYPE_CLUSTER_LIST:
636 while (tlen>0) {
637 printf("%s%s",
638 getname(tptr),
639 (tlen>4) ? ", " : "");
640 tlen -=4;
641 tptr +=4;
642 }
643 break;
644 case BGPTYPE_MP_REACH_NLRI:
645 af = EXTRACT_16BITS(tptr);
646 safi = tptr[2];
647
648 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
649 tok2str(bgp_afi_values, "Unknown AFI", af),
650 af,
651 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
652 tok2str(bgp_safi_values, "Unknown SAFI", safi),
653 safi);
654
655 if (af == AFNUM_INET || af==AFNUM_L2VPN)
656 ;
657 #ifdef INET6
658 else if (af == AFNUM_INET6)
659 ;
660 #endif
661 else {
662 printf("\n\t no AFI %u decoder",af);
663 if (!vflag)
664 print_unknown_data(tptr,"\n\t ",tlen);
665 break;
666 }
667
668 tptr +=3;
669
670 tlen = tptr[0];
671 tptr++;
672
673 if (tlen) {
674 printf("\n\t nexthop: ");
675 while (tlen > 0) {
676 switch (af) {
677 case AFNUM_INET:
678 switch(safi) {
679 case SAFNUM_UNICAST:
680 case SAFNUM_MULTICAST:
681 case SAFNUM_UNIMULTICAST:
682 case SAFNUM_LABUNICAST:
683 printf("%s",getname(tptr));
684 tlen -= sizeof(struct in_addr);
685 tptr += sizeof(struct in_addr);
686 break;
687 case SAFNUM_VPNUNICAST:
688 case SAFNUM_VPNMULTICAST:
689 case SAFNUM_VPNUNIMULTICAST:
690 printf("RD: %s, %s",
691 bgp_vpn_rd_print(tptr),
692 getname(tptr+BGP_VPN_RD_LEN));
693 tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
694 tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
695 break;
696 default:
697 printf("no SAFI %u decoder",safi);
698 if (!vflag)
699 print_unknown_data(tptr,"\n\t ",tlen);
700 break;
701 }
702 break;
703 #ifdef INET6
704 case AFNUM_INET6:
705 switch(safi) {
706 case SAFNUM_UNICAST:
707 case SAFNUM_MULTICAST:
708 case SAFNUM_UNIMULTICAST:
709 case SAFNUM_LABUNICAST:
710 printf("%s", getname6(tptr));
711 tlen -= sizeof(struct in6_addr);
712 tptr += sizeof(struct in6_addr);
713 break;
714 case SAFNUM_VPNUNICAST:
715 case SAFNUM_VPNMULTICAST:
716 case SAFNUM_VPNUNIMULTICAST:
717 printf("RD: %s, %s",
718 bgp_vpn_rd_print(tptr),
719 getname6(tptr+BGP_VPN_RD_LEN));
720 tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
721 tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
722 break;
723 default:
724 printf("no SAFI %u decoder",safi);
725 if (!vflag)
726 print_unknown_data(tptr,"\n\t ",tlen);
727 break;
728 }
729 break;
730 #endif
731 case AFNUM_L2VPN:
732 switch(safi) {
733 case SAFNUM_VPNUNICAST:
734 case SAFNUM_VPNMULTICAST:
735 case SAFNUM_VPNUNIMULTICAST:
736 printf("%s", getname(tptr));
737 tlen -= (sizeof(struct in_addr));
738 tptr += (sizeof(struct in_addr));
739 break;
740 default:
741 printf("no SAFI %u decoder",safi);
742 if (!vflag)
743 print_unknown_data(tptr,"\n\t ",tlen);
744 break;
745 }
746 break;
747
748 default:
749 printf("no AFI %u decoder",af);
750 if (!vflag)
751 print_unknown_data(tptr,"\n\t ",tlen);
752 break;
753 }
754 }
755 }
756 tptr += tlen;
757
758 snpa = tptr[0];
759 tptr++;
760
761 if (snpa) {
762 printf("\n\t %u SNPA", snpa);
763 for (/*nothing*/; snpa > 0; snpa--) {
764 printf("\n\t %d bytes", tptr[0]);
765 tptr += tptr[0] + 1;
766 }
767 } else {
768 printf(", no SNPA");
769 }
770
771 while (len - (tptr - pptr) > 0) {
772 switch (af) {
773 case AFNUM_INET:
774 switch (safi) {
775 case SAFNUM_UNICAST:
776 case SAFNUM_MULTICAST:
777 case SAFNUM_UNIMULTICAST:
778 advance = decode_prefix4(tptr, buf, sizeof(buf));
779 printf("\n\t %s", buf);
780 break;
781 case SAFNUM_LABUNICAST:
782 advance = decode_labeled_prefix4(tptr, buf, sizeof(buf));
783 printf("\n\t %s", buf);
784 break;
785 case SAFNUM_VPNUNICAST:
786 case SAFNUM_VPNMULTICAST:
787 case SAFNUM_VPNUNIMULTICAST:
788 advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf));
789 printf("\n\t %s", buf);
790 break;
791 default:
792 printf("\n\t no SAFI %u decoder",safi);
793 if (!vflag)
794 print_unknown_data(tptr-3,"\n\t ",tlen);
795 advance = 0;
796 tptr = pptr + len;
797 break;
798 }
799 break;
800 #ifdef INET6
801 case AFNUM_INET6:
802 switch (safi) {
803 case SAFNUM_UNICAST:
804 case SAFNUM_MULTICAST:
805 case SAFNUM_UNIMULTICAST:
806 advance = decode_prefix6(tptr, buf, sizeof(buf));
807 printf("\n\t %s", buf);
808 break;
809 default:
810 printf("\n\t no SAFI %u decoder ",safi);
811 if (!vflag)
812 print_unknown_data(tptr-3,"\n\t ",tlen);
813 advance = 0;
814 tptr = pptr + len;
815 break;
816 }
817 break;
818 #endif
819 case AFNUM_L2VPN:
820 switch(safi) {
821 case SAFNUM_VPNUNICAST:
822 case SAFNUM_VPNMULTICAST:
823 case SAFNUM_VPNUNIMULTICAST:
824 advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf));
825 printf("\n\t %s", buf);
826 break;
827 default:
828 printf("no SAFI %u decoder",safi);
829 if (!vflag)
830 print_unknown_data(tptr,"\n\t ",tlen);
831 advance = 0;
832 tptr = pptr + len;
833 break;
834 }
835 break;
836
837
838 default:
839 printf("\n\t no AFI %u decoder ",af);
840 if (!vflag)
841 print_unknown_data(tptr-3,"\n\t ",tlen);
842 advance = 0;
843 tptr = pptr + len;
844 break;
845 }
846 tptr += advance;
847 }
848 break;
849
850 case BGPTYPE_MP_UNREACH_NLRI:
851 af = EXTRACT_16BITS(tptr);
852 safi = tptr[2];
853
854 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
855 tok2str(bgp_afi_values, "Unknown AFI", af),
856 af,
857 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
858 tok2str(bgp_safi_values, "Unknown SAFI", safi),
859 safi);
860
861 tptr += 3;
862
863 while (len - (tptr - pptr) > 0) {
864 switch (af) {
865 case AFNUM_INET:
866 switch (safi) {
867 case SAFNUM_UNICAST:
868 case SAFNUM_MULTICAST:
869 case SAFNUM_UNIMULTICAST:
870 advance = decode_prefix4(tptr, buf, sizeof(buf));
871 printf("\n\t %s", buf);
872 break;
873 case SAFNUM_LABUNICAST:
874 advance = decode_labeled_prefix4(tptr, buf, sizeof(buf));
875 printf("\n\t %s", buf);
876 break;
877 case SAFNUM_VPNUNICAST:
878 case SAFNUM_VPNMULTICAST:
879 case SAFNUM_VPNUNIMULTICAST:
880 advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf));
881 printf("\n\t %s", buf);
882 break;
883 default:
884 printf("\n\t no SAFI %u decoder",safi);
885 if (!vflag)
886 print_unknown_data(tptr-3,"\n\t ",tlen);
887 advance = 0;
888 tptr = pptr + len;
889 break;
890 }
891 break;
892
893 #ifdef INET6
894 case AFNUM_INET6:
895 switch (safi) {
896 case SAFNUM_UNICAST:
897 case SAFNUM_MULTICAST:
898 case SAFNUM_UNIMULTICAST:
899 advance = decode_prefix6(tptr, buf, sizeof(buf));
900 printf("\n\t %s", buf);
901 break;
902 default:
903 printf("\n\t no SAFI %u decoder",safi);
904 if (!vflag)
905 print_unknown_data(tptr-3,"\n\t ",tlen);
906 advance = 0;
907 tptr = pptr + len;
908 break;
909 }
910 break;
911 #endif
912
913 case AFNUM_L2VPN:
914 switch(safi) {
915 case SAFNUM_VPNUNICAST:
916 case SAFNUM_VPNMULTICAST:
917 case SAFNUM_VPNUNIMULTICAST:
918 advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf));
919 printf("\n\t %s", buf);
920 break;
921 default:
922 printf("no SAFI %u decoder",safi);
923 if (!vflag)
924 print_unknown_data(tptr-3,"\n\t ",tlen);
925 advance = 0;
926 tptr = pptr + len;
927 break;
928 }
929 break;
930
931 default:
932 printf("\n\t no AFI %u decoder",af);
933 if (!vflag)
934 print_unknown_data(tptr-3,"\n\t ",tlen);
935 advance = 0;
936 tptr = pptr + len;
937 break;
938 }
939
940 tptr += advance;
941 }
942 break;
943 case BGPTYPE_EXTD_COMMUNITIES:
944 if (len % 8) {
945 printf("invalid len");
946 break;
947 }
948 while (tlen>0) {
949 u_int8_t extd_comm,extd_comm_type,extd_comm_subtype;
950 extd_comm=*tptr;
951 extd_comm_type=extd_comm&0x3f;
952 extd_comm_subtype=*(tptr+1);
953 switch(extd_comm_type) {
954 case 0:
955 switch (extd_comm_subtype) {
956 case 2:
957 case 3:
958 case 4:
959 printf("\n\t %s%s%s:%u:%s",
960 (extd_comm&0x80) ? "vendor-specific: " : "",
961 (extd_comm&0x40) ? "non-transitive: " : "",
962 tok2str(bgp_extd_comm_subtype_values,
963 "unknown",
964 extd_comm_subtype&0x3f),
965 EXTRACT_16BITS(tptr+2),
966 getname(tptr+4));
967 break;
968 /* juniper has allocated typecode 10 to convey l2 information */
969 case 10:
970 printf("\n\t %s%s:%s:Control Flags [0x%02x]:MTU %u",
971 (extd_comm&0x40) ? "non-transitive: " : "",
972 tok2str(bgp_extd_comm_subtype_values,
973 "unknown",
974 extd_comm_subtype&0x3f),
975 tok2str(bgp_l2vpn_encaps_values,
976 "unknown encaps",
977 *(tptr+2)),
978 *(tptr+3),
979 EXTRACT_16BITS(tptr+4));
980 break;
981 }
982 break;
983 case 1:
984 printf("\n\t %s%s%s:%s:%u",
985 (extd_comm&0x80) ? "vendor-specific: " : "",
986 (extd_comm&0x40) ? "non-transitive: " : "",
987 tok2str(bgp_extd_comm_subtype_values,
988 "unknown",
989 extd_comm_subtype&0x3f),
990 getname(tptr+2),
991 EXTRACT_16BITS(tptr+6));
992 break;
993 case 2:
994 printf("\n\t %s%s%s:%u:%u",
995 (extd_comm&0x80) ? "vendor-specific: " : "",
996 (extd_comm&0x40) ? "non-transitive: " : "",
997 tok2str(bgp_extd_comm_subtype_values,
998 "unknown",
999 extd_comm_subtype&0x3f),
1000 EXTRACT_32BITS(tptr+2),
1001 EXTRACT_16BITS(tptr+6));
1002 break;
1003 default:
1004 printf("\n\t no typecode %u decoder",
1005 extd_comm_type);
1006 print_unknown_data(tptr,"\n\t ",8);
1007 break;
1008 }
1009 tlen -=8;
1010 tptr +=8;
1011 }
1012 break;
1013
1014 default:
1015 printf("\n\t no Attribute %u decoder",attr->bgpa_type); /* we have no decoder for the attribute */
1016 if (!vflag)
1017 print_unknown_data(pptr,"\n\t ",len);
1018 break;
1019 }
1020 if (vflag&&len) /* omit zero length attributes*/
1021 print_unknown_data(pptr,"\n\t ",len);
1022 }
1023
1024 static void
1025 bgp_open_print(const u_char *dat, int length)
1026 {
1027 struct bgp_open bgpo;
1028 struct bgp_opt bgpopt;
1029 int hlen;
1030 const u_char *opt;
1031 int i,cap_type,cap_len;
1032
1033 TCHECK2(dat[0], BGP_OPEN_SIZE);
1034 memcpy(&bgpo, dat, BGP_OPEN_SIZE);
1035 hlen = ntohs(bgpo.bgpo_len);
1036
1037 printf("\n\t Version %d, ", bgpo.bgpo_version);
1038 printf("my AS %u, ", ntohs(bgpo.bgpo_myas));
1039 printf("Holdtime %us, ", ntohs(bgpo.bgpo_holdtime));
1040 printf("ID %s", getname((u_char *)&bgpo.bgpo_id));
1041 printf("\n\t Optional parameters, length: %u", bgpo.bgpo_optlen);
1042
1043 /* ugly! */
1044 opt = &((const struct bgp_open *)dat)->bgpo_optlen;
1045 opt++;
1046
1047 i = 0;
1048 while (i < bgpo.bgpo_optlen) {
1049 TCHECK2(opt[i], BGP_OPT_SIZE);
1050 memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE);
1051 if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
1052 printf("\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len);
1053 break;
1054 }
1055
1056 printf("\n\t Option %s (%u), length: %u",
1057 tok2str(bgp_opt_values,"Unknown", bgpopt.bgpopt_type),
1058 bgpopt.bgpopt_type,
1059 bgpopt.bgpopt_len);
1060
1061 /* now lets decode the options we know*/
1062 switch(bgpopt.bgpopt_type) {
1063 case BGP_OPT_CAP:
1064 cap_type=opt[i+BGP_OPT_SIZE];
1065 cap_len=opt[i+BGP_OPT_SIZE+1];
1066 printf("\n\t %s, length: %u",
1067 tok2str(bgp_capcode_values,"Unknown", cap_type),
1068 cap_len);
1069 switch(cap_type) {
1070 case BGP_CAPCODE_MP:
1071 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1072 tok2str(bgp_afi_values,"Unknown", EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2)),
1073 EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2),
1074 tok2str(bgp_safi_values,"Unknown", opt[i+BGP_OPT_SIZE+5]),
1075 opt[i+BGP_OPT_SIZE+5]);
1076 break;
1077 case BGP_CAPCODE_RR:
1078 case BGP_CAPCODE_RR_CISCO:
1079 break;
1080 default:
1081 printf("\n\t\tno decoder for Capability %u",
1082 cap_type);
1083 break;
1084 }
1085 break;
1086 case BGP_OPT_AUTH:
1087 default:
1088 printf("\n\t no decoder for option %u",
1089 bgpopt.bgpopt_type);
1090 break;
1091 }
1092
1093 i += BGP_OPT_SIZE + bgpopt.bgpopt_len;
1094 }
1095 return;
1096 trunc:
1097 printf("[|BGP]");
1098 }
1099
1100 static void
1101 bgp_update_print(const u_char *dat, int length)
1102 {
1103 struct bgp bgp;
1104 struct bgp_attr bgpa;
1105 int hlen;
1106 const u_char *p;
1107 int len;
1108 int i;
1109
1110 TCHECK2(dat[0], BGP_SIZE);
1111 memcpy(&bgp, dat, BGP_SIZE);
1112 hlen = ntohs(bgp.bgp_len);
1113 p = dat + BGP_SIZE; /*XXX*/
1114
1115 /* Unfeasible routes */
1116 len = EXTRACT_16BITS(p);
1117 if (len) {
1118 /*
1119 * Without keeping state from the original NLRI message,
1120 * it's not possible to tell if this a v4 or v6 route,
1121 * so only try to decode it if we're not v6 enabled.
1122 */
1123 #ifdef INET6
1124 printf("\n\t Withdrawn routes: %d bytes", len);
1125 #else
1126 char buf[MAXHOSTNAMELEN + 100];
1127
1128 TCHECK2(p[2], len);
1129 i = 2;
1130
1131 printf("\n\t Withdrawn routes:");
1132
1133 while(i < 2 + len) {
1134 i += decode_prefix4(&p[i], buf, sizeof(buf));
1135 printf("\n\t %s", buf);
1136 }
1137 #endif
1138 }
1139 p += 2 + len;
1140
1141 TCHECK2(p[0], 2);
1142 len = EXTRACT_16BITS(p);
1143 if (len) {
1144 /* do something more useful!*/
1145 i = 2;
1146 while (i < 2 + len) {
1147 int alen, aoff;
1148
1149 TCHECK2(p[i], sizeof(bgpa));
1150 memcpy(&bgpa, &p[i], sizeof(bgpa));
1151 alen = bgp_attr_len(&bgpa);
1152 aoff = bgp_attr_off(&bgpa);
1153
1154 printf("\n\t %s (%u), length: %u",
1155 tok2str(bgp_attr_values, "Unknown Attribute", bgpa.bgpa_type),
1156 bgpa.bgpa_type,
1157 alen);
1158
1159 if (bgpa.bgpa_flags) {
1160 printf(", flags [%s%s%s%s",
1161 bgpa.bgpa_flags & 0x80 ? "O" : "",
1162 bgpa.bgpa_flags & 0x40 ? "T" : "",
1163 bgpa.bgpa_flags & 0x20 ? "P" : "",
1164 bgpa.bgpa_flags & 0x10 ? "E" : "");
1165 if (bgpa.bgpa_flags & 0xf)
1166 printf("+%x", bgpa.bgpa_flags & 0xf);
1167 printf("]: ");
1168 }
1169 bgp_attr_print(&bgpa, &p[i + aoff], alen);
1170 i += aoff + alen;
1171 }
1172 }
1173 p += 2 + len;
1174
1175 if (dat + length > p) {
1176 printf("\n\t Updated routes:");
1177 while (dat + length > p) {
1178 char buf[MAXHOSTNAMELEN + 100];
1179 i = decode_prefix4(p, buf, sizeof(buf));
1180 printf("\n\t %s", buf);
1181 if (i < 0)
1182 break;
1183 p += i;
1184 }
1185 }
1186 return;
1187 trunc:
1188 printf("[|BGP]");
1189 }
1190
1191 static void
1192 bgp_notification_print(const u_char *dat, int length)
1193 {
1194 struct bgp_notification bgpn;
1195 int hlen;
1196
1197 TCHECK2(dat[0], BGP_NOTIFICATION_SIZE);
1198 memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE);
1199 hlen = ntohs(bgpn.bgpn_len);
1200
1201 printf(", Error - %s", tok2str(bgp_notify_major_values, "Unknown", bgpn.bgpn_major));
1202
1203 switch (bgpn.bgpn_major) {
1204
1205 case BGP_NOTIFY_MAJOR_MSG:
1206 printf(" subcode %s", tok2str(bgp_notify_minor_msg_values, "Unknown", bgpn.bgpn_minor));
1207 break;
1208 case BGP_NOTIFY_MAJOR_OPEN:
1209 printf(" subcode %s", tok2str(bgp_notify_minor_open_values, "Unknown", bgpn.bgpn_minor));
1210 break;
1211 case BGP_NOTIFY_MAJOR_UPDATE:
1212 printf(" subcode %s", tok2str(bgp_notify_minor_update_values, "Unknown", bgpn.bgpn_minor));
1213 break;
1214 default:
1215 break;
1216 }
1217
1218 return;
1219 trunc:
1220 printf("[|BGP]");
1221 }
1222
1223 static void
1224 bgp_route_refresh_print(const u_char *pptr, int len) {
1225
1226 const struct bgp_route_refresh *bgp_route_refresh_header;
1227 bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
1228
1229 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1230 tok2str(bgp_afi_values,"Unknown",
1231 EXTRACT_16BITS(&bgp_route_refresh_header->afi)), /* this stinks but the compiler pads the structure weird */
1232 EXTRACT_16BITS(&bgp_route_refresh_header->afi),
1233 tok2str(bgp_safi_values,"Unknown",
1234 bgp_route_refresh_header->safi),
1235 bgp_route_refresh_header->safi);
1236
1237 if (vflag)
1238 print_unknown_data(pptr,"\n\t ", len);
1239
1240 return;
1241 }
1242
1243 static void
1244 bgp_header_print(const u_char *dat, int length)
1245 {
1246 struct bgp bgp;
1247
1248 TCHECK2(dat[0], BGP_SIZE);
1249 memcpy(&bgp, dat, BGP_SIZE);
1250 printf("\n\t%s Message (%u), length: %u ",
1251 tok2str(bgp_msg_values, "Unknown", bgp.bgp_type),
1252 bgp.bgp_type,
1253 length);
1254
1255 switch (bgp.bgp_type) {
1256 case BGP_OPEN:
1257 bgp_open_print(dat, length);
1258 break;
1259 case BGP_UPDATE:
1260 bgp_update_print(dat, length);
1261 break;
1262 case BGP_NOTIFICATION:
1263 bgp_notification_print(dat, length);
1264 break;
1265 case BGP_KEEPALIVE:
1266 break;
1267 case BGP_ROUTE_REFRESH:
1268 bgp_route_refresh_print(dat, length);
1269 break;
1270 default:
1271 /* we have no decoder for the BGP message */
1272 printf("\n\t no Message %u decoder",bgp.bgp_type);
1273 print_unknown_data(dat,"\n\t ",length);
1274 break;
1275 }
1276 return;
1277 trunc:
1278 printf("[|BGP]");
1279 }
1280
1281 void
1282 bgp_print(const u_char *dat, int length)
1283 {
1284 const u_char *p;
1285 const u_char *ep;
1286 const u_char *start;
1287 const u_char marker[] = {
1288 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1289 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1290 };
1291 struct bgp bgp;
1292 u_int16_t hlen;
1293
1294 ep = dat + length;
1295 if (snapend < dat + length)
1296 ep = snapend;
1297
1298 printf(": BGP");
1299
1300 p = dat;
1301 start = p;
1302 while (p < snapend) {
1303 if (!TTEST2(p[0], 1))
1304 break;
1305 if (p[0] != 0xff) {
1306 p++;
1307 continue;
1308 }
1309
1310 if (!TTEST2(p[0], sizeof(marker)))
1311 break;
1312 if (memcmp(p, marker, sizeof(marker)) != 0) {
1313 p++;
1314 continue;
1315 }
1316
1317 /* found BGP header */
1318 TCHECK2(p[0], BGP_SIZE); /*XXX*/
1319 memcpy(&bgp, p, BGP_SIZE);
1320
1321 if (start != p)
1322 printf(" [|BGP]");
1323
1324 hlen = ntohs(bgp.bgp_len);
1325
1326 if (TTEST2(p[0], hlen)) {
1327 bgp_header_print(p, hlen);
1328 p += hlen;
1329 start = p;
1330 } else {
1331 printf("[|BGP %s]", tok2str(bgp_msg_values, "Unknown Message Type",bgp.bgp_type));
1332 break;
1333 }
1334 }
1335
1336 return;
1337
1338 trunc:
1339 printf(" [|BGP]");
1340 }
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351