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
[] _U_
=
39 "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.72.2.4 2004-03-24 00:04:04 guy 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];
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 EXTRACT_16BITS(&(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"},
165 #define BGP_AS_SEQUENCE 2
166 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
167 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
169 static struct tok bgp_as_path_segment_open_values
[] = {
170 { BGP_AS_SEQUENCE
, ""},
172 { BGP_CONFED_AS_SEQUENCE
, "( "},
173 { BGP_CONFED_AS_SET
, "({ "},
177 static struct tok bgp_as_path_segment_close_values
[] = {
178 { BGP_AS_SEQUENCE
, ""},
180 { BGP_CONFED_AS_SEQUENCE
, ")"},
181 { BGP_CONFED_AS_SET
, "})"},
185 #define BGP_OPT_AUTH 1
186 #define BGP_OPT_CAP 2
189 static struct tok bgp_opt_values
[] = {
190 { BGP_OPT_AUTH
, "Authentication Information"},
191 { BGP_OPT_CAP
, "Capabilities Advertisement"},
195 #define BGP_CAPCODE_MP 1
196 #define BGP_CAPCODE_RR 2
197 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
198 #define BGP_CAPCODE_RR_CISCO 128
200 static struct tok bgp_capcode_values
[] = {
201 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
202 { BGP_CAPCODE_RR
, "Route Refresh"},
203 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
204 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
208 #define BGP_NOTIFY_MAJOR_MSG 1
209 #define BGP_NOTIFY_MAJOR_OPEN 2
210 #define BGP_NOTIFY_MAJOR_UPDATE 3
211 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
212 #define BGP_NOTIFY_MAJOR_FSM 5
213 #define BGP_NOTIFY_MAJOR_CEASE 6
214 #define BGP_NOTIFY_MAJOR_CAP 7
216 static struct tok bgp_notify_major_values
[] = {
217 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
218 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
219 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
220 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
221 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
222 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
223 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
227 /* draft-ietf-idr-cease-subcode-02 */
228 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
229 static struct tok bgp_notify_minor_cease_values
[] = {
230 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
231 { 2, "Administratively Shutdown"},
232 { 3, "Peer Unconfigured"},
233 { 4, "Administratively Reset"},
234 { 5, "Connection Rejected"},
235 { 6, "Other Configuration Change"},
236 { 7, "Connection Collision Resolution"},
240 static struct tok bgp_notify_minor_msg_values
[] = {
241 { 1, "Connection Not Synchronized"},
242 { 2, "Bad Message Length"},
243 { 3, "Bad Message Type"},
247 static struct tok bgp_notify_minor_open_values
[] = {
248 { 1, "Unsupported Version Number"},
250 { 3, "Bad BGP Identifier"},
251 { 4, "Unsupported Optional Parameter"},
252 { 5, "Authentication Failure"},
253 { 6, "Unacceptable Hold Time"},
257 static struct tok bgp_notify_minor_update_values
[] = {
258 { 1, "Malformed Attribute List"},
259 { 2, "Unrecognized Well-known Attribute"},
260 { 3, "Missing Well-known Attribute"},
261 { 4, "Attribute Flags Error"},
262 { 5, "Attribute Length Error"},
263 { 6, "Invalid ORIGIN Attribute"},
264 { 7, "AS Routing Loop"},
265 { 8, "Invalid NEXT_HOP Attribute"},
266 { 9, "Optional Attribute Error"},
267 { 10, "Invalid Network Field"},
268 { 11, "Malformed AS_PATH"},
272 static struct tok bgp_notify_minor_cap_values
[] = {
273 { 1, "Invalid Action Value" },
274 { 2, "Invalid Capability Length" },
275 { 3, "Malformed Capability Value" },
276 { 4, "Unsupported Capability Code" },
280 static struct tok bgp_origin_values
[] = {
287 /* Subsequent address family identifier, RFC2283 section 7 */
289 #define SAFNUM_UNICAST 1
290 #define SAFNUM_MULTICAST 2
291 #define SAFNUM_UNIMULTICAST 3
292 /* labeled BGP RFC3107 */
293 #define SAFNUM_LABUNICAST 4
294 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
295 #define SAFNUM_VPNUNICAST 128
296 #define SAFNUM_VPNMULTICAST 129
297 #define SAFNUM_VPNUNIMULTICAST 130
298 /* draft-marques-ppvpn-rt-constrain-01.txt */
299 #define SAFNUM_RT_ROUTING_INFO 132
301 #define BGP_VPN_RD_LEN 8
303 static struct tok bgp_safi_values
[] = {
304 { SAFNUM_RES
, "Reserved"},
305 { SAFNUM_UNICAST
, "Unicast"},
306 { SAFNUM_MULTICAST
, "Multicast"},
307 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
308 { SAFNUM_LABUNICAST
, "labeled Unicast"},
309 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
310 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
311 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
312 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
316 /* well-known community */
317 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
318 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
319 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
321 /* RFC1700 address family numbers */
323 #define AFNUM_INET6 2
326 #define AFNUM_BBN1822 5
331 #define AFNUM_X121 10
333 #define AFNUM_ATALK 12
334 #define AFNUM_DECNET 13
335 #define AFNUM_BANYAN 14
336 #define AFNUM_E164NSAP 15
337 /* draft-kompella-ppvpn-l2vpn */
338 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
340 static struct tok bgp_afi_values
[] = {
342 { AFNUM_INET
, "IPv4"},
343 { AFNUM_INET6
, "IPv6"},
344 { AFNUM_NSAP
, "NSAP"},
345 { AFNUM_HDLC
, "HDLC"},
346 { AFNUM_BBN1822
, "BBN 1822"},
348 { AFNUM_E163
, "E.163"},
349 { AFNUM_E164
, "E.164"},
350 { AFNUM_F69
, "F.69"},
351 { AFNUM_X121
, "X.121"},
352 { AFNUM_IPX
, "Novell IPX"},
353 { AFNUM_ATALK
, "Appletalk"},
354 { AFNUM_DECNET
, "Decnet IV"},
355 { AFNUM_BANYAN
, "Banyan Vines"},
356 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
357 { AFNUM_L2VPN
, "Layer-2 VPN"},
361 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
362 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
363 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
364 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
365 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
366 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
367 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
368 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
369 /* rfc2547 bgp-mpls-vpns */
371 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
372 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
373 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
374 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
376 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
377 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
379 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
380 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
382 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
384 static struct tok bgp_extd_comm_flag_values
[] = {
385 { 0x8000, "vendor-specific"},
386 { 0x4000, "non-transitive"},
390 static struct tok bgp_extd_comm_subtype_values
[] = {
391 { BGP_EXT_COM_RT_0
, "target"},
392 { BGP_EXT_COM_RT_1
, "target"},
393 { BGP_EXT_COM_RT_2
, "target"},
394 { BGP_EXT_COM_RO_0
, "origin"},
395 { BGP_EXT_COM_RO_1
, "origin"},
396 { BGP_EXT_COM_RO_2
, "origin"},
397 { BGP_EXT_COM_LINKBAND
, "link-BW"},
398 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
399 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
400 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
401 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
402 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
403 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
404 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
405 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
406 { BGP_EXT_COM_L2INFO
, "layer2-info"},
410 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
411 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
412 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
413 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
414 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
415 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
416 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
417 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
419 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
420 { BGP_OSPF_RTYPE_RTR
, "Router" },
421 { BGP_OSPF_RTYPE_NET
, "Network" },
422 { BGP_OSPF_RTYPE_SUM
, "Summary" },
423 { BGP_OSPF_RTYPE_EXT
, "External" },
424 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
425 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
429 static struct tok bgp_l2vpn_encaps_values
[] = {
432 { 2, "ATM AAL5 VCC transport"},
433 { 3, "ATM transparent cell transport"},
434 { 4, "Ethernet VLAN"},
439 { 9, "ATM VCC cell transport"},
440 { 10, "ATM VPC cell transport"},
443 { 64, "IP-interworking"},
448 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
458 memset(&addr
, 0, sizeof(addr
));
459 TCHECK2(pptr
[1], (plen
+ 7) / 8);
460 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
462 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
463 ((0xff00 >> (plen
% 8)) & 0xff);
465 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
466 return 1 + (plen
+ 7) / 8;
473 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
479 plen
= pptr
[0]; /* get prefix length */
481 /* this is one of the weirdnesses of rfc3107
482 the label length (actually the label + COS bits)
483 is added to the prefix length;
484 we also do only read out just one label -
485 there is no real application for advertisement of
486 stacked labels in a a single BGP message
489 plen
-=24; /* adjust prefixlen - labellength */
494 memset(&addr
, 0, sizeof(addr
));
495 TCHECK2(pptr
[4], (plen
+ 7) / 8);
496 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
498 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
499 ((0xff00 >> (plen
% 8)) & 0xff);
501 /* the label may get offsetted by 4 bits so lets shift it right */
502 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
503 getname((u_char
*)&addr
),
505 EXTRACT_24BITS(pptr
+1)>>4,
506 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
508 return 4 + (plen
+ 7) / 8;
514 /* RDs and RTs share the same semantics
515 * we use bgp_vpn_rd_print for
516 * printing route targets inside a NLRI */
518 bgp_vpn_rd_print (const u_char
*pptr
) {
520 /* allocate space for the following string
521 * xxx.xxx.xxx.xxx:xxxxx
522 * 21 bytes plus one termination byte */
526 /* ok lets load the RD format */
527 switch (EXTRACT_16BITS(pptr
)) {
529 /* AS:IP-address fmt*/
531 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
532 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
534 /* IP-address:AS fmt*/
537 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
538 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
541 /* 4-byte-AS:number fmt*/
543 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u",
544 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6));
547 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
556 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
558 u_int8_t route_target
[8];
562 plen
= pptr
[0]; /* get prefix length */
564 plen
-=32; /* adjust prefix length */
569 memset(&route_target
, 0, sizeof(route_target
));
570 TCHECK2(pptr
[1], (plen
+ 7) / 8);
571 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
573 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
574 ((0xff00 >> (plen
% 8)) & 0xff);
576 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
577 EXTRACT_32BITS(pptr
+1),
578 bgp_vpn_rd_print((u_char
*)&route_target
));
580 return 5 + (plen
+ 7) / 8;
587 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
593 plen
= pptr
[0]; /* get prefix length */
595 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
600 memset(&addr
, 0, sizeof(addr
));
601 TCHECK2(pptr
[12], (plen
+ 7) / 8);
602 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
604 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
605 ((0xff00 >> (plen
% 8)) & 0xff);
607 /* the label may get offsetted by 4 bits so lets shift it right */
608 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
609 bgp_vpn_rd_print(pptr
+4),
610 getname((u_char
*)&addr
),
612 EXTRACT_24BITS(pptr
+1)>>4,
613 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
615 return 12 + (plen
+ 7) / 8;
622 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
624 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
627 plen
=EXTRACT_16BITS(pptr
);
631 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
632 bgp_vpn_rd_print(pptr
),
633 EXTRACT_16BITS(pptr
+8),
634 EXTRACT_16BITS(pptr
+10),
635 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
639 /* ok now the variable part - lets read out TLVs*/
645 tlv_len
=EXTRACT_16BITS(pptr
);
651 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
654 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
657 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
662 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
667 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
677 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
679 struct in6_addr addr
;
687 memset(&addr
, 0, sizeof(addr
));
688 TCHECK2(pd
[1], (plen
+ 7) / 8);
689 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
691 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
692 ((0xff00 >> (plen
% 8)) & 0xff);
694 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
695 return 1 + (plen
+ 7) / 8;
702 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
704 struct in6_addr addr
;
708 plen
= pptr
[0]; /* get prefix length */
709 plen
-=24; /* adjust prefixlen - labellength */
714 memset(&addr
, 0, sizeof(addr
));
715 TCHECK2(pptr
[4], (plen
+ 7) / 8);
716 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
718 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
719 ((0xff00 >> (plen
% 8)) & 0xff);
721 /* the label may get offsetted by 4 bits so lets shift it right */
722 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
723 getname6((u_char
*)&addr
),
725 EXTRACT_24BITS(pptr
+1)>>4,
726 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
728 return 4 + (plen
+ 7) / 8;
735 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
737 struct in6_addr addr
;
741 plen
= pptr
[0]; /* get prefix length */
743 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
748 memset(&addr
, 0, sizeof(addr
));
749 TCHECK2(pptr
[12], (plen
+ 7) / 8);
750 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
752 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
753 ((0xff00 >> (plen
% 8)) & 0xff);
755 /* the label may get offsetted by 4 bits so lets shift it right */
756 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
757 bgp_vpn_rd_print(pptr
+4),
758 getname6((u_char
*)&addr
),
760 EXTRACT_24BITS(pptr
+1)>>4,
761 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
763 return 12 + (plen
+ 7) / 8;
771 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
776 union { /* copy buffer for bandwidth values */
783 char buf
[MAXHOSTNAMELEN
+ 100];
788 switch (attr
->bgpa_type
) {
791 printf("invalid len");
794 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
797 case BGPTYPE_AS_PATH
:
799 printf("invalid len");
807 while (tptr
< pptr
+ len
) {
809 printf("%s", tok2str(bgp_as_path_segment_open_values
, "?", tptr
[0]));
810 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
811 TCHECK2(tptr
[2 + i
], 2);
812 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
815 printf("%s", tok2str(bgp_as_path_segment_close_values
, "?", tptr
[0]));
817 tptr
+= 2 + tptr
[1] * 2;
820 case BGPTYPE_NEXT_HOP
:
822 printf("invalid len");
825 printf("%s", getname(tptr
));
828 case BGPTYPE_MULTI_EXIT_DISC
:
829 case BGPTYPE_LOCAL_PREF
:
831 printf("invalid len");
834 printf("%u", EXTRACT_32BITS(tptr
));
837 case BGPTYPE_ATOMIC_AGGREGATE
:
839 printf("invalid len");
841 case BGPTYPE_AGGREGATOR
:
843 printf("invalid len");
847 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
850 case BGPTYPE_COMMUNITIES
:
852 printf("invalid len");
858 comm
= EXTRACT_32BITS(tptr
);
860 case BGP_COMMUNITY_NO_EXPORT
:
861 printf(" NO_EXPORT");
863 case BGP_COMMUNITY_NO_ADVERT
:
864 printf(" NO_ADVERTISE");
866 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
867 printf(" NO_EXPORT_SUBCONFED");
871 (comm
>> 16) & 0xffff,
873 (tlen
>4) ? ", " : "");
880 case BGPTYPE_ORIGINATOR_ID
:
882 printf("invalid len");
886 printf("%s",getname(tptr
));
888 case BGPTYPE_CLUSTER_LIST
:
890 printf("invalid len");
897 (tlen
>4) ? ", " : "");
902 case BGPTYPE_MP_REACH_NLRI
:
904 af
= EXTRACT_16BITS(tptr
);
907 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
908 tok2str(bgp_afi_values
, "Unknown AFI", af
),
910 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
911 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
914 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
917 else if (af
== AFNUM_INET6
)
921 printf("\n\t no AFI %u decoder",af
);
923 print_unknown_data(tptr
,"\n\t ",tlen
);
934 printf("\n\t nexthop: ");
940 case SAFNUM_MULTICAST
:
941 case SAFNUM_UNIMULTICAST
:
942 case SAFNUM_LABUNICAST
:
943 case SAFNUM_RT_ROUTING_INFO
:
944 if (tlen
< (int)sizeof(struct in_addr
)) {
945 printf("invalid len");
948 TCHECK2(tptr
[0], sizeof(struct in_addr
));
949 printf("%s",getname(tptr
));
950 tlen
-= sizeof(struct in_addr
);
951 tptr
+= sizeof(struct in_addr
);
954 case SAFNUM_VPNUNICAST
:
955 case SAFNUM_VPNMULTICAST
:
956 case SAFNUM_VPNUNIMULTICAST
:
957 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
958 printf("invalid len");
961 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
963 bgp_vpn_rd_print(tptr
),
964 getname(tptr
+BGP_VPN_RD_LEN
));
965 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
966 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
970 TCHECK2(tptr
[0], tlen
);
971 printf("no SAFI %u decoder",safi
);
973 print_unknown_data(tptr
,"\n\t ",tlen
);
983 case SAFNUM_MULTICAST
:
984 case SAFNUM_UNIMULTICAST
:
985 case SAFNUM_LABUNICAST
:
986 case SAFNUM_RT_ROUTING_INFO
:
987 if (tlen
< (int)sizeof(struct in6_addr
)) {
988 printf("invalid len");
991 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
992 printf("%s", getname6(tptr
));
993 tlen
-= sizeof(struct in6_addr
);
994 tptr
+= sizeof(struct in6_addr
);
997 case SAFNUM_VPNUNICAST
:
998 case SAFNUM_VPNMULTICAST
:
999 case SAFNUM_VPNUNIMULTICAST
:
1000 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1001 printf("invalid len");
1004 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1005 printf("RD: %s, %s",
1006 bgp_vpn_rd_print(tptr
),
1007 getname6(tptr
+BGP_VPN_RD_LEN
));
1008 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1009 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1013 TCHECK2(tptr
[0], tlen
);
1014 printf("no SAFI %u decoder",safi
);
1016 print_unknown_data(tptr
,"\n\t ",tlen
);
1025 case SAFNUM_VPNUNICAST
:
1026 case SAFNUM_VPNMULTICAST
:
1027 case SAFNUM_VPNUNIMULTICAST
:
1028 if (tlen
< (int)sizeof(struct in_addr
)) {
1029 printf("invalid len");
1032 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1033 printf("%s", getname(tptr
));
1034 tlen
-= (sizeof(struct in_addr
));
1035 tptr
+= (sizeof(struct in_addr
));
1039 TCHECK2(tptr
[0], tlen
);
1040 printf("no SAFI %u decoder",safi
);
1042 print_unknown_data(tptr
,"\n\t ",tlen
);
1050 TCHECK2(tptr
[0], tlen
);
1051 printf("no AFI %u decoder",af
);
1053 print_unknown_data(tptr
,"\n\t ",tlen
);
1067 printf("\n\t %u SNPA", snpa
);
1068 for (/*nothing*/; snpa
> 0; snpa
--) {
1070 printf("\n\t %d bytes", tptr
[0]);
1071 tptr
+= tptr
[0] + 1;
1074 printf(", no SNPA");
1077 while (len
- (tptr
- pptr
) > 0) {
1081 case SAFNUM_UNICAST
:
1082 case SAFNUM_MULTICAST
:
1083 case SAFNUM_UNIMULTICAST
:
1084 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1086 printf("\n\t (illegal prefix length)");
1087 else if (advance
== -2)
1090 printf("\n\t %s", buf
);
1092 case SAFNUM_LABUNICAST
:
1093 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1095 printf("\n\t (illegal prefix length)");
1096 else if (advance
== -2)
1099 printf("\n\t %s", buf
);
1101 case SAFNUM_VPNUNICAST
:
1102 case SAFNUM_VPNMULTICAST
:
1103 case SAFNUM_VPNUNIMULTICAST
:
1104 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1106 printf("\n\t (illegal prefix length)");
1107 else if (advance
== -2)
1110 printf("\n\t %s", buf
);
1112 case SAFNUM_RT_ROUTING_INFO
:
1113 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1115 printf("\n\t (illegal prefix length)");
1116 else if (advance
== -2)
1119 printf("\n\t %s", buf
);
1122 TCHECK2(*(tptr
-3),tlen
);
1123 printf("\n\t no SAFI %u decoder",safi
);
1125 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1134 case SAFNUM_UNICAST
:
1135 case SAFNUM_MULTICAST
:
1136 case SAFNUM_UNIMULTICAST
:
1137 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1139 printf("\n\t (illegal prefix length)");
1140 else if (advance
== -2)
1143 printf("\n\t %s", buf
);
1145 case SAFNUM_LABUNICAST
:
1146 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1148 printf("\n\t (illegal prefix length)");
1149 else if (advance
== -2)
1152 printf("\n\t %s", buf
);
1154 case SAFNUM_VPNUNICAST
:
1155 case SAFNUM_VPNMULTICAST
:
1156 case SAFNUM_VPNUNIMULTICAST
:
1157 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1159 printf("\n\t (illegal prefix length)");
1160 else if (advance
== -2)
1163 printf("\n\t %s", buf
);
1165 case SAFNUM_RT_ROUTING_INFO
:
1166 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1168 printf("\n\t (illegal prefix length)");
1169 else if (advance
== -2)
1172 printf("\n\t %s", buf
);
1175 TCHECK2(*(tptr
-3),tlen
);
1176 printf("\n\t no SAFI %u decoder ",safi
);
1178 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1187 case SAFNUM_VPNUNICAST
:
1188 case SAFNUM_VPNMULTICAST
:
1189 case SAFNUM_VPNUNIMULTICAST
:
1190 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1192 printf("\n\t (illegal length)");
1193 else if (advance
== -2)
1196 printf("\n\t %s", buf
);
1199 TCHECK2(*tptr
,tlen
);
1200 printf("no SAFI %u decoder",safi
);
1202 print_unknown_data(tptr
,"\n\t ",tlen
);
1211 TCHECK2(*(tptr
-3),tlen
);
1212 printf("\n\t no AFI %u decoder ",af
);
1214 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1223 case BGPTYPE_MP_UNREACH_NLRI
:
1224 TCHECK2(tptr
[0], 3);
1225 af
= EXTRACT_16BITS(tptr
);
1228 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1229 tok2str(bgp_afi_values
, "Unknown AFI", af
),
1231 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1232 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1237 while (len
- (tptr
- pptr
) > 0) {
1241 case SAFNUM_UNICAST
:
1242 case SAFNUM_MULTICAST
:
1243 case SAFNUM_UNIMULTICAST
:
1244 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1246 printf("\n\t (illegal prefix length)");
1247 else if (advance
== -2)
1250 printf("\n\t %s", buf
);
1252 case SAFNUM_LABUNICAST
:
1253 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1255 printf("\n\t (illegal prefix length)");
1256 else if (advance
== -2)
1259 printf("\n\t %s", buf
);
1261 case SAFNUM_VPNUNICAST
:
1262 case SAFNUM_VPNMULTICAST
:
1263 case SAFNUM_VPNUNIMULTICAST
:
1264 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1266 printf("\n\t (illegal prefix length)");
1267 else if (advance
== -2)
1270 printf("\n\t %s", buf
);
1273 TCHECK2(*(tptr
-3),tlen
);
1274 printf("\n\t no SAFI %u decoder",safi
);
1276 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1286 case SAFNUM_UNICAST
:
1287 case SAFNUM_MULTICAST
:
1288 case SAFNUM_UNIMULTICAST
:
1289 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1291 printf("\n\t (illegal prefix length)");
1292 else if (advance
== -2)
1295 printf("\n\t %s", buf
);
1297 case SAFNUM_LABUNICAST
:
1298 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1300 printf("\n\t (illegal prefix length)");
1301 else if (advance
== -2)
1304 printf("\n\t %s", buf
);
1306 case SAFNUM_VPNUNICAST
:
1307 case SAFNUM_VPNMULTICAST
:
1308 case SAFNUM_VPNUNIMULTICAST
:
1309 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1311 printf("\n\t (illegal prefix length)");
1312 else if (advance
== -2)
1315 printf("\n\t %s", buf
);
1318 TCHECK2(*(tptr
-3),tlen
);
1319 printf("\n\t no SAFI %u decoder",safi
);
1321 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1331 case SAFNUM_VPNUNICAST
:
1332 case SAFNUM_VPNMULTICAST
:
1333 case SAFNUM_VPNUNIMULTICAST
:
1334 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1336 printf("\n\t (illegal length)");
1337 else if (advance
== -2)
1340 printf("\n\t %s", buf
);
1343 TCHECK2(*(tptr
-3),tlen
);
1344 printf("no SAFI %u decoder",safi
);
1346 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1354 TCHECK2(*(tptr
-3),tlen
);
1355 printf("\n\t no AFI %u decoder",af
);
1357 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1366 case BGPTYPE_EXTD_COMMUNITIES
:
1368 printf("invalid len");
1372 u_int16_t extd_comm
;
1374 TCHECK2(tptr
[0], 2);
1375 extd_comm
=EXTRACT_16BITS(tptr
);
1377 printf("\n\t %s (0x%04x), Flags [%s]",
1378 tok2str(bgp_extd_comm_subtype_values
, "unknown extd community typecode", extd_comm
),
1380 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1382 TCHECK2(*(tptr
+2), 6);
1384 case BGP_EXT_COM_RT_0
:
1385 case BGP_EXT_COM_RO_0
:
1387 EXTRACT_16BITS(tptr
+2),
1390 case BGP_EXT_COM_RT_1
:
1391 case BGP_EXT_COM_RO_1
:
1394 EXTRACT_16BITS(tptr
+6));
1396 case BGP_EXT_COM_RT_2
:
1397 case BGP_EXT_COM_RO_2
:
1399 EXTRACT_32BITS(tptr
+2),
1400 EXTRACT_16BITS(tptr
+6));
1402 case BGP_EXT_COM_LINKBAND
:
1403 bw
.i
= EXTRACT_32BITS(tptr
+2);
1404 printf(": bandwidth: %.3f Mbps",
1407 case BGP_EXT_COM_VPN_ORIGIN
:
1408 case BGP_EXT_COM_VPN_ORIGIN2
:
1409 case BGP_EXT_COM_VPN_ORIGIN3
:
1410 case BGP_EXT_COM_VPN_ORIGIN4
:
1411 case BGP_EXT_COM_OSPF_RID
:
1412 case BGP_EXT_COM_OSPF_RID2
:
1413 printf("%s", getname(tptr
+2));
1415 case BGP_EXT_COM_OSPF_RTYPE
:
1416 case BGP_EXT_COM_OSPF_RTYPE2
:
1417 printf(": area:%s, router-type:%s, metric-type:%s%s",
1419 tok2str(bgp_extd_comm_ospf_rtype_values
,
1422 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1423 (*(tptr
+6) == (BGP_OSPF_RTYPE_EXT
||BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1425 case BGP_EXT_COM_L2INFO
:
1426 printf(": %s Control Flags [0x%02x]:MTU %u",
1427 tok2str(bgp_l2vpn_encaps_values
,
1431 EXTRACT_16BITS(tptr
+4));
1434 print_unknown_data(tptr
,"\n\t ",8);
1444 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1446 print_unknown_data(pptr
,"\n\t ",len
);
1449 if (vflag
> 1 && len
) /* omit zero length attributes*/
1450 print_unknown_data(pptr
,"\n\t ",len
);
1458 bgp_open_print(const u_char
*dat
, int length
)
1460 struct bgp_open bgpo
;
1461 struct bgp_opt bgpopt
;
1464 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1466 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1467 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1468 hlen
= ntohs(bgpo
.bgpo_len
);
1470 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1471 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1472 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1473 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1474 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1476 /* some little sanity checking */
1477 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1481 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1485 while (i
< bgpo
.bgpo_optlen
) {
1486 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1487 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1488 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1489 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1493 printf("\n\t Option %s (%u), length: %u",
1494 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1498 /* now lets decode the options we know*/
1499 switch(bgpopt
.bgpopt_type
) {
1501 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1502 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1504 printf("\n\t %s, length: %u",
1505 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1508 case BGP_CAPCODE_MP
:
1509 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1510 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1511 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1512 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1513 opt
[i
+BGP_OPT_SIZE
+5]);
1515 case BGP_CAPCODE_RESTART
:
1516 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1517 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1518 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1521 while(tcap_len
>=4) {
1522 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1523 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
)),
1524 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1525 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+cap_offset
+2]),
1526 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1527 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1532 case BGP_CAPCODE_RR
:
1533 case BGP_CAPCODE_RR_CISCO
:
1536 printf("\n\t\tno decoder for Capability %u",
1539 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1543 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1547 printf("\n\t no decoder for option %u",
1548 bgpopt
.bgpopt_type
);
1552 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1560 bgp_update_print(const u_char
*dat
, int length
)
1563 struct bgp_attr bgpa
;
1569 TCHECK2(dat
[0], BGP_SIZE
);
1570 memcpy(&bgp
, dat
, BGP_SIZE
);
1571 hlen
= ntohs(bgp
.bgp_len
);
1572 p
= dat
+ BGP_SIZE
; /*XXX*/
1574 /* Unfeasible routes */
1575 len
= EXTRACT_16BITS(p
);
1578 * Without keeping state from the original NLRI message,
1579 * it's not possible to tell if this a v4 or v6 route,
1580 * so only try to decode it if we're not v6 enabled.
1583 printf("\n\t Withdrawn routes: %d bytes", len
);
1585 char buf
[MAXHOSTNAMELEN
+ 100];
1591 printf("\n\t Withdrawn routes:");
1593 while(i
< 2 + len
) {
1594 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1596 printf("\n\t (illegal prefix length)");
1598 } else if (wpfx
== -2)
1602 printf("\n\t %s", buf
);
1610 len
= EXTRACT_16BITS(p
);
1612 /* do something more useful!*/
1614 while (i
< 2 + len
) {
1617 TCHECK2(p
[i
], sizeof(bgpa
));
1618 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1619 alen
= bgp_attr_len(&bgpa
);
1620 aoff
= bgp_attr_off(&bgpa
);
1622 printf("\n\t %s (%u), length: %u",
1623 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1627 if (bgpa
.bgpa_flags
) {
1628 printf(", Flags [%s%s%s%s",
1629 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1630 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1631 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1632 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1633 if (bgpa
.bgpa_flags
& 0xf)
1634 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1637 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
1644 if (dat
+ length
> p
) {
1645 printf("\n\t Updated routes:");
1646 while (dat
+ length
> p
) {
1647 char buf
[MAXHOSTNAMELEN
+ 100];
1648 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1650 printf("\n\t (illegal prefix length)");
1654 printf("\n\t %s", buf
);
1665 bgp_notification_print(const u_char
*dat
, int length
)
1667 struct bgp_notification bgpn
;
1671 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1672 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1673 hlen
= ntohs(bgpn
.bgpn_len
);
1675 /* some little sanity checking */
1676 if (length
<BGP_NOTIFICATION_SIZE
)
1680 tok2str(bgp_notify_major_values
, "Unknown Error", bgpn
.bgpn_major
),
1683 switch (bgpn
.bgpn_major
) {
1685 case BGP_NOTIFY_MAJOR_MSG
:
1686 printf(", subcode %s (%u)",
1687 tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
),
1690 case BGP_NOTIFY_MAJOR_OPEN
:
1691 printf(", subcode %s (%u)",
1692 tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
),
1695 case BGP_NOTIFY_MAJOR_UPDATE
:
1696 printf(", subcode %s (%u)",
1697 tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
),
1700 case BGP_NOTIFY_MAJOR_CAP
:
1701 printf(" subcode %s (%u)",
1702 tok2str(bgp_notify_minor_cap_values
, "Unknown", bgpn
.bgpn_minor
),
1704 case BGP_NOTIFY_MAJOR_CEASE
:
1705 printf(", subcode %s (%u)",
1706 tok2str(bgp_notify_minor_cease_values
, "Unknown", bgpn
.bgpn_minor
),
1709 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1710 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1712 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
1713 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
1715 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1716 tok2str(bgp_afi_values
, "Unknown", EXTRACT_16BITS(tptr
)),
1717 EXTRACT_16BITS(tptr
),
1718 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
1720 EXTRACT_32BITS(tptr
+3));
1733 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1735 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1736 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1738 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1739 tok2str(bgp_afi_values
,"Unknown",
1740 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1741 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1742 tok2str(bgp_safi_values
,"Unknown",
1743 bgp_route_refresh_header
->safi
),
1744 bgp_route_refresh_header
->safi
);
1747 print_unknown_data(pptr
,"\n\t ", len
);
1753 bgp_header_print(const u_char
*dat
, int length
)
1757 TCHECK2(dat
[0], BGP_SIZE
);
1758 memcpy(&bgp
, dat
, BGP_SIZE
);
1759 printf("\n\t%s Message (%u), length: %u",
1760 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1764 switch (bgp
.bgp_type
) {
1766 bgp_open_print(dat
, length
);
1769 bgp_update_print(dat
, length
);
1771 case BGP_NOTIFICATION
:
1772 bgp_notification_print(dat
, length
);
1776 case BGP_ROUTE_REFRESH
:
1777 bgp_route_refresh_print(dat
, length
);
1780 /* we have no decoder for the BGP message */
1781 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1782 print_unknown_data(dat
,"\n\t ",length
);
1792 bgp_print(const u_char
*dat
, int length
)
1796 const u_char
*start
;
1797 const u_char marker
[] = {
1798 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1799 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1805 if (snapend
< dat
+ length
)
1808 printf(": BGP, length: %u",length
);
1810 if (vflag
< 1) /* lets be less chatty */
1815 while (p
< snapend
) {
1816 if (!TTEST2(p
[0], 1))
1823 if (!TTEST2(p
[0], sizeof(marker
)))
1825 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1830 /* found BGP header */
1831 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1832 memcpy(&bgp
, p
, BGP_SIZE
);
1837 hlen
= ntohs(bgp
.bgp_len
);
1838 if (hlen
< BGP_SIZE
) {
1839 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
1844 if (TTEST2(p
[0], hlen
)) {
1845 if (!bgp_header_print(p
, hlen
))
1850 printf("\n[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));