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