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.77 2004-01-15 18:59:15 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 */
142 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
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 { BGPTYPE_ATTR_SET
, "Attribute Set"},
162 { 255, "Reserved for development"},
167 #define BGP_AS_SEQUENCE 2
168 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
169 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
171 static struct tok bgp_as_path_segment_open_values
[] = {
172 { BGP_AS_SEQUENCE
, ""},
174 { BGP_CONFED_AS_SEQUENCE
, "( "},
175 { BGP_CONFED_AS_SET
, "({ "},
179 static struct tok bgp_as_path_segment_close_values
[] = {
180 { BGP_AS_SEQUENCE
, ""},
182 { BGP_CONFED_AS_SEQUENCE
, ")"},
183 { BGP_CONFED_AS_SET
, "})"},
187 #define BGP_OPT_AUTH 1
188 #define BGP_OPT_CAP 2
191 static struct tok bgp_opt_values
[] = {
192 { BGP_OPT_AUTH
, "Authentication Information"},
193 { BGP_OPT_CAP
, "Capabilities Advertisement"},
197 #define BGP_CAPCODE_MP 1
198 #define BGP_CAPCODE_RR 2
199 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
200 #define BGP_CAPCODE_RR_CISCO 128
202 static struct tok bgp_capcode_values
[] = {
203 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
204 { BGP_CAPCODE_RR
, "Route Refresh"},
205 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
206 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
210 #define BGP_NOTIFY_MAJOR_MSG 1
211 #define BGP_NOTIFY_MAJOR_OPEN 2
212 #define BGP_NOTIFY_MAJOR_UPDATE 3
213 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
214 #define BGP_NOTIFY_MAJOR_FSM 5
215 #define BGP_NOTIFY_MAJOR_CEASE 6
216 #define BGP_NOTIFY_MAJOR_CAP 7
218 static struct tok bgp_notify_major_values
[] = {
219 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
220 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
221 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
222 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
223 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
224 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
225 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
229 /* draft-ietf-idr-cease-subcode-02 */
230 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
231 static struct tok bgp_notify_minor_cease_values
[] = {
232 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
233 { 2, "Administratively Shutdown"},
234 { 3, "Peer Unconfigured"},
235 { 4, "Administratively Reset"},
236 { 5, "Connection Rejected"},
237 { 6, "Other Configuration Change"},
238 { 7, "Connection Collision Resolution"},
242 static struct tok bgp_notify_minor_msg_values
[] = {
243 { 1, "Connection Not Synchronized"},
244 { 2, "Bad Message Length"},
245 { 3, "Bad Message Type"},
249 static struct tok bgp_notify_minor_open_values
[] = {
250 { 1, "Unsupported Version Number"},
252 { 3, "Bad BGP Identifier"},
253 { 4, "Unsupported Optional Parameter"},
254 { 5, "Authentication Failure"},
255 { 6, "Unacceptable Hold Time"},
259 static struct tok bgp_notify_minor_update_values
[] = {
260 { 1, "Malformed Attribute List"},
261 { 2, "Unrecognized Well-known Attribute"},
262 { 3, "Missing Well-known Attribute"},
263 { 4, "Attribute Flags Error"},
264 { 5, "Attribute Length Error"},
265 { 6, "Invalid ORIGIN Attribute"},
266 { 7, "AS Routing Loop"},
267 { 8, "Invalid NEXT_HOP Attribute"},
268 { 9, "Optional Attribute Error"},
269 { 10, "Invalid Network Field"},
270 { 11, "Malformed AS_PATH"},
274 static struct tok bgp_notify_minor_cap_values
[] = {
275 { 1, "Invalid Action Value" },
276 { 2, "Invalid Capability Length" },
277 { 3, "Malformed Capability Value" },
278 { 4, "Unsupported Capability Code" },
282 static struct tok bgp_origin_values
[] = {
289 /* Subsequent address family identifier, RFC2283 section 7 */
291 #define SAFNUM_UNICAST 1
292 #define SAFNUM_MULTICAST 2
293 #define SAFNUM_UNIMULTICAST 3
294 /* labeled BGP RFC3107 */
295 #define SAFNUM_LABUNICAST 4
296 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
297 #define SAFNUM_VPNUNICAST 128
298 #define SAFNUM_VPNMULTICAST 129
299 #define SAFNUM_VPNUNIMULTICAST 130
300 /* draft-marques-ppvpn-rt-constrain-01.txt */
301 #define SAFNUM_RT_ROUTING_INFO 132
303 #define BGP_VPN_RD_LEN 8
305 static struct tok bgp_safi_values
[] = {
306 { SAFNUM_RES
, "Reserved"},
307 { SAFNUM_UNICAST
, "Unicast"},
308 { SAFNUM_MULTICAST
, "Multicast"},
309 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
310 { SAFNUM_LABUNICAST
, "labeled Unicast"},
311 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
312 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
313 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
314 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"}, /* draft-marques-ppvpn-rt-constrain-01.txt */
318 /* well-known community */
319 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
320 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
321 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
323 /* RFC1700 address family numbers */
325 #define AFNUM_INET6 2
328 #define AFNUM_BBN1822 5
333 #define AFNUM_X121 10
335 #define AFNUM_ATALK 12
336 #define AFNUM_DECNET 13
337 #define AFNUM_BANYAN 14
338 #define AFNUM_E164NSAP 15
339 /* draft-kompella-ppvpn-l2vpn */
340 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
342 static struct tok bgp_afi_values
[] = {
344 { AFNUM_INET
, "IPv4"},
345 { AFNUM_INET6
, "IPv6"},
346 { AFNUM_NSAP
, "NSAP"},
347 { AFNUM_HDLC
, "HDLC"},
348 { AFNUM_BBN1822
, "BBN 1822"},
350 { AFNUM_E163
, "E.163"},
351 { AFNUM_E164
, "E.164"},
352 { AFNUM_F69
, "F.69"},
353 { AFNUM_X121
, "X.121"},
354 { AFNUM_IPX
, "Novell IPX"},
355 { AFNUM_ATALK
, "Appletalk"},
356 { AFNUM_DECNET
, "Decnet IV"},
357 { AFNUM_BANYAN
, "Banyan Vines"},
358 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
359 { AFNUM_L2VPN
, "Layer-2 VPN"},
363 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
364 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
365 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
366 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
367 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
368 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
369 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
370 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
371 /* rfc2547 bgp-mpls-vpns */
373 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
374 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
375 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
376 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
378 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
379 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
381 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
382 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
384 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
386 static struct tok bgp_extd_comm_flag_values
[] = {
387 { 0x8000, "vendor-specific"},
388 { 0x4000, "non-transitive"},
392 static struct tok bgp_extd_comm_subtype_values
[] = {
393 { BGP_EXT_COM_RT_0
, "target"},
394 { BGP_EXT_COM_RT_1
, "target"},
395 { BGP_EXT_COM_RT_2
, "target"},
396 { BGP_EXT_COM_RO_0
, "origin"},
397 { BGP_EXT_COM_RO_1
, "origin"},
398 { BGP_EXT_COM_RO_2
, "origin"},
399 { BGP_EXT_COM_LINKBAND
, "link-BW"},
400 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
401 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
402 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
403 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
404 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
405 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
406 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
407 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
408 { BGP_EXT_COM_L2INFO
, "layer2-info"},
412 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
413 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
414 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
415 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
416 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
417 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
418 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
419 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
421 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
422 { BGP_OSPF_RTYPE_RTR
, "Router" },
423 { BGP_OSPF_RTYPE_NET
, "Network" },
424 { BGP_OSPF_RTYPE_SUM
, "Summary" },
425 { BGP_OSPF_RTYPE_EXT
, "External" },
426 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
427 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
431 static struct tok bgp_l2vpn_encaps_values
[] = {
434 { 2, "ATM AAL5 VCC transport"},
435 { 3, "ATM transparent cell transport"},
436 { 4, "Ethernet VLAN"},
441 { 9, "ATM VCC cell transport"},
442 { 10, "ATM VPC cell transport"},
445 { 64, "IP-interworking"},
450 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
459 memset(&addr
, 0, sizeof(addr
));
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;
470 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
475 plen
= pptr
[0]; /* get prefix length */
477 /* this is one of the weirdnesses of rfc3107
478 the label length (actually the label + COS bits)
479 is added to the prefix length;
480 we also do only read out just one label -
481 there is no real application for advertisement of
482 stacked labels in a a single BGP message
485 plen
-=24; /* adjust prefixlen - labellength */
490 memset(&addr
, 0, sizeof(addr
));
491 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
493 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
494 ((0xff00 >> (plen
% 8)) & 0xff);
496 /* the label may get offsetted by 4 bits so lets shift it right */
497 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
498 getname((u_char
*)&addr
),
500 EXTRACT_24BITS(pptr
+1)>>4,
501 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
503 return 4 + (plen
+ 7) / 8;
506 /* RDs and RTs share the same semantics
507 * we use bgp_vpn_rd_print for
508 * printing route targets inside a NLRI */
510 bgp_vpn_rd_print (const u_char
*pptr
) {
512 /* allocate space for the following string
513 * xxx.xxx.xxx.xxx:xxxxx
514 * 21 bytes plus one termination byte */
518 /* ok lets load the RD format */
519 switch (EXTRACT_16BITS(pptr
)) {
521 /* AS:IP-address fmt*/
523 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
524 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
526 /* IP-address:AS fmt*/
529 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
530 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
533 /* 4-byte-AS:number fmt*/
535 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u",
536 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6));
539 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
548 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
550 u_int8_t route_target
[8];
553 plen
= pptr
[0]; /* get prefix length */
555 plen
-=32; /* adjust prefix length */
560 memset(&route_target
, 0, sizeof(route_target
));
561 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
563 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
564 ((0xff00 >> (plen
% 8)) & 0xff);
566 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
567 EXTRACT_32BITS(pptr
+1),
568 bgp_vpn_rd_print((u_char
*)&route_target
));
570 return 5 + (plen
+ 7) / 8;
574 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
579 plen
= pptr
[0]; /* get prefix length */
581 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
586 memset(&addr
, 0, sizeof(addr
));
587 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
589 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
590 ((0xff00 >> (plen
% 8)) & 0xff);
592 /* the label may get offsetted by 4 bits so lets shift it right */
593 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
594 bgp_vpn_rd_print(pptr
+4),
595 getname((u_char
*)&addr
),
597 EXTRACT_24BITS(pptr
+1)>>4,
598 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
600 return 12 + (plen
+ 7) / 8;
604 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
606 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
607 plen
=EXTRACT_16BITS(pptr
);
610 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
611 bgp_vpn_rd_print(pptr
),
612 EXTRACT_16BITS(pptr
+8),
613 EXTRACT_16BITS(pptr
+10),
614 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
618 /* ok now the variable part - lets read out TLVs*/
621 tlv_len
=EXTRACT_16BITS(pptr
);
627 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
630 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
632 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
637 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
642 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
649 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
651 struct in6_addr addr
;
658 memset(&addr
, 0, sizeof(addr
));
659 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
661 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
662 ((0xff00 >> (plen
% 8)) & 0xff);
664 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
665 return 1 + (plen
+ 7) / 8;
669 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
671 struct in6_addr addr
;
674 plen
= pptr
[0]; /* get prefix length */
675 plen
-=24; /* adjust prefixlen - labellength */
680 memset(&addr
, 0, sizeof(addr
));
681 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
683 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
684 ((0xff00 >> (plen
% 8)) & 0xff);
686 /* the label may get offsetted by 4 bits so lets shift it right */
687 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
688 getname6((u_char
*)&addr
),
690 EXTRACT_24BITS(pptr
+1)>>4,
691 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
693 return 4 + (plen
+ 7) / 8;
697 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
699 struct in6_addr addr
;
702 plen
= pptr
[0]; /* get prefix length */
704 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
709 memset(&addr
, 0, sizeof(addr
));
710 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
712 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
713 ((0xff00 >> (plen
% 8)) & 0xff);
715 /* the label may get offsetted by 4 bits so lets shift it right */
716 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
717 bgp_vpn_rd_print(pptr
+4),
718 getname6((u_char
*)&addr
),
720 EXTRACT_24BITS(pptr
+1)>>4,
721 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
723 return 12 + (plen
+ 7) / 8;
728 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
733 union { /* copy buffer for bandwidth values */
740 char buf
[MAXHOSTNAMELEN
+ 100];
745 switch (attr
->bgpa_type
) {
748 printf("invalid len");
750 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
752 case BGPTYPE_AS_PATH
:
754 printf("invalid len");
762 while (tptr
< pptr
+ len
) {
763 printf("%s", tok2str(bgp_as_path_segment_open_values
, "?", tptr
[0]));
764 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
765 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
767 printf("%s", tok2str(bgp_as_path_segment_close_values
, "?", tptr
[0]));
768 tptr
+= 2 + tptr
[1] * 2;
771 case BGPTYPE_NEXT_HOP
:
773 printf("invalid len");
775 printf("%s", getname(tptr
));
777 case BGPTYPE_MULTI_EXIT_DISC
:
778 case BGPTYPE_LOCAL_PREF
:
780 printf("invalid len");
782 printf("%u", EXTRACT_32BITS(tptr
));
784 case BGPTYPE_ATOMIC_AGGREGATE
:
786 printf("invalid len");
788 case BGPTYPE_AGGREGATOR
:
790 printf("invalid len");
793 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
796 case BGPTYPE_COMMUNITIES
:
798 printf("invalid len");
803 comm
= EXTRACT_32BITS(tptr
);
805 case BGP_COMMUNITY_NO_EXPORT
:
806 printf(" NO_EXPORT");
808 case BGP_COMMUNITY_NO_ADVERT
:
809 printf(" NO_ADVERTISE");
811 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
812 printf(" NO_EXPORT_SUBCONFED");
816 (comm
>> 16) & 0xffff,
818 (tlen
>4) ? ", " : "");
825 case BGPTYPE_ORIGINATOR_ID
:
827 printf("invalid len");
830 printf("%s",getname(tptr
));
832 case BGPTYPE_CLUSTER_LIST
:
836 (tlen
>4) ? ", " : "");
841 case BGPTYPE_MP_REACH_NLRI
:
842 af
= EXTRACT_16BITS(tptr
);
845 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
846 tok2str(bgp_afi_values
, "Unknown AFI", af
),
848 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
849 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
852 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
855 else if (af
== AFNUM_INET6
)
859 printf("\n\t no AFI %u decoder",af
);
861 print_unknown_data(tptr
,"\n\t ",tlen
);
871 printf("\n\t nexthop: ");
877 case SAFNUM_MULTICAST
:
878 case SAFNUM_UNIMULTICAST
:
879 case SAFNUM_LABUNICAST
:
880 case SAFNUM_RT_ROUTING_INFO
:
881 printf("%s",getname(tptr
));
882 tlen
-= sizeof(struct in_addr
);
883 tptr
+= sizeof(struct in_addr
);
885 case SAFNUM_VPNUNICAST
:
886 case SAFNUM_VPNMULTICAST
:
887 case SAFNUM_VPNUNIMULTICAST
:
889 bgp_vpn_rd_print(tptr
),
890 getname(tptr
+BGP_VPN_RD_LEN
));
891 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
892 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
895 printf("no SAFI %u decoder",safi
);
897 print_unknown_data(tptr
,"\n\t ",tlen
);
905 case SAFNUM_MULTICAST
:
906 case SAFNUM_UNIMULTICAST
:
907 case SAFNUM_LABUNICAST
:
908 case SAFNUM_RT_ROUTING_INFO
:
909 printf("%s", getname6(tptr
));
910 tlen
-= sizeof(struct in6_addr
);
911 tptr
+= sizeof(struct in6_addr
);
913 case SAFNUM_VPNUNICAST
:
914 case SAFNUM_VPNMULTICAST
:
915 case SAFNUM_VPNUNIMULTICAST
:
917 bgp_vpn_rd_print(tptr
),
918 getname6(tptr
+BGP_VPN_RD_LEN
));
919 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
920 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
923 printf("no SAFI %u decoder",safi
);
925 print_unknown_data(tptr
,"\n\t ",tlen
);
932 case SAFNUM_VPNUNICAST
:
933 case SAFNUM_VPNMULTICAST
:
934 case SAFNUM_VPNUNIMULTICAST
:
935 printf("%s", getname(tptr
));
936 tlen
-= (sizeof(struct in_addr
));
937 tptr
+= (sizeof(struct in_addr
));
940 printf("no SAFI %u decoder",safi
);
942 print_unknown_data(tptr
,"\n\t ",tlen
);
948 printf("no AFI %u decoder",af
);
950 print_unknown_data(tptr
,"\n\t ",tlen
);
961 printf("\n\t %u SNPA", snpa
);
962 for (/*nothing*/; snpa
> 0; snpa
--) {
963 printf("\n\t %d bytes", tptr
[0]);
970 while (len
- (tptr
- pptr
) > 0) {
975 case SAFNUM_MULTICAST
:
976 case SAFNUM_UNIMULTICAST
:
977 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
979 printf("\n\t %s", buf
);
981 printf("\n\t (illegal prefix length)");
983 case SAFNUM_LABUNICAST
:
984 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
985 printf("\n\t %s", buf
);
987 case SAFNUM_VPNUNICAST
:
988 case SAFNUM_VPNMULTICAST
:
989 case SAFNUM_VPNUNIMULTICAST
:
990 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
991 printf("\n\t %s", buf
);
993 case SAFNUM_RT_ROUTING_INFO
:
994 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
995 printf("\n\t %s", buf
);
998 printf("\n\t no SAFI %u decoder",safi
);
1000 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1009 case SAFNUM_UNICAST
:
1010 case SAFNUM_MULTICAST
:
1011 case SAFNUM_UNIMULTICAST
:
1012 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1013 printf("\n\t %s", buf
);
1015 case SAFNUM_LABUNICAST
:
1016 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1017 printf("\n\t %s", buf
);
1019 case SAFNUM_VPNUNICAST
:
1020 case SAFNUM_VPNMULTICAST
:
1021 case SAFNUM_VPNUNIMULTICAST
:
1022 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1023 printf("\n\t %s", buf
);
1025 case SAFNUM_RT_ROUTING_INFO
:
1026 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1027 printf("\n\t %s", buf
);
1030 printf("\n\t no SAFI %u decoder ",safi
);
1032 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1041 case SAFNUM_VPNUNICAST
:
1042 case SAFNUM_VPNMULTICAST
:
1043 case SAFNUM_VPNUNIMULTICAST
:
1044 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1045 printf("\n\t %s", buf
);
1048 printf("no SAFI %u decoder",safi
);
1050 print_unknown_data(tptr
,"\n\t ",tlen
);
1059 printf("\n\t no AFI %u decoder ",af
);
1061 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1070 case BGPTYPE_MP_UNREACH_NLRI
:
1071 af
= EXTRACT_16BITS(tptr
);
1074 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1075 tok2str(bgp_afi_values
, "Unknown AFI", af
),
1077 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1078 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1083 while (len
- (tptr
- pptr
) > 0) {
1087 case SAFNUM_UNICAST
:
1088 case SAFNUM_MULTICAST
:
1089 case SAFNUM_UNIMULTICAST
:
1090 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1092 printf("\n\t %s", buf
);
1094 printf("\n\t (illegal prefix length)");
1096 case SAFNUM_LABUNICAST
:
1097 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1098 printf("\n\t %s", buf
);
1100 case SAFNUM_VPNUNICAST
:
1101 case SAFNUM_VPNMULTICAST
:
1102 case SAFNUM_VPNUNIMULTICAST
:
1103 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1104 printf("\n\t %s", buf
);
1107 printf("\n\t no SAFI %u decoder",safi
);
1109 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1119 case SAFNUM_UNICAST
:
1120 case SAFNUM_MULTICAST
:
1121 case SAFNUM_UNIMULTICAST
:
1122 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1123 printf("\n\t %s", buf
);
1125 case SAFNUM_LABUNICAST
:
1126 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1127 printf("\n\t %s", buf
);
1129 case SAFNUM_VPNUNICAST
:
1130 case SAFNUM_VPNMULTICAST
:
1131 case SAFNUM_VPNUNIMULTICAST
:
1132 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1133 printf("\n\t %s", buf
);
1136 printf("\n\t no SAFI %u decoder",safi
);
1138 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1148 case SAFNUM_VPNUNICAST
:
1149 case SAFNUM_VPNMULTICAST
:
1150 case SAFNUM_VPNUNIMULTICAST
:
1151 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1152 printf("\n\t %s", buf
);
1155 printf("no SAFI %u decoder",safi
);
1157 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1165 printf("\n\t no AFI %u decoder",af
);
1167 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1176 case BGPTYPE_EXTD_COMMUNITIES
:
1178 printf("invalid len");
1182 u_int16_t extd_comm
;
1183 extd_comm
=EXTRACT_16BITS(tptr
);
1185 printf("\n\t %s (0x%04x), Flags [%s]",
1186 tok2str(bgp_extd_comm_subtype_values
, "unknown extd community typecode", extd_comm
),
1188 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1191 case BGP_EXT_COM_RT_0
:
1192 case BGP_EXT_COM_RO_0
:
1194 EXTRACT_16BITS(tptr
+2),
1197 case BGP_EXT_COM_RT_1
:
1198 case BGP_EXT_COM_RO_1
:
1201 EXTRACT_16BITS(tptr
+6));
1203 case BGP_EXT_COM_RT_2
:
1204 case BGP_EXT_COM_RO_2
:
1206 EXTRACT_32BITS(tptr
+2),
1207 EXTRACT_16BITS(tptr
+6));
1209 case BGP_EXT_COM_LINKBAND
:
1210 bw
.i
= EXTRACT_32BITS(tptr
+2);
1211 printf(": bandwidth: %.3f Mbps",
1214 case BGP_EXT_COM_VPN_ORIGIN
:
1215 case BGP_EXT_COM_VPN_ORIGIN2
:
1216 case BGP_EXT_COM_VPN_ORIGIN3
:
1217 case BGP_EXT_COM_VPN_ORIGIN4
:
1218 case BGP_EXT_COM_OSPF_RID
:
1219 case BGP_EXT_COM_OSPF_RID2
:
1220 printf("%s", getname(tptr
+2));
1222 case BGP_EXT_COM_OSPF_RTYPE
:
1223 case BGP_EXT_COM_OSPF_RTYPE2
:
1224 printf(": area:%s, router-type:%s, metric-type:%s%s",
1226 tok2str(bgp_extd_comm_ospf_rtype_values
,
1229 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1230 (*(tptr
+6) == (BGP_OSPF_RTYPE_EXT
||BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1232 case BGP_EXT_COM_L2INFO
:
1233 printf(": %s Control Flags [0x%02x]:MTU %u",
1234 tok2str(bgp_l2vpn_encaps_values
,
1238 EXTRACT_16BITS(tptr
+4));
1241 print_unknown_data(tptr
,"\n\t ",8);
1249 case BGPTYPE_ATTR_SET
:
1250 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1256 struct bgp_attr bgpa
;
1258 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1259 alen
= bgp_attr_len(&bgpa
);
1260 tptr
+= bgp_attr_off(&bgpa
);
1261 len
-= bgp_attr_off(&bgpa
);
1263 printf("\n\t %s (%u), length: %u",
1264 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1268 if (bgpa
.bgpa_flags
) {
1269 printf(", Flags [%s%s%s%s",
1270 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1271 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1272 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1273 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1274 if (bgpa
.bgpa_flags
& 0xf)
1275 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1278 bgp_attr_print(&bgpa
, tptr
, alen
); /* FIXME check for recursion */
1286 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1288 print_unknown_data(pptr
,"\n\t ",len
);
1291 if (vflag
> 1 && len
) /* omit zero length attributes*/
1292 print_unknown_data(pptr
,"\n\t ",len
);
1296 bgp_open_print(const u_char
*dat
, int length
)
1298 struct bgp_open bgpo
;
1299 struct bgp_opt bgpopt
;
1302 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1304 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1305 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1306 hlen
= ntohs(bgpo
.bgpo_len
);
1308 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1309 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1310 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1311 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1312 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1314 /* some little sanity checking */
1315 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1319 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1323 while (i
< bgpo
.bgpo_optlen
) {
1324 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1325 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1326 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1327 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1331 printf("\n\t Option %s (%u), length: %u",
1332 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1336 /* now lets decode the options we know*/
1337 switch(bgpopt
.bgpopt_type
) {
1339 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1340 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1342 printf("\n\t %s, length: %u",
1343 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1346 case BGP_CAPCODE_MP
:
1347 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1348 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1349 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1350 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1351 opt
[i
+BGP_OPT_SIZE
+5]);
1353 case BGP_CAPCODE_RESTART
:
1354 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1355 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1356 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1359 while(tcap_len
>=4) {
1360 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1361 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
)),
1362 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1363 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+cap_offset
+2]),
1364 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1365 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1370 case BGP_CAPCODE_RR
:
1371 case BGP_CAPCODE_RR_CISCO
:
1374 printf("\n\t\tno decoder for Capability %u",
1377 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1381 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1385 printf("\n\t no decoder for option %u",
1386 bgpopt
.bgpopt_type
);
1390 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1398 bgp_update_print(const u_char
*dat
, int length
)
1401 struct bgp_attr bgpa
;
1407 TCHECK2(dat
[0], BGP_SIZE
);
1408 memcpy(&bgp
, dat
, BGP_SIZE
);
1409 hlen
= ntohs(bgp
.bgp_len
);
1410 p
= dat
+ BGP_SIZE
; /*XXX*/
1412 /* Unfeasible routes */
1413 len
= EXTRACT_16BITS(p
);
1416 * Without keeping state from the original NLRI message,
1417 * it's not possible to tell if this a v4 or v6 route,
1418 * so only try to decode it if we're not v6 enabled.
1421 printf("\n\t Withdrawn routes: %d bytes", len
);
1423 char buf
[MAXHOSTNAMELEN
+ 100];
1429 printf("\n\t Withdrawn routes:");
1431 while(i
< 2 + len
) {
1432 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1435 printf("\n\t %s", buf
);
1437 printf("\n\t (illegal prefix length)");
1446 len
= EXTRACT_16BITS(p
);
1448 /* do something more useful!*/
1450 while (i
< 2 + len
) {
1453 TCHECK2(p
[i
], sizeof(bgpa
));
1454 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1455 alen
= bgp_attr_len(&bgpa
);
1456 aoff
= bgp_attr_off(&bgpa
);
1458 printf("\n\t %s (%u), length: %u",
1459 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1463 if (bgpa
.bgpa_flags
) {
1464 printf(", Flags [%s%s%s%s",
1465 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1466 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1467 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1468 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1469 if (bgpa
.bgpa_flags
& 0xf)
1470 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1473 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1479 if (dat
+ length
> p
) {
1480 printf("\n\t Updated routes:");
1481 while (dat
+ length
> p
) {
1482 char buf
[MAXHOSTNAMELEN
+ 100];
1483 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1485 printf("\n\t %s", buf
);
1488 printf("\n\t (illegal prefix length)");
1499 bgp_notification_print(const u_char
*dat
, int length
)
1501 struct bgp_notification bgpn
;
1505 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1506 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1507 hlen
= ntohs(bgpn
.bgpn_len
);
1509 /* some little sanity checking */
1510 if (length
<BGP_NOTIFICATION_SIZE
)
1514 tok2str(bgp_notify_major_values
, "Unknown Error", bgpn
.bgpn_major
),
1517 switch (bgpn
.bgpn_major
) {
1519 case BGP_NOTIFY_MAJOR_MSG
:
1520 printf(", subcode %s (%u)",
1521 tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
),
1524 case BGP_NOTIFY_MAJOR_OPEN
:
1525 printf(", subcode %s (%u)",
1526 tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
),
1529 case BGP_NOTIFY_MAJOR_UPDATE
:
1530 printf(", subcode %s (%u)",
1531 tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
),
1534 case BGP_NOTIFY_MAJOR_CAP
:
1535 printf(" subcode %s (%u)",
1536 tok2str(bgp_notify_minor_cap_values
, "Unknown", bgpn
.bgpn_minor
),
1538 case BGP_NOTIFY_MAJOR_CEASE
:
1539 printf(", subcode %s (%u)",
1540 tok2str(bgp_notify_minor_cease_values
, "Unknown", bgpn
.bgpn_minor
),
1543 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1544 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1546 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
1547 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
1549 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1550 tok2str(bgp_afi_values
, "Unknown", EXTRACT_16BITS(tptr
)),
1551 EXTRACT_16BITS(tptr
),
1552 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
1554 EXTRACT_32BITS(tptr
+3));
1567 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1569 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1570 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1572 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1573 tok2str(bgp_afi_values
,"Unknown",
1574 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1575 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1576 tok2str(bgp_safi_values
,"Unknown",
1577 bgp_route_refresh_header
->safi
),
1578 bgp_route_refresh_header
->safi
);
1581 print_unknown_data(pptr
,"\n\t ", len
);
1587 bgp_header_print(const u_char
*dat
, int length
)
1591 TCHECK2(dat
[0], BGP_SIZE
);
1592 memcpy(&bgp
, dat
, BGP_SIZE
);
1593 printf("\n\t%s Message (%u), length: %u",
1594 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1598 switch (bgp
.bgp_type
) {
1600 bgp_open_print(dat
, length
);
1603 bgp_update_print(dat
, length
);
1605 case BGP_NOTIFICATION
:
1606 bgp_notification_print(dat
, length
);
1610 case BGP_ROUTE_REFRESH
:
1611 bgp_route_refresh_print(dat
, length
);
1614 /* we have no decoder for the BGP message */
1615 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1616 print_unknown_data(dat
,"\n\t ",length
);
1625 bgp_print(const u_char
*dat
, int length
)
1629 const u_char
*start
;
1630 const u_char marker
[] = {
1631 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1632 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1638 if (snapend
< dat
+ length
)
1641 printf(": BGP, length: %u",length
);
1643 if (vflag
< 1) /* lets be less chatty */
1648 while (p
< snapend
) {
1649 if (!TTEST2(p
[0], 1))
1656 if (!TTEST2(p
[0], sizeof(marker
)))
1658 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1663 /* found BGP header */
1664 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1665 memcpy(&bgp
, p
, BGP_SIZE
);
1670 hlen
= ntohs(bgp
.bgp_len
);
1671 if (hlen
< BGP_SIZE
) {
1672 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
1677 if (TTEST2(p
[0], hlen
)) {
1678 bgp_header_print(p
, hlen
);
1682 printf("\n[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));