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.3 2004-01-16 10:07:20 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];
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
)
457 memset(&addr
, 0, sizeof(addr
));
458 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
460 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
461 ((0xff00 >> (plen
% 8)) & 0xff);
463 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
464 return 1 + (plen
+ 7) / 8;
468 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
473 plen
= pptr
[0]; /* get prefix length */
475 /* this is one of the weirdnesses of rfc3107
476 the label length (actually the label + COS bits)
477 is added to the prefix length;
478 we also do only read out just one label -
479 there is no real application for advertisement of
480 stacked labels in a a single BGP message
483 plen
-=24; /* adjust prefixlen - labellength */
488 memset(&addr
, 0, sizeof(addr
));
489 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
491 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
492 ((0xff00 >> (plen
% 8)) & 0xff);
494 /* the label may get offsetted by 4 bits so lets shift it right */
495 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
496 getname((u_char
*)&addr
),
498 EXTRACT_24BITS(pptr
+1)>>4,
499 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
501 return 4 + (plen
+ 7) / 8;
504 /* RDs and RTs share the same semantics
505 * we use bgp_vpn_rd_print for
506 * printing route targets inside a NLRI */
508 bgp_vpn_rd_print (const u_char
*pptr
) {
510 /* allocate space for the following string
511 * xxx.xxx.xxx.xxx:xxxxx
512 * 21 bytes plus one termination byte */
516 /* ok lets load the RD format */
517 switch (EXTRACT_16BITS(pptr
)) {
519 /* AS:IP-address fmt*/
521 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
522 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
524 /* IP-address:AS fmt*/
527 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
528 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
531 /* 4-byte-AS:number fmt*/
533 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u",
534 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6));
537 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
546 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
548 u_int8_t route_target
[8];
551 plen
= pptr
[0]; /* get prefix length */
553 plen
-=32; /* adjust prefix length */
558 memset(&route_target
, 0, sizeof(route_target
));
559 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
561 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
562 ((0xff00 >> (plen
% 8)) & 0xff);
564 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
565 EXTRACT_32BITS(pptr
+1),
566 bgp_vpn_rd_print((u_char
*)&route_target
));
568 return 5 + (plen
+ 7) / 8;
572 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
577 plen
= pptr
[0]; /* get prefix length */
579 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
584 memset(&addr
, 0, sizeof(addr
));
585 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
587 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
588 ((0xff00 >> (plen
% 8)) & 0xff);
590 /* the label may get offsetted by 4 bits so lets shift it right */
591 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
592 bgp_vpn_rd_print(pptr
+4),
593 getname((u_char
*)&addr
),
595 EXTRACT_24BITS(pptr
+1)>>4,
596 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
598 return 12 + (plen
+ 7) / 8;
602 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
604 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
605 plen
=EXTRACT_16BITS(pptr
);
608 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
609 bgp_vpn_rd_print(pptr
),
610 EXTRACT_16BITS(pptr
+8),
611 EXTRACT_16BITS(pptr
+10),
612 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
616 /* ok now the variable part - lets read out TLVs*/
619 tlv_len
=EXTRACT_16BITS(pptr
);
625 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
628 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
630 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
635 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
640 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
647 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
649 struct in6_addr addr
;
656 memset(&addr
, 0, sizeof(addr
));
657 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
659 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
660 ((0xff00 >> (plen
% 8)) & 0xff);
662 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
663 return 1 + (plen
+ 7) / 8;
667 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
669 struct in6_addr addr
;
672 plen
= pptr
[0]; /* get prefix length */
673 plen
-=24; /* adjust prefixlen - labellength */
678 memset(&addr
, 0, sizeof(addr
));
679 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
681 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
682 ((0xff00 >> (plen
% 8)) & 0xff);
684 /* the label may get offsetted by 4 bits so lets shift it right */
685 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
686 getname6((u_char
*)&addr
),
688 EXTRACT_24BITS(pptr
+1)>>4,
689 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
691 return 4 + (plen
+ 7) / 8;
695 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
697 struct in6_addr addr
;
700 plen
= pptr
[0]; /* get prefix length */
702 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
707 memset(&addr
, 0, sizeof(addr
));
708 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
710 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
711 ((0xff00 >> (plen
% 8)) & 0xff);
713 /* the label may get offsetted by 4 bits so lets shift it right */
714 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
715 bgp_vpn_rd_print(pptr
+4),
716 getname6((u_char
*)&addr
),
718 EXTRACT_24BITS(pptr
+1)>>4,
719 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
721 return 12 + (plen
+ 7) / 8;
726 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
731 union { /* copy buffer for bandwidth values */
738 char buf
[MAXHOSTNAMELEN
+ 100];
743 switch (attr
->bgpa_type
) {
746 printf("invalid len");
748 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
750 case BGPTYPE_AS_PATH
:
752 printf("invalid len");
760 while (tptr
< pptr
+ len
) {
761 printf("%s", tok2str(bgp_as_path_segment_open_values
, "?", tptr
[0]));
762 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
763 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
765 printf("%s", tok2str(bgp_as_path_segment_close_values
, "?", tptr
[0]));
766 tptr
+= 2 + tptr
[1] * 2;
769 case BGPTYPE_NEXT_HOP
:
771 printf("invalid len");
773 printf("%s", getname(tptr
));
775 case BGPTYPE_MULTI_EXIT_DISC
:
776 case BGPTYPE_LOCAL_PREF
:
778 printf("invalid len");
780 printf("%u", EXTRACT_32BITS(tptr
));
782 case BGPTYPE_ATOMIC_AGGREGATE
:
784 printf("invalid len");
786 case BGPTYPE_AGGREGATOR
:
788 printf("invalid len");
791 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
794 case BGPTYPE_COMMUNITIES
:
796 printf("invalid len");
801 comm
= EXTRACT_32BITS(tptr
);
803 case BGP_COMMUNITY_NO_EXPORT
:
804 printf(" NO_EXPORT");
806 case BGP_COMMUNITY_NO_ADVERT
:
807 printf(" NO_ADVERTISE");
809 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
810 printf(" NO_EXPORT_SUBCONFED");
814 (comm
>> 16) & 0xffff,
816 (tlen
>4) ? ", " : "");
823 case BGPTYPE_ORIGINATOR_ID
:
825 printf("invalid len");
828 printf("%s",getname(tptr
));
830 case BGPTYPE_CLUSTER_LIST
:
834 (tlen
>4) ? ", " : "");
839 case BGPTYPE_MP_REACH_NLRI
:
840 af
= EXTRACT_16BITS(tptr
);
843 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
844 tok2str(bgp_afi_values
, "Unknown AFI", af
),
846 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
847 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
850 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
853 else if (af
== AFNUM_INET6
)
857 printf("\n\t no AFI %u decoder",af
);
859 print_unknown_data(tptr
,"\n\t ",tlen
);
869 printf("\n\t nexthop: ");
875 case SAFNUM_MULTICAST
:
876 case SAFNUM_UNIMULTICAST
:
877 case SAFNUM_LABUNICAST
:
878 case SAFNUM_RT_ROUTING_INFO
:
879 printf("%s",getname(tptr
));
880 tlen
-= sizeof(struct in_addr
);
881 tptr
+= sizeof(struct in_addr
);
883 case SAFNUM_VPNUNICAST
:
884 case SAFNUM_VPNMULTICAST
:
885 case SAFNUM_VPNUNIMULTICAST
:
887 bgp_vpn_rd_print(tptr
),
888 getname(tptr
+BGP_VPN_RD_LEN
));
889 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
890 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
893 printf("no SAFI %u decoder",safi
);
895 print_unknown_data(tptr
,"\n\t ",tlen
);
903 case SAFNUM_MULTICAST
:
904 case SAFNUM_UNIMULTICAST
:
905 case SAFNUM_LABUNICAST
:
906 case SAFNUM_RT_ROUTING_INFO
:
907 printf("%s", getname6(tptr
));
908 tlen
-= sizeof(struct in6_addr
);
909 tptr
+= sizeof(struct in6_addr
);
911 case SAFNUM_VPNUNICAST
:
912 case SAFNUM_VPNMULTICAST
:
913 case SAFNUM_VPNUNIMULTICAST
:
915 bgp_vpn_rd_print(tptr
),
916 getname6(tptr
+BGP_VPN_RD_LEN
));
917 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
918 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
921 printf("no SAFI %u decoder",safi
);
923 print_unknown_data(tptr
,"\n\t ",tlen
);
930 case SAFNUM_VPNUNICAST
:
931 case SAFNUM_VPNMULTICAST
:
932 case SAFNUM_VPNUNIMULTICAST
:
933 printf("%s", getname(tptr
));
934 tlen
-= (sizeof(struct in_addr
));
935 tptr
+= (sizeof(struct in_addr
));
938 printf("no SAFI %u decoder",safi
);
940 print_unknown_data(tptr
,"\n\t ",tlen
);
946 printf("no AFI %u decoder",af
);
948 print_unknown_data(tptr
,"\n\t ",tlen
);
959 printf("\n\t %u SNPA", snpa
);
960 for (/*nothing*/; snpa
> 0; snpa
--) {
961 printf("\n\t %d bytes", tptr
[0]);
968 while (len
- (tptr
- pptr
) > 0) {
973 case SAFNUM_MULTICAST
:
974 case SAFNUM_UNIMULTICAST
:
975 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
977 printf("\n\t %s", buf
);
979 printf("\n\t (illegal prefix length)");
981 case SAFNUM_LABUNICAST
:
982 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
983 printf("\n\t %s", buf
);
985 case SAFNUM_VPNUNICAST
:
986 case SAFNUM_VPNMULTICAST
:
987 case SAFNUM_VPNUNIMULTICAST
:
988 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
989 printf("\n\t %s", buf
);
991 case SAFNUM_RT_ROUTING_INFO
:
992 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
993 printf("\n\t %s", buf
);
996 printf("\n\t no SAFI %u decoder",safi
);
998 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1007 case SAFNUM_UNICAST
:
1008 case SAFNUM_MULTICAST
:
1009 case SAFNUM_UNIMULTICAST
:
1010 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1011 printf("\n\t %s", buf
);
1013 case SAFNUM_LABUNICAST
:
1014 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1015 printf("\n\t %s", buf
);
1017 case SAFNUM_VPNUNICAST
:
1018 case SAFNUM_VPNMULTICAST
:
1019 case SAFNUM_VPNUNIMULTICAST
:
1020 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1021 printf("\n\t %s", buf
);
1023 case SAFNUM_RT_ROUTING_INFO
:
1024 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1025 printf("\n\t %s", buf
);
1028 printf("\n\t no SAFI %u decoder ",safi
);
1030 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1039 case SAFNUM_VPNUNICAST
:
1040 case SAFNUM_VPNMULTICAST
:
1041 case SAFNUM_VPNUNIMULTICAST
:
1042 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1043 printf("\n\t %s", buf
);
1046 printf("no SAFI %u decoder",safi
);
1048 print_unknown_data(tptr
,"\n\t ",tlen
);
1057 printf("\n\t no AFI %u decoder ",af
);
1059 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1068 case BGPTYPE_MP_UNREACH_NLRI
:
1069 af
= EXTRACT_16BITS(tptr
);
1072 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1073 tok2str(bgp_afi_values
, "Unknown AFI", af
),
1075 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1076 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1081 while (len
- (tptr
- pptr
) > 0) {
1085 case SAFNUM_UNICAST
:
1086 case SAFNUM_MULTICAST
:
1087 case SAFNUM_UNIMULTICAST
:
1088 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1090 printf("\n\t %s", buf
);
1092 printf("\n\t (illegal prefix length)");
1094 case SAFNUM_LABUNICAST
:
1095 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1096 printf("\n\t %s", buf
);
1098 case SAFNUM_VPNUNICAST
:
1099 case SAFNUM_VPNMULTICAST
:
1100 case SAFNUM_VPNUNIMULTICAST
:
1101 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1102 printf("\n\t %s", buf
);
1105 printf("\n\t no SAFI %u decoder",safi
);
1107 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1117 case SAFNUM_UNICAST
:
1118 case SAFNUM_MULTICAST
:
1119 case SAFNUM_UNIMULTICAST
:
1120 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1121 printf("\n\t %s", buf
);
1123 case SAFNUM_LABUNICAST
:
1124 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1125 printf("\n\t %s", buf
);
1127 case SAFNUM_VPNUNICAST
:
1128 case SAFNUM_VPNMULTICAST
:
1129 case SAFNUM_VPNUNIMULTICAST
:
1130 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1131 printf("\n\t %s", buf
);
1134 printf("\n\t no SAFI %u decoder",safi
);
1136 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1146 case SAFNUM_VPNUNICAST
:
1147 case SAFNUM_VPNMULTICAST
:
1148 case SAFNUM_VPNUNIMULTICAST
:
1149 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1150 printf("\n\t %s", buf
);
1153 printf("no SAFI %u decoder",safi
);
1155 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1163 printf("\n\t no AFI %u decoder",af
);
1165 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1174 case BGPTYPE_EXTD_COMMUNITIES
:
1176 printf("invalid len");
1180 u_int16_t extd_comm
;
1181 extd_comm
=EXTRACT_16BITS(tptr
);
1183 printf("\n\t %s (0x%04x), Flags [%s]",
1184 tok2str(bgp_extd_comm_subtype_values
, "unknown extd community typecode", extd_comm
),
1186 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1189 case BGP_EXT_COM_RT_0
:
1190 case BGP_EXT_COM_RO_0
:
1192 EXTRACT_16BITS(tptr
+2),
1195 case BGP_EXT_COM_RT_1
:
1196 case BGP_EXT_COM_RO_1
:
1199 EXTRACT_16BITS(tptr
+6));
1201 case BGP_EXT_COM_RT_2
:
1202 case BGP_EXT_COM_RO_2
:
1204 EXTRACT_32BITS(tptr
+2),
1205 EXTRACT_16BITS(tptr
+6));
1207 case BGP_EXT_COM_LINKBAND
:
1208 bw
.i
= EXTRACT_32BITS(tptr
+2);
1209 printf(": bandwidth: %.3f Mbps",
1212 case BGP_EXT_COM_VPN_ORIGIN
:
1213 case BGP_EXT_COM_VPN_ORIGIN2
:
1214 case BGP_EXT_COM_VPN_ORIGIN3
:
1215 case BGP_EXT_COM_VPN_ORIGIN4
:
1216 case BGP_EXT_COM_OSPF_RID
:
1217 case BGP_EXT_COM_OSPF_RID2
:
1218 printf("%s", getname(tptr
+2));
1220 case BGP_EXT_COM_OSPF_RTYPE
:
1221 case BGP_EXT_COM_OSPF_RTYPE2
:
1222 printf(": area:%s, router-type:%s, metric-type:%s%s",
1224 tok2str(bgp_extd_comm_ospf_rtype_values
,
1227 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1228 (*(tptr
+6) == (BGP_OSPF_RTYPE_EXT
||BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1230 case BGP_EXT_COM_L2INFO
:
1231 printf(": %s Control Flags [0x%02x]:MTU %u",
1232 tok2str(bgp_l2vpn_encaps_values
,
1236 EXTRACT_16BITS(tptr
+4));
1239 print_unknown_data(tptr
,"\n\t ",8);
1248 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1250 print_unknown_data(pptr
,"\n\t ",len
);
1253 if (vflag
> 1 && len
) /* omit zero length attributes*/
1254 print_unknown_data(pptr
,"\n\t ",len
);
1258 bgp_open_print(const u_char
*dat
, int length
)
1260 struct bgp_open bgpo
;
1261 struct bgp_opt bgpopt
;
1264 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1266 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1267 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1268 hlen
= ntohs(bgpo
.bgpo_len
);
1270 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1271 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1272 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1273 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1274 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1276 /* some little sanity checking */
1277 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1281 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1285 while (i
< bgpo
.bgpo_optlen
) {
1286 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1287 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1288 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1289 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1293 printf("\n\t Option %s (%u), length: %u",
1294 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1298 /* now lets decode the options we know*/
1299 switch(bgpopt
.bgpopt_type
) {
1301 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1302 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1304 printf("\n\t %s, length: %u",
1305 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1308 case BGP_CAPCODE_MP
:
1309 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1310 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1311 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1312 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1313 opt
[i
+BGP_OPT_SIZE
+5]);
1315 case BGP_CAPCODE_RESTART
:
1316 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1317 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1318 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1321 while(tcap_len
>=4) {
1322 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1323 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
)),
1324 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1325 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+cap_offset
+2]),
1326 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1327 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1332 case BGP_CAPCODE_RR
:
1333 case BGP_CAPCODE_RR_CISCO
:
1336 printf("\n\t\tno decoder for Capability %u",
1339 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1343 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1347 printf("\n\t no decoder for option %u",
1348 bgpopt
.bgpopt_type
);
1352 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1360 bgp_update_print(const u_char
*dat
, int length
)
1363 struct bgp_attr bgpa
;
1369 TCHECK2(dat
[0], BGP_SIZE
);
1370 memcpy(&bgp
, dat
, BGP_SIZE
);
1371 hlen
= ntohs(bgp
.bgp_len
);
1372 p
= dat
+ BGP_SIZE
; /*XXX*/
1374 /* Unfeasible routes */
1375 len
= EXTRACT_16BITS(p
);
1378 * Without keeping state from the original NLRI message,
1379 * it's not possible to tell if this a v4 or v6 route,
1380 * so only try to decode it if we're not v6 enabled.
1383 printf("\n\t Withdrawn routes: %d bytes", len
);
1385 char buf
[MAXHOSTNAMELEN
+ 100];
1391 printf("\n\t Withdrawn routes:");
1393 while(i
< 2 + len
) {
1394 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1397 printf("\n\t %s", buf
);
1399 printf("\n\t (illegal prefix length)");
1408 len
= EXTRACT_16BITS(p
);
1410 /* do something more useful!*/
1412 while (i
< 2 + len
) {
1415 TCHECK2(p
[i
], sizeof(bgpa
));
1416 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1417 alen
= bgp_attr_len(&bgpa
);
1418 aoff
= bgp_attr_off(&bgpa
);
1420 printf("\n\t %s (%u), length: %u",
1421 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1425 if (bgpa
.bgpa_flags
) {
1426 printf(", Flags [%s%s%s%s",
1427 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1428 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1429 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1430 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1431 if (bgpa
.bgpa_flags
& 0xf)
1432 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1435 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1441 if (dat
+ length
> p
) {
1442 printf("\n\t Updated routes:");
1443 while (dat
+ length
> p
) {
1444 char buf
[MAXHOSTNAMELEN
+ 100];
1445 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1447 printf("\n\t %s", buf
);
1450 printf("\n\t (illegal prefix length)");
1461 bgp_notification_print(const u_char
*dat
, int length
)
1463 struct bgp_notification bgpn
;
1467 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1468 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1469 hlen
= ntohs(bgpn
.bgpn_len
);
1471 /* some little sanity checking */
1472 if (length
<BGP_NOTIFICATION_SIZE
)
1476 tok2str(bgp_notify_major_values
, "Unknown Error", bgpn
.bgpn_major
),
1479 switch (bgpn
.bgpn_major
) {
1481 case BGP_NOTIFY_MAJOR_MSG
:
1482 printf(", subcode %s (%u)",
1483 tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
),
1486 case BGP_NOTIFY_MAJOR_OPEN
:
1487 printf(", subcode %s (%u)",
1488 tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
),
1491 case BGP_NOTIFY_MAJOR_UPDATE
:
1492 printf(", subcode %s (%u)",
1493 tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
),
1496 case BGP_NOTIFY_MAJOR_CAP
:
1497 printf(" subcode %s (%u)",
1498 tok2str(bgp_notify_minor_cap_values
, "Unknown", bgpn
.bgpn_minor
),
1500 case BGP_NOTIFY_MAJOR_CEASE
:
1501 printf(", subcode %s (%u)",
1502 tok2str(bgp_notify_minor_cease_values
, "Unknown", bgpn
.bgpn_minor
),
1505 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1506 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1508 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
1509 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
1511 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1512 tok2str(bgp_afi_values
, "Unknown", EXTRACT_16BITS(tptr
)),
1513 EXTRACT_16BITS(tptr
),
1514 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
1516 EXTRACT_32BITS(tptr
+3));
1529 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1531 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1532 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1534 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1535 tok2str(bgp_afi_values
,"Unknown",
1536 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1537 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1538 tok2str(bgp_safi_values
,"Unknown",
1539 bgp_route_refresh_header
->safi
),
1540 bgp_route_refresh_header
->safi
);
1543 print_unknown_data(pptr
,"\n\t ", len
);
1549 bgp_header_print(const u_char
*dat
, int length
)
1553 TCHECK2(dat
[0], BGP_SIZE
);
1554 memcpy(&bgp
, dat
, BGP_SIZE
);
1555 printf("\n\t%s Message (%u), length: %u",
1556 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1560 switch (bgp
.bgp_type
) {
1562 bgp_open_print(dat
, length
);
1565 bgp_update_print(dat
, length
);
1567 case BGP_NOTIFICATION
:
1568 bgp_notification_print(dat
, length
);
1572 case BGP_ROUTE_REFRESH
:
1573 bgp_route_refresh_print(dat
, length
);
1576 /* we have no decoder for the BGP message */
1577 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1578 print_unknown_data(dat
,"\n\t ",length
);
1587 bgp_print(const u_char
*dat
, int length
)
1591 const u_char
*start
;
1592 const u_char marker
[] = {
1593 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1594 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1600 if (snapend
< dat
+ length
)
1603 printf(": BGP, length: %u",length
);
1605 if (vflag
< 1) /* lets be less chatty */
1610 while (p
< snapend
) {
1611 if (!TTEST2(p
[0], 1))
1618 if (!TTEST2(p
[0], sizeof(marker
)))
1620 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1625 /* found BGP header */
1626 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1627 memcpy(&bgp
, p
, BGP_SIZE
);
1632 hlen
= ntohs(bgp
.bgp_len
);
1633 if (hlen
< BGP_SIZE
) {
1634 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
1639 if (TTEST2(p
[0], hlen
)) {
1640 bgp_header_print(p
, hlen
);
1644 printf("\n[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));