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
29 * Extensively modified by Hannes Gredler (hannes@juniper.net) for more
30 * complete BGP support.
38 static const char rcsid
[] =
39 "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.48 2002-08-24 13:55:31 hannes Exp $";
42 #include <tcpdump-stdinc.h>
47 #include "interface.h"
48 #include "addrtoname.h"
52 u_int8_t bgp_marker
[16];
56 #define BGP_SIZE 19 /* unaligned */
60 #define BGP_NOTIFICATION 3
61 #define BGP_KEEPALIVE 4
62 #define BGP_ROUTE_REFRESH 5
64 static struct tok bgp_msg_values
[] = {
66 { BGP_UPDATE
, "Update"},
67 { BGP_NOTIFICATION
, "Notification"},
68 { BGP_KEEPALIVE
, "Keepalive"},
69 { BGP_ROUTE_REFRESH
, "Route Refresh"},
74 u_int8_t bgpo_marker
[16];
77 u_int8_t bgpo_version
;
79 u_int16_t bgpo_holdtime
;
82 /* options should follow */
84 #define BGP_OPEN_SIZE 29 /* unaligned */
91 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
93 struct bgp_notification
{
94 u_int8_t bgpn_marker
[16];
99 /* data should follow */
101 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
103 struct bgp_route_refresh
{
104 u_int8_t bgp_marker
[16];
107 u_int8_t afi
[2]; /* the compiler messes this structure up */
108 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
109 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
110 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
111 #define BGP_ROUTE_REFRESH_SIZE 23
120 #define bgp_attr_len(p) \
121 (((p)->bgpa_flags & 0x10) ? \
122 ntohs((p)->bgpa_len.elen) : (p)->bgpa_len.len)
123 #define bgp_attr_off(p) \
124 (((p)->bgpa_flags & 0x10) ? 4 : 3)
127 #define BGPTYPE_ORIGIN 1
128 #define BGPTYPE_AS_PATH 2
129 #define BGPTYPE_NEXT_HOP 3
130 #define BGPTYPE_MULTI_EXIT_DISC 4
131 #define BGPTYPE_LOCAL_PREF 5
132 #define BGPTYPE_ATOMIC_AGGREGATE 6
133 #define BGPTYPE_AGGREGATOR 7
134 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
135 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
136 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
137 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
138 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
139 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
140 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
141 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
142 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
144 static struct tok bgp_attr_values
[] = {
145 { BGPTYPE_ORIGIN
, "Origin"},
146 { BGPTYPE_AS_PATH
, "AS Path"},
147 { BGPTYPE_NEXT_HOP
, "Next Hop"},
148 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
149 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
150 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
151 { BGPTYPE_AGGREGATOR
, "Aggregator"},
152 { BGPTYPE_COMMUNITIES
, "Community"},
153 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
154 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
155 { BGPTYPE_DPA
, "DPA"},
156 { BGPTYPE_ADVERTISERS
, "Advertisers"},
157 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
158 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
159 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
160 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
161 { 255, "Reserved for development"},
165 #define BGP_OPT_AUTH 1
166 #define BGP_OPT_CAP 2
169 static struct tok bgp_opt_values
[] = {
170 { BGP_OPT_AUTH
, "Authentication Information"},
171 { BGP_OPT_CAP
, "Capabilities Advertisement"},
175 #define BGP_CAPCODE_MP 1
176 #define BGP_CAPCODE_RR 2
177 #define BGP_CAPCODE_RR_CISCO 128
179 static struct tok bgp_capcode_values
[] = {
180 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
181 { BGP_CAPCODE_RR
, "Route Refresh"},
182 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
186 #define BGP_NOTIFY_MAJOR_MSG 1
187 #define BGP_NOTIFY_MAJOR_OPEN 2
188 #define BGP_NOTIFY_MAJOR_UPDATE 3
189 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
190 #define BGP_NOTIFY_MAJOR_FSM 5
191 #define BGP_NOTIFY_MAJOR_CEASE 6
193 static struct tok bgp_notify_major_values
[] = {
194 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
195 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
196 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
197 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
198 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
199 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
203 static struct tok bgp_notify_minor_msg_values
[] = {
204 { 1, "Connection Not Synchronized"},
205 { 2, "Bad Message Length"},
206 { 3, "Bad Message Type"},
210 static struct tok bgp_notify_minor_open_values
[] = {
211 { 1, "Unsupported Version Number"},
213 { 3, "Bad BGP Identifier"},
214 { 4, "Unsupported Optional Parameter"},
215 { 5, "Authentication Failure"},
216 { 6, "Unacceptable Hold Time"},
220 static struct tok bgp_notify_minor_update_values
[] = {
221 { 1, "Malformed Attribute List"},
222 { 2, "Unrecognized Well-known Attribute"},
223 { 3, "Missing Well-known Attribute"},
224 { 4, "Attribute Flags Error"},
225 { 5, "Attribute Length Error"},
226 { 6, "Invalid ORIGIN Attribute"},
227 { 7, "AS Routing Loop"},
228 { 8, "Invalid NEXT_HOP Attribute"},
229 { 9, "Optional Attribute Error"},
230 { 10, "Invalid Network Field"},
231 { 11, "Malformed AS_PATH"},
235 static struct tok bgp_origin_values
[] = {
242 /* Subsequent address family identifier, RFC2283 section 7 */
244 #define SAFNUM_UNICAST 1
245 #define SAFNUM_MULTICAST 2
246 #define SAFNUM_UNIMULTICAST 3
247 /* labeled BGP RFC3107 */
248 #define SAFNUM_LABUNICAST 4
249 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
250 #define SAFNUM_VPNUNICAST 128
251 #define SAFNUM_VPNMULTICAST 129
252 #define SAFNUM_VPNUNIMULTICAST 130
254 #define BGP_VPN_RD_LEN 8
256 static struct tok bgp_safi_values
[] = {
257 { SAFNUM_RES
, "Reserved"},
258 { SAFNUM_UNICAST
, "Unicast"},
259 { SAFNUM_MULTICAST
, "Multicast"},
260 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
261 { SAFNUM_LABUNICAST
, "labeled Unicast"},
262 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
263 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
264 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
268 /* well-known community */
269 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
270 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
271 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
273 /* RFC1700 address family numbers */
275 #define AFNUM_INET6 2
278 #define AFNUM_BBN1822 5
283 #define AFNUM_X121 10
285 #define AFNUM_ATALK 12
286 #define AFNUM_DECNET 13
287 #define AFNUM_BANYAN 14
288 #define AFNUM_E164NSAP 15
289 /* draft-kompella-ppvpn-l2vpn */
290 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
292 static struct tok bgp_afi_values
[] = {
294 { AFNUM_INET
, "IPv4"},
295 { AFNUM_INET6
, "IPv6"},
296 { AFNUM_NSAP
, "NSAP"},
297 { AFNUM_HDLC
, "HDLC"},
298 { AFNUM_BBN1822
, "BBN 1822"},
300 { AFNUM_E163
, "E.163"},
301 { AFNUM_E164
, "E.164"},
302 { AFNUM_F69
, "F.69"},
303 { AFNUM_X121
, "X.121"},
304 { AFNUM_IPX
, "Novell IPX"},
305 { AFNUM_ATALK
, "Appletalk"},
306 { AFNUM_DECNET
, "Decnet IV"},
307 { AFNUM_BANYAN
, "Banyan Vines"},
308 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
309 { AFNUM_L2VPN
, "Layer-2 VPN"},
313 /* Extended community type - draft-ramachandra-bgp-ext-communities */
314 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
315 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
316 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
317 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
318 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
319 /* rfc2547 bgp-mpls-vpns */
320 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin */
321 /* draft-rosen-vpns-ospf-bgp-mpls */
322 #define BGP_EXT_COM_OSPF_RTYPE 0x8000 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
323 #define BGP_EXT_COM_OSPF_RID 0x8001 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
324 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
326 static struct tok bgp_extd_comm_subtype_values
[] = {
327 { BGP_EXT_COM_RT_0
, "target"},
328 { BGP_EXT_COM_RT_1
, "target"},
329 { BGP_EXT_COM_RO_0
, "origin"},
330 { BGP_EXT_COM_RO_1
, "origin"},
331 { BGP_EXT_COM_LINKBAND
, "link-BW"},
332 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
333 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
334 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
335 { BGP_EXT_COM_L2INFO
, "layer2-info"},
339 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
340 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
341 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
342 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
343 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
344 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
345 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
346 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
348 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
349 { BGP_OSPF_RTYPE_RTR
, "Router" },
350 { BGP_OSPF_RTYPE_NET
, "Network" },
351 { BGP_OSPF_RTYPE_SUM
, "Summary" },
352 { BGP_OSPF_RTYPE_EXT
, "External" },
353 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
354 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
358 static struct tok bgp_l2vpn_encaps_values
[] = {
361 { 2, "ATM AAL5 VCC transport"},
362 { 3, "ATM transparent cell transport"},
363 { 4, "Ethernet VLAN"},
368 { 9, "ATM VCC cell transport"},
369 { 10, "ATM VPC cell transport"},
372 { 64, "IP-interworking"},
377 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
383 if (plen
< 0 || 32 < plen
)
386 memset(&addr
, 0, sizeof(addr
));
387 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
389 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
390 ((0xff00 >> (plen
% 8)) & 0xff);
392 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
393 return 1 + (plen
+ 7) / 8;
397 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
402 plen
= pptr
[0]; /* get prefix length */
404 /* this is one of the weirdnesses of rfc3107
405 the label length (actually the label + COS bits)
406 is added to the prefix length;
407 we also do only read out just one label -
408 there is no real application for advertisement of
409 stacked labels in a a single BGP message
412 plen
-=24; /* adjust prefixlen - labellength */
414 if (plen
< 0 || 32 < plen
)
417 memset(&addr
, 0, sizeof(addr
));
418 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
420 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
421 ((0xff00 >> (plen
% 8)) & 0xff);
423 /* the label may get offsetted by 4 bits so lets shift it right */
424 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
425 getname((u_char
*)&addr
),
427 EXTRACT_24BITS(pptr
+1)>>4,
428 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
430 return 4 + (plen
+ 7) / 8;
435 bgp_vpn_rd_print (const u_char
*pptr
) {
437 /* allocate space for the following string
438 * xxx.xxx.xxx.xxx:xxxxx
439 * 21 bytes plus one termination byte */
443 /* ok lets load the RD format */
444 switch (EXTRACT_16BITS(pptr
)) {
445 /* AS:IP-address fmt*/
447 pos
+=sprintf(pos
, "%u:%u.%u.%u.%u",
448 EXTRACT_16BITS(pptr
+2),
454 /* IP-address:AS fmt*/
456 pos
+=sprintf(pos
, "%u.%u.%u.%u:%u",
461 EXTRACT_16BITS(pptr
+6));
464 pos
+=sprintf(pos
, "unknown RD format");
472 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
477 plen
= pptr
[0]; /* get prefix length */
479 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
481 if (plen
< 0 || 32 < plen
)
484 memset(&addr
, 0, sizeof(addr
));
485 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
487 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
488 ((0xff00 >> (plen
% 8)) & 0xff);
490 /* the label may get offsetted by 4 bits so lets shift it right */
491 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
492 bgp_vpn_rd_print(pptr
+4),
493 getname((u_char
*)&addr
),
495 EXTRACT_24BITS(pptr
+1)>>4,
496 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
498 return 12 + (plen
+ 7) / 8;
502 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
504 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
505 plen
=EXTRACT_16BITS(pptr
);
508 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
509 bgp_vpn_rd_print(pptr
),
510 EXTRACT_16BITS(pptr
+8),
511 EXTRACT_16BITS(pptr
+10),
512 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
516 /* ok now the variable part - lets read out TLVs*/
519 tlv_len
=EXTRACT_16BITS(pptr
);
525 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
528 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
530 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
535 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
540 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
547 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
549 struct in6_addr addr
;
553 if (plen
< 0 || 128 < plen
)
556 memset(&addr
, 0, sizeof(addr
));
557 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
559 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
560 ((0xff00 >> (plen
% 8)) & 0xff);
562 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
563 return 1 + (plen
+ 7) / 8;
568 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
576 char buf
[MAXHOSTNAMELEN
+ 100];
581 switch (attr
->bgpa_type
) {
584 printf("invalid len");
586 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
588 case BGPTYPE_AS_PATH
:
590 printf("invalid len");
597 while (tptr
< pptr
+ len
) {
599 * under RFC1965, p[0] means:
600 * 1: AS_SET 2: AS_SEQUENCE
601 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
603 if (tptr
[0] == 3 || tptr
[0] == 4)
605 printf("%s", (tptr
[0] & 1) ? "{" : "");
606 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
607 printf("%s%u", i
== 0 ? "" : " ",
608 EXTRACT_16BITS(&tptr
[2 + i
]));
610 printf("%s", (tptr
[0] & 1) ? "}" : "");
611 tptr
+= 2 + tptr
[1] * 2;
614 case BGPTYPE_NEXT_HOP
:
616 printf("invalid len");
618 printf("%s", getname(tptr
));
620 case BGPTYPE_MULTI_EXIT_DISC
:
621 case BGPTYPE_LOCAL_PREF
:
623 printf("invalid len");
625 printf("%u", EXTRACT_32BITS(tptr
));
627 case BGPTYPE_ATOMIC_AGGREGATE
:
629 printf("invalid len");
631 case BGPTYPE_AGGREGATOR
:
633 printf("invalid len");
636 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
639 case BGPTYPE_COMMUNITIES
:
641 printf("invalid len");
646 comm
= EXTRACT_32BITS(tptr
);
648 case BGP_COMMUNITY_NO_EXPORT
:
649 printf(" NO_EXPORT");
651 case BGP_COMMUNITY_NO_ADVERT
:
652 printf(" NO_ADVERTISE");
654 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
655 printf(" NO_EXPORT_SUBCONFED");
659 (comm
>> 16) & 0xffff,
661 (tlen
>4) ? ", " : "");
668 case BGPTYPE_ORIGINATOR_ID
:
670 printf("invalid len");
673 printf("%s",getname(tptr
));
675 case BGPTYPE_CLUSTER_LIST
:
679 (tlen
>4) ? ", " : "");
684 case BGPTYPE_MP_REACH_NLRI
:
685 af
= EXTRACT_16BITS(tptr
);
688 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
689 tok2str(bgp_afi_values
, "Unknown AFI", af
),
691 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
692 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
695 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
698 else if (af
== AFNUM_INET6
)
702 printf("\n\t no AFI %u decoder",af
);
704 print_unknown_data(tptr
,"\n\t ",tlen
);
714 printf("\n\t nexthop: ");
720 case SAFNUM_MULTICAST
:
721 case SAFNUM_UNIMULTICAST
:
722 case SAFNUM_LABUNICAST
:
723 printf("%s",getname(tptr
));
724 tlen
-= sizeof(struct in_addr
);
725 tptr
+= sizeof(struct in_addr
);
727 case SAFNUM_VPNUNICAST
:
728 case SAFNUM_VPNMULTICAST
:
729 case SAFNUM_VPNUNIMULTICAST
:
731 bgp_vpn_rd_print(tptr
),
732 getname(tptr
+BGP_VPN_RD_LEN
));
733 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
734 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
737 printf("no SAFI %u decoder",safi
);
739 print_unknown_data(tptr
,"\n\t ",tlen
);
747 case SAFNUM_MULTICAST
:
748 case SAFNUM_UNIMULTICAST
:
749 case SAFNUM_LABUNICAST
:
750 printf("%s", getname6(tptr
));
751 tlen
-= sizeof(struct in6_addr
);
752 tptr
+= sizeof(struct in6_addr
);
754 case SAFNUM_VPNUNICAST
:
755 case SAFNUM_VPNMULTICAST
:
756 case SAFNUM_VPNUNIMULTICAST
:
758 bgp_vpn_rd_print(tptr
),
759 getname6(tptr
+BGP_VPN_RD_LEN
));
760 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
761 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
764 printf("no SAFI %u decoder",safi
);
766 print_unknown_data(tptr
,"\n\t ",tlen
);
773 case SAFNUM_VPNUNICAST
:
774 case SAFNUM_VPNMULTICAST
:
775 case SAFNUM_VPNUNIMULTICAST
:
776 printf("%s", getname(tptr
));
777 tlen
-= (sizeof(struct in_addr
));
778 tptr
+= (sizeof(struct in_addr
));
781 printf("no SAFI %u decoder",safi
);
783 print_unknown_data(tptr
,"\n\t ",tlen
);
789 printf("no AFI %u decoder",af
);
791 print_unknown_data(tptr
,"\n\t ",tlen
);
802 printf("\n\t %u SNPA", snpa
);
803 for (/*nothing*/; snpa
> 0; snpa
--) {
804 printf("\n\t %d bytes", tptr
[0]);
811 while (len
- (tptr
- pptr
) > 0) {
816 case SAFNUM_MULTICAST
:
817 case SAFNUM_UNIMULTICAST
:
818 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
819 printf("\n\t %s", buf
);
821 case SAFNUM_LABUNICAST
:
822 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
823 printf("\n\t %s", buf
);
825 case SAFNUM_VPNUNICAST
:
826 case SAFNUM_VPNMULTICAST
:
827 case SAFNUM_VPNUNIMULTICAST
:
828 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
829 printf("\n\t %s", buf
);
832 printf("\n\t no SAFI %u decoder",safi
);
834 print_unknown_data(tptr
-3,"\n\t ",tlen
);
844 case SAFNUM_MULTICAST
:
845 case SAFNUM_UNIMULTICAST
:
846 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
847 printf("\n\t %s", buf
);
850 printf("\n\t no SAFI %u decoder ",safi
);
852 print_unknown_data(tptr
-3,"\n\t ",tlen
);
861 case SAFNUM_VPNUNICAST
:
862 case SAFNUM_VPNMULTICAST
:
863 case SAFNUM_VPNUNIMULTICAST
:
864 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
865 printf("\n\t %s", buf
);
868 printf("no SAFI %u decoder",safi
);
870 print_unknown_data(tptr
,"\n\t ",tlen
);
879 printf("\n\t no AFI %u decoder ",af
);
881 print_unknown_data(tptr
-3,"\n\t ",tlen
);
890 case BGPTYPE_MP_UNREACH_NLRI
:
891 af
= EXTRACT_16BITS(tptr
);
894 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
895 tok2str(bgp_afi_values
, "Unknown AFI", af
),
897 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
898 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
903 while (len
- (tptr
- pptr
) > 0) {
908 case SAFNUM_MULTICAST
:
909 case SAFNUM_UNIMULTICAST
:
910 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
911 printf("\n\t %s", buf
);
913 case SAFNUM_LABUNICAST
:
914 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
915 printf("\n\t %s", buf
);
917 case SAFNUM_VPNUNICAST
:
918 case SAFNUM_VPNMULTICAST
:
919 case SAFNUM_VPNUNIMULTICAST
:
920 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
921 printf("\n\t %s", buf
);
924 printf("\n\t no SAFI %u decoder",safi
);
926 print_unknown_data(tptr
-3,"\n\t ",tlen
);
937 case SAFNUM_MULTICAST
:
938 case SAFNUM_UNIMULTICAST
:
939 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
940 printf("\n\t %s", buf
);
943 printf("\n\t no SAFI %u decoder",safi
);
945 print_unknown_data(tptr
-3,"\n\t ",tlen
);
955 case SAFNUM_VPNUNICAST
:
956 case SAFNUM_VPNMULTICAST
:
957 case SAFNUM_VPNUNIMULTICAST
:
958 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
959 printf("\n\t %s", buf
);
962 printf("no SAFI %u decoder",safi
);
964 print_unknown_data(tptr
-3,"\n\t ",tlen
);
972 printf("\n\t no AFI %u decoder",af
);
974 print_unknown_data(tptr
-3,"\n\t ",tlen
);
983 case BGPTYPE_EXTD_COMMUNITIES
:
985 printf("invalid len");
990 extd_comm
=EXTRACT_16BITS(tptr
);
992 case BGP_EXT_COM_RT_0
:
993 case BGP_EXT_COM_RO_0
:
994 printf("\n\t %s%s%s:%u:%s",
995 (extd_comm
&0x8000) ? "vendor-specific: " : "",
996 (extd_comm
&0x4000) ? "non-transitive: " : "",
997 tok2str(bgp_extd_comm_subtype_values
,
1000 EXTRACT_16BITS(tptr
+2),
1003 case BGP_EXT_COM_RT_1
:
1004 case BGP_EXT_COM_RO_1
:
1005 printf("\n\t %s%s%s:%s:%u",
1006 (extd_comm
&0x8000) ? "vendor-specific: " : "",
1007 (extd_comm
&0x4000) ? "non-transitive: " : "",
1008 tok2str(bgp_extd_comm_subtype_values
,
1012 EXTRACT_16BITS(tptr
+6));
1014 case BGP_EXT_COM_VPN_ORIGIN
:
1015 case BGP_EXT_COM_OSPF_RID
:
1016 printf("\n\t %s%s%s:%s",
1017 (extd_comm
&0x8000) ? "vendor-specific: " : "",
1018 (extd_comm
&0x4000) ? "non-transitive: " : "",
1019 tok2str(bgp_extd_comm_subtype_values
,
1024 case BGP_EXT_COM_OSPF_RTYPE
:
1025 printf("\n\t %s%s%s, area:%s, router-type:%s, metric-type:%s%s",
1026 (extd_comm
&0x8000) ? "vendor-specific: " : "",
1027 (extd_comm
&0x4000) ? "non-transitive: " : "",
1028 tok2str(bgp_extd_comm_subtype_values
,
1032 tok2str(bgp_extd_comm_ospf_rtype_values
,
1035 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1036 (*(tptr
+6) == (BGP_OSPF_RTYPE_EXT
||BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1038 case BGP_EXT_COM_L2INFO
:
1039 printf("\n\t %s%s:%s:Control Flags [0x%02x]:MTU %u",
1040 (extd_comm
&0x4000) ? "non-transitive: " : "",
1041 tok2str(bgp_extd_comm_subtype_values
,
1044 tok2str(bgp_l2vpn_encaps_values
,
1048 EXTRACT_16BITS(tptr
+4));
1051 printf("\n\t no typecode %u decoder",
1053 print_unknown_data(tptr
,"\n\t ",8);
1062 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1064 print_unknown_data(pptr
,"\n\t ",len
);
1067 if (vflag
&&len
) /* omit zero length attributes*/
1068 print_unknown_data(pptr
,"\n\t ",len
);
1072 bgp_open_print(const u_char
*dat
, int length
)
1074 struct bgp_open bgpo
;
1075 struct bgp_opt bgpopt
;
1078 int i
,cap_type
,cap_len
;
1080 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1081 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1082 hlen
= ntohs(bgpo
.bgpo_len
);
1084 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1085 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1086 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1087 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1088 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1091 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1095 while (i
< bgpo
.bgpo_optlen
) {
1096 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1097 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1098 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1099 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1103 printf("\n\t Option %s (%u), length: %u",
1104 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1108 /* now lets decode the options we know*/
1109 switch(bgpopt
.bgpopt_type
) {
1111 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1112 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1113 printf("\n\t %s, length: %u",
1114 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1117 case BGP_CAPCODE_MP
:
1118 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1119 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1120 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1121 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1122 opt
[i
+BGP_OPT_SIZE
+5]);
1124 case BGP_CAPCODE_RR
:
1125 case BGP_CAPCODE_RR_CISCO
:
1128 printf("\n\t\tno decoder for Capability %u",
1135 printf("\n\t no decoder for option %u",
1136 bgpopt
.bgpopt_type
);
1140 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1148 bgp_update_print(const u_char
*dat
, int length
)
1151 struct bgp_attr bgpa
;
1157 TCHECK2(dat
[0], BGP_SIZE
);
1158 memcpy(&bgp
, dat
, BGP_SIZE
);
1159 hlen
= ntohs(bgp
.bgp_len
);
1160 p
= dat
+ BGP_SIZE
; /*XXX*/
1162 /* Unfeasible routes */
1163 len
= EXTRACT_16BITS(p
);
1166 * Without keeping state from the original NLRI message,
1167 * it's not possible to tell if this a v4 or v6 route,
1168 * so only try to decode it if we're not v6 enabled.
1171 printf("\n\t Withdrawn routes: %d bytes", len
);
1173 char buf
[MAXHOSTNAMELEN
+ 100];
1178 printf("\n\t Withdrawn routes:");
1180 while(i
< 2 + len
) {
1181 i
+= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1182 printf("\n\t %s", buf
);
1189 len
= EXTRACT_16BITS(p
);
1191 /* do something more useful!*/
1193 while (i
< 2 + len
) {
1196 TCHECK2(p
[i
], sizeof(bgpa
));
1197 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1198 alen
= bgp_attr_len(&bgpa
);
1199 aoff
= bgp_attr_off(&bgpa
);
1201 printf("\n\t %s (%u), length: %u",
1202 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1206 if (bgpa
.bgpa_flags
) {
1207 printf(", flags [%s%s%s%s",
1208 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1209 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1210 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1211 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1212 if (bgpa
.bgpa_flags
& 0xf)
1213 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1216 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1222 if (dat
+ length
> p
) {
1223 printf("\n\t Updated routes:");
1224 while (dat
+ length
> p
) {
1225 char buf
[MAXHOSTNAMELEN
+ 100];
1226 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1227 printf("\n\t %s", buf
);
1239 bgp_notification_print(const u_char
*dat
, int length
)
1241 struct bgp_notification bgpn
;
1244 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1245 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1246 hlen
= ntohs(bgpn
.bgpn_len
);
1248 printf(", Error - %s", tok2str(bgp_notify_major_values
, "Unknown", bgpn
.bgpn_major
));
1250 switch (bgpn
.bgpn_major
) {
1252 case BGP_NOTIFY_MAJOR_MSG
:
1253 printf(" subcode %s", tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
));
1255 case BGP_NOTIFY_MAJOR_OPEN
:
1256 printf(" subcode %s", tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
));
1258 case BGP_NOTIFY_MAJOR_UPDATE
:
1259 printf(" subcode %s", tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
));
1271 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1273 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1274 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1276 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1277 tok2str(bgp_afi_values
,"Unknown",
1278 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1279 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1280 tok2str(bgp_safi_values
,"Unknown",
1281 bgp_route_refresh_header
->safi
),
1282 bgp_route_refresh_header
->safi
);
1285 print_unknown_data(pptr
,"\n\t ", len
);
1291 bgp_header_print(const u_char
*dat
, int length
)
1295 TCHECK2(dat
[0], BGP_SIZE
);
1296 memcpy(&bgp
, dat
, BGP_SIZE
);
1297 printf("\n\t%s Message (%u), length: %u",
1298 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1302 switch (bgp
.bgp_type
) {
1304 bgp_open_print(dat
, length
);
1307 bgp_update_print(dat
, length
);
1309 case BGP_NOTIFICATION
:
1310 bgp_notification_print(dat
, length
);
1314 case BGP_ROUTE_REFRESH
:
1315 bgp_route_refresh_print(dat
, length
);
1318 /* we have no decoder for the BGP message */
1319 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1320 print_unknown_data(dat
,"\n\t ",length
);
1329 bgp_print(const u_char
*dat
, int length
)
1333 const u_char
*start
;
1334 const u_char marker
[] = {
1335 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1336 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1342 if (snapend
< dat
+ length
)
1345 printf(": BGP, length: %u",length
);
1349 while (p
< snapend
) {
1350 if (!TTEST2(p
[0], 1))
1357 if (!TTEST2(p
[0], sizeof(marker
)))
1359 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1364 /* found BGP header */
1365 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1366 memcpy(&bgp
, p
, BGP_SIZE
);
1371 hlen
= ntohs(bgp
.bgp_len
);
1373 if (TTEST2(p
[0], hlen
)) {
1374 bgp_header_print(p
, hlen
);
1378 printf("[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));