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.43 2002-07-24 21:07:20 hannes Exp $";
39 #include <sys/param.h>
41 #include <sys/types.h>
42 #include <sys/socket.h>
44 #include <netinet/in.h>
51 #include "interface.h"
52 #include "addrtoname.h"
56 u_int8_t bgp_marker
[16];
60 #define BGP_SIZE 19 /* unaligned */
64 #define BGP_NOTIFICATION 3
65 #define BGP_KEEPALIVE 4
66 #define BGP_ROUTE_REFRESH 5
68 static struct tok bgp_msg_values
[] = {
70 { BGP_UPDATE
, "Update"},
71 { BGP_NOTIFICATION
, "Notification"},
72 { BGP_KEEPALIVE
, "Keepalive"},
73 { BGP_ROUTE_REFRESH
, "Route Refresh"},
78 u_int8_t bgpo_marker
[16];
81 u_int8_t bgpo_version
;
83 u_int16_t bgpo_holdtime
;
86 /* options should follow */
88 #define BGP_OPEN_SIZE 29 /* unaligned */
95 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
97 struct bgp_notification
{
98 u_int8_t bgpn_marker
[16];
103 /* data should follow */
105 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
107 struct bgp_route_refresh
{
108 u_int8_t bgp_marker
[16];
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
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)
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 */
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"},
169 #define BGP_OPT_AUTH 1
170 #define BGP_OPT_CAP 2
173 static struct tok bgp_opt_values
[] = {
174 { BGP_OPT_AUTH
, "Authentication Information"},
175 { BGP_OPT_CAP
, "Capabilities Advertisement"},
179 #define BGP_CAPCODE_MP 1
180 #define BGP_CAPCODE_RR 2
181 #define BGP_CAPCODE_RR_CISCO 128
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)"},
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
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"},
207 static struct tok bgp_notify_minor_msg_values
[] = {
208 { 1, "Connection Not Synchronized"},
209 { 2, "Bad Message Length"},
210 { 3, "Bad Message Type"},
214 static struct tok bgp_notify_minor_open_values
[] = {
215 { 1, "Unsupported Version Number"},
217 { 3, "Bad BGP Identifier"},
218 { 4, "Unsupported Optional Parameter"},
219 { 5, "Authentication Failure"},
220 { 6, "Unacceptable Hold Time"},
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"},
239 static struct tok bgp_origin_values
[] = {
246 /* Subsequent address family identifier, RFC2283 section 7 */
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
258 #define BGP_VPN_RD_LEN 8
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"},
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
277 /* RFC1700 address family numbers */
279 #define AFNUM_INET6 2
282 #define AFNUM_BBN1822 5
287 #define AFNUM_X121 10
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 */
296 static struct tok bgp_afi_values
[] = {
298 { AFNUM_INET
, "IPv4"},
299 { AFNUM_INET6
, "IPv6"},
300 { AFNUM_NSAP
, "NSAP"},
301 { AFNUM_HDLC
, "HDLC"},
302 { AFNUM_BBN1822
, "BBN 1822"},
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"},
317 static struct tok bgp_extd_comm_subtype_values
[] = {
321 { 10, "layer2-info"},
325 static struct tok bgp_l2vpn_encaps_values
[] = {
328 { 2, "ATM AAL5 VCC transport"},
329 { 3, "ATM transparent cell transport"},
330 { 4, "Ethernet VLAN"},
335 { 9, "ATM VCC cell transport"},
336 { 10, "ATM VPC cell transport"},
339 { 64, "IP-interworking"},
344 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
350 if (plen
< 0 || 32 < plen
)
353 memset(&addr
, 0, sizeof(addr
));
354 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
356 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
357 ((0xff00 >> (plen
% 8)) & 0xff);
359 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
360 return 1 + (plen
+ 7) / 8;
364 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
369 plen
= pptr
[0]; /* get prefix length */
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
379 plen
-=24; /* adjust prefixlen - labellength */
381 if (plen
< 0 || 32 < plen
)
384 memset(&addr
, 0, sizeof(addr
));
385 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
387 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
388 ((0xff00 >> (plen
% 8)) & 0xff);
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
),
394 EXTRACT_24BITS(pptr
+1)>>4,
395 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
397 return 4 + (plen
+ 7) / 8;
402 bgp_vpn_rd_print (const u_char
*pptr
) {
404 /* allocate space for the following string
405 * xxx.xxx.xxx.xxx:xxxxx
406 * 21 bytes plus one termination byte */
410 /* ok lets load the RD format */
411 switch (EXTRACT_16BITS(pptr
)) {
412 /* AS:IP-address fmt*/
414 pos
+=sprintf(pos
, "%u:%u.%u.%u.%u",
415 EXTRACT_16BITS(pptr
+2),
421 /* IP-address:AS fmt*/
423 pos
+=sprintf(pos
, "%u.%u.%u.%u:%u",
428 EXTRACT_16BITS(pptr
+6));
431 pos
+=sprintf(pos
, "unknown RD format");
439 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
444 plen
= pptr
[0]; /* get prefix length */
446 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
448 if (plen
< 0 || 32 < plen
)
451 memset(&addr
, 0, sizeof(addr
));
452 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
454 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
455 ((0xff00 >> (plen
% 8)) & 0xff);
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
),
462 EXTRACT_24BITS(pptr
+1)>>4,
463 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
465 return 12 + (plen
+ 7) / 8;
469 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
471 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
472 plen
=EXTRACT_16BITS(pptr
);
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 */
483 /* ok now the variable part - lets read out TLVs*/
486 tlv_len
=EXTRACT_16BITS(pptr
);
492 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
495 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
497 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
502 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
507 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
514 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
516 struct in6_addr addr
;
520 if (plen
< 0 || 128 < plen
)
523 memset(&addr
, 0, sizeof(addr
));
524 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
526 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
527 ((0xff00 >> (plen
% 8)) & 0xff);
529 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
530 return 1 + (plen
+ 7) / 8;
535 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
543 char buf
[MAXHOSTNAMELEN
+ 100];
548 switch (attr
->bgpa_type
) {
551 printf("invalid len");
553 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
555 case BGPTYPE_AS_PATH
:
557 printf("invalid len");
564 while (tptr
< pptr
+ len
) {
566 * under RFC1965, p[0] means:
567 * 1: AS_SET 2: AS_SEQUENCE
568 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
570 if (tptr
[0] == 3 || tptr
[0] == 4)
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
]));
577 printf("%s", (tptr
[0] & 1) ? "}" : "");
578 tptr
+= 2 + tptr
[1] * 2;
581 case BGPTYPE_NEXT_HOP
:
583 printf("invalid len");
585 printf("%s", getname(tptr
));
587 case BGPTYPE_MULTI_EXIT_DISC
:
588 case BGPTYPE_LOCAL_PREF
:
590 printf("invalid len");
592 printf("%u", EXTRACT_32BITS(tptr
));
594 case BGPTYPE_ATOMIC_AGGREGATE
:
596 printf("invalid len");
598 case BGPTYPE_AGGREGATOR
:
600 printf("invalid len");
603 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
606 case BGPTYPE_COMMUNITIES
:
608 printf("invalid len");
613 comm
= EXTRACT_32BITS(tptr
);
615 case BGP_COMMUNITY_NO_EXPORT
:
616 printf(" NO_EXPORT");
618 case BGP_COMMUNITY_NO_ADVERT
:
619 printf(" NO_ADVERTISE");
621 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
622 printf(" NO_EXPORT_SUBCONFED");
626 (comm
>> 16) & 0xffff,
628 (tlen
>4) ? ", " : "");
635 case BGPTYPE_ORIGINATOR_ID
:
637 printf("invalid len");
640 printf("%s",getname(tptr
));
642 case BGPTYPE_CLUSTER_LIST
:
646 (tlen
>4) ? ", " : "");
651 case BGPTYPE_MP_REACH_NLRI
:
652 af
= EXTRACT_16BITS(tptr
);
655 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
656 tok2str(bgp_afi_values
, "Unknown AFI", af
),
658 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
659 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
662 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
665 else if (af
== AFNUM_INET6
)
669 printf("\n\t no AFI %u decoder",af
);
671 print_unknown_data(tptr
,"\n\t ",tlen
);
681 printf("\n\t nexthop: ");
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
);
694 case SAFNUM_VPNUNICAST
:
695 case SAFNUM_VPNMULTICAST
:
696 case SAFNUM_VPNUNIMULTICAST
:
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
);
704 printf("no SAFI %u decoder",safi
);
706 print_unknown_data(tptr
,"\n\t ",tlen
);
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
);
721 case SAFNUM_VPNUNICAST
:
722 case SAFNUM_VPNMULTICAST
:
723 case SAFNUM_VPNUNIMULTICAST
:
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
);
731 printf("no SAFI %u decoder",safi
);
733 print_unknown_data(tptr
,"\n\t ",tlen
);
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
));
748 printf("no SAFI %u decoder",safi
);
750 print_unknown_data(tptr
,"\n\t ",tlen
);
756 printf("no AFI %u decoder",af
);
758 print_unknown_data(tptr
,"\n\t ",tlen
);
769 printf("\n\t %u SNPA", snpa
);
770 for (/*nothing*/; snpa
> 0; snpa
--) {
771 printf("\n\t %d bytes", tptr
[0]);
778 while (len
- (tptr
- pptr
) > 0) {
783 case SAFNUM_MULTICAST
:
784 case SAFNUM_UNIMULTICAST
:
785 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
786 printf("\n\t %s", buf
);
788 case SAFNUM_LABUNICAST
:
789 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
790 printf("\n\t %s", buf
);
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
);
799 printf("\n\t no SAFI %u decoder",safi
);
801 print_unknown_data(tptr
-3,"\n\t ",tlen
);
811 case SAFNUM_MULTICAST
:
812 case SAFNUM_UNIMULTICAST
:
813 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
814 printf("\n\t %s", buf
);
817 printf("\n\t no SAFI %u decoder ",safi
);
819 print_unknown_data(tptr
-3,"\n\t ",tlen
);
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
);
835 printf("no SAFI %u decoder",safi
);
837 print_unknown_data(tptr
,"\n\t ",tlen
);
846 printf("\n\t no AFI %u decoder ",af
);
848 print_unknown_data(tptr
-3,"\n\t ",tlen
);
857 case BGPTYPE_MP_UNREACH_NLRI
:
858 af
= EXTRACT_16BITS(tptr
);
861 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
862 tok2str(bgp_afi_values
, "Unknown AFI", af
),
864 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
865 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
870 while (len
- (tptr
- pptr
) > 0) {
875 case SAFNUM_MULTICAST
:
876 case SAFNUM_UNIMULTICAST
:
877 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
878 printf("\n\t %s", buf
);
880 case SAFNUM_LABUNICAST
:
881 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
882 printf("\n\t %s", buf
);
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
);
891 printf("\n\t no SAFI %u decoder",safi
);
893 print_unknown_data(tptr
-3,"\n\t ",tlen
);
904 case SAFNUM_MULTICAST
:
905 case SAFNUM_UNIMULTICAST
:
906 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
907 printf("\n\t %s", buf
);
910 printf("\n\t no SAFI %u decoder",safi
);
912 print_unknown_data(tptr
-3,"\n\t ",tlen
);
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
);
929 printf("no SAFI %u decoder",safi
);
931 print_unknown_data(tptr
-3,"\n\t ",tlen
);
939 printf("\n\t no AFI %u decoder",af
);
941 print_unknown_data(tptr
-3,"\n\t ",tlen
);
950 case BGPTYPE_EXTD_COMMUNITIES
:
952 printf("invalid len");
956 u_int8_t extd_comm
,extd_comm_type
,extd_comm_subtype
;
958 extd_comm_type
=extd_comm
&0x3f;
959 extd_comm_subtype
=*(tptr
+1);
960 switch(extd_comm_type
) {
962 switch (extd_comm_subtype
) {
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
,
971 extd_comm_subtype
&0x3f),
972 EXTRACT_16BITS(tptr
+2),
975 /* juniper has allocated typecode 10 to convey l2 information */
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
,
981 extd_comm_subtype
&0x3f),
982 tok2str(bgp_l2vpn_encaps_values
,
986 EXTRACT_16BITS(tptr
+4));
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
,
996 extd_comm_subtype
&0x3f),
998 EXTRACT_16BITS(tptr
+6));
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
,
1006 extd_comm_subtype
&0x3f),
1007 EXTRACT_32BITS(tptr
+2),
1008 EXTRACT_16BITS(tptr
+6));
1011 printf("\n\t no typecode %u decoder",
1013 print_unknown_data(tptr
,"\n\t ",8);
1022 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1024 print_unknown_data(pptr
,"\n\t ",len
);
1027 if (vflag
&&len
) /* omit zero length attributes*/
1028 print_unknown_data(pptr
,"\n\t ",len
);
1032 bgp_open_print(const u_char
*dat
, int length
)
1034 struct bgp_open bgpo
;
1035 struct bgp_opt bgpopt
;
1038 int i
,cap_type
,cap_len
;
1040 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1041 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1042 hlen
= ntohs(bgpo
.bgpo_len
);
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
);
1051 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
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
);
1063 printf("\n\t Option %s (%u), length: %u",
1064 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1068 /* now lets decode the options we know*/
1069 switch(bgpopt
.bgpopt_type
) {
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
),
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]);
1084 case BGP_CAPCODE_RR
:
1085 case BGP_CAPCODE_RR_CISCO
:
1088 printf("\n\t\tno decoder for Capability %u",
1095 printf("\n\t no decoder for option %u",
1096 bgpopt
.bgpopt_type
);
1100 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1108 bgp_update_print(const u_char
*dat
, int length
)
1111 struct bgp_attr bgpa
;
1117 TCHECK2(dat
[0], BGP_SIZE
);
1118 memcpy(&bgp
, dat
, BGP_SIZE
);
1119 hlen
= ntohs(bgp
.bgp_len
);
1120 p
= dat
+ BGP_SIZE
; /*XXX*/
1122 /* Unfeasible routes */
1123 len
= EXTRACT_16BITS(p
);
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.
1131 printf("\n\t Withdrawn routes: %d bytes", len
);
1133 char buf
[MAXHOSTNAMELEN
+ 100];
1138 printf("\n\t Withdrawn routes:");
1140 while(i
< 2 + len
) {
1141 i
+= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1142 printf("\n\t %s", buf
);
1149 len
= EXTRACT_16BITS(p
);
1151 /* do something more useful!*/
1153 while (i
< 2 + len
) {
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
);
1161 printf("\n\t %s (%u), length: %u",
1162 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
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);
1176 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
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
);
1199 bgp_notification_print(const u_char
*dat
, int length
)
1201 struct bgp_notification bgpn
;
1204 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1205 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1206 hlen
= ntohs(bgpn
.bgpn_len
);
1208 printf(", Error - %s", tok2str(bgp_notify_major_values
, "Unknown", bgpn
.bgpn_major
));
1210 switch (bgpn
.bgpn_major
) {
1212 case BGP_NOTIFY_MAJOR_MSG
:
1213 printf(" subcode %s", tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
));
1215 case BGP_NOTIFY_MAJOR_OPEN
:
1216 printf(" subcode %s", tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
));
1218 case BGP_NOTIFY_MAJOR_UPDATE
:
1219 printf(" subcode %s", tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
));
1231 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1233 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1234 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
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
);
1245 print_unknown_data(pptr
,"\n\t ", len
);
1251 bgp_header_print(const u_char
*dat
, int length
)
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
),
1262 switch (bgp
.bgp_type
) {
1264 bgp_open_print(dat
, length
);
1267 bgp_update_print(dat
, length
);
1269 case BGP_NOTIFICATION
:
1270 bgp_notification_print(dat
, length
);
1274 case BGP_ROUTE_REFRESH
:
1275 bgp_route_refresh_print(dat
, length
);
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
);
1289 bgp_print(const u_char
*dat
, int length
)
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,
1302 if (snapend
< dat
+ length
)
1309 while (p
< snapend
) {
1310 if (!TTEST2(p
[0], 1))
1317 if (!TTEST2(p
[0], sizeof(marker
)))
1319 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1324 /* found BGP header */
1325 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1326 memcpy(&bgp
, p
, BGP_SIZE
);
1331 hlen
= ntohs(bgp
.bgp_len
);
1333 if (TTEST2(p
[0], hlen
)) {
1334 bgp_header_print(p
, hlen
);
1338 printf("[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));