2 * Copyright (C) 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
35 static const char rcsid
[] =
36 "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.46 2002-08-06 04:42:04 guy Exp $";
39 #include <tcpdump-stdinc.h>
44 #include "interface.h"
45 #include "addrtoname.h"
49 u_int8_t bgp_marker
[16];
53 #define BGP_SIZE 19 /* unaligned */
57 #define BGP_NOTIFICATION 3
58 #define BGP_KEEPALIVE 4
59 #define BGP_ROUTE_REFRESH 5
61 static struct tok bgp_msg_values
[] = {
63 { BGP_UPDATE
, "Update"},
64 { BGP_NOTIFICATION
, "Notification"},
65 { BGP_KEEPALIVE
, "Keepalive"},
66 { BGP_ROUTE_REFRESH
, "Route Refresh"},
71 u_int8_t bgpo_marker
[16];
74 u_int8_t bgpo_version
;
76 u_int16_t bgpo_holdtime
;
79 /* options should follow */
81 #define BGP_OPEN_SIZE 29 /* unaligned */
88 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
90 struct bgp_notification
{
91 u_int8_t bgpn_marker
[16];
96 /* data should follow */
98 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
100 struct bgp_route_refresh
{
101 u_int8_t bgp_marker
[16];
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
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)
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 */
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"},
162 #define BGP_OPT_AUTH 1
163 #define BGP_OPT_CAP 2
166 static struct tok bgp_opt_values
[] = {
167 { BGP_OPT_AUTH
, "Authentication Information"},
168 { BGP_OPT_CAP
, "Capabilities Advertisement"},
172 #define BGP_CAPCODE_MP 1
173 #define BGP_CAPCODE_RR 2
174 #define BGP_CAPCODE_RR_CISCO 128
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)"},
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
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"},
200 static struct tok bgp_notify_minor_msg_values
[] = {
201 { 1, "Connection Not Synchronized"},
202 { 2, "Bad Message Length"},
203 { 3, "Bad Message Type"},
207 static struct tok bgp_notify_minor_open_values
[] = {
208 { 1, "Unsupported Version Number"},
210 { 3, "Bad BGP Identifier"},
211 { 4, "Unsupported Optional Parameter"},
212 { 5, "Authentication Failure"},
213 { 6, "Unacceptable Hold Time"},
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"},
232 static struct tok bgp_origin_values
[] = {
239 /* Subsequent address family identifier, RFC2283 section 7 */
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
251 #define BGP_VPN_RD_LEN 8
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"},
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
270 /* RFC1700 address family numbers */
272 #define AFNUM_INET6 2
275 #define AFNUM_BBN1822 5
280 #define AFNUM_X121 10
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 */
289 static struct tok bgp_afi_values
[] = {
291 { AFNUM_INET
, "IPv4"},
292 { AFNUM_INET6
, "IPv6"},
293 { AFNUM_NSAP
, "NSAP"},
294 { AFNUM_HDLC
, "HDLC"},
295 { AFNUM_BBN1822
, "BBN 1822"},
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"},
310 static struct tok bgp_extd_comm_subtype_values
[] = {
314 { 10, "layer2-info"},
318 static struct tok bgp_l2vpn_encaps_values
[] = {
321 { 2, "ATM AAL5 VCC transport"},
322 { 3, "ATM transparent cell transport"},
323 { 4, "Ethernet VLAN"},
328 { 9, "ATM VCC cell transport"},
329 { 10, "ATM VPC cell transport"},
332 { 64, "IP-interworking"},
337 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
343 if (plen
< 0 || 32 < plen
)
346 memset(&addr
, 0, sizeof(addr
));
347 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
349 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
350 ((0xff00 >> (plen
% 8)) & 0xff);
352 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
353 return 1 + (plen
+ 7) / 8;
357 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
362 plen
= pptr
[0]; /* get prefix length */
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
372 plen
-=24; /* adjust prefixlen - labellength */
374 if (plen
< 0 || 32 < plen
)
377 memset(&addr
, 0, sizeof(addr
));
378 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
380 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
381 ((0xff00 >> (plen
% 8)) & 0xff);
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
),
387 EXTRACT_24BITS(pptr
+1)>>4,
388 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
390 return 4 + (plen
+ 7) / 8;
395 bgp_vpn_rd_print (const u_char
*pptr
) {
397 /* allocate space for the following string
398 * xxx.xxx.xxx.xxx:xxxxx
399 * 21 bytes plus one termination byte */
403 /* ok lets load the RD format */
404 switch (EXTRACT_16BITS(pptr
)) {
405 /* AS:IP-address fmt*/
407 pos
+=sprintf(pos
, "%u:%u.%u.%u.%u",
408 EXTRACT_16BITS(pptr
+2),
414 /* IP-address:AS fmt*/
416 pos
+=sprintf(pos
, "%u.%u.%u.%u:%u",
421 EXTRACT_16BITS(pptr
+6));
424 pos
+=sprintf(pos
, "unknown RD format");
432 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
437 plen
= pptr
[0]; /* get prefix length */
439 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
441 if (plen
< 0 || 32 < plen
)
444 memset(&addr
, 0, sizeof(addr
));
445 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
447 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
448 ((0xff00 >> (plen
% 8)) & 0xff);
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
),
455 EXTRACT_24BITS(pptr
+1)>>4,
456 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
458 return 12 + (plen
+ 7) / 8;
462 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
464 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
465 plen
=EXTRACT_16BITS(pptr
);
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 */
476 /* ok now the variable part - lets read out TLVs*/
479 tlv_len
=EXTRACT_16BITS(pptr
);
485 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
488 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
490 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
495 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
500 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
507 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
509 struct in6_addr addr
;
513 if (plen
< 0 || 128 < plen
)
516 memset(&addr
, 0, sizeof(addr
));
517 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
519 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
520 ((0xff00 >> (plen
% 8)) & 0xff);
522 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
523 return 1 + (plen
+ 7) / 8;
528 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
536 char buf
[MAXHOSTNAMELEN
+ 100];
541 switch (attr
->bgpa_type
) {
544 printf("invalid len");
546 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
548 case BGPTYPE_AS_PATH
:
550 printf("invalid len");
557 while (tptr
< pptr
+ len
) {
559 * under RFC1965, p[0] means:
560 * 1: AS_SET 2: AS_SEQUENCE
561 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
563 if (tptr
[0] == 3 || tptr
[0] == 4)
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
]));
570 printf("%s", (tptr
[0] & 1) ? "}" : "");
571 tptr
+= 2 + tptr
[1] * 2;
574 case BGPTYPE_NEXT_HOP
:
576 printf("invalid len");
578 printf("%s", getname(tptr
));
580 case BGPTYPE_MULTI_EXIT_DISC
:
581 case BGPTYPE_LOCAL_PREF
:
583 printf("invalid len");
585 printf("%u", EXTRACT_32BITS(tptr
));
587 case BGPTYPE_ATOMIC_AGGREGATE
:
589 printf("invalid len");
591 case BGPTYPE_AGGREGATOR
:
593 printf("invalid len");
596 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
599 case BGPTYPE_COMMUNITIES
:
601 printf("invalid len");
606 comm
= EXTRACT_32BITS(tptr
);
608 case BGP_COMMUNITY_NO_EXPORT
:
609 printf(" NO_EXPORT");
611 case BGP_COMMUNITY_NO_ADVERT
:
612 printf(" NO_ADVERTISE");
614 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
615 printf(" NO_EXPORT_SUBCONFED");
619 (comm
>> 16) & 0xffff,
621 (tlen
>4) ? ", " : "");
628 case BGPTYPE_ORIGINATOR_ID
:
630 printf("invalid len");
633 printf("%s",getname(tptr
));
635 case BGPTYPE_CLUSTER_LIST
:
639 (tlen
>4) ? ", " : "");
644 case BGPTYPE_MP_REACH_NLRI
:
645 af
= EXTRACT_16BITS(tptr
);
648 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
649 tok2str(bgp_afi_values
, "Unknown AFI", af
),
651 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
652 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
655 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
658 else if (af
== AFNUM_INET6
)
662 printf("\n\t no AFI %u decoder",af
);
664 print_unknown_data(tptr
,"\n\t ",tlen
);
674 printf("\n\t nexthop: ");
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
);
687 case SAFNUM_VPNUNICAST
:
688 case SAFNUM_VPNMULTICAST
:
689 case SAFNUM_VPNUNIMULTICAST
:
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
);
697 printf("no SAFI %u decoder",safi
);
699 print_unknown_data(tptr
,"\n\t ",tlen
);
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
);
714 case SAFNUM_VPNUNICAST
:
715 case SAFNUM_VPNMULTICAST
:
716 case SAFNUM_VPNUNIMULTICAST
:
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
);
724 printf("no SAFI %u decoder",safi
);
726 print_unknown_data(tptr
,"\n\t ",tlen
);
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
));
741 printf("no SAFI %u decoder",safi
);
743 print_unknown_data(tptr
,"\n\t ",tlen
);
749 printf("no AFI %u decoder",af
);
751 print_unknown_data(tptr
,"\n\t ",tlen
);
762 printf("\n\t %u SNPA", snpa
);
763 for (/*nothing*/; snpa
> 0; snpa
--) {
764 printf("\n\t %d bytes", tptr
[0]);
771 while (len
- (tptr
- pptr
) > 0) {
776 case SAFNUM_MULTICAST
:
777 case SAFNUM_UNIMULTICAST
:
778 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
779 printf("\n\t %s", buf
);
781 case SAFNUM_LABUNICAST
:
782 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
783 printf("\n\t %s", buf
);
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
);
792 printf("\n\t no SAFI %u decoder",safi
);
794 print_unknown_data(tptr
-3,"\n\t ",tlen
);
804 case SAFNUM_MULTICAST
:
805 case SAFNUM_UNIMULTICAST
:
806 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
807 printf("\n\t %s", buf
);
810 printf("\n\t no SAFI %u decoder ",safi
);
812 print_unknown_data(tptr
-3,"\n\t ",tlen
);
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
);
828 printf("no SAFI %u decoder",safi
);
830 print_unknown_data(tptr
,"\n\t ",tlen
);
839 printf("\n\t no AFI %u decoder ",af
);
841 print_unknown_data(tptr
-3,"\n\t ",tlen
);
850 case BGPTYPE_MP_UNREACH_NLRI
:
851 af
= EXTRACT_16BITS(tptr
);
854 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
855 tok2str(bgp_afi_values
, "Unknown AFI", af
),
857 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
858 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
863 while (len
- (tptr
- pptr
) > 0) {
868 case SAFNUM_MULTICAST
:
869 case SAFNUM_UNIMULTICAST
:
870 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
871 printf("\n\t %s", buf
);
873 case SAFNUM_LABUNICAST
:
874 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
875 printf("\n\t %s", buf
);
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
);
884 printf("\n\t no SAFI %u decoder",safi
);
886 print_unknown_data(tptr
-3,"\n\t ",tlen
);
897 case SAFNUM_MULTICAST
:
898 case SAFNUM_UNIMULTICAST
:
899 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
900 printf("\n\t %s", buf
);
903 printf("\n\t no SAFI %u decoder",safi
);
905 print_unknown_data(tptr
-3,"\n\t ",tlen
);
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
);
922 printf("no SAFI %u decoder",safi
);
924 print_unknown_data(tptr
-3,"\n\t ",tlen
);
932 printf("\n\t no AFI %u decoder",af
);
934 print_unknown_data(tptr
-3,"\n\t ",tlen
);
943 case BGPTYPE_EXTD_COMMUNITIES
:
945 printf("invalid len");
949 u_int8_t extd_comm
,extd_comm_type
,extd_comm_subtype
;
951 extd_comm_type
=extd_comm
&0x3f;
952 extd_comm_subtype
=*(tptr
+1);
953 switch(extd_comm_type
) {
955 switch (extd_comm_subtype
) {
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
,
964 extd_comm_subtype
&0x3f),
965 EXTRACT_16BITS(tptr
+2),
968 /* juniper has allocated typecode 10 to convey l2 information */
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
,
974 extd_comm_subtype
&0x3f),
975 tok2str(bgp_l2vpn_encaps_values
,
979 EXTRACT_16BITS(tptr
+4));
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
,
989 extd_comm_subtype
&0x3f),
991 EXTRACT_16BITS(tptr
+6));
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
,
999 extd_comm_subtype
&0x3f),
1000 EXTRACT_32BITS(tptr
+2),
1001 EXTRACT_16BITS(tptr
+6));
1004 printf("\n\t no typecode %u decoder",
1006 print_unknown_data(tptr
,"\n\t ",8);
1015 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1017 print_unknown_data(pptr
,"\n\t ",len
);
1020 if (vflag
&&len
) /* omit zero length attributes*/
1021 print_unknown_data(pptr
,"\n\t ",len
);
1025 bgp_open_print(const u_char
*dat
, int length
)
1027 struct bgp_open bgpo
;
1028 struct bgp_opt bgpopt
;
1031 int i
,cap_type
,cap_len
;
1033 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1034 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1035 hlen
= ntohs(bgpo
.bgpo_len
);
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
);
1044 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
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
);
1056 printf("\n\t Option %s (%u), length: %u",
1057 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1061 /* now lets decode the options we know*/
1062 switch(bgpopt
.bgpopt_type
) {
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
),
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]);
1077 case BGP_CAPCODE_RR
:
1078 case BGP_CAPCODE_RR_CISCO
:
1081 printf("\n\t\tno decoder for Capability %u",
1088 printf("\n\t no decoder for option %u",
1089 bgpopt
.bgpopt_type
);
1093 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1101 bgp_update_print(const u_char
*dat
, int length
)
1104 struct bgp_attr bgpa
;
1110 TCHECK2(dat
[0], BGP_SIZE
);
1111 memcpy(&bgp
, dat
, BGP_SIZE
);
1112 hlen
= ntohs(bgp
.bgp_len
);
1113 p
= dat
+ BGP_SIZE
; /*XXX*/
1115 /* Unfeasible routes */
1116 len
= EXTRACT_16BITS(p
);
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.
1124 printf("\n\t Withdrawn routes: %d bytes", len
);
1126 char buf
[MAXHOSTNAMELEN
+ 100];
1131 printf("\n\t Withdrawn routes:");
1133 while(i
< 2 + len
) {
1134 i
+= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1135 printf("\n\t %s", buf
);
1142 len
= EXTRACT_16BITS(p
);
1144 /* do something more useful!*/
1146 while (i
< 2 + len
) {
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
);
1154 printf("\n\t %s (%u), length: %u",
1155 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
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);
1169 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
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
);
1192 bgp_notification_print(const u_char
*dat
, int length
)
1194 struct bgp_notification bgpn
;
1197 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1198 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1199 hlen
= ntohs(bgpn
.bgpn_len
);
1201 printf(", Error - %s", tok2str(bgp_notify_major_values
, "Unknown", bgpn
.bgpn_major
));
1203 switch (bgpn
.bgpn_major
) {
1205 case BGP_NOTIFY_MAJOR_MSG
:
1206 printf(" subcode %s", tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
));
1208 case BGP_NOTIFY_MAJOR_OPEN
:
1209 printf(" subcode %s", tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
));
1211 case BGP_NOTIFY_MAJOR_UPDATE
:
1212 printf(" subcode %s", tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
));
1224 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1226 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1227 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
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
);
1238 print_unknown_data(pptr
,"\n\t ", len
);
1244 bgp_header_print(const u_char
*dat
, int length
)
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
),
1255 switch (bgp
.bgp_type
) {
1257 bgp_open_print(dat
, length
);
1260 bgp_update_print(dat
, length
);
1262 case BGP_NOTIFICATION
:
1263 bgp_notification_print(dat
, length
);
1267 case BGP_ROUTE_REFRESH
:
1268 bgp_route_refresh_print(dat
, length
);
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
);
1282 bgp_print(const u_char
*dat
, int length
)
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,
1295 if (snapend
< dat
+ length
)
1302 while (p
< snapend
) {
1303 if (!TTEST2(p
[0], 1))
1310 if (!TTEST2(p
[0], sizeof(marker
)))
1312 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1317 /* found BGP header */
1318 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1319 memcpy(&bgp
, p
, BGP_SIZE
);
1324 hlen
= ntohs(bgp
.bgp_len
);
1326 if (TTEST2(p
[0], hlen
)) {
1327 bgp_header_print(p
, hlen
);
1331 printf("[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));