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.45 2002-08-02 04:04:37 guy Exp $";
39 #include <tcpdump-stdinc.h>
46 #include "interface.h"
47 #include "addrtoname.h"
51 u_int8_t bgp_marker
[16];
55 #define BGP_SIZE 19 /* unaligned */
59 #define BGP_NOTIFICATION 3
60 #define BGP_KEEPALIVE 4
61 #define BGP_ROUTE_REFRESH 5
63 static struct tok bgp_msg_values
[] = {
65 { BGP_UPDATE
, "Update"},
66 { BGP_NOTIFICATION
, "Notification"},
67 { BGP_KEEPALIVE
, "Keepalive"},
68 { BGP_ROUTE_REFRESH
, "Route Refresh"},
73 u_int8_t bgpo_marker
[16];
76 u_int8_t bgpo_version
;
78 u_int16_t bgpo_holdtime
;
81 /* options should follow */
83 #define BGP_OPEN_SIZE 29 /* unaligned */
90 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
92 struct bgp_notification
{
93 u_int8_t bgpn_marker
[16];
98 /* data should follow */
100 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
102 struct bgp_route_refresh
{
103 u_int8_t bgp_marker
[16];
106 u_int8_t afi
[2]; /* the compiler messes this structure up */
107 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
108 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
109 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
110 #define BGP_ROUTE_REFRESH_SIZE 23
119 #define bgp_attr_len(p) \
120 (((p)->bgpa_flags & 0x10) ? \
121 ntohs((p)->bgpa_len.elen) : (p)->bgpa_len.len)
122 #define bgp_attr_off(p) \
123 (((p)->bgpa_flags & 0x10) ? 4 : 3)
126 #define BGPTYPE_ORIGIN 1
127 #define BGPTYPE_AS_PATH 2
128 #define BGPTYPE_NEXT_HOP 3
129 #define BGPTYPE_MULTI_EXIT_DISC 4
130 #define BGPTYPE_LOCAL_PREF 5
131 #define BGPTYPE_ATOMIC_AGGREGATE 6
132 #define BGPTYPE_AGGREGATOR 7
133 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
134 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
135 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
136 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
137 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
138 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
139 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
140 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
141 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
143 static struct tok bgp_attr_values
[] = {
144 { BGPTYPE_ORIGIN
, "Origin"},
145 { BGPTYPE_AS_PATH
, "AS Path"},
146 { BGPTYPE_NEXT_HOP
, "Next Hop"},
147 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
148 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
149 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
150 { BGPTYPE_AGGREGATOR
, "Aggregator"},
151 { BGPTYPE_COMMUNITIES
, "Community"},
152 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
153 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
154 { BGPTYPE_DPA
, "DPA"},
155 { BGPTYPE_ADVERTISERS
, "Advertisers"},
156 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
157 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
158 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
159 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
160 { 255, "Reserved for development"},
164 #define BGP_OPT_AUTH 1
165 #define BGP_OPT_CAP 2
168 static struct tok bgp_opt_values
[] = {
169 { BGP_OPT_AUTH
, "Authentication Information"},
170 { BGP_OPT_CAP
, "Capabilities Advertisement"},
174 #define BGP_CAPCODE_MP 1
175 #define BGP_CAPCODE_RR 2
176 #define BGP_CAPCODE_RR_CISCO 128
178 static struct tok bgp_capcode_values
[] = {
179 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
180 { BGP_CAPCODE_RR
, "Route Refresh"},
181 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
185 #define BGP_NOTIFY_MAJOR_MSG 1
186 #define BGP_NOTIFY_MAJOR_OPEN 2
187 #define BGP_NOTIFY_MAJOR_UPDATE 3
188 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
189 #define BGP_NOTIFY_MAJOR_FSM 5
190 #define BGP_NOTIFY_MAJOR_CEASE 6
192 static struct tok bgp_notify_major_values
[] = {
193 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
194 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
195 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
196 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
197 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
198 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
202 static struct tok bgp_notify_minor_msg_values
[] = {
203 { 1, "Connection Not Synchronized"},
204 { 2, "Bad Message Length"},
205 { 3, "Bad Message Type"},
209 static struct tok bgp_notify_minor_open_values
[] = {
210 { 1, "Unsupported Version Number"},
212 { 3, "Bad BGP Identifier"},
213 { 4, "Unsupported Optional Parameter"},
214 { 5, "Authentication Failure"},
215 { 6, "Unacceptable Hold Time"},
219 static struct tok bgp_notify_minor_update_values
[] = {
220 { 1, "Malformed Attribute List"},
221 { 2, "Unrecognized Well-known Attribute"},
222 { 3, "Missing Well-known Attribute"},
223 { 4, "Attribute Flags Error"},
224 { 5, "Attribute Length Error"},
225 { 6, "Invalid ORIGIN Attribute"},
226 { 7, "AS Routing Loop"},
227 { 8, "Invalid NEXT_HOP Attribute"},
228 { 9, "Optional Attribute Error"},
229 { 10, "Invalid Network Field"},
230 { 11, "Malformed AS_PATH"},
234 static struct tok bgp_origin_values
[] = {
241 /* Subsequent address family identifier, RFC2283 section 7 */
243 #define SAFNUM_UNICAST 1
244 #define SAFNUM_MULTICAST 2
245 #define SAFNUM_UNIMULTICAST 3
246 /* labeled BGP RFC3107 */
247 #define SAFNUM_LABUNICAST 4
248 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
249 #define SAFNUM_VPNUNICAST 128
250 #define SAFNUM_VPNMULTICAST 129
251 #define SAFNUM_VPNUNIMULTICAST 130
253 #define BGP_VPN_RD_LEN 8
255 static struct tok bgp_safi_values
[] = {
256 { SAFNUM_RES
, "Reserved"},
257 { SAFNUM_UNICAST
, "Unicast"},
258 { SAFNUM_MULTICAST
, "Multicast"},
259 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
260 { SAFNUM_LABUNICAST
, "labeled Unicast"},
261 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
262 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
263 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
267 /* well-known community */
268 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
269 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
270 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
272 /* RFC1700 address family numbers */
274 #define AFNUM_INET6 2
277 #define AFNUM_BBN1822 5
282 #define AFNUM_X121 10
284 #define AFNUM_ATALK 12
285 #define AFNUM_DECNET 13
286 #define AFNUM_BANYAN 14
287 #define AFNUM_E164NSAP 15
288 /* draft-kompella-ppvpn-l2vpn */
289 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
291 static struct tok bgp_afi_values
[] = {
293 { AFNUM_INET
, "IPv4"},
294 { AFNUM_INET6
, "IPv6"},
295 { AFNUM_NSAP
, "NSAP"},
296 { AFNUM_HDLC
, "HDLC"},
297 { AFNUM_BBN1822
, "BBN 1822"},
299 { AFNUM_E163
, "E.163"},
300 { AFNUM_E164
, "E.164"},
301 { AFNUM_F69
, "F.69"},
302 { AFNUM_X121
, "X.121"},
303 { AFNUM_IPX
, "Novell IPX"},
304 { AFNUM_ATALK
, "Appletalk"},
305 { AFNUM_DECNET
, "Decnet IV"},
306 { AFNUM_BANYAN
, "Banyan Vines"},
307 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
308 { AFNUM_L2VPN
, "Layer-2 VPN"},
312 static struct tok bgp_extd_comm_subtype_values
[] = {
316 { 10, "layer2-info"},
320 static struct tok bgp_l2vpn_encaps_values
[] = {
323 { 2, "ATM AAL5 VCC transport"},
324 { 3, "ATM transparent cell transport"},
325 { 4, "Ethernet VLAN"},
330 { 9, "ATM VCC cell transport"},
331 { 10, "ATM VPC cell transport"},
334 { 64, "IP-interworking"},
339 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
345 if (plen
< 0 || 32 < plen
)
348 memset(&addr
, 0, sizeof(addr
));
349 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
351 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
352 ((0xff00 >> (plen
% 8)) & 0xff);
354 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
355 return 1 + (plen
+ 7) / 8;
359 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
364 plen
= pptr
[0]; /* get prefix length */
366 /* this is one of the weirdnesses of rfc3107
367 the label length (actually the label + COS bits)
368 is added to the prefix length;
369 we also do only read out just one label -
370 there is no real application for advertisement of
371 stacked labels in a a single BGP message
374 plen
-=24; /* adjust prefixlen - labellength */
376 if (plen
< 0 || 32 < plen
)
379 memset(&addr
, 0, sizeof(addr
));
380 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
382 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
383 ((0xff00 >> (plen
% 8)) & 0xff);
385 /* the label may get offsetted by 4 bits so lets shift it right */
386 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
387 getname((u_char
*)&addr
),
389 EXTRACT_24BITS(pptr
+1)>>4,
390 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
392 return 4 + (plen
+ 7) / 8;
397 bgp_vpn_rd_print (const u_char
*pptr
) {
399 /* allocate space for the following string
400 * xxx.xxx.xxx.xxx:xxxxx
401 * 21 bytes plus one termination byte */
405 /* ok lets load the RD format */
406 switch (EXTRACT_16BITS(pptr
)) {
407 /* AS:IP-address fmt*/
409 pos
+=sprintf(pos
, "%u:%u.%u.%u.%u",
410 EXTRACT_16BITS(pptr
+2),
416 /* IP-address:AS fmt*/
418 pos
+=sprintf(pos
, "%u.%u.%u.%u:%u",
423 EXTRACT_16BITS(pptr
+6));
426 pos
+=sprintf(pos
, "unknown RD format");
434 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
439 plen
= pptr
[0]; /* get prefix length */
441 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
443 if (plen
< 0 || 32 < plen
)
446 memset(&addr
, 0, sizeof(addr
));
447 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
449 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
450 ((0xff00 >> (plen
% 8)) & 0xff);
452 /* the label may get offsetted by 4 bits so lets shift it right */
453 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
454 bgp_vpn_rd_print(pptr
+4),
455 getname((u_char
*)&addr
),
457 EXTRACT_24BITS(pptr
+1)>>4,
458 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
460 return 12 + (plen
+ 7) / 8;
464 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
466 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
467 plen
=EXTRACT_16BITS(pptr
);
470 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
471 bgp_vpn_rd_print(pptr
),
472 EXTRACT_16BITS(pptr
+8),
473 EXTRACT_16BITS(pptr
+10),
474 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
478 /* ok now the variable part - lets read out TLVs*/
481 tlv_len
=EXTRACT_16BITS(pptr
);
487 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
490 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
492 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
497 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
502 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
509 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
511 struct in6_addr addr
;
515 if (plen
< 0 || 128 < plen
)
518 memset(&addr
, 0, sizeof(addr
));
519 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
521 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
522 ((0xff00 >> (plen
% 8)) & 0xff);
524 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
525 return 1 + (plen
+ 7) / 8;
530 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
538 char buf
[MAXHOSTNAMELEN
+ 100];
543 switch (attr
->bgpa_type
) {
546 printf("invalid len");
548 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
550 case BGPTYPE_AS_PATH
:
552 printf("invalid len");
559 while (tptr
< pptr
+ len
) {
561 * under RFC1965, p[0] means:
562 * 1: AS_SET 2: AS_SEQUENCE
563 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
565 if (tptr
[0] == 3 || tptr
[0] == 4)
567 printf("%s", (tptr
[0] & 1) ? "{" : "");
568 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
569 printf("%s%u", i
== 0 ? "" : " ",
570 EXTRACT_16BITS(&tptr
[2 + i
]));
572 printf("%s", (tptr
[0] & 1) ? "}" : "");
573 tptr
+= 2 + tptr
[1] * 2;
576 case BGPTYPE_NEXT_HOP
:
578 printf("invalid len");
580 printf("%s", getname(tptr
));
582 case BGPTYPE_MULTI_EXIT_DISC
:
583 case BGPTYPE_LOCAL_PREF
:
585 printf("invalid len");
587 printf("%u", EXTRACT_32BITS(tptr
));
589 case BGPTYPE_ATOMIC_AGGREGATE
:
591 printf("invalid len");
593 case BGPTYPE_AGGREGATOR
:
595 printf("invalid len");
598 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
601 case BGPTYPE_COMMUNITIES
:
603 printf("invalid len");
608 comm
= EXTRACT_32BITS(tptr
);
610 case BGP_COMMUNITY_NO_EXPORT
:
611 printf(" NO_EXPORT");
613 case BGP_COMMUNITY_NO_ADVERT
:
614 printf(" NO_ADVERTISE");
616 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
617 printf(" NO_EXPORT_SUBCONFED");
621 (comm
>> 16) & 0xffff,
623 (tlen
>4) ? ", " : "");
630 case BGPTYPE_ORIGINATOR_ID
:
632 printf("invalid len");
635 printf("%s",getname(tptr
));
637 case BGPTYPE_CLUSTER_LIST
:
641 (tlen
>4) ? ", " : "");
646 case BGPTYPE_MP_REACH_NLRI
:
647 af
= EXTRACT_16BITS(tptr
);
650 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
651 tok2str(bgp_afi_values
, "Unknown AFI", af
),
653 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
654 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
657 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
660 else if (af
== AFNUM_INET6
)
664 printf("\n\t no AFI %u decoder",af
);
666 print_unknown_data(tptr
,"\n\t ",tlen
);
676 printf("\n\t nexthop: ");
682 case SAFNUM_MULTICAST
:
683 case SAFNUM_UNIMULTICAST
:
684 case SAFNUM_LABUNICAST
:
685 printf("%s",getname(tptr
));
686 tlen
-= sizeof(struct in_addr
);
687 tptr
+= sizeof(struct in_addr
);
689 case SAFNUM_VPNUNICAST
:
690 case SAFNUM_VPNMULTICAST
:
691 case SAFNUM_VPNUNIMULTICAST
:
693 bgp_vpn_rd_print(tptr
),
694 getname(tptr
+BGP_VPN_RD_LEN
));
695 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
696 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
699 printf("no SAFI %u decoder",safi
);
701 print_unknown_data(tptr
,"\n\t ",tlen
);
709 case SAFNUM_MULTICAST
:
710 case SAFNUM_UNIMULTICAST
:
711 case SAFNUM_LABUNICAST
:
712 printf("%s", getname6(tptr
));
713 tlen
-= sizeof(struct in6_addr
);
714 tptr
+= sizeof(struct in6_addr
);
716 case SAFNUM_VPNUNICAST
:
717 case SAFNUM_VPNMULTICAST
:
718 case SAFNUM_VPNUNIMULTICAST
:
720 bgp_vpn_rd_print(tptr
),
721 getname6(tptr
+BGP_VPN_RD_LEN
));
722 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
723 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
726 printf("no SAFI %u decoder",safi
);
728 print_unknown_data(tptr
,"\n\t ",tlen
);
735 case SAFNUM_VPNUNICAST
:
736 case SAFNUM_VPNMULTICAST
:
737 case SAFNUM_VPNUNIMULTICAST
:
738 printf("%s", getname(tptr
));
739 tlen
-= (sizeof(struct in_addr
));
740 tptr
+= (sizeof(struct in_addr
));
743 printf("no SAFI %u decoder",safi
);
745 print_unknown_data(tptr
,"\n\t ",tlen
);
751 printf("no AFI %u decoder",af
);
753 print_unknown_data(tptr
,"\n\t ",tlen
);
764 printf("\n\t %u SNPA", snpa
);
765 for (/*nothing*/; snpa
> 0; snpa
--) {
766 printf("\n\t %d bytes", tptr
[0]);
773 while (len
- (tptr
- pptr
) > 0) {
778 case SAFNUM_MULTICAST
:
779 case SAFNUM_UNIMULTICAST
:
780 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
781 printf("\n\t %s", buf
);
783 case SAFNUM_LABUNICAST
:
784 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
785 printf("\n\t %s", buf
);
787 case SAFNUM_VPNUNICAST
:
788 case SAFNUM_VPNMULTICAST
:
789 case SAFNUM_VPNUNIMULTICAST
:
790 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
791 printf("\n\t %s", buf
);
794 printf("\n\t no SAFI %u decoder",safi
);
796 print_unknown_data(tptr
-3,"\n\t ",tlen
);
806 case SAFNUM_MULTICAST
:
807 case SAFNUM_UNIMULTICAST
:
808 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
809 printf("\n\t %s", buf
);
812 printf("\n\t no SAFI %u decoder ",safi
);
814 print_unknown_data(tptr
-3,"\n\t ",tlen
);
823 case SAFNUM_VPNUNICAST
:
824 case SAFNUM_VPNMULTICAST
:
825 case SAFNUM_VPNUNIMULTICAST
:
826 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
827 printf("\n\t %s", buf
);
830 printf("no SAFI %u decoder",safi
);
832 print_unknown_data(tptr
,"\n\t ",tlen
);
841 printf("\n\t no AFI %u decoder ",af
);
843 print_unknown_data(tptr
-3,"\n\t ",tlen
);
852 case BGPTYPE_MP_UNREACH_NLRI
:
853 af
= EXTRACT_16BITS(tptr
);
856 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
857 tok2str(bgp_afi_values
, "Unknown AFI", af
),
859 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
860 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
865 while (len
- (tptr
- pptr
) > 0) {
870 case SAFNUM_MULTICAST
:
871 case SAFNUM_UNIMULTICAST
:
872 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
873 printf("\n\t %s", buf
);
875 case SAFNUM_LABUNICAST
:
876 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
877 printf("\n\t %s", buf
);
879 case SAFNUM_VPNUNICAST
:
880 case SAFNUM_VPNMULTICAST
:
881 case SAFNUM_VPNUNIMULTICAST
:
882 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
883 printf("\n\t %s", buf
);
886 printf("\n\t no SAFI %u decoder",safi
);
888 print_unknown_data(tptr
-3,"\n\t ",tlen
);
899 case SAFNUM_MULTICAST
:
900 case SAFNUM_UNIMULTICAST
:
901 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
902 printf("\n\t %s", buf
);
905 printf("\n\t no SAFI %u decoder",safi
);
907 print_unknown_data(tptr
-3,"\n\t ",tlen
);
917 case SAFNUM_VPNUNICAST
:
918 case SAFNUM_VPNMULTICAST
:
919 case SAFNUM_VPNUNIMULTICAST
:
920 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
921 printf("\n\t %s", buf
);
924 printf("no SAFI %u decoder",safi
);
926 print_unknown_data(tptr
-3,"\n\t ",tlen
);
934 printf("\n\t no AFI %u decoder",af
);
936 print_unknown_data(tptr
-3,"\n\t ",tlen
);
945 case BGPTYPE_EXTD_COMMUNITIES
:
947 printf("invalid len");
951 u_int8_t extd_comm
,extd_comm_type
,extd_comm_subtype
;
953 extd_comm_type
=extd_comm
&0x3f;
954 extd_comm_subtype
=*(tptr
+1);
955 switch(extd_comm_type
) {
957 switch (extd_comm_subtype
) {
961 printf("\n\t %s%s%s:%u:%s",
962 (extd_comm
&0x80) ? "vendor-specific: " : "",
963 (extd_comm
&0x40) ? "non-transitive: " : "",
964 tok2str(bgp_extd_comm_subtype_values
,
966 extd_comm_subtype
&0x3f),
967 EXTRACT_16BITS(tptr
+2),
970 /* juniper has allocated typecode 10 to convey l2 information */
972 printf("\n\t %s%s:%s:Control Flags [0x%02x]:MTU %u",
973 (extd_comm
&0x40) ? "non-transitive: " : "",
974 tok2str(bgp_extd_comm_subtype_values
,
976 extd_comm_subtype
&0x3f),
977 tok2str(bgp_l2vpn_encaps_values
,
981 EXTRACT_16BITS(tptr
+4));
986 printf("\n\t %s%s%s:%s:%u",
987 (extd_comm
&0x80) ? "vendor-specific: " : "",
988 (extd_comm
&0x40) ? "non-transitive: " : "",
989 tok2str(bgp_extd_comm_subtype_values
,
991 extd_comm_subtype
&0x3f),
993 EXTRACT_16BITS(tptr
+6));
996 printf("\n\t %s%s%s:%u:%u",
997 (extd_comm
&0x80) ? "vendor-specific: " : "",
998 (extd_comm
&0x40) ? "non-transitive: " : "",
999 tok2str(bgp_extd_comm_subtype_values
,
1001 extd_comm_subtype
&0x3f),
1002 EXTRACT_32BITS(tptr
+2),
1003 EXTRACT_16BITS(tptr
+6));
1006 printf("\n\t no typecode %u decoder",
1008 print_unknown_data(tptr
,"\n\t ",8);
1017 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1019 print_unknown_data(pptr
,"\n\t ",len
);
1022 if (vflag
&&len
) /* omit zero length attributes*/
1023 print_unknown_data(pptr
,"\n\t ",len
);
1027 bgp_open_print(const u_char
*dat
, int length
)
1029 struct bgp_open bgpo
;
1030 struct bgp_opt bgpopt
;
1033 int i
,cap_type
,cap_len
;
1035 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1036 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1037 hlen
= ntohs(bgpo
.bgpo_len
);
1039 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1040 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1041 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1042 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1043 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1046 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1050 while (i
< bgpo
.bgpo_optlen
) {
1051 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1052 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1053 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1054 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1058 printf("\n\t Option %s (%u), length: %u",
1059 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1063 /* now lets decode the options we know*/
1064 switch(bgpopt
.bgpopt_type
) {
1066 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1067 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1068 printf("\n\t %s, length: %u",
1069 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1072 case BGP_CAPCODE_MP
:
1073 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1074 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1075 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1076 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1077 opt
[i
+BGP_OPT_SIZE
+5]);
1079 case BGP_CAPCODE_RR
:
1080 case BGP_CAPCODE_RR_CISCO
:
1083 printf("\n\t\tno decoder for Capability %u",
1090 printf("\n\t no decoder for option %u",
1091 bgpopt
.bgpopt_type
);
1095 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1103 bgp_update_print(const u_char
*dat
, int length
)
1106 struct bgp_attr bgpa
;
1112 TCHECK2(dat
[0], BGP_SIZE
);
1113 memcpy(&bgp
, dat
, BGP_SIZE
);
1114 hlen
= ntohs(bgp
.bgp_len
);
1115 p
= dat
+ BGP_SIZE
; /*XXX*/
1117 /* Unfeasible routes */
1118 len
= EXTRACT_16BITS(p
);
1121 * Without keeping state from the original NLRI message,
1122 * it's not possible to tell if this a v4 or v6 route,
1123 * so only try to decode it if we're not v6 enabled.
1126 printf("\n\t Withdrawn routes: %d bytes", len
);
1128 char buf
[MAXHOSTNAMELEN
+ 100];
1133 printf("\n\t Withdrawn routes:");
1135 while(i
< 2 + len
) {
1136 i
+= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1137 printf("\n\t %s", buf
);
1144 len
= EXTRACT_16BITS(p
);
1146 /* do something more useful!*/
1148 while (i
< 2 + len
) {
1151 TCHECK2(p
[i
], sizeof(bgpa
));
1152 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1153 alen
= bgp_attr_len(&bgpa
);
1154 aoff
= bgp_attr_off(&bgpa
);
1156 printf("\n\t %s (%u), length: %u",
1157 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1161 if (bgpa
.bgpa_flags
) {
1162 printf(", flags [%s%s%s%s",
1163 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1164 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1165 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1166 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1167 if (bgpa
.bgpa_flags
& 0xf)
1168 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1171 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1177 if (dat
+ length
> p
) {
1178 printf("\n\t Updated routes:");
1179 while (dat
+ length
> p
) {
1180 char buf
[MAXHOSTNAMELEN
+ 100];
1181 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1182 printf("\n\t %s", buf
);
1194 bgp_notification_print(const u_char
*dat
, int length
)
1196 struct bgp_notification bgpn
;
1199 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1200 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1201 hlen
= ntohs(bgpn
.bgpn_len
);
1203 printf(", Error - %s", tok2str(bgp_notify_major_values
, "Unknown", bgpn
.bgpn_major
));
1205 switch (bgpn
.bgpn_major
) {
1207 case BGP_NOTIFY_MAJOR_MSG
:
1208 printf(" subcode %s", tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
));
1210 case BGP_NOTIFY_MAJOR_OPEN
:
1211 printf(" subcode %s", tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
));
1213 case BGP_NOTIFY_MAJOR_UPDATE
:
1214 printf(" subcode %s", tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
));
1226 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1228 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1229 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1231 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1232 tok2str(bgp_afi_values
,"Unknown",
1233 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1234 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1235 tok2str(bgp_safi_values
,"Unknown",
1236 bgp_route_refresh_header
->safi
),
1237 bgp_route_refresh_header
->safi
);
1240 print_unknown_data(pptr
,"\n\t ", len
);
1246 bgp_header_print(const u_char
*dat
, int length
)
1250 TCHECK2(dat
[0], BGP_SIZE
);
1251 memcpy(&bgp
, dat
, BGP_SIZE
);
1252 printf("\n\t%s Message (%u), length: %u ",
1253 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1257 switch (bgp
.bgp_type
) {
1259 bgp_open_print(dat
, length
);
1262 bgp_update_print(dat
, length
);
1264 case BGP_NOTIFICATION
:
1265 bgp_notification_print(dat
, length
);
1269 case BGP_ROUTE_REFRESH
:
1270 bgp_route_refresh_print(dat
, length
);
1273 /* we have no decoder for the BGP message */
1274 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1275 print_unknown_data(dat
,"\n\t ",length
);
1284 bgp_print(const u_char
*dat
, int length
)
1288 const u_char
*start
;
1289 const u_char marker
[] = {
1290 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1291 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1297 if (snapend
< dat
+ length
)
1304 while (p
< snapend
) {
1305 if (!TTEST2(p
[0], 1))
1312 if (!TTEST2(p
[0], sizeof(marker
)))
1314 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1319 /* found BGP header */
1320 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1321 memcpy(&bgp
, p
, BGP_SIZE
);
1326 hlen
= ntohs(bgp
.bgp_len
);
1328 if (TTEST2(p
[0], hlen
)) {
1329 bgp_header_print(p
, hlen
);
1333 printf("[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));